]> de.git.xonotic.org Git - voretournament/voretournament.git/blob - misc/source/fteqcc-src/pr_comp.h
3559086383ba057f2acfaae14c608b7072b4accf
[voretournament/voretournament.git] / misc / source / fteqcc-src / pr_comp.h
1 // this file is shared by the execution and compiler
2
3 /*i'm part way through making this work
4 I've given up now that I can't work out a way to load pointers.
5 Setting them should be fine.
6 */
7 #ifndef __PR_COMP_H__
8 #define __PR_COMP_H__
9
10
11 /*this distinction is made as the execution uses c pointers while compiler uses pointers from the start of the string table of the current progs*/
12 #ifdef COMPILER
13 typedef int QCC_string_t;
14 #else
15 //typedef char *string_t;
16 #endif
17
18 //typedef enum {ev_void, ev_string, ev_float, ev_vector, ev_entity, ev_field, ev_function, ev_pointer, ev_integer, ev_struct, ev_union} etype_t;
19 //                              0                       1               2                       3                       4               5                       6                               7                       8               9                       10
20
21 #define OFS_NULL                0
22 #define OFS_RETURN              1
23 #define OFS_PARM0               4               // leave 3 ofs for each parm to hold vectors
24 #define OFS_PARM1               7
25 #define OFS_PARM2               10
26 #define OFS_PARM3               13
27 #define OFS_PARM4               16
28 #define OFS_PARM5               19
29 #define OFS_PARM6               22
30 #define OFS_PARM7               25
31 #define RESERVED_OFS    28
32
33
34 enum qcop_e {
35         OP_DONE,        //0
36         OP_MUL_F,
37         OP_MUL_V,
38         OP_MUL_FV,
39         OP_MUL_VF,
40         OP_DIV_F,
41         OP_ADD_F,
42         OP_ADD_V,
43         OP_SUB_F,
44         OP_SUB_V,
45         
46         OP_EQ_F,        //10
47         OP_EQ_V,
48         OP_EQ_S,
49         OP_EQ_E,
50         OP_EQ_FNC,
51         
52         OP_NE_F,
53         OP_NE_V,
54         OP_NE_S,
55         OP_NE_E,
56         OP_NE_FNC,
57         
58         OP_LE_F,        //20
59         OP_GE_F,
60         OP_LT_F,
61         OP_GT_F,
62
63         OP_LOAD_F,
64         OP_LOAD_V,
65         OP_LOAD_S,
66         OP_LOAD_ENT,
67         OP_LOAD_FLD,
68         OP_LOAD_FNC,
69
70         OP_ADDRESS,     //30
71
72         OP_STORE_F,
73         OP_STORE_V,
74         OP_STORE_S,
75         OP_STORE_ENT,
76         OP_STORE_FLD,
77         OP_STORE_FNC,
78
79         OP_STOREP_F,
80         OP_STOREP_V,
81         OP_STOREP_S,
82         OP_STOREP_ENT,  //40
83         OP_STOREP_FLD,
84         OP_STOREP_FNC,
85
86         OP_RETURN,
87         OP_NOT_F,
88         OP_NOT_V,
89         OP_NOT_S,
90         OP_NOT_ENT,
91         OP_NOT_FNC,
92         OP_IF_I,
93         OP_IFNOT_I,             //50
94         OP_CALL0,               //careful... hexen2 and q1 have different calling conventions
95         OP_CALL1,               //remap hexen2 calls to OP_CALL2H
96         OP_CALL2,
97         OP_CALL3,
98         OP_CALL4,
99         OP_CALL5,
100         OP_CALL6,
101         OP_CALL7,
102         OP_CALL8,
103         OP_STATE,               //60
104         OP_GOTO,
105         OP_AND_F,
106         OP_OR_F,
107         
108         OP_BITAND_F,
109         OP_BITOR_F,
110
111         
112         //these following ones are Hexen 2 constants.
113         
114         OP_MULSTORE_F,
115         OP_MULSTORE_VF,
116         OP_MULSTOREP_F,
117         OP_MULSTOREP_VF,
118
119         OP_DIVSTORE_F,  //70
120         OP_DIVSTOREP_F,
121
122         OP_ADDSTORE_F,
123         OP_ADDSTORE_V,
124         OP_ADDSTOREP_F,
125         OP_ADDSTOREP_V,
126
127         OP_SUBSTORE_F,
128         OP_SUBSTORE_V,
129         OP_SUBSTOREP_F,
130         OP_SUBSTOREP_V,
131
132         OP_FETCH_GBL_F, //80
133         OP_FETCH_GBL_V,
134         OP_FETCH_GBL_S,
135         OP_FETCH_GBL_E,
136         OP_FETCH_GBL_FNC,
137
138         OP_CSTATE,
139         OP_CWSTATE,
140
141         OP_THINKTIME,
142
143         OP_BITSET,
144         OP_BITSETP,
145         OP_BITCLR,              //90
146         OP_BITCLRP,
147
148         OP_RAND0,
149         OP_RAND1,
150         OP_RAND2,
151         OP_RANDV0,
152         OP_RANDV1,
153         OP_RANDV2,
154
155         OP_SWITCH_F,
156         OP_SWITCH_V,
157         OP_SWITCH_S,    //100
158         OP_SWITCH_E,
159         OP_SWITCH_FNC,
160
161         OP_CASE,
162         OP_CASERANGE,
163
164
165
166
167
168         //the rest are added
169         //mostly they are various different ways of adding two vars with conversions.
170
171         OP_CALL1H,
172         OP_CALL2H,
173         OP_CALL3H,
174         OP_CALL4H,
175         OP_CALL5H,
176         OP_CALL6H,              //110
177         OP_CALL7H,
178         OP_CALL8H,
179
180
181         OP_STORE_I,
182         OP_STORE_IF,
183         OP_STORE_FI,
184         
185         OP_ADD_I,
186         OP_ADD_FI,
187         OP_ADD_IF,
188   
189         OP_SUB_I,
190         OP_SUB_FI,              //120
191         OP_SUB_IF,
192
193         OP_CONV_ITOF,
194         OP_CONV_FTOI,
195         OP_CP_ITOF,
196         OP_CP_FTOI,
197         OP_LOAD_I,
198         OP_STOREP_I,
199         OP_STOREP_IF,
200         OP_STOREP_FI,
201
202         OP_BITAND_I,    //130
203         OP_BITOR_I,
204
205         OP_MUL_I,
206         OP_DIV_I,
207         OP_EQ_I,
208         OP_NE_I,
209
210         OP_IFNOT_S,
211         OP_IF_S,
212
213         OP_NOT_I,
214
215         OP_DIV_VF,
216
217         OP_XOR_I,               //140
218         OP_RSHIFT_I,
219         OP_LSHIFT_I,
220
221         OP_GLOBALADDRESS,
222         OP_POINTER_ADD, //32 bit pointers
223
224         OP_LOADA_F,
225         OP_LOADA_V,     
226         OP_LOADA_S,
227         OP_LOADA_ENT,
228         OP_LOADA_FLD,
229         OP_LOADA_FNC,   //150
230         OP_LOADA_I,
231
232         OP_STORE_P,     //152... erm.. wait...
233         OP_LOAD_P,
234
235         OP_LOADP_F,
236         OP_LOADP_V,     
237         OP_LOADP_S,
238         OP_LOADP_ENT,
239         OP_LOADP_FLD,
240         OP_LOADP_FNC,
241         OP_LOADP_I,             //160
242
243         OP_LE_I,
244         OP_GE_I,
245         OP_LT_I,
246         OP_GT_I,
247
248         OP_LE_IF,
249         OP_GE_IF,
250         OP_LT_IF,
251         OP_GT_IF,
252
253         OP_LE_FI,
254         OP_GE_FI,               //170
255         OP_LT_FI,
256         OP_GT_FI,
257
258         OP_EQ_IF,
259         OP_EQ_FI,
260
261         //-------------------------------------
262         //string manipulation.
263         OP_ADD_SF,      //(char*)c = (char*)a + (float)b    add_fi->i
264         OP_SUB_S,       //(float)c = (char*)a - (char*)b    sub_ii->f
265         OP_STOREP_C,//(float)c = *(char*)b = (float)a
266         OP_LOADP_C,     //(float)c = *(char*)
267         //-------------------------------------
268
269
270         OP_MUL_IF,
271         OP_MUL_FI,              //180
272         OP_MUL_VI,
273         OP_MUL_IV,
274         OP_DIV_IF,
275         OP_DIV_FI,
276         OP_BITAND_IF,
277         OP_BITOR_IF,
278         OP_BITAND_FI,
279         OP_BITOR_FI,
280         OP_AND_I,
281         OP_OR_I,                //190
282         OP_AND_IF,
283         OP_OR_IF,
284         OP_AND_FI,
285         OP_OR_FI,
286         OP_NE_IF,
287         OP_NE_FI,
288
289 //erm... FTEQCC doesn't make use of these... These are for DP.
290         OP_GSTOREP_I,
291         OP_GSTOREP_F,
292         OP_GSTOREP_ENT,
293         OP_GSTOREP_FLD,         // integers   //200
294         OP_GSTOREP_S,
295         OP_GSTOREP_FNC,         // pointers
296         OP_GSTOREP_V,
297         OP_GADDRESS,
298         OP_GLOAD_I,
299         OP_GLOAD_F,
300         OP_GLOAD_FLD,
301         OP_GLOAD_ENT,
302         OP_GLOAD_S,
303         OP_GLOAD_FNC,           //210
304         OP_BOUNDCHECK,
305
306 //back to ones that we do use.
307         OP_UNUSED,      //used to be OP_STOREP_P, which is now emulated with OP_STOREP_I, fteqcc nor fte generated it
308         OP_PUSH,        //push 4octets onto the local-stack (which is ALWAYS poped on function return). Returns a pointer.
309         OP_POP,         //pop those ones that were pushed (don't over do it). Needs assembler.
310
311         OP_SWITCH_I,//hmm.
312         OP_GLOAD_V,
313
314         OP_IF_F,
315         OP_IFNOT_F,
316
317         OP_NUMREALOPS,
318
319         /*
320         These ops are emulated out, always, and are only present in the compiler.
321         */
322
323         OP_BITSET_I,    //220
324         OP_BITSETP_I,
325
326         OP_MULSTORE_I,
327         OP_DIVSTORE_I,
328         OP_ADDSTORE_I,
329         OP_SUBSTORE_I,
330         OP_MULSTOREP_I,
331         OP_DIVSTOREP_I,
332         OP_ADDSTOREP_I,
333         OP_SUBSTOREP_I,
334
335         OP_MULSTORE_IF, //230
336         OP_MULSTOREP_IF,
337         OP_DIVSTORE_IF,
338         OP_DIVSTOREP_IF,
339         OP_ADDSTORE_IF,
340         OP_ADDSTOREP_IF,
341         OP_SUBSTORE_IF,
342         OP_SUBSTOREP_IF,
343
344         OP_MULSTORE_FI,
345         OP_MULSTOREP_FI,
346         OP_DIVSTORE_FI,         //240
347         OP_DIVSTOREP_FI,
348         OP_ADDSTORE_FI,
349         OP_ADDSTOREP_FI,
350         OP_SUBSTORE_FI,
351         OP_SUBSTOREP_FI,
352
353         OP_MULSTORE_VI,
354         OP_MULSTOREP_VI,
355
356         OP_LOADA_STRUCT,
357         OP_STOREP_P,
358
359         OP_NUMOPS
360 };
361
362 #define MAX_PARMS       8
363
364 // qtest structs (used for reordering and not execution)
365 typedef struct qtest_statement_s
366 {
367         unsigned int    line; // line number in source code file
368         unsigned short  op;
369         unsigned short  a,b,c;
370 } qtest_statement_t;
371
372 typedef struct qtest_def_s
373 {
374         unsigned int    type; // no DEFGLOBAL found in qtest progs
375         unsigned int    s_name; // different order!
376         unsigned int    ofs;
377 } qtest_def_t;
378
379 typedef struct qtest_function_s
380 {
381         int             first_statement;
382         int             unused1;
383         int             locals; // assumed! (always 0 in real qtest progs)
384         int             profile; // assumed! (always 0 in real qtest progs)
385         
386         int             s_name;
387         int             s_file;
388         
389         int             numparms;
390         int             parm_start; // different order
391         int             parm_size[MAX_PARMS]; // ints instead of bytes...
392 } qtest_function_t;
393
394 #ifndef COMPILER
395 typedef struct statement16_s
396 {
397         unsigned short  op;
398         unsigned short  a,b,c;
399 } dstatement16_t;
400 typedef struct statement32_s
401 {
402         unsigned int    op;
403         unsigned int    a,b,c;
404 } dstatement32_t;
405 #else
406 typedef struct QCC_statement16_s
407 {
408         unsigned short  op;
409         unsigned short  a,b,c;
410 } QCC_dstatement16_t;
411 typedef struct QCC_statement32_s
412 {
413         unsigned int    op;
414         unsigned int    a,b,c;
415 } QCC_dstatement32_t;
416 #define QCC_dstatement_t QCC_dstatement32_t
417 #endif
418
419 //these should be the same except the string type
420 #ifndef COMPILER
421 typedef struct ddef16_s
422 {
423         unsigned short  type;           // if DEF_SAVEGLOBAL bit is set
424                                                                 // the variable needs to be saved in savegames
425         unsigned short  ofs;
426         string_t                s_name;
427 } ddef16_t;
428
429 typedef struct ddef32_s
430 {
431         unsigned int    type;           // if DEF_SAVEGLOBAL bit is set
432                                                                 // the variable needs to be saved in savegames
433         unsigned int    ofs;
434         string_t                s_name;
435 } ddef32_t;
436
437 typedef struct fdef_s
438 {
439         unsigned int    type;           // if DEF_SAVEGLOBAL bit is set
440                                                                 // the variable needs to be saved in savegames
441         unsigned int    ofs;
442         unsigned int    progsofs;       //used at loading time, so maching field offsets (unions/members) are positioned at the same runtime offset.
443         char *          name;
444 } fdef_t;
445
446 typedef void *ddefXX_t;
447 #else
448 typedef struct QCC_ddef16_s
449 {
450         unsigned short  type;           // if DEF_SAVEGLOBAL bit is set
451                                                                 // the variable needs to be saved in savegames
452         unsigned short  ofs;
453         QCC_string_t            s_name;
454 } QCC_ddef16_t;
455
456 typedef struct QCC_ddef32_s
457 {
458         unsigned int    type;           // if DEF_SAVEGLOBAL bit is set
459                                                                 // the variable needs to be saved in savegames
460         unsigned int    ofs;
461         QCC_string_t            s_name;
462 } QCC_ddef32_t;
463
464 #define QCC_ddef_t QCC_ddef32_t
465 #endif
466
467 #define DEF_SAVEGLOBAL          (1<<15)
468 #define DEF_SHARED              (1<<14)
469
470 #ifndef COMPILER
471 typedef struct
472 {
473         int             first_statement;        // negative numbers are builtins
474         int             parm_start;
475         int             locals;                         // total ints of parms + locals
476         
477         int             profile;                // runtime
478         
479         string_t        s_name;
480         string_t        s_file;                 // source file defined in
481         
482         int             numparms;
483         qbyte   parm_size[MAX_PARMS];
484 } dfunction_t;
485 #else
486 typedef struct
487 {
488         unsigned int            first_statement;        // negative numbers are builtins
489         unsigned int            parm_start;
490         int             locals;                         // total ints of parms + locals
491         
492         int             profile;                // runtime
493         
494         QCC_string_t    s_name;
495         QCC_string_t    s_file;                 // source file defined in
496         
497         int             numparms;
498         qbyte   parm_size[MAX_PARMS];
499 } QCC_dfunction_t;
500 #endif
501
502 #define PROG_QTESTVERSION       3
503 #define PROG_VERSION    6
504 #define PROG_KKQWSVVERSION 7
505 #define PROG_EXTENDEDVERSION    7
506 #define PROG_SECONDARYVERSION16 (*(int*)"1FTE" ^ *(int*)"PROG") //something unlikly and still meaningful (to me)
507 #define PROG_SECONDARYVERSION32 (*(int*)"1FTE" ^ *(int*)"32B ") //something unlikly and still meaningful (to me)
508 typedef struct
509 {
510         int             version;
511         int             crc;                    // check of header file
512         
513         unsigned int            ofs_statements; //comp 1
514         unsigned int            numstatements;  // statement 0 is an error
515
516         unsigned int            ofs_globaldefs; //comp 2
517         unsigned int            numglobaldefs;
518         
519         unsigned int            ofs_fielddefs;  //comp 4
520         unsigned int            numfielddefs;
521         
522         unsigned int            ofs_functions;  //comp 8
523         unsigned int            numfunctions;   // function 0 is an empty
524         
525         unsigned int            ofs_strings;    //comp 16
526         unsigned int            numstrings;             // first string is a null string
527
528         unsigned int            ofs_globals;    //comp 32
529         unsigned int            numglobals;
530         
531         unsigned int            entityfields;
532
533         //debug / version 7 extensions
534         unsigned int            ofsfiles;       //non list format. no comp
535         unsigned int            ofslinenums;    //numstatements big     //comp 64
536         unsigned int            ofsbodylessfuncs;       //no comp
537         unsigned int            numbodylessfuncs;
538
539         unsigned int    ofs_types;      //comp 128
540         unsigned int    numtypes;
541         unsigned int    blockscompressed;
542
543         int     secondaryversion;       //Constant - to say that any version 7 progs are actually ours, not someone else's alterations.
544 } dprograms_t;
545 #define standard_dprograms_t_size ((size_t)&((dprograms_t*)NULL)->ofsfiles)
546
547 #endif
548
549
550
551
552
553 typedef struct {
554         char filename[128];
555         int size;
556         int compsize;
557         int compmethod;
558         int ofs;
559 } includeddatafile_t;
560
561
562
563
564 typedef struct typeinfo_s
565 {
566         etype_t type;
567
568         int             next;
569         int             aux_type;
570         int             num_parms;
571
572         int             ofs;    //inside a structure.
573         int             size;
574         string_t        name;
575 } typeinfo_t;