-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqcc_pr_comp.c
9730 lines (8617 loc) · 273 KB
/
qcc_pr_comp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef MINIMAL
#include "qcc.h"
void QCC_PR_ParseAsm(void);
#define MEMBERFIELDNAME "__m%s"
#define STRCMP(s1,s2) (((*s1)!=(*s2)) || strcmp(s1+1,s2+1)) //saves about 2-6 out of 120 - expansion of idea from fastqcc
#define STRNCMP(s1,s2,l) (((*s1)!=(*s2)) || strncmp(s1+1,s2+1,l)) //pathetic saving here.
extern char *compilingfile;
int conditional;
//standard qcc keywords
#define keyword_do 1
#define keyword_return 1
#define keyword_if 1
#define keyword_else 1
#define keyword_local 1
#define keyword_while 1
//extended keywords.
pbool keyword_asm;
pbool keyword_break;
pbool keyword_case;
pbool keyword_class;
pbool keyword_const; //fixme
pbool keyword_continue;
pbool keyword_default;
pbool keyword_entity; //for skipping the local
pbool keyword_float; //for skipping the local
pbool keyword_for;
pbool keyword_goto;
pbool keyword_int; //for skipping the local
pbool keyword_integer; //for skipping the local
pbool keyword_state;
pbool keyword_string; //for skipping the local
pbool keyword_struct;
pbool keyword_switch;
pbool keyword_thinktime;
pbool keyword_var; //allow it to be initialised and set around the place.
pbool keyword_vector; //for skipping the local
pbool keyword_enum; //kinda like in c, but typedef not supported.
pbool keyword_enumflags; //like enum, but doubles instead of adds 1.
pbool keyword_typedef; //fixme
#define keyword_codesys flag_acc //reacc needs this (forces the resultant crc)
#define keyword_function flag_acc //reacc needs this (reacc has this on all functions, wierd eh?)
#define keyword_objdata flag_acc //reacc needs this (following defs are fields rather than globals, use var to disable)
#define keyword_object flag_acc //reacc needs this (an entity)
#define keyword_pfunc flag_acc //reacc needs this (pointer to function)
#define keyword_system flag_acc //reacc needs this (potatos)
#define keyword_real flag_acc //reacc needs this (a float)
#define keyword_exit flag_acc //emits an OP_DONE opcode.
#define keyword_external flag_acc //reacc needs this (a builtin)
pbool keyword_extern; //function is external, don't error or warn if the body was not found
pbool keyword_shared; //mark global to be copied over when progs changes (part of FTE_MULTIPROGS)
pbool keyword_noref; //nowhere else references this, don't strip it.
pbool keyword_nosave; //don't write the def to the output.
pbool keyword_union; //you surly know what a union is!
#define keyword_not 1 //hexenc support needs this, and fteqcc can optimise without it, but it adds an extra token after the if, so it can cause no namespace conflicts
pbool keywords_coexist; //don't disable a keyword simply because a var was made with the same name.
pbool output_parms; //emit some PARMX fields. confuses decompilers.
pbool autoprototype; //take two passes over the source code. First time round doesn't enter and functions or initialise variables.
pbool pr_subscopedlocals; //causes locals to be valid ONLY within their statement block. (they simply can't be referenced by name outside of it)
pbool flag_ifstring; //makes if (blah) equivelent to if (blah != "") which resolves some issues in multiprogs situations.
pbool flag_iffloat; //use an op_if_f instruction instead of op_if so if(-0) evaluates to false.
pbool flag_acc; //reacc like behaviour of src files (finds *.qc in start dir and compiles all in alphabetical order)
pbool flag_caseinsensative; //symbols will be matched to an insensative case if the specified case doesn't exist. This should b usable for any mod
pbool flag_laxcasts; //Allow lax casting. This'll produce loadsa warnings of course. But allows compilation of certain dodgy code.
pbool flag_hashonly; //Allows use of only #constant for precompiler constants, allows certain preqcc using mods to compile
pbool flag_fasttrackarrays; //Faster arrays, dynamically detected, activated only in supporting engines.
pbool flag_msvcstyle; //MSVC style warnings, so msvc's ide works properly
pbool flag_assume_integer; //5 - is that an integer or a float? qcc says float. but we support int too, so maybe we want that instead?
pbool opt_overlaptemps; //reduce numpr_globals by reuse of temps. When they are not needed they are freed for reuse. The way this is implemented is better than frikqcc's. (This is the single most important optimisation)
pbool opt_assignments; //STORE_F isn't used if an operation wrote to a temp.
pbool opt_shortenifnots; //if(!var) is made an IF rather than NOT IFNOT
pbool opt_noduplicatestrings; //brute force string check. time consuming but more effective than the equivelent in frikqcc.
pbool opt_constantarithmatic; //3*5 appears as 15 instead of the extra statement.
pbool opt_nonvec_parms; //store_f instead of store_v on function calls, where possible.
pbool opt_constant_names; //take out the defs and name strings of constants.
pbool opt_constant_names_strings;//removes the defs of strings too. plays havok with multiprogs.
pbool opt_precache_file; //remove the call, the parameters, everything.
pbool opt_filenames; //strip filenames. hinders older decompilers.
pbool opt_unreferenced; //strip defs that are not referenced.
pbool opt_function_names; //strip out the names of builtin functions.
pbool opt_locals; //strip out the names of locals and immediates.
pbool opt_dupconstdefs; //float X = 5; and float Y = 5; occupy the same global with this.
pbool opt_return_only; //RETURN; DONE; at the end of a function strips out the done statement if there is no way to get to it.
pbool opt_compound_jumps; //jumps to jump statements jump to the final point.
pbool opt_stripfunctions; //if a functions is only ever called directly or by exe, don't emit the def.
pbool opt_locals_marshalling; //make the local vars of all functions occupy the same globals.
pbool opt_logicops; //don't make conditions enter functions if the return value will be discarded due to a previous value. (C style if statements)
pbool opt_vectorcalls; //vectors can be packed into 3 floats, which can yield lower numpr_globals, but cost two more statements per call (only works for q1 calling conventions).
pbool opt_simplifiedifs; //if (f != 0) -> if (f). if (f == 0) -> ifnot (f)
//bool opt_comexprremoval;
//these are the results of the opt_. The values are printed out when compilation is compleate, showing effectivness.
int optres_shortenifnots;
int optres_assignments;
int optres_overlaptemps;
int optres_noduplicatestrings;
int optres_constantarithmatic;
int optres_nonvec_parms;
int optres_constant_names;
int optres_constant_names_strings;
int optres_precache_file;
int optres_filenames;
int optres_unreferenced;
int optres_function_names;
int optres_locals;
int optres_dupconstdefs;
int optres_return_only;
int optres_compound_jumps;
//int optres_comexprremoval;
int optres_stripfunctions;
int optres_locals_marshalling;
int optres_logicops;
int optres_test1;
int optres_test2;
void *(*pHash_Get)(hashtable_t *table, char *name);
void *(*pHash_GetNext)(hashtable_t *table, char *name, void *old);
void *(*pHash_Add)(hashtable_t *table, char *name, void *data, bucket_t *);
QCC_def_t *QCC_PR_DummyDef(QCC_type_t *type, char *name, QCC_def_t *scope, int arraysize, unsigned int ofs, int referable, pbool saved);
QCC_type_t *QCC_PR_NewType (char *name, int basictype);
QCC_type_t *QCC_PR_FindType (QCC_type_t *type);
QCC_type_t *QCC_PR_PointerType (QCC_type_t *pointsto);
QCC_type_t *QCC_PR_FieldType (QCC_type_t *pointsto);
void QCC_PR_ParseState (void);
pbool simplestore;
pbool expandedemptymacro;
QCC_pr_info_t pr;
//QCC_def_t **pr_global_defs/*[MAX_REGS]*/; // to find def for a global variable
//keeps track of how many funcs are called while parsing a statement
//int qcc_functioncalled;
//========================================
QCC_def_t *pr_scope; // the function being parsed, or NULL
QCC_type_t *pr_classtype;
pbool pr_dumpasm;
QCC_string_t s_file, s_file2; // filename for function definition
unsigned int locals_start; // for tracking local variables vs temps
unsigned int locals_end; // for tracking local variables vs temps
jmp_buf pr_parse_abort; // longjump with this on parse error
void QCC_PR_ParseDefs (char *classname);
pbool qcc_usefulstatement;
int max_breaks;
int max_continues;
int max_cases;
int num_continues;
int num_breaks;
int num_cases;
int *pr_breaks;
int *pr_continues;
int *pr_cases;
QCC_def_t **pr_casesdef;
QCC_def_t **pr_casesdef2;
typedef struct {
int statementno;
int lineno;
char name[256];
} gotooperator_t;
int max_labels;
int max_gotos;
gotooperator_t *pr_labels;
gotooperator_t *pr_gotos;
int num_gotos;
int num_labels;
QCC_def_t *extra_parms[MAX_EXTRA_PARMS];
#define ASSOC_RIGHT_RESULT ASSOC_RIGHT
//========================================
//FIXME: modifiy list so most common GROUPS are first
//use look up table for value of first char and sort by first char and most common...?
//if true, effectivly {b=a; return a;}
QCC_opcode_t pr_opcodes[] =
{
{6, "<DONE>", "DONE", -1, ASSOC_LEFT, &type_void, &type_void, &type_void},
{6, "*", "MUL_F", 3, ASSOC_LEFT, &type_float, &type_float, &type_float},
{6, "*", "MUL_V", 3, ASSOC_LEFT, &type_vector, &type_vector, &type_float},
{6, "*", "MUL_FV", 3, ASSOC_LEFT, &type_float, &type_vector, &type_vector},
{6, "*", "MUL_VF", 3, ASSOC_LEFT, &type_vector, &type_float, &type_vector},
{6, "/", "DIV_F", 3, ASSOC_LEFT, &type_float, &type_float, &type_float},
{6, "+", "ADD_F", 4, ASSOC_LEFT, &type_float, &type_float, &type_float},
{6, "+", "ADD_V", 4, ASSOC_LEFT, &type_vector, &type_vector, &type_vector},
{6, "-", "SUB_F", 4, ASSOC_LEFT, &type_float, &type_float, &type_float},
{6, "-", "SUB_V", 4, ASSOC_LEFT, &type_vector, &type_vector, &type_vector},
{6, "==", "EQ_F", 5, ASSOC_LEFT, &type_float, &type_float, &type_float},
{6, "==", "EQ_V", 5, ASSOC_LEFT, &type_vector, &type_vector, &type_float},
{6, "==", "EQ_S", 5, ASSOC_LEFT, &type_string, &type_string, &type_float},
{6, "==", "EQ_E", 5, ASSOC_LEFT, &type_entity, &type_entity, &type_float},
{6, "==", "EQ_FNC", 5, ASSOC_LEFT, &type_function, &type_function, &type_float},
{6, "!=", "NE_F", 5, ASSOC_LEFT, &type_float, &type_float, &type_float},
{6, "!=", "NE_V", 5, ASSOC_LEFT, &type_vector, &type_vector, &type_float},
{6, "!=", "NE_S", 5, ASSOC_LEFT, &type_string, &type_string, &type_float},
{6, "!=", "NE_E", 5, ASSOC_LEFT, &type_entity, &type_entity, &type_float},
{6, "!=", "NE_FNC", 5, ASSOC_LEFT, &type_function, &type_function, &type_float},
{6, "<=", "LE", 5, ASSOC_LEFT, &type_float, &type_float, &type_float},
{6, ">=", "GE", 5, ASSOC_LEFT, &type_float, &type_float, &type_float},
{6, "<", "LT", 5, ASSOC_LEFT, &type_float, &type_float, &type_float},
{6, ">", "GT", 5, ASSOC_LEFT, &type_float, &type_float, &type_float},
{6, ".", "INDIRECT_F", 1, ASSOC_LEFT, &type_entity, &type_field, &type_float},
{6, ".", "INDIRECT_V", 1, ASSOC_LEFT, &type_entity, &type_field, &type_vector},
{6, ".", "INDIRECT_S", 1, ASSOC_LEFT, &type_entity, &type_field, &type_string},
{6, ".", "INDIRECT_E", 1, ASSOC_LEFT, &type_entity, &type_field, &type_entity},
{6, ".", "INDIRECT_FI", 1, ASSOC_LEFT, &type_entity, &type_field, &type_field},
{6, ".", "INDIRECT_FU", 1, ASSOC_LEFT, &type_entity, &type_field, &type_function},
{6, ".", "ADDRESS", 1, ASSOC_LEFT, &type_entity, &type_field, &type_pointer},
{6, "=", "STORE_F", 6, ASSOC_RIGHT, &type_float, &type_float, &type_float},
{6, "=", "STORE_V", 6, ASSOC_RIGHT, &type_vector, &type_vector, &type_vector},
{6, "=", "STORE_S", 6, ASSOC_RIGHT, &type_string, &type_string, &type_string},
{6, "=", "STORE_ENT", 6, ASSOC_RIGHT, &type_entity, &type_entity, &type_entity},
{6, "=", "STORE_FLD", 6, ASSOC_RIGHT, &type_field, &type_field, &type_field},
{6, "=", "STORE_FNC", 6, ASSOC_RIGHT, &type_function, &type_function, &type_function},
{6, "=", "STOREP_F", 6, ASSOC_RIGHT, &type_pointer, &type_float, &type_float},
{6, "=", "STOREP_V", 6, ASSOC_RIGHT, &type_pointer, &type_vector, &type_vector},
{6, "=", "STOREP_S", 6, ASSOC_RIGHT, &type_pointer, &type_string, &type_string},
{6, "=", "STOREP_ENT", 6, ASSOC_RIGHT, &type_pointer, &type_entity, &type_entity},
{6, "=", "STOREP_FLD", 6, ASSOC_RIGHT, &type_pointer, &type_field, &type_field},
{6, "=", "STOREP_FNC", 6, ASSOC_RIGHT, &type_pointer, &type_function, &type_function},
{6, "<RETURN>", "RETURN", -1, ASSOC_LEFT, &type_float, &type_void, &type_void},
{6, "!", "NOT_F", -1, ASSOC_LEFT, &type_float, &type_void, &type_float},
{6, "!", "NOT_V", -1, ASSOC_LEFT, &type_vector, &type_void, &type_float},
{6, "!", "NOT_S", -1, ASSOC_LEFT, &type_vector, &type_void, &type_float},
{6, "!", "NOT_ENT", -1, ASSOC_LEFT, &type_entity, &type_void, &type_float},
{6, "!", "NOT_FNC", -1, ASSOC_LEFT, &type_function, &type_void, &type_float},
{6, "<IF>", "IF", -1, ASSOC_RIGHT, &type_float, NULL, &type_void},
{6, "<IFNOT>", "IFNOT", -1, ASSOC_RIGHT, &type_float, NULL, &type_void},
// calls returns REG_RETURN
{6, "<CALL0>", "CALL0", -1, ASSOC_LEFT, &type_function, &type_void, &type_void},
{6, "<CALL1>", "CALL1", -1, ASSOC_LEFT, &type_function, &type_void, &type_void},
{6, "<CALL2>", "CALL2", -1, ASSOC_LEFT, &type_function, &type_void, &type_void},
{6, "<CALL3>", "CALL3", -1, ASSOC_LEFT, &type_function, &type_void, &type_void},
{6, "<CALL4>", "CALL4", -1, ASSOC_LEFT, &type_function, &type_void, &type_void},
{6, "<CALL5>", "CALL5", -1, ASSOC_LEFT, &type_function, &type_void, &type_void},
{6, "<CALL6>", "CALL6", -1, ASSOC_LEFT, &type_function, &type_void, &type_void},
{6, "<CALL7>", "CALL7", -1, ASSOC_LEFT, &type_function, &type_void, &type_void},
{6, "<CALL8>", "CALL8", -1, ASSOC_LEFT, &type_function, &type_void, &type_void},
{6, "<STATE>", "STATE", -1, ASSOC_LEFT, &type_float, &type_float, &type_void},
{6, "<GOTO>", "GOTO", -1, ASSOC_RIGHT, NULL, &type_void, &type_void},
{6, "&&", "AND", 7, ASSOC_LEFT, &type_float, &type_float, &type_float},
{6, "||", "OR", 7, ASSOC_LEFT, &type_float, &type_float, &type_float},
{6, "&", "BITAND", 3, ASSOC_LEFT, &type_float, &type_float, &type_float},
{6, "|", "BITOR", 3, ASSOC_LEFT, &type_float, &type_float, &type_float},
//version 6 are in normal progs.
//these are hexen2
{7, "*=", "MULSTORE_F", 6, ASSOC_RIGHT_RESULT, &type_float, &type_float, &type_float},
{7, "*=", "MULSTORE_V", 6, ASSOC_RIGHT_RESULT, &type_vector, &type_float, &type_vector},
{7, "*=", "MULSTOREP_F", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_float, &type_float},
{7, "*=", "MULSTOREP_V", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_float, &type_vector},
{7, "/=", "DIVSTORE_F", 6, ASSOC_RIGHT_RESULT, &type_float, &type_float, &type_float},
{7, "/=", "DIVSTOREP_F", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_float, &type_float},
{7, "+=", "ADDSTORE_F", 6, ASSOC_RIGHT_RESULT, &type_float, &type_float, &type_float},
{7, "+=", "ADDSTORE_V", 6, ASSOC_RIGHT_RESULT, &type_vector, &type_vector, &type_vector},
{7, "+=", "ADDSTOREP_F", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_float, &type_float},
{7, "+=", "ADDSTOREP_V", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_vector, &type_vector},
{7, "-=", "SUBSTORE_F", 6, ASSOC_RIGHT_RESULT, &type_float, &type_float, &type_float},
{7, "-=", "SUBSTORE_V", 6, ASSOC_RIGHT_RESULT, &type_vector, &type_vector, &type_vector},
{7, "-=", "SUBSTOREP_F", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_float, &type_float},
{7, "-=", "SUBSTOREP_V", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_vector, &type_vector},
{7, "<FETCH_GBL_F>", "FETCH_GBL_F", -1, ASSOC_LEFT, &type_float, &type_float, &type_float},
{7, "<FETCH_GBL_V>", "FETCH_GBL_V", -1, ASSOC_LEFT, &type_vector, &type_float, &type_vector},
{7, "<FETCH_GBL_S>", "FETCH_GBL_S", -1, ASSOC_LEFT, &type_string, &type_float, &type_string},
{7, "<FETCH_GBL_E>", "FETCH_GBL_E", -1, ASSOC_LEFT, &type_entity, &type_float, &type_entity},
{7, "<FETCH_GBL_FNC>", "FETCH_GBL_FNC", -1, ASSOC_LEFT, &type_function, &type_float, &type_function},
{7, "<CSTATE>", "CSTATE", -1, ASSOC_LEFT, &type_float, &type_float, &type_void},
{7, "<CWSTATE>", "CWSTATE", -1, ASSOC_LEFT, &type_float, &type_float, &type_void},
{7, "<THINKTIME>", "THINKTIME", -1, ASSOC_LEFT, &type_entity, &type_float, &type_void},
{7, "|=", "BITSET_F", 6, ASSOC_RIGHT, &type_float, &type_float, &type_float},
{7, "|=", "BITSETP_F", 6, ASSOC_RIGHT, &type_pointer, &type_float, &type_float},
{7, "&~=", "BITCLR_F", 6, ASSOC_RIGHT, &type_float, &type_float, &type_float},
{7, "&~=", "BITCLRP_F", 6, ASSOC_RIGHT, &type_pointer, &type_float, &type_float},
{7, "<RAND0>", "RAND0", -1, ASSOC_LEFT, &type_void, &type_void, &type_float},
{7, "<RAND1>", "RAND1", -1, ASSOC_LEFT, &type_float, &type_void, &type_float},
{7, "<RAND2>", "RAND2", -1, ASSOC_LEFT, &type_float, &type_float, &type_float},
{7, "<RANDV0>", "RANDV0", -1, ASSOC_LEFT, &type_void, &type_void, &type_vector},
{7, "<RANDV1>", "RANDV1", -1, ASSOC_LEFT, &type_vector, &type_void, &type_vector},
{7, "<RANDV2>", "RANDV2", -1, ASSOC_LEFT, &type_vector, &type_vector, &type_vector},
{7, "<SWITCH_F>", "SWITCH_F", -1, ASSOC_LEFT, &type_void, NULL, &type_void},
{7, "<SWITCH_V>", "SWITCH_V", -1, ASSOC_LEFT, &type_void, NULL, &type_void},
{7, "<SWITCH_S>", "SWITCH_S", -1, ASSOC_LEFT, &type_void, NULL, &type_void},
{7, "<SWITCH_E>", "SWITCH_E", -1, ASSOC_LEFT, &type_void, NULL, &type_void},
{7, "<SWITCH_FNC>", "SWITCH_FNC", -1, ASSOC_LEFT, &type_void, NULL, &type_void},
{7, "<CASE>", "CASE", -1, ASSOC_LEFT, &type_void, NULL, &type_void},
{7, "<CASERANGE>", "CASERANGE", -1, ASSOC_LEFT, &type_void, &type_void, NULL},
//Later are additions by DMW.
{7, "<CALL1H>", "CALL1H", -1, ASSOC_LEFT, &type_function, &type_vector, &type_void},
{7, "<CALL2H>", "CALL2H", -1, ASSOC_LEFT, &type_function, &type_vector, &type_vector},
{7, "<CALL3H>", "CALL3H", -1, ASSOC_LEFT, &type_function, &type_vector, &type_vector},
{7, "<CALL4H>", "CALL4H", -1, ASSOC_LEFT, &type_function, &type_vector, &type_vector},
{7, "<CALL5H>", "CALL5H", -1, ASSOC_LEFT, &type_function, &type_vector, &type_vector},
{7, "<CALL6H>", "CALL6H", -1, ASSOC_LEFT, &type_function, &type_vector, &type_vector},
{7, "<CALL7H>", "CALL7H", -1, ASSOC_LEFT, &type_function, &type_vector, &type_vector},
{7, "<CALL8H>", "CALL8H", -1, ASSOC_LEFT, &type_function, &type_vector, &type_vector},
{7, "=", "STORE_I", 6, ASSOC_RIGHT, &type_integer, &type_integer, &type_integer},
{7, "=", "STORE_IF", 6, ASSOC_RIGHT, &type_integer, &type_float, &type_integer},
{7, "=", "STORE_FI", 6, ASSOC_RIGHT, &type_float, &type_integer, &type_float},
{7, "+", "ADD_I", 4, ASSOC_LEFT, &type_integer, &type_integer, &type_integer},
{7, "+", "ADD_FI", 4, ASSOC_LEFT, &type_float, &type_integer, &type_float},
{7, "+", "ADD_IF", 4, ASSOC_LEFT, &type_integer, &type_float, &type_float},
{7, "-", "SUB_I", 4, ASSOC_LEFT, &type_integer, &type_integer, &type_integer},
{7, "-", "SUB_FI", 4, ASSOC_LEFT, &type_float, &type_integer, &type_float},
{7, "-", "SUB_IF", 4, ASSOC_LEFT, &type_integer, &type_float, &type_float},
{7, "<CIF>", "C_ITOF", -1, ASSOC_LEFT, &type_integer, &type_void, &type_float},
{7, "<CFI>", "C_FTOI", -1, ASSOC_LEFT, &type_float, &type_void, &type_integer},
{7, "<CPIF>", "CP_ITOF", -1, ASSOC_LEFT, &type_pointer, &type_integer, &type_float},
{7, "<CPFI>", "CP_FTOI", -1, ASSOC_LEFT, &type_pointer, &type_float, &type_integer},
{7, ".", "INDIRECT", 1, ASSOC_LEFT, &type_entity, &type_field, &type_integer},
{7, "=", "STOREP_I", 6, ASSOC_RIGHT, &type_pointer, &type_integer, &type_integer},
{7, "=", "STOREP_IF", 6, ASSOC_RIGHT, &type_pointer, &type_float, &type_integer},
{7, "=", "STOREP_FI", 6, ASSOC_RIGHT, &type_pointer, &type_integer, &type_float},
{7, "&", "BITAND_I", 3, ASSOC_LEFT, &type_integer, &type_integer, &type_integer},
{7, "|", "BITOR_I", 3, ASSOC_LEFT, &type_integer, &type_integer, &type_integer},
{7, "*", "MUL_I", 3, ASSOC_LEFT, &type_integer, &type_integer, &type_integer},
{7, "/", "DIV_I", 3, ASSOC_LEFT, &type_integer, &type_integer, &type_integer},
{7, "==", "EQ_I", 5, ASSOC_LEFT, &type_integer, &type_integer, &type_integer},
{7, "!=", "NE_I", 5, ASSOC_LEFT, &type_integer, &type_integer, &type_integer},
{7, "<IFNOTS>", "IFNOTS", -1, ASSOC_RIGHT, &type_string, NULL, &type_void},
{7, "<IFS>", "IFS", -1, ASSOC_RIGHT, &type_string, NULL, &type_void},
{7, "!", "NOT_I", -1, ASSOC_LEFT, &type_integer, &type_void, &type_integer},
{7, "/", "DIV_VF", 3, ASSOC_LEFT, &type_vector, &type_float, &type_float},
{7, "^", "XOR_I", 3, ASSOC_LEFT, &type_integer, &type_integer, &type_integer},
{7, ">>", "RSHIFT_I", 3, ASSOC_LEFT, &type_integer, &type_integer, &type_integer},
{7, "<<", "LSHIFT_I", 3, ASSOC_LEFT, &type_integer, &type_integer, &type_integer},
//var, offset return
{7, "<ARRAY>", "GET_POINTER", -1, ASSOC_LEFT, &type_float, &type_integer, &type_pointer},
{7, "<ARRAY>", "ARRAY_OFS", -1, ASSOC_LEFT, &type_pointer, &type_integer, &type_pointer},
{7, "=", "LOADA_F", 6, ASSOC_LEFT, &type_float, &type_integer, &type_float},
{7, "=", "LOADA_V", 6, ASSOC_LEFT, &type_vector, &type_integer, &type_vector},
{7, "=", "LOADA_S", 6, ASSOC_LEFT, &type_string, &type_integer, &type_string},
{7, "=", "LOADA_ENT", 6, ASSOC_LEFT, &type_entity, &type_integer, &type_entity},
{7, "=", "LOADA_FLD", 6, ASSOC_LEFT, &type_field, &type_integer, &type_field},
{7, "=", "LOADA_FNC", 6, ASSOC_LEFT, &type_function, &type_integer, &type_function},
{7, "=", "LOADA_I", 6, ASSOC_LEFT, &type_integer, &type_integer, &type_integer},
{7, "=", "STORE_P", 6, ASSOC_RIGHT, &type_pointer, &type_pointer, &type_void},
{7, ".", "INDIRECT_P", 1, ASSOC_LEFT, &type_entity, &type_field, &type_pointer},
{7, "=", "LOADP_F", 6, ASSOC_LEFT, &type_pointer, &type_integer, &type_float},
{7, "=", "LOADP_V", 6, ASSOC_LEFT, &type_pointer, &type_integer, &type_vector},
{7, "=", "LOADP_S", 6, ASSOC_LEFT, &type_pointer, &type_integer, &type_string},
{7, "=", "LOADP_ENT", 6, ASSOC_LEFT, &type_pointer, &type_integer, &type_entity},
{7, "=", "LOADP_FLD", 6, ASSOC_LEFT, &type_pointer, &type_integer, &type_field},
{7, "=", "LOADP_FNC", 6, ASSOC_LEFT, &type_pointer, &type_integer, &type_function},
{7, "=", "LOADP_I", 6, ASSOC_LEFT, &type_pointer, &type_integer, &type_integer},
{7, "<=", "LE_I", 5, ASSOC_LEFT, &type_integer, &type_integer, &type_integer},
{7, ">=", "GE_I", 5, ASSOC_LEFT, &type_integer, &type_integer, &type_integer},
{7, "<", "LT_I", 5, ASSOC_LEFT, &type_integer, &type_integer, &type_integer},
{7, ">", "GT_I", 5, ASSOC_LEFT, &type_integer, &type_integer, &type_integer},
{7, "<=", "LE_IF", 5, ASSOC_LEFT, &type_integer, &type_float, &type_integer},
{7, ">=", "GE_IF", 5, ASSOC_LEFT, &type_integer, &type_float, &type_integer},
{7, "<", "LT_IF", 5, ASSOC_LEFT, &type_integer, &type_float, &type_integer},
{7, ">", "GT_IF", 5, ASSOC_LEFT, &type_integer, &type_float, &type_integer},
{7, "<=", "LE_FI", 5, ASSOC_LEFT, &type_float, &type_integer, &type_integer},
{7, ">=", "GE_FI", 5, ASSOC_LEFT, &type_float, &type_integer, &type_integer},
{7, "<", "LT_FI", 5, ASSOC_LEFT, &type_float, &type_integer, &type_integer},
{7, ">", "GT_FI", 5, ASSOC_LEFT, &type_float, &type_integer, &type_integer},
{7, "==", "EQ_IF", 5, ASSOC_LEFT, &type_integer, &type_float, &type_integer},
{7, "==", "EQ_FI", 5, ASSOC_LEFT, &type_float, &type_integer, &type_float},
//-------------------------------------
//string manipulation.
{7, "+", "ADD_SF", 4, ASSOC_LEFT, &type_string, &type_float, &type_string},
{7, "-", "SUB_S", 4, ASSOC_LEFT, &type_string, &type_string, &type_float},
{7, "<STOREP_C>", "STOREP_C", 1, ASSOC_RIGHT, &type_string, &type_float, &type_float},
{7, "<LOADP_C>", "LOADP_C", 1, ASSOC_LEFT, &type_string, &type_void, &type_float},
//-------------------------------------
{7, "*", "MUL_IF", 5, ASSOC_LEFT, &type_integer, &type_float, &type_integer},
{7, "*", "MUL_FI", 5, ASSOC_LEFT, &type_float, &type_integer, &type_float},
{7, "*", "MUL_VI", 5, ASSOC_LEFT, &type_vector, &type_integer, &type_vector},
{7, "*", "MUL_IV", 5, ASSOC_LEFT, &type_integer, &type_vector, &type_vector},
{7, "/", "DIV_IF", 5, ASSOC_LEFT, &type_integer, &type_float, &type_integer},
{7, "/", "DIV_FI", 5, ASSOC_LEFT, &type_float, &type_integer, &type_float},
{7, "&", "BITAND_IF", 5, ASSOC_LEFT, &type_integer, &type_float, &type_integer},
{7, "|", "BITOR_IF", 5, ASSOC_LEFT, &type_integer, &type_float, &type_integer},
{7, "&", "BITAND_FI", 5, ASSOC_LEFT, &type_float, &type_integer, &type_float},
{7, "|", "BITOR_FI", 5, ASSOC_LEFT, &type_float, &type_integer, &type_float},
{7, "&&", "AND_I", 7, ASSOC_LEFT, &type_integer, &type_integer, &type_integer},
{7, "||", "OR_I", 7, ASSOC_LEFT, &type_integer, &type_integer, &type_integer},
{7, "&&", "AND_IF", 7, ASSOC_LEFT, &type_integer, &type_float, &type_integer},
{7, "||", "OR_IF", 7, ASSOC_LEFT, &type_integer, &type_float, &type_integer},
{7, "&&", "AND_FI", 7, ASSOC_LEFT, &type_float, &type_integer, &type_integer},
{7, "||", "OR_FI", 7, ASSOC_LEFT, &type_float, &type_integer, &type_integer},
{7, "!=", "NE_IF", 5, ASSOC_LEFT, &type_integer, &type_float, &type_integer},
{7, "!=", "NE_FI", 5, ASSOC_LEFT, &type_float, &type_float, &type_integer},
{7, "<>", "GSTOREP_I", -1, ASSOC_LEFT, &type_float, &type_float, &type_float},
{7, "<>", "GSTOREP_F", -1, ASSOC_LEFT, &type_float, &type_float, &type_float},
{7, "<>", "GSTOREP_ENT", -1, ASSOC_LEFT, &type_float, &type_float, &type_float},
{7, "<>", "GSTOREP_FLD", -1, ASSOC_LEFT, &type_float, &type_float, &type_float},
{7, "<>", "GSTOREP_S", -1, ASSOC_LEFT, &type_float, &type_float, &type_float},
{7, "<>", "GSTOREP_FNC", -1, ASSOC_LEFT, &type_float, &type_float, &type_float},
{7, "<>", "GSTOREP_V", -1, ASSOC_LEFT, &type_float, &type_float, &type_float},
{7, "<>", "GADDRESS", -1, ASSOC_LEFT, &type_float, &type_float, &type_float},
{7, "<>", "GLOAD_I", -1, ASSOC_LEFT, &type_float, &type_float, &type_float},
{7, "<>", "GLOAD_F", -1, ASSOC_LEFT, &type_float, &type_float, &type_float},
{7, "<>", "GLOAD_FLD", -1, ASSOC_LEFT, &type_float, &type_float, &type_float},
{7, "<>", "GLOAD_ENT", -1, ASSOC_LEFT, &type_float, &type_float, &type_float},
{7, "<>", "GLOAD_S", -1, ASSOC_LEFT, &type_float, &type_float, &type_float},
{7, "<>", "GLOAD_FNC", -1, ASSOC_LEFT, &type_float, &type_float, &type_float},
{7, "<>", "BOUNDCHECK", -1, ASSOC_LEFT, &type_float, &type_float, &type_float},
{7, "=", "STOREP_P", 6, ASSOC_RIGHT, &type_pointer, &type_pointer, &type_void},
{7, "<PUSH>", "PUSH", -1, ASSOC_RIGHT, &type_float, &type_void, &type_pointer},
{7, "<POP>", "POP", -1, ASSOC_RIGHT, &type_float, &type_void, &type_void},
{7, "<SWITCH_I>", "SWITCH_I", -1, ASSOC_LEFT, &type_void, NULL, &type_void},
{7, "<>", "GLOAD_S", -1, ASSOC_LEFT, &type_float, &type_float, &type_float},
{6, "<IF_F>", "IF_F", -1, ASSOC_RIGHT, &type_float, NULL, &type_void},
{6, "<IFNOT_F>","IFNOT_F", -1, ASSOC_RIGHT, &type_float, NULL, &type_void},
/* emulated ops begin here */
{7, "<>", "OP_EMULATED", -1, ASSOC_LEFT, &type_float, &type_float, &type_float},
{7, "|=", "BITSET_I", 6, ASSOC_RIGHT, &type_integer, &type_integer, &type_integer},
{7, "|=", "BITSETP_I", 6, ASSOC_RIGHT, &type_pointer, &type_integer, &type_integer},
{7, "*=", "MULSTORE_I", 6, ASSOC_RIGHT_RESULT, &type_integer, &type_integer, &type_integer},
{7, "/=", "DIVSTORE_I", 6, ASSOC_RIGHT_RESULT, &type_integer, &type_integer, &type_integer},
{7, "+=", "ADDSTORE_I", 6, ASSOC_RIGHT_RESULT, &type_integer, &type_integer, &type_integer},
{7, "-=", "SUBSTORE_I", 6, ASSOC_RIGHT_RESULT, &type_integer, &type_integer, &type_integer},
{7, "*=", "MULSTOREP_I", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_integer, &type_integer},
{7, "/=", "DIVSTOREP_I", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_integer, &type_integer},
{7, "+=", "ADDSTOREP_I", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_integer, &type_integer},
{7, "-=", "SUBSTOREP_I", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_integer, &type_integer},
{7, "*=", "OP_MULSTORE_IF", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_float, &type_integer},
{7, "*=", "OP_MULSTOREP_IF", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_float, &type_integer},
{7, "/=", "OP_DIVSTORE_IF", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_float, &type_integer},
{7, "/=", "OP_DIVSTOREP_IF", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_float, &type_integer},
{7, "+=", "OP_ADDSTORE_IF", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_float, &type_integer},
{7, "+=", "OP_ADDSTOREP_IF", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_float, &type_integer},
{7, "-=", "OP_SUBSTORE_IF", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_float, &type_integer},
{7, "-=", "OP_SUBSTOREP_IF", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_float, &type_integer},
{7, "*=", "OP_MULSTORE_FI", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_integer, &type_float},
{7, "*=", "OP_MULSTOREP_FI", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_integer, &type_float},
{7, "/=", "OP_DIVSTORE_FI", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_integer, &type_float},
{7, "/=", "OP_DIVSTOREP_FI", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_integer, &type_float},
{7, "+=", "OP_ADDSTORE_FI", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_integer, &type_float},
{7, "+=", "OP_ADDSTOREP_FI", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_integer, &type_float},
{7, "-=", "OP_SUBSTORE_FI", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_integer, &type_float},
{7, "-=", "OP_SUBSTOREP_FI", 6, ASSOC_RIGHT_RESULT, &type_pointer, &type_integer, &type_float},
{0, NULL}
};
pbool OpAssignsToC(unsigned int op)
{
// calls, switches and cases DON'T
if(pr_opcodes[op].type_c == &type_void)
return false;
if(op >= OP_SWITCH_F && op <= OP_CALL8H)
return false;
if(op >= OP_RAND0 && op <= OP_RANDV2)
return false;
// they use a and b, but have 3 types
// safety
if(op >= OP_BITSET && op <= OP_BITCLRP)
return false;
/*if(op >= OP_STORE_I && op <= OP_STORE_FI)
return false; <- add STOREP_*?*/
if(op == OP_STOREP_C || op == OP_LOADP_C)
return false;
if(op >= OP_MULSTORE_F && op <= OP_SUBSTOREP_V)
return false;
return true;
}
pbool OpAssignsToB(unsigned int op)
{
if(op >= OP_BITSET && op <= OP_BITCLRP)
return true;
if(op >= OP_STORE_I && op <= OP_STORE_FI)
return true;
if(op == OP_STOREP_C || op == OP_LOADP_C)
return true;
if(op >= OP_MULSTORE_F && op <= OP_SUBSTOREP_V)
return true;
if(op >= OP_STORE_F && op <= OP_STOREP_FNC)
return true;
return false;
}
/*pbool OpAssignedTo(QCC_def_t *v, unsigned int op)
{
if(OpAssignsToC(op))
{
}
else if(OpAssignsToB(op))
{
}
return false;
}
*/
#undef ASSOC_RIGHT_RESULT
#define TOP_PRIORITY 7
#define UNARY_PRIORITY 1
#define NOT_PRIORITY 5
//conditional and/or
#define CONDITION_PRIORITY 7
//this system cuts out 10/120
//these evaluate as top first.
QCC_opcode_t *opcodeprioritized[TOP_PRIORITY+1][128] =
{
{ //don't use
/* &pr_opcodes[OP_DONE],
&pr_opcodes[OP_RETURN],
&pr_opcodes[OP_NOT_F],
&pr_opcodes[OP_NOT_V],
&pr_opcodes[OP_NOT_S],
&pr_opcodes[OP_NOT_ENT],
&pr_opcodes[OP_NOT_FNC],
&pr_opcodes[OP_IF],
&pr_opcodes[OP_IFNOT],
&pr_opcodes[OP_CALL0],
&pr_opcodes[OP_CALL1],
&pr_opcodes[OP_CALL2],
&pr_opcodes[OP_CALL3],
&pr_opcodes[OP_CALL4],
&pr_opcodes[OP_CALL5],
&pr_opcodes[OP_CALL6],
&pr_opcodes[OP_CALL7],
&pr_opcodes[OP_CALL8],
&pr_opcodes[OP_STATE],
&pr_opcodes[OP_GOTO],
&pr_opcodes[OP_IFNOTS],
&pr_opcodes[OP_IFS],
&pr_opcodes[OP_NOT_I],
*/ NULL
}, { //1
&pr_opcodes[OP_LOAD_F],
&pr_opcodes[OP_LOAD_V],
&pr_opcodes[OP_LOAD_S],
&pr_opcodes[OP_LOAD_ENT],
&pr_opcodes[OP_LOAD_FLD],
&pr_opcodes[OP_LOAD_FNC],
&pr_opcodes[OP_LOAD_I],
&pr_opcodes[OP_LOAD_P],
&pr_opcodes[OP_ADDRESS],
NULL
}, { //2
/* //conversion. don't use
&pr_opcodes[OP_C_ITOF],
&pr_opcodes[OP_C_FTOI],
&pr_opcodes[OP_CP_ITOF],
&pr_opcodes[OP_CP_FTOI],
*/ NULL
}, { //3
&pr_opcodes[OP_MUL_F],
&pr_opcodes[OP_MUL_V],
&pr_opcodes[OP_MUL_FV],
&pr_opcodes[OP_MUL_VF],
&pr_opcodes[OP_MUL_I],
&pr_opcodes[OP_DIV_F],
&pr_opcodes[OP_DIV_I],
&pr_opcodes[OP_DIV_VF],
&pr_opcodes[OP_BITAND],
&pr_opcodes[OP_BITAND_I],
&pr_opcodes[OP_BITAND_IF],
&pr_opcodes[OP_BITAND_FI],
&pr_opcodes[OP_BITOR],
&pr_opcodes[OP_BITOR_I],
&pr_opcodes[OP_BITOR_IF],
&pr_opcodes[OP_BITOR_FI],
&pr_opcodes[OP_XOR_I],
&pr_opcodes[OP_RSHIFT_I],
&pr_opcodes[OP_LSHIFT_I],
NULL
}, { //4
&pr_opcodes[OP_ADD_F],
&pr_opcodes[OP_ADD_V],
&pr_opcodes[OP_ADD_I],
&pr_opcodes[OP_ADD_FI],
&pr_opcodes[OP_ADD_IF],
&pr_opcodes[OP_ADD_SF],
&pr_opcodes[OP_SUB_F],
&pr_opcodes[OP_SUB_V],
&pr_opcodes[OP_SUB_I],
&pr_opcodes[OP_SUB_FI],
&pr_opcodes[OP_SUB_IF],
&pr_opcodes[OP_SUB_S],
NULL
}, { //5
&pr_opcodes[OP_EQ_F],
&pr_opcodes[OP_EQ_V],
&pr_opcodes[OP_EQ_S],
&pr_opcodes[OP_EQ_E],
&pr_opcodes[OP_EQ_FNC],
&pr_opcodes[OP_EQ_I],
&pr_opcodes[OP_EQ_IF],
&pr_opcodes[OP_EQ_FI],
&pr_opcodes[OP_NE_F],
&pr_opcodes[OP_NE_V],
&pr_opcodes[OP_NE_S],
&pr_opcodes[OP_NE_E],
&pr_opcodes[OP_NE_FNC],
&pr_opcodes[OP_NE_I],
&pr_opcodes[OP_NE_IF],
&pr_opcodes[OP_NE_FI],
&pr_opcodes[OP_LE],
&pr_opcodes[OP_LE_I],
&pr_opcodes[OP_LE_IF],
&pr_opcodes[OP_LE_FI],
&pr_opcodes[OP_GE],
&pr_opcodes[OP_GE_I],
&pr_opcodes[OP_GE_IF],
&pr_opcodes[OP_GE_FI],
&pr_opcodes[OP_LT],
&pr_opcodes[OP_LT_I],
&pr_opcodes[OP_LT_IF],
&pr_opcodes[OP_LT_FI],
&pr_opcodes[OP_GT],
&pr_opcodes[OP_GT_I],
&pr_opcodes[OP_GT_IF],
&pr_opcodes[OP_GT_FI],
NULL
}, { //6
&pr_opcodes[OP_STORE_F],
&pr_opcodes[OP_STORE_V],
&pr_opcodes[OP_STORE_S],
&pr_opcodes[OP_STORE_ENT],
&pr_opcodes[OP_STORE_FLD],
&pr_opcodes[OP_STORE_FNC],
&pr_opcodes[OP_STORE_I],
&pr_opcodes[OP_STORE_IF],
&pr_opcodes[OP_STORE_FI],
&pr_opcodes[OP_STORE_P],
&pr_opcodes[OP_STOREP_F],
&pr_opcodes[OP_STOREP_V],
&pr_opcodes[OP_STOREP_S],
&pr_opcodes[OP_STOREP_ENT],
&pr_opcodes[OP_STOREP_FLD],
&pr_opcodes[OP_STOREP_FNC],
&pr_opcodes[OP_STOREP_I],
&pr_opcodes[OP_STOREP_IF],
&pr_opcodes[OP_STOREP_FI],
&pr_opcodes[OP_STOREP_P],
&pr_opcodes[OP_DIVSTORE_F],
&pr_opcodes[OP_DIVSTORE_I],
&pr_opcodes[OP_DIVSTORE_FI],
&pr_opcodes[OP_DIVSTORE_IF],
&pr_opcodes[OP_DIVSTOREP_F],
&pr_opcodes[OP_DIVSTOREP_I],
&pr_opcodes[OP_DIVSTOREP_IF],
&pr_opcodes[OP_DIVSTOREP_FI],
&pr_opcodes[OP_MULSTORE_F],
&pr_opcodes[OP_MULSTORE_V],
&pr_opcodes[OP_MULSTORE_I],
&pr_opcodes[OP_MULSTORE_IF],
&pr_opcodes[OP_MULSTORE_FI],
&pr_opcodes[OP_MULSTOREP_F],
&pr_opcodes[OP_MULSTOREP_V],
&pr_opcodes[OP_MULSTOREP_I],
&pr_opcodes[OP_MULSTOREP_IF],
&pr_opcodes[OP_MULSTOREP_FI],
&pr_opcodes[OP_ADDSTORE_F],
&pr_opcodes[OP_ADDSTORE_V],
&pr_opcodes[OP_ADDSTORE_I],
&pr_opcodes[OP_ADDSTORE_IF],
&pr_opcodes[OP_ADDSTORE_FI],
&pr_opcodes[OP_ADDSTOREP_F],
&pr_opcodes[OP_ADDSTOREP_V],
&pr_opcodes[OP_ADDSTOREP_I],
&pr_opcodes[OP_ADDSTOREP_IF],
&pr_opcodes[OP_ADDSTOREP_FI],
&pr_opcodes[OP_SUBSTORE_F],
&pr_opcodes[OP_SUBSTORE_V],
&pr_opcodes[OP_SUBSTORE_I],
&pr_opcodes[OP_SUBSTORE_IF],
&pr_opcodes[OP_SUBSTORE_FI],
&pr_opcodes[OP_SUBSTOREP_F],
&pr_opcodes[OP_SUBSTOREP_V],
&pr_opcodes[OP_SUBSTOREP_I],
&pr_opcodes[OP_SUBSTOREP_IF],
&pr_opcodes[OP_SUBSTOREP_FI],
&pr_opcodes[OP_BITSET],
&pr_opcodes[OP_BITSET_I],
// &pr_opcodes[OP_BITSET_IF],
// &pr_opcodes[OP_BITSET_FI],
&pr_opcodes[OP_BITSETP],
&pr_opcodes[OP_BITSETP_I],
// &pr_opcodes[OP_BITSETP_IF],
// &pr_opcodes[OP_BITSETP_FI],
&pr_opcodes[OP_BITCLR],
&pr_opcodes[OP_BITCLRP],
NULL
}, { //7
&pr_opcodes[OP_AND],
&pr_opcodes[OP_AND_I],
&pr_opcodes[OP_AND_IF],
&pr_opcodes[OP_AND_FI],
&pr_opcodes[OP_OR],
&pr_opcodes[OP_OR_I],
&pr_opcodes[OP_OR_IF],
&pr_opcodes[OP_OR_FI],
NULL
}
};
pbool QCC_OPCodeValid(QCC_opcode_t *op)
{
int num;
num = op - pr_opcodes;
switch(qcc_targetformat)
{
case QCF_STANDARD:
case QCF_KK7:
if (num < OP_MULSTORE_F)
return true;
return false;
case QCF_HEXEN2:
if (num >= OP_SWITCH_V && num <= OP_SWITCH_FNC) //these were assigned numbers but were never actually implemtented in standard h2.
return false;
// if (num >= OP_MULSTORE_F && num <= OP_SUBSTOREP_V)
// return false;
if (num <= OP_CALL8H) //CALLXH are fixed up. This is to provide more dynamic switching...??
return true;
return false;
case QCF_FTE:
case QCF_FTEDEBUG:
//no emulated opcodes
if (num >= OP_NUMREALOPS)
return false;
return true;
case QCF_DARKPLACES:
//all id opcodes.
if (num < OP_MULSTORE_F)
return true;
//no emulated opcodes
if (num >= OP_NUMREALOPS)
return false;
//extended opcodes.
//DPFIXME: this is a list of the extended opcodes. I was conservative regarding supported ones.
// at the time of writing, these are the ones that look like they'll work just fine in Blub\0's patch.
// the ones that looked too permissive with bounds checks, or would give false positives are disabled.
// if the DP guys want I can change them as desired.
switch(num)
{
//maths and conditionals (simple opcodes that read from specific globals and write to a global)
case OP_ADD_I:
case OP_ADD_IF:
case OP_ADD_FI:
case OP_SUB_I:
case OP_SUB_IF:
case OP_SUB_FI:
case OP_MUL_I:
case OP_MUL_IF:
case OP_MUL_FI:
case OP_MUL_VI:
case OP_DIV_VF:
case OP_DIV_I:
case OP_DIV_IF:
case OP_DIV_FI:
case OP_BITAND_I:
case OP_BITOR_I:
case OP_BITAND_IF:
case OP_BITOR_IF:
case OP_BITAND_FI:
case OP_BITOR_FI:
case OP_GE_I:
case OP_LE_I:
case OP_GT_I:
case OP_LT_I:
case OP_AND_I:
case OP_OR_I:
case OP_GE_IF:
case OP_LE_IF:
case OP_GT_IF:
case OP_LT_IF:
case OP_AND_IF:
case OP_OR_IF:
case OP_GE_FI:
case OP_LE_FI:
case OP_GT_FI:
case OP_LT_FI:
case OP_AND_FI:
case OP_OR_FI:
case OP_NOT_I:
case OP_EQ_I:
case OP_EQ_IF:
case OP_EQ_FI:
case OP_NE_I:
case OP_NE_IF:
case OP_NE_FI:
return true;
//stores into a pointer (generated from 'ent.field=XXX')
case OP_STOREP_I: //no worse than the other OP_STOREP_X functions
case OP_STOREP_P:
//reads from an entity field
case OP_LOAD_I: //no worse than the other OP_LOAD_X functions.
case OP_LOAD_P:
return true;
//stores into the globals array.
//they can change any global dynamically, but thats no security risk.
//fteqcc will not automatically generate these.
//fteqw does not support them either.
case OP_GSTOREP_I:
case OP_GSTOREP_F:
case OP_GSTOREP_ENT:
case OP_GSTOREP_FLD:
case OP_GSTOREP_S:
case OP_GSTOREP_FNC:
case OP_GSTOREP_V:
return true;
//this opcode looks weird
case OP_GADDRESS://floatc = globals[inta + floatb] (fte does not support)
return true;
//fteqcc will not automatically generate these
//fteqw does not support them either, for that matter.
case OP_GLOAD_I://c = globals[inta]
case OP_GLOAD_F://note: fte does not support these
case OP_GLOAD_FLD:
case OP_GLOAD_ENT:
case OP_GLOAD_S:
case OP_GLOAD_FNC:
return true;
case OP_GLOAD_V:
return false; //DPFIXME: this is commented out in the patch I was given a link to... because the opcode wasn't defined.
//these are reportedly functional.
case OP_CALL8H:
case OP_CALL7H:
case OP_CALL6H:
case OP_CALL5H:
case OP_CALL4H:
case OP_CALL3H:
case OP_CALL2H:
case OP_CALL1H:
return true;
case OP_RAND0:
case OP_RAND1:
case OP_RAND2:
case OP_RANDV0:
case OP_RANDV1:
case OP_RANDV2:
return true;
case OP_BITSET: // b |= a
case OP_BITCLR: // b &= ~a
case OP_BITSETP: // *b |= a
case OP_BITCLRP: // *b &= ~a
return false; //FIXME: I do not fully follow the controversy over these.
case OP_SWITCH_F:
case OP_SWITCH_V:
case OP_SWITCH_S:
case OP_SWITCH_E:
case OP_SWITCH_FNC:
case OP_CASE:
case OP_CASERANGE:
return true;
//assuming the pointers here are fine, the return values are a little strange.
//but its fine
case OP_ADDSTORE_F:
case OP_ADDSTORE_V:
case OP_ADDSTOREP_F: // e.f += f
case OP_ADDSTOREP_V: // e.v += v
case OP_SUBSTORE_F:
case OP_SUBSTORE_V:
case OP_SUBSTOREP_F: // e.f += f
case OP_SUBSTOREP_V: // e.v += v
return true;
case OP_LOADA_I:
case OP_LOADA_F:
case OP_LOADA_FLD:
case OP_LOADA_ENT:
case OP_LOADA_S:
case OP_LOADA_FNC:
case OP_LOADA_V:
return false; //DPFIXME: DP does not bounds check these properly. I won't generate them.