This repository has been archived by the owner on Dec 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
printutils.c
1353 lines (1280 loc) · 39.2 KB
/
printutils.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
/****************************************************************************\
Copyright (c) 2002, NVIDIA Corporation.
NVIDIA Corporation("NVIDIA") supplies this software to you in
consideration of your agreement to the following terms, and your use,
installation, modification or redistribution of this NVIDIA software
constitutes acceptance of these terms. If you do not agree with these
terms, please do not use, install, modify or redistribute this NVIDIA
software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, NVIDIA grants you a personal, non-exclusive
license, under NVIDIA's copyrights in this original NVIDIA software (the
"NVIDIA Software"), to use, reproduce, modify and redistribute the
NVIDIA Software, with or without modifications, in source and/or binary
forms; provided that if you redistribute the NVIDIA Software, you must
retain the copyright notice of NVIDIA, this notice and the following
text and disclaimers in all such redistributions of the NVIDIA Software.
Neither the name, trademarks, service marks nor logos of NVIDIA
Corporation may be used to endorse or promote products derived from the
NVIDIA Software without specific prior written permission from NVIDIA.
Except as expressly stated in this notice, no other rights or licenses
express or implied, are granted by NVIDIA herein, including but not
limited to any patent rights that may be infringed by your derivative
works or by other works in which the NVIDIA Software may be
incorporated. No hardware is licensed hereunder.
THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER
PRODUCTS.
IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,
INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY
OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE
NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\****************************************************************************/
// printutils.c
//
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "slglobals.h"
///////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// Debug Printing Functions: //////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
#undef PICK
#define PICK(a, b, c, d, e) b
const char *opcode_name[] = {
OPCODE_TABLE
};
#undef PICK
#define PICK(a, b, c, d, e) e
const subopkind subop_table[] = {
OPCODE_TABLE
};
#undef PICK
/*
* lIndent()
*
*/
static void lIndent(int level)
{
int ii;
for (ii = 0; ii < level; ii++)
printf(" ");
} // lIndent
/*
* lBPrintExpression() - Print a low level representation of an expression tree.
*
*/
static void lBPrintExpression(expr *fexpr, int level)
{
char s[32];
int subop, mask, ii, nn, bval;
int OK = 1, HasString = 0;
lIndent(level);
if (fexpr) {
switch (fexpr->common.kind) {
case DECL_N:
printf("DECLARATION");
OK = 0;
break;
case SYMB_N:
printf("S ");
break;
case CONST_N:
printf("C ");
break;
case UNARY_N:
printf("U ");
break;
case BINARY_N:
printf("B ");
break;
case TRINARY_N:
printf("T ");
break;
default:
printf("<kind=%02x>", fexpr->common.kind);
OK = 0;
break;
}
if (OK) {
printf("%c%c", fexpr->sym.IsLValue ? 'L' : ' ',
fexpr->common.HasSideEffects ? '+' : ' ');
subop = fexpr->co.subop;
switch (subop_table[fexpr->co.op]) {
case SUB_NONE:
printf("- - - ");
mask = ~0;
break;
case SUB_S:
printf("- - %1x ", SUBOP_GET_T(subop));
mask = 0x0000000f;
break;
case SUB_V:
case SUB_VS:
case SUB_SV:
printf("- %1x %1x ", SUBOP_GET_S(subop), SUBOP_GET_T(subop));
mask = 0x000000ff;
break;
case SUB_M:
case SUB_VM:
case SUB_MV:
printf("%1x %1x %1x ", SUBOP_GET_S2(subop), SUBOP_GET_S1(subop),
SUBOP_GET_T1(subop));
mask = 0x0000f0ff;
break;
case SUB_Z:
printf("%1x %1x %1x ", SUBOP_GET_S2(subop), SUBOP_GET_S1(subop),
SUBOP_GET_T1(subop));
mask = SUBOP_GET_MASK(subop);
nn = SUBOP_GET_S2(subop);
if (nn == 0)
nn = 1; // var.x is scalar, not array[1]
s[nn] = '\0';
for (ii = 0; ii < nn; ii++)
s[ii] = "xyzw"[(mask >> ii*2) & 3];
mask = 0x00fff0ff;
HasString = 1;
break;
case SUB_ZM:
printf("%1x %1x %1x %1x ", SUBOP_GET_S2(subop), SUBOP_GET_T2(subop),
SUBOP_GET_S1(subop), SUBOP_GET_T1(subop));
mask = SUBOP_GET_MASK16(subop);
nn = SUBOP_GET_T2(subop);
if (nn == 0)
nn = 1; // var.x is scalar, not array[1]
s[nn*3] = '\0';
for (ii = 0; ii < nn; ii++) {
s[ii*3] = '_';
s[ii*3 + 1] = '0' + ((mask >> (ii*4 + 2)) & 3);
s[ii*3 + 2] = '0' + ((mask >> ii*4) & 3);
}
mask = 0xffffffff;
HasString = 1;
break;
case SUB_CS:
printf("%1x - %1x ", SUBOP_GET_T2(subop), SUBOP_GET_T1(subop));
mask = 0x00000f0f;
break;
case SUB_CV:
printf("%1x %1x %1x ", SUBOP_GET_T2(subop), SUBOP_GET_S1(subop),
SUBOP_GET_T1(subop));
mask = 0x00000fff;
break;
case SUB_CM:
printf("%1x %1x %1x %1x ", SUBOP_GET_S2(subop), SUBOP_GET_T2(subop),
SUBOP_GET_S1(subop), SUBOP_GET_T1(subop));
mask = 0x0000ffff;
break;
case SUB_KV:
printf("- %1x %1x ", SUBOP_GET_S(subop), SUBOP_GET_T(subop));
mask = SUBOP_GET_MASK(subop) & 0xf;
for (ii = 0; ii < 4; ii++)
printf("%c", (mask >> ii) & 1 ? "xyzw"[ii] : '-');
printf(" ");
mask = 0x000f00ff;
break;
default:
mask = 0;
break;
}
if (subop & ~mask)
printf("<<non-zero:%08x>> ", subop & ~mask);
printf("%-6s ", opcode_name[fexpr->co.op]);
switch (fexpr->common.kind) {
case SYMB_N:
printf("\"%s\"", GetAtomString(atable, fexpr->sym.symbol->name));
break;
case CONST_N:
switch (fexpr->co.op) {
case ICONST_OP:
printf("%d", fexpr->co.val[0].i);
break;
case ICONST_V_OP:
nn = SUBOP_GET_S(subop);
printf("{ ");
for (ii = 0; ii < nn; ii++) {
if (ii > 0)
printf(", ");
printf("%d", fexpr->co.val[ii].i);
}
printf(" }");
break;
case BCONST_OP:
bval = fexpr->co.val[0].i;
if (bval == 0) {
printf("false");
} else if (bval == 1) {
printf("true");
} else {
printf("<<bad-bool-%08x>>", fexpr->co.val[0].i);
}
break;
case BCONST_V_OP:
nn = SUBOP_GET_S(subop);
printf("{ ");
for (ii = 0; ii < nn; ii++) {
if (ii > 0)
printf(", ");
bval = fexpr->co.val[ii].i;
if (bval == 0) {
printf("false");
} else if (bval == 1) {
printf("true");
} else {
printf("<<bad-bool-%08x>>", fexpr->co.val[ii].i);
}
}
printf(" }");
break;
case FCONST_OP:
case HCONST_OP:
case XCONST_OP:
printf("%1.6g", fexpr->co.val[0].f);
break;
case FCONST_V_OP:
case HCONST_V_OP:
case XCONST_V_OP:
nn = SUBOP_GET_S(subop);
printf("{ ");
for (ii = 0; ii < nn; ii++) {
if (ii > 0)
printf(", ");
printf("%1.6g", fexpr->co.val[ii].f);
}
printf(" }");
break;
default:
printf("UNKNOWN-CONSTANT");
break;
}
break;
case UNARY_N:
break;
case BINARY_N:
break;
case TRINARY_N:
break;
}
if (HasString)
printf(" %s", s);
printf(" ");
PrintType(fexpr->common.type, 1);
printf("\n");
switch (fexpr->common.kind) {
case SYMB_N:
break;
case CONST_N:
break;
case UNARY_N:
lBPrintExpression(fexpr->un.arg, level + 1);
break;
case BINARY_N:
lBPrintExpression(fexpr->bin.left, level + 1);
lBPrintExpression(fexpr->bin.right, level + 1);
break;
case TRINARY_N:
lBPrintExpression(fexpr->tri.arg1, level + 1);
lBPrintExpression(fexpr->tri.arg2, level + 1);
lBPrintExpression(fexpr->tri.arg3, level + 1);
break;
}
} else {
printf("\n");
}
} else {
printf("NULL\n");
}
} // lBPrintExpression
void BPrintExpression(expr *fexpr)
{
lBPrintExpression(fexpr, 0);
}
static void lBPrintStmt(stmt *fstmt, int level);
/*
* lBPrintStmtList()
*
*/
void lBPrintStmtList(stmt *fstmt, int level)
{
while (fstmt) {
lBPrintStmt(fstmt, level);
fstmt = fstmt->commonst.next;
}
} // lBPrintStmtList
void BPrintStmtList(stmt *fstmt)
{
lBPrintStmtList(fstmt, 0);
}
/*
* lBPrintStmt()
*
*/
static void lBPrintStmt(stmt *fstmt, int level)
{
stmt *lstmt;
switch (fstmt->exprst.kind) {
case EXPR_STMT:
if (fstmt->exprst.exp) {
lBPrintExpression(fstmt->exprst.exp, level);
} else {
printf("/* empty statement */\n");
}
break;
case IF_STMT:
lIndent(level);
printf("if\n");
lBPrintExpression(fstmt->ifst.cond, level + 1);
lIndent(level);
printf("then\n");
lBPrintStmtList(fstmt->ifst.thenstmt, level + 1);
if (fstmt->ifst.elsestmt) {
lIndent(level);
printf("else\n");
lBPrintStmtList(fstmt->ifst.elsestmt, level + 1);
}
break;
case WHILE_STMT:
lIndent(level);
printf("while\n");
lBPrintExpression(fstmt->whilest.cond, level + 1);
lBPrintStmtList(fstmt->whilest.body, level + 1);
break;
case DO_STMT:
lIndent(level);
printf("do\n");
lBPrintStmtList(fstmt->whilest.body, level + 1);
lIndent(level);
printf("while\n");
lBPrintExpression(fstmt->whilest.cond, level + 1);
break;
case FOR_STMT:
lIndent(level);
printf("for\n");
lstmt = fstmt->forst.init;
if (lstmt) {
lBPrintStmtList(fstmt->forst.init, level + 1);
}
printf("for-cond\n");
if (fstmt->forst.cond) {
lBPrintExpression(fstmt->forst.cond, level + 1);
}
printf("for-step\n");
lstmt = fstmt->forst.step;
if (lstmt) {
lBPrintStmtList(fstmt->forst.step, level + 1);
}
printf("for-body\n");
lBPrintStmtList(fstmt->forst.body, level + 1);
break;
case BLOCK_STMT:
if (level > 1)
lIndent(level - 1);
printf("{\n");
lBPrintStmtList(fstmt->blockst.body, level);
if (level > 1)
lIndent(level - 1);
printf("}\n");
break;
case RETURN_STMT:
lIndent(level);
printf("return\n");
if (fstmt->returnst.exp) {
lBPrintExpression(fstmt->returnst.exp, level + 1);
}
break;
case DISCARD_STMT:
lIndent(level);
printf("discard\n");
if (fstmt->discardst.cond)
lBPrintExpression(fstmt->discardst.cond, level + 1);
break;
case COMMENT_STMT:
lIndent(level);
printf("// %s\n", GetAtomString(atable, fstmt->commentst.str));
break;
default:
lIndent(level);
printf("<!BadStmt-0x%2x>\n", fstmt->exprst.kind);
}
} // lBPrintStmt
void BPrintStmt(stmt *fstmt)
{
lBPrintStmt(fstmt, 0);
}
/*
* FormatTypeString() - Build a printable string of a type.
*
* Arrays are shown as: "packed float[4]" instead of "float4".
*
*/
void FormatTypeString(char *name, int size, char *name2, int size2, Type *fType)
{
int qualifiers, category, base, cid;
char tname[32];
strcpy(name2, "");
if (fType) {
strcpy(name, "");
base = GetBase(fType);
qualifiers = GetQualifiers(fType);
if (qualifiers & TYPE_QUALIFIER_CONST)
strcat(name, "const ");
if ((qualifiers & TYPE_QUALIFIER_INOUT) == TYPE_QUALIFIER_INOUT) {
strcat(name, "inout ");
} else {
if (qualifiers & TYPE_QUALIFIER_IN)
strcat(name, "in ");
if (qualifiers & TYPE_QUALIFIER_OUT)
strcat(name, "out ");
}
category = GetCategory(fType);
switch (category) {
case TYPE_CATEGORY_NONE:
strcat(name, "<<category=NONE>>");
break;
case TYPE_CATEGORY_SCALAR:
strcat(name, GetBaseTypeNameString(base));
break;
case TYPE_CATEGORY_ARRAY:
FormatTypeString(name, size, name2, size2, fType->arr.eltype);
sprintf(tname, "[%d]", fType->arr.numels);
strcat(name2, tname);
break;
case TYPE_CATEGORY_FUNCTION:
strcat(name, "FUNCTION");
break;
case TYPE_CATEGORY_STRUCT:
strcat(name, "struct ");
strcat(name, GetAtomString(atable, fType->str.tag));
break;
case TYPE_CATEGORY_CONNECTOR:
cid = Cg->theHAL->GetConnectorAtom(fType->str.variety);
strcat(name, GetAtomString(atable, cid));
strcat(name, " connector ");
strcat(name, GetAtomString(atable, fType->str.tag));
break;
default:
strcat(name, "<<bad-category>>");
break;
}
} else {
strcpy(name, "<<NULL>>");
}
} // FormatTypeString
/*
* FormatTypeStringRT() - Build a printable string of a type for export to the run-time.
*
* Arrays are shown as predefined typedefs: "float4" instead of "packed float[4]"
*
*/
void FormatTypeStringRT(char *name, int size, char *name2, int size2, Type *fType, int Unqualified)
{
int qualifiers, category, base, cid;
char tname[32];
int len, len2;
strcpy(name2, "");
if (fType) {
strcpy(name, "");
base = GetBase(fType);
if (!Unqualified) {
qualifiers = GetQualifiers(fType);
if (qualifiers & TYPE_QUALIFIER_CONST)
strcat(name, "const ");
if ((qualifiers & TYPE_QUALIFIER_INOUT) == TYPE_QUALIFIER_INOUT) {
strcat(name, "inout ");
} else {
if (qualifiers & TYPE_QUALIFIER_IN)
strcat(name, "in ");
if (qualifiers & TYPE_QUALIFIER_OUT)
strcat(name, "out ");
}
}
category = GetCategory(fType);
switch (category) {
case TYPE_CATEGORY_NONE:
strcat(name, "<<category=NONE>>");
break;
case TYPE_CATEGORY_SCALAR:
strcat(name, GetBaseTypeNameString(base));
break;
case TYPE_CATEGORY_ARRAY:
if (IsMatrix(fType, &len, &len2)) {
strcat(name, GetBaseTypeNameString(base));
sprintf(tname, "%dx%d", len2, len);
strcat(name, tname);
} else if (IsVector(fType, &len)) {
strcat(name, GetBaseTypeNameString(base));
tname[0] = '0' + len;
tname[1] = '\0';
strcat(name, tname);
} else {
FormatTypeStringRT(name, size, name2, size2, fType->arr.eltype, Unqualified);
sprintf(tname, "[%d]", fType->arr.numels);
strcat(name2, tname);
}
break;
case TYPE_CATEGORY_FUNCTION:
strcat(name, "FUNCTION");
break;
case TYPE_CATEGORY_STRUCT:
strcat(name, "struct ");
strcat(name, GetAtomString(atable, fType->str.tag));
break;
case TYPE_CATEGORY_CONNECTOR:
cid = Cg->theHAL->GetConnectorAtom(fType->str.variety);
strcat(name, GetAtomString(atable, cid));
strcat(name, " connector ");
strcat(name, GetAtomString(atable, fType->str.tag));
break;
default:
strcat(name, "<<bad-category>>");
break;
}
} else {
strcpy(name, "<<NULL>>");
}
} // FormatTypeStringRT
/*
* PrintType()
*
*/
void PrintType(Type *fType, int level)
{
int base, category, qualifiers, domain, cid;
TypeList *lTypeList;
if (fType) {
qualifiers = GetQualifiers(fType);
if (qualifiers & TYPE_QUALIFIER_CONST)
printf("const ");
if (qualifiers & TYPE_QUALIFIER_IN)
printf("in ");
if (qualifiers & TYPE_QUALIFIER_OUT)
printf("out ");
domain = GetDomain(fType);
switch (domain) {
case TYPE_DOMAIN_UNKNOWN:
break;
case TYPE_DOMAIN_UNIFORM:
printf("uniform ");
break;
case TYPE_DOMAIN_VARYING:
printf("varying ");
break;
default:
printf("<<domain=%02x>>", domain >> TYPE_DOMAIN_SHIFT);
break;
}
category = GetCategory(fType);
switch (category) {
case TYPE_CATEGORY_NONE:
printf("<<category=NONE>>");
break;
case TYPE_CATEGORY_SCALAR:
base = GetBase(fType);
printf("%s", GetBaseTypeNameString(base));
break;
case TYPE_CATEGORY_ARRAY:
PrintType(fType->arr.eltype, level);
printf("[%d]", fType->arr.numels);
break;
case TYPE_CATEGORY_FUNCTION:
printf("(");
lTypeList = fType->fun.paramtypes;
while (lTypeList) {
PrintType(lTypeList->type, level);
lTypeList = lTypeList->next;
if (lTypeList)
printf(", ");
}
printf(")");
break;
case TYPE_CATEGORY_STRUCT:
if (fType->str.tag) {
printf("struct %s", GetAtomString(atable, fType->str.tag));
} else {
printf("struct");
}
break;
case TYPE_CATEGORY_CONNECTOR:
if (fType->str.tag) {
cid = Cg->theHAL->GetConnectorAtom(fType->str.variety);
printf("%s connector %s",
GetAtomString(atable, cid),
GetAtomString(atable, fType->str.tag));
} else {
printf("connector");
}
break;
default:
printf("<<category=%02x>>", category >> TYPE_CATEGORY_SHIFT);
break;
}
//printf(" ");
} else {
printf("<<NULL-TYPE>>");
}
} // PrintType
/*
* PrintSymbolTree()
*
*/
void PrintSymbolTree(Symbol *fSymb)
{
Symbol *lSymb;
int DoType;
if (fSymb) {
DoType = 1;
PrintSymbolTree(fSymb->left);
switch (fSymb->kind) {
case TYPEDEF_S:
printf("TYP: %s : %d:%d", GetAtomString(atable, fSymb->name),
Cg->theHAL->GetSizeof(fSymb->type), Cg->theHAL->GetAlignment(fSymb->type));
break;
case VARIABLE_S:
if (fSymb->properties & SYMB_IS_PARAMETER) {
printf("PAR: %s ", GetAtomString(atable, fSymb->name));
} else {
printf("VAR: %s ", GetAtomString(atable, fSymb->name));
}
break;
case CONSTANT_S:
printf("CON: %s ", GetAtomString(atable, fSymb->name));
break;
case FUNCTION_S:
lSymb = fSymb;
while (lSymb) {
if (lSymb == fSymb) {
printf("FUN");
} else {
printf(" ");
}
printf(": %s ", GetAtomString(atable, fSymb->name));
PrintType(lSymb->type, 0);
if (!lSymb->properties & SYMB_IS_DEFINED)
printf(" UNDEFINED");
if (lSymb->properties & SYMB_IS_BUILTIN)
printf(" BUILTIN");
if (lSymb->properties & SYMB_IS_INLINE_FUNCTION)
printf(" INLINE");
printf("\n");
lSymb = lSymb->details.fun.overload;
}
DoType = 0;
break;
default:
printf("???%04x???: %s ", fSymb->kind, GetAtomString(atable, fSymb->name));
break;
}
if (DoType) {
PrintType(fSymb->type, 0);
printf("\n");
}
PrintSymbolTree(fSymb->right);
}
} // PrintSymbolTree
/*
* PrintScopeDeclarations()
*
*/
void PrintScopeDeclarations(void)
{
printf("*** Scope %d definitions: ***\n", CurrentScope->level);
PrintSymbolTree(CurrentScope->symbols);
printf("*** End of Scope %d ***\n\n", CurrentScope->level);
} // PrintScopeDeclarations
/*
* lPrintExpr()
*
*/
void lPrintExpr(expr *fexpr)
{
int ii, mask, len;
unsigned int uval;
char s[16], tag;
switch (fexpr->common.kind) {
case SYMB_N:
printf("%s", GetAtomString(atable, fexpr->sym.symbol->name));
break;
case CONST_N:
switch (fexpr->co.op) {
case ICONST_OP:
printf("%d", fexpr->co.val[0].i);
break;
case ICONST_V_OP:
printf("{ %d", fexpr->co.val[0].i);
len = SUBOP_GET_S(fexpr->co.subop);
for (ii = 1; ii < len; ii++)
printf(", %d", fexpr->co.val[ii].i);
printf(" }");
break;
case BCONST_OP:
if (fexpr->co.val[0].i == 0) {
printf("false");
} else if (fexpr->co.val[0].i == 1) {
printf("true");
} else {
printf("<<BBCONST=%d>>", fexpr->co.val[0].i);
}
break;
case BCONST_V_OP:
printf("{ ");
len = SUBOP_GET_S(fexpr->co.subop);
for (ii = 0; ii < len; ii++)
if (ii) printf(", ");
if (fexpr->co.val[ii].i == 0) {
printf("false");
} else if (fexpr->co.val[ii].i == 1) {
printf("true");
} else {
printf("<<BBCONST=%d>>", fexpr->co.val[ii].i);
}
printf(" }");
break;
case FCONST_OP:
printf("%.6gf", fexpr->co.val[0].f);
break;
case HCONST_OP:
printf("%.6gh", fexpr->co.val[0].f);
break;
case XCONST_OP:
printf("%.6gx", fexpr->co.val[0].f);
break;
case FCONST_V_OP:
tag = 'f';
goto floatvec;
case HCONST_V_OP:
tag = 'h';
goto floatvec;
case XCONST_V_OP:
tag = 'x';
floatvec:
printf("{ %.6g%c", fexpr->co.val[0].f, tag);
len = SUBOP_GET_S(fexpr->co.subop);
for (ii = 1; ii < len; ii++)
printf(", %.6g%c", fexpr->co.val[ii].f, tag);
printf(" }");
break;
}
break;
case UNARY_N:
switch (fexpr->un.op) {
case CAST_CS_OP:
printf("(%s) ", GetBaseTypeNameString(SUBOP_GET_T2(fexpr->un.subop)));
break;
case CAST_CV_OP:
printf("(%s [%d]) ",
GetBaseTypeNameString(SUBOP_GET_T2(fexpr->un.subop)),
SUBOP_GET_S1(fexpr->un.subop));
break;
case CAST_CM_OP:
printf("(%s [%d][%d]) ",
GetBaseTypeNameString(SUBOP_GET_T2(fexpr->un.subop)),
SUBOP_GET_S2(fexpr->un.subop), SUBOP_GET_S1(fexpr->un.subop));
break;
case VECTOR_V_OP:
printf("{ ");
break;
case NEG_OP:
case NEG_V_OP:
printf("-");
break;
case POS_OP:
case POS_V_OP:
printf("+");
break;
case NOT_OP:
case NOT_V_OP:
printf("~");
break;
case BNOT_OP:
case BNOT_V_OP:
printf("!");
break;
case SWIZZLE_Z_OP:
case SWIZMAT_Z_OP:
break;
case PREDEC_OP:
printf("--");
break;
case PREINC_OP:
printf("++");
break;
}
lPrintExpr(fexpr->un.arg);
switch (fexpr->un.op) {
case SWIZZLE_Z_OP:
mask = SUBOP_GET_MASK(fexpr->un.subop);
ii = SUBOP_GET_S2(fexpr->un.subop);
if (ii == 0)
ii = 1; // var.x is scalar, not array[1]
s[ii] = '\0';
while (ii > 0) {
ii--;
s[ii] = "xyzw"[(mask >> ii*2) & 3];
}
printf(".%s", s);
break;
case SWIZMAT_Z_OP:
mask = SUBOP_GET_MASK16(fexpr->un.subop);
ii = SUBOP_GET_T2(fexpr->un.subop);
if (ii == 0)
ii = 1; // var.x is scalar, not array[1]
s[ii*3] = '\0';
while (ii > 0) {
ii--;
uval = (mask >> ii*4) & 15;
s[ii*3] = '_';
s[ii*3 + 1] = '0' + ((uval >> 2) & 3);
s[ii*3 + 2] = '0' + (uval & 3);
}
printf(".m%s", s);
break;
case VECTOR_V_OP:
printf(" }");
break;
case POSTDEC_OP:
printf("--");
break;
case POSTINC_OP:
printf("++");
break;
}
break;
case BINARY_N:
lPrintExpr(fexpr->bin.left);
switch (fexpr->bin.op) {
case MEMBER_SELECTOR_OP:
printf(".");
break;
case ARRAY_INDEX_OP:
printf("[");
break;
case FUN_CALL_OP:
case FUN_BUILTIN_OP:
printf("(");
break;
case FUN_ARG_OP:
case EXPR_LIST_OP:
if (fexpr->bin.right)
printf(", ");
break;
case MUL_OP:
case MUL_SV_OP:
case MUL_VS_OP:
case MUL_V_OP:
printf("*");
break;
case DIV_OP:
case DIV_SV_OP:
case DIV_VS_OP:
case DIV_V_OP:
printf("/");
break;
case MOD_OP:
case MOD_SV_OP:
case MOD_VS_OP:
case MOD_V_OP:
printf("%");
break;
case ADD_OP:
case ADD_SV_OP:
case ADD_VS_OP:
case ADD_V_OP:
printf(" + ");
break;
case SUB_OP:
case SUB_SV_OP:
case SUB_VS_OP:
case SUB_V_OP:
printf(" - ");
break;
case SHL_OP:
case SHL_V_OP:
printf(" << ");
break;
case SHR_OP:
case SHR_V_OP:
printf(" >> ");
break;
case LT_OP:
case LT_SV_OP:
case LT_VS_OP:
case LT_V_OP:
printf(" < ");
break;
case GT_OP:
case GT_SV_OP:
case GT_VS_OP:
case GT_V_OP:
printf(" > ");
break;
case LE_OP:
case LE_SV_OP:
case LE_VS_OP:
case LE_V_OP:
printf(" <= ");
break;
case GE_OP:
case GE_SV_OP:
case GE_VS_OP:
case GE_V_OP:
printf(" >= ");
break;
case EQ_OP:
case EQ_SV_OP:
case EQ_VS_OP:
case EQ_V_OP:
printf(" == ");
break;
case NE_OP:
case NE_SV_OP:
case NE_VS_OP:
case NE_V_OP:
printf(" != ");
break;
case AND_OP:
case AND_SV_OP:
case AND_VS_OP:
case AND_V_OP:
printf(" & ");
break;
case XOR_OP: