5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is furnished to do
10 * so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 int16_t s1; /* signed */
33 uint16_t u1; /* unsigned */
37 int16_t s2; /* signed */
38 uint16_t u2; /* unsigned */
42 int16_t s3; /* signed */
43 uint16_t u3; /* unsigned */
47 * This is the same as the structure in darkplaces
52 * But this one is more sane to work with, and the
53 * type sizes are guranteed.
55 } prog_section_statement;
58 /* The type is (I assume)
67 * 8 = ev_bad (is this right for uint16_t type?)
70 uint16_t offset; /* offset in file? (what about length) */
71 uint32_t name; /* offset in string table? (confused :() */
75 * var and field use the same structure. But lets not use the same
76 * name just for safety reasons? (still castable ...).
78 typedef prog_section_both prog_section_var;
79 typedef prog_section_both prog_section_field;
82 int32_t entry; /* in statement table for instructions */
83 uint32_t args; /* What is this? */
84 uint32_t locals; /* Total ints of params + locals */
85 uint32_t profile; /* What is this? */
86 uint32_t name; /* name of function in string table */
87 uint32_t nargs; /* number of arguments */
88 uint8_t argsize[8]; /* size of arguments (keep 8 always?) */
89 } prog_section_function;
92 uint32_t offset; /* Offset in file of where data begins */
93 uint32_t length; /* Length of section (how many of) */
97 uint32_t version; /* Program version (6) */
98 uint32_t crc16; /* What is this? */
99 prog_section statements; /* prog_section_statement */
100 prog_section vars; /* prog_section_var */
101 prog_section fields; /* prog_section_field */
102 prog_section functions; /* prog_section_function */
103 prog_section strings; /* What is this? */
104 prog_section globals; /* What is this? */
105 uint32_t entfield; /* Number of entity fields */
109 * The macros below expand to a typesafe vector implementation, which
110 * can be viewed in gmqcc.h
112 * code_statements_data -- raw prog_section_statement array
113 * code_statements_elements -- number of elements
114 * code_statements_allocated -- size of the array allocated
115 * code_statements_add(T) -- add element (returns -1 on error)
117 * code_vars_data -- raw prog_section_var array
118 * code_vars_elements -- number of elements
119 * code_vars_allocated -- size of the array allocated
120 * code_vars_add(T) -- add element (returns -1 on error)
122 * code_fields_data -- raw prog_section_field array
123 * code_fields_elements -- number of elements
124 * code_fields_allocated -- size of the array allocated
125 * code_fields_add(T) -- add element (returns -1 on error)
127 * code_functions_data -- raw prog_section_function array
128 * code_functions_elements -- number of elements
129 * code_functions_allocated -- size of the array allocated
130 * code_functions_add(T) -- add element (returns -1 on error)
132 * code_globals_data -- raw prog_section_var array
133 * code_globals_elements -- number of elements
134 * code_globals_allocated -- size of the array allocated
135 * code_globals_add(T) -- add element (returns -1 on error)
137 * code_strings_data -- raw char* array
138 * code_strings_elements -- number of elements
139 * code_strings_allocated -- size of the array allocated
140 * code_strings_add(T) -- add element (returns -1 on error)
142 VECTOR_MAKE(prog_section_statement, code_statements);
143 VECTOR_MAKE(prog_section_var, code_vars );
144 VECTOR_MAKE(prog_section_field, code_fields );
145 VECTOR_MAKE(prog_section_function, code_functions );
146 VECTOR_MAKE(prog_section_var, code_globals );
147 VECTOR_MAKE(char*, code_strings );
150 prog_header code_header;
152 code_header.version = 6;
153 code_header.crc16 = 0; /* TODO: */
154 code_header.statements = (prog_section){sizeof(prog_header), code_statements_elements };
155 code_header.vars = (prog_section){sizeof(prog_header)+sizeof(prog_section_statement)*code_statements_elements, code_vars_elements };
156 code_header.fields = (prog_section){sizeof(prog_header)+sizeof(prog_section_var) *code_vars_elements, code_fields_elements };
157 code_header.functions = (prog_section){sizeof(prog_header)+sizeof(prog_section_field) *code_fields_elements, code_functions_elements };
158 code_header.globals = (prog_section){sizeof(prog_header)+sizeof(prog_section_function) *code_functions_elements, code_globals_elements };
159 /* how, I think I don't have strings figured out yet :| */
160 code_header.entfield = 0; /* TODO: */
162 #if 0 /* is this right? */
163 fwrite(&code_header, 1, sizeof(prog_header), fp);
164 fwrite(code_statements_data, 1, sizeof(prog_section_statement)*code_statements_elements, fp);
165 fwrite(code_vars_data, 1, sizeof(prog_section_var) *code_vars_elements, fp);
166 fwrite(code_fields_data, 1, sizeof(prog_section_field) *code_fields_elements, fp);
167 fwrite(code_functions_data, 1, sizeof(prog_section_function) *code_functions_elements, fp);
168 fwrite(code_globals_data, 1, sizeof(prog_section_var) *code_globals_elements, fp);
171 free(code_statements_data);
172 free(code_vars_data);
173 free(code_fields_data);
174 free(code_functions_data);
175 free(code_globals_data);
176 free(code_strings_data);