3
* Dump/print a slang_operation tree
8
#include "slang_compile.h"
9
#include "slang_print.h"
21
print_type(const slang_fully_specified_type *t)
23
switch (t->qualifier) {
27
case SLANG_QUAL_CONST:
30
case SLANG_QUAL_ATTRIBUTE:
33
case SLANG_QUAL_VARYING:
36
case SLANG_QUAL_UNIFORM:
42
case SLANG_QUAL_INOUT:
45
case SLANG_QUAL_FIXEDOUTPUT:
46
printf("fixedoutput");
48
case SLANG_QUAL_FIXEDINPUT:
52
printf("unknown qualifer!");
55
switch (t->specifier.type) {
62
case SLANG_SPEC_BVEC2:
65
case SLANG_SPEC_BVEC3:
68
case SLANG_SPEC_BVEC4:
74
case SLANG_SPEC_IVEC2:
77
case SLANG_SPEC_IVEC3:
80
case SLANG_SPEC_IVEC4:
83
case SLANG_SPEC_FLOAT:
101
case SLANG_SPEC_MAT4:
104
case SLANG_SPEC_MAT23:
107
case SLANG_SPEC_MAT32:
110
case SLANG_SPEC_MAT24:
113
case SLANG_SPEC_MAT42:
116
case SLANG_SPEC_MAT34:
119
case SLANG_SPEC_MAT43:
122
case SLANG_SPEC_SAMPLER1D:
125
case SLANG_SPEC_SAMPLER2D:
128
case SLANG_SPEC_SAMPLER3D:
131
case SLANG_SPEC_SAMPLERCUBE:
132
printf("samplerCube");
134
case SLANG_SPEC_SAMPLER1DSHADOW:
135
printf("sampler1DShadow");
137
case SLANG_SPEC_SAMPLER2DSHADOW:
138
printf("sampler2DShadow");
140
case SLANG_SPEC_STRUCT:
143
case SLANG_SPEC_ARRAY:
147
printf("unknown type");
154
print_variable(const slang_variable *v, int indent)
158
print_type(&v->type);
159
printf(" %s", (char *) v->a_name);
160
if (v->initializer) {
162
slang_print_tree(v->initializer, indent + 3);
171
print_binary(const slang_operation *op, const char *oper, int indent)
173
assert(op->num_children == 2);
174
slang_print_tree(&op->children[0], indent + 3);
176
printf("%s\n", oper);
177
slang_print_tree(&op->children[1], indent + 3);
182
print_generic2(const slang_operation *op, const char *oper,
183
const char *s, int indent)
188
printf("[%p locals %p] %s %s\n", (void*) op, (void*) op->locals, oper, s);
190
for (i = 0; i < op->num_children; i++) {
192
printf("//child %d:\n", i);
193
slang_print_tree(&op->children[i], indent);
198
print_generic(const slang_operation *op, const char *oper, int indent)
200
print_generic2(op, oper, "", indent);
204
static const slang_variable_scope *
205
find_scope(const slang_variable_scope *s, slang_atom name)
208
for (i = 0; i < s->num_variables; i++) {
209
if (s->variables[i]->a_name == name)
213
return find_scope(s->outer_scope, name);
218
static const slang_variable *
219
find_var(const slang_variable_scope *s, slang_atom name)
222
for (i = 0; i < s->num_variables; i++) {
223
if (s->variables[i]->a_name == name)
224
return s->variables[i];
227
return find_var(s->outer_scope, name);
234
slang_print_tree(const slang_operation *op, int indent)
240
case SLANG_OPER_NONE:
242
printf("SLANG_OPER_NONE\n");
245
case SLANG_OPER_BLOCK_NO_NEW_SCOPE:
247
printf("{ locals %p outer %p\n", (void*)op->locals, (void*)op->locals->outer_scope);
248
print_generic(op, NULL, indent+3);
253
case SLANG_OPER_BLOCK_NEW_SCOPE:
255
printf("{{ // new scope locals %p\n", (void*)op->locals);
256
print_generic(op, NULL, indent+3);
261
case SLANG_OPER_VARIABLE_DECL:
262
assert(op->num_children == 0 || op->num_children == 1);
265
v = _slang_locate_variable(op->locals, op->a_id, GL_TRUE);
268
printf("DECL (locals=%p outer=%p) ", (void*)op->locals, (void*) op->locals->outer_scope);
269
print_type(&v->type);
270
printf(" %s (%p)", (char *) op->a_id,
271
(void *) find_var(op->locals, op->a_id));
273
printf(" (in scope %p) ",
274
(void *) find_scope(op->locals, op->a_id));
275
if (op->num_children == 1) {
277
slang_print_tree(&op->children[0], indent + 3);
279
else if (v->initializer) {
280
printf(" := INITIALIZER\n");
281
slang_print_tree(v->initializer, indent + 3);
289
print_type(&v->type);
291
printf("ADDR: %d size: %d\n", v->address, v->size);
296
printf("DECL %s (anonymous variable!!!!)\n", (char *) op->a_id);
303
printf("ASM: %s\n", (char*) op->a_id);
304
print_generic(op, NULL, indent+3);
307
case SLANG_OPER_BREAK:
312
case SLANG_OPER_CONTINUE:
314
printf("CONTINUE\n");
317
case SLANG_OPER_DISCARD:
322
case SLANG_OPER_RETURN:
325
if (op->num_children > 0)
326
slang_print_tree(&op->children[0], indent + 3);
329
case SLANG_OPER_LABEL:
331
printf("LABEL %s\n", (char *) op->a_id);
334
case SLANG_OPER_EXPRESSION:
336
printf("EXPR: locals %p\n", (void*) op->locals);
337
/*print_generic(op, "SLANG_OPER_EXPRESSION", indent);*/
338
slang_print_tree(&op->children[0], indent + 3);
344
slang_print_tree(&op->children[0], indent + 3);
347
slang_print_tree(&op->children[1], indent + 3);
350
slang_print_tree(&op->children[2], indent + 3);
355
case SLANG_OPER_WHILE:
356
assert(op->num_children == 2);
358
printf("WHILE cond:\n");
359
slang_print_tree(&op->children[0], indent + 3);
361
printf("WHILE body:\n");
362
slang_print_tree(&op->children[1], indent + 3);
367
printf("DO body:\n");
368
slang_print_tree(&op->children[0], indent + 3);
370
printf("DO cond:\n");
371
slang_print_tree(&op->children[1], indent + 3);
376
printf("FOR init:\n");
377
slang_print_tree(&op->children[0], indent + 3);
379
printf("FOR while:\n");
380
slang_print_tree(&op->children[1], indent + 3);
382
printf("FOR step:\n");
383
slang_print_tree(&op->children[2], indent + 3);
385
printf("FOR body:\n");
386
slang_print_tree(&op->children[3], indent + 3);
390
print_generic(op, "FOR", indent + 3);
394
case SLANG_OPER_VOID:
396
printf("(oper-void)\n");
399
case SLANG_OPER_LITERAL_BOOL:
402
for (i = 0; i < op->literal_size; i++)
403
printf("%s ", op->literal[0] ? "TRUE" : "FALSE");
408
case SLANG_OPER_LITERAL_INT:
411
for (i = 0; i < op->literal_size; i++)
412
printf("%d ", (int) op->literal[i]);
416
case SLANG_OPER_LITERAL_FLOAT:
419
for (i = 0; i < op->literal_size; i++)
420
printf("%f ", op->literal[i]);
424
case SLANG_OPER_IDENTIFIER:
426
if (op->var && op->var->a_name)
427
printf("VAR %s (in scope %p)\n", (char *) op->var->a_name,
428
(void *) find_scope(op->locals, op->a_id));
430
printf("VAR' %s (in scope %p)\n", (char *) op->a_id,
431
(void *) find_scope(op->locals, op->a_id));
434
case SLANG_OPER_SEQUENCE:
435
print_generic(op, "COMMA-SEQ", indent+3);
438
case SLANG_OPER_ASSIGN:
440
printf("ASSIGNMENT locals %p\n", (void*)op->locals);
441
print_binary(op, ":=", indent);
444
case SLANG_OPER_ADDASSIGN:
447
print_binary(op, "+=", indent);
450
case SLANG_OPER_SUBASSIGN:
453
print_binary(op, "-=", indent);
456
case SLANG_OPER_MULASSIGN:
459
print_binary(op, "*=", indent);
462
case SLANG_OPER_DIVASSIGN:
465
print_binary(op, "/=", indent);
468
/*SLANG_OPER_MODASSIGN,*/
469
/*SLANG_OPER_LSHASSIGN,*/
470
/*SLANG_OPER_RSHASSIGN,*/
471
/*SLANG_OPER_ORASSIGN,*/
472
/*SLANG_OPER_XORASSIGN,*/
473
/*SLANG_OPER_ANDASSIGN,*/
474
case SLANG_OPER_SELECT:
476
printf("SLANG_OPER_SELECT n=%d\n", op->num_children);
477
assert(op->num_children == 3);
478
slang_print_tree(&op->children[0], indent+3);
481
slang_print_tree(&op->children[1], indent+3);
484
slang_print_tree(&op->children[2], indent+3);
487
case SLANG_OPER_LOGICALOR:
488
print_binary(op, "||", indent);
491
case SLANG_OPER_LOGICALXOR:
492
print_binary(op, "^^", indent);
495
case SLANG_OPER_LOGICALAND:
496
print_binary(op, "&&", indent);
500
/*SLANG_OPER_BITXOR*/
501
/*SLANG_OPER_BITAND*/
502
case SLANG_OPER_EQUAL:
503
print_binary(op, "==", indent);
506
case SLANG_OPER_NOTEQUAL:
507
print_binary(op, "!=", indent);
510
case SLANG_OPER_LESS:
511
print_binary(op, "<", indent);
514
case SLANG_OPER_GREATER:
515
print_binary(op, ">", indent);
518
case SLANG_OPER_LESSEQUAL:
519
print_binary(op, "<=", indent);
522
case SLANG_OPER_GREATEREQUAL:
523
print_binary(op, ">=", indent);
526
/*SLANG_OPER_LSHIFT*/
527
/*SLANG_OPER_RSHIFT*/
529
print_binary(op, "+", indent);
532
case SLANG_OPER_SUBTRACT:
533
print_binary(op, "-", indent);
536
case SLANG_OPER_MULTIPLY:
537
print_binary(op, "*", indent);
540
case SLANG_OPER_DIVIDE:
541
print_binary(op, "/", indent);
544
/*SLANG_OPER_MODULUS*/
545
case SLANG_OPER_PREINCREMENT:
548
slang_print_tree(&op->children[0], indent+3);
551
case SLANG_OPER_PREDECREMENT:
554
slang_print_tree(&op->children[0], indent+3);
557
case SLANG_OPER_PLUS:
559
printf("SLANG_OPER_PLUS\n");
562
case SLANG_OPER_MINUS:
564
printf("SLANG_OPER_MINUS\n");
567
/*SLANG_OPER_COMPLEMENT*/
571
slang_print_tree(&op->children[0], indent+3);
574
case SLANG_OPER_SUBSCRIPT:
576
printf("SLANG_OPER_SUBSCRIPT\n");
577
print_generic(op, NULL, indent+3);
580
case SLANG_OPER_CALL:
583
= _slang_locate_function(A->space.funcs, oper->a_id,
585
oper->num_children, &A->space, A->atoms);
588
printf("CALL %s(\n", (char *) op->a_id);
589
for (i = 0; i < op->num_children; i++) {
590
slang_print_tree(&op->children[i], indent+3);
591
if (i + 1 < op->num_children) {
600
case SLANG_OPER_FIELD:
602
printf("FIELD %s of\n", (char*) op->a_id);
603
slang_print_tree(&op->children[0], indent+3);
606
case SLANG_OPER_POSTINCREMENT:
609
slang_print_tree(&op->children[0], indent+3);
612
case SLANG_OPER_POSTDECREMENT:
615
slang_print_tree(&op->children[0], indent+3);
619
printf("unknown op->type %d\n", (int) op->type);
627
slang_print_function(const slang_function *f, GLboolean body)
632
if (_mesa_strcmp((char *) f->header.a_name, "main") != 0)
636
printf("FUNCTION %s (\n",
637
(char *) f->header.a_name);
639
for (i = 0; i < f->param_count; i++) {
640
print_variable(f->parameters->variables[i], 3);
645
slang_print_tree(f->body, 0);
653
slang_type_qual_string(slang_type_qualifier q)
656
case SLANG_QUAL_NONE:
658
case SLANG_QUAL_CONST:
660
case SLANG_QUAL_ATTRIBUTE:
662
case SLANG_QUAL_VARYING:
664
case SLANG_QUAL_UNIFORM:
668
case SLANG_QUAL_INOUT:
670
case SLANG_QUAL_FIXEDOUTPUT:
671
return "fixedoutput";
672
case SLANG_QUAL_FIXEDINPUT:
673
return "fixedinputk";
681
slang_type_string(slang_type_specifier_type t)
684
case SLANG_SPEC_VOID:
686
case SLANG_SPEC_BOOL:
688
case SLANG_SPEC_BVEC2:
690
case SLANG_SPEC_BVEC3:
692
case SLANG_SPEC_BVEC4:
696
case SLANG_SPEC_IVEC2:
698
case SLANG_SPEC_IVEC3:
700
case SLANG_SPEC_IVEC4:
702
case SLANG_SPEC_FLOAT:
704
case SLANG_SPEC_VEC2:
706
case SLANG_SPEC_VEC3:
708
case SLANG_SPEC_VEC4:
710
case SLANG_SPEC_MAT2:
712
case SLANG_SPEC_MAT3:
714
case SLANG_SPEC_MAT4:
716
case SLANG_SPEC_SAMPLER1D:
718
case SLANG_SPEC_SAMPLER2D:
720
case SLANG_SPEC_SAMPLER3D:
722
case SLANG_SPEC_SAMPLERCUBE:
723
return "samplerCube";
724
case SLANG_SPEC_SAMPLER1DSHADOW:
725
return "sampler1DShadow";
726
case SLANG_SPEC_SAMPLER2DSHADOW:
727
return "sampler2DShadow";
728
case SLANG_SPEC_SAMPLER2DRECT:
729
return "sampler2DRect";
730
case SLANG_SPEC_SAMPLER2DRECTSHADOW:
731
return "sampler2DRectShadow";
732
case SLANG_SPEC_STRUCT:
734
case SLANG_SPEC_ARRAY:
743
slang_fq_type_string(const slang_fully_specified_type *t)
745
static char str[1000];
746
sprintf(str, "%s %s", slang_type_qual_string(t->qualifier),
747
slang_type_string(t->specifier.type));
753
slang_print_type(const slang_fully_specified_type *t)
755
printf("%s %s", slang_type_qual_string(t->qualifier),
756
slang_type_string(t->specifier.type));
762
slang_var_string(const slang_variable *v)
764
static char str[1000];
765
sprintf(str, "%s : %s",
767
slang_fq_type_string(&v->type));
774
slang_print_variable(const slang_variable *v)
776
printf("Name: %s\n", (char *) v->a_name);
777
printf("Type: %s\n", slang_fq_type_string(&v->type));
782
_slang_print_var_scope(const slang_variable_scope *vars, int indent)
787
printf("Var scope %p %d vars:\n", (void *) vars, vars->num_variables);
788
for (i = 0; i < vars->num_variables; i++) {
790
printf("%s (at %p)\n", (char *) vars->variables[i]->a_name, (void*) (vars->variables + i));
793
printf("outer_scope = %p\n", (void*) vars->outer_scope);
795
if (vars->outer_scope) {
796
/*spaces(indent + 3);*/
797
_slang_print_var_scope(vars->outer_scope, indent + 3);
804
slang_checksum_tree(const slang_operation *op)
806
int s = op->num_children;
809
for (i = 0; i < op->num_children; i++) {
810
s += slang_checksum_tree(&op->children[i]);