Filled in the rest of the missing print_ast() cases.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 23 Feb 2010 11:34:36 -0500
changeset 854 65e06097e450
parent 853 f6b69debce78
child 855 575a443074af
Filled in the rest of the missing print_ast() cases.
mojoshader_compiler.c
mojoshader_parser_hlsl.lemon
--- a/mojoshader_compiler.c	Mon Feb 22 12:43:55 2010 -0500
+++ b/mojoshader_compiler.c	Tue Feb 23 11:34:36 2010 -0500
@@ -428,7 +428,7 @@
 {
     ASTNode ast;
     struct Statement *next;
-    int64 unroll;  // # times to unroll, 0 to loop, -1 for compiler's choice.
+    int64 unroll;  // # times to unroll, 0 to loop, negative for compiler's choice.
     Expression *expr;
     Statement *statement;
 } WhileStatement;
@@ -439,7 +439,7 @@
 {
     ASTNode ast;
     struct Statement *next;
-    int64 unroll;  // # times to unroll, 0 to loop, -1 for compiler's choice.
+    int64 unroll;  // # times to unroll, 0 to loop, negative for compiler's choice.
     VariableDeclaration *var_decl;
     Expression *initializer;
     Expression *looptest;
@@ -2362,11 +2362,90 @@
             break;
 
         case AST_STATEMENT_FOR:
+            if (((ForStatement *) ast)->unroll == 0)
+                printf("[loop] ");
+            else if (((ForStatement *) ast)->unroll == -1)
+                printf("[unroll] ");
+            else if (((ForStatement *) ast)->unroll > 0)
+            {
+                printf("[unroll(%lld)] ",
+                        (long long) (((ForStatement *) ast)->unroll) );
+            } // else if
+
+            printf("for (");
+            print_ast(((ForStatement *) ast)->var_decl);
+            print_ast(((ForStatement *) ast)->initializer);
+            printf("; ");
+            print_ast(((ForStatement *) ast)->looptest);
+            printf("; ");
+            print_ast(((ForStatement *) ast)->counter);
+            printf(")\n");
+            for (i = 0; i < indent; i++) printf("    ");
+            printf("{\n");
+            indent++;
+            for (i = 0; i < indent; i++) printf("    ");
+            print_ast(((ForStatement *) ast)->statement);
+            printf("\n");
+            indent--;
+            for (i = 0; i < indent; i++) printf("    ");
+            printf("}\n");
+            for (i = 0; i < indent; i++) printf("    ");
+            print_ast(((Statement *) ast)->next);
+            break;
+
         case AST_STATEMENT_DO:
+            if (((DoStatement *) ast)->unroll == 0)
+                printf("[loop] ");
+            else if (((DoStatement *) ast)->unroll == -1)
+                printf("[unroll] ");
+            else if (((DoStatement *) ast)->unroll > 0)
+            {
+                printf("[unroll(%lld)] ",
+                        (long long) (((DoStatement *) ast)->unroll) );
+            } // else if
+
+            printf("do\n");
+            for (i = 0; i < indent; i++) printf("    ");
+            printf("{\n");
+            indent++;
+            for (i = 0; i < indent; i++) printf("    ");
+            print_ast(((DoStatement *) ast)->statement);
+            printf("\n");
+            indent--;
+            for (i = 0; i < indent; i++) printf("    ");
+            printf("} while (");
+            print_ast(((DoStatement *) ast)->expr);
+            printf(");\n");
+            for (i = 0; i < indent; i++) printf("    ");
+            print_ast(((Statement *) ast)->next);
+            break;
+
         case AST_STATEMENT_WHILE:
-            printf("[!!!]");
+            if (((WhileStatement *) ast)->unroll == 0)
+                printf("[loop] ");
+            else if (((WhileStatement *) ast)->unroll == -1)
+                printf("[unroll] ");
+            else if (((WhileStatement *) ast)->unroll > 0)
+            {
+                printf("[unroll(%lld)] ",
+                        (long long) (((WhileStatement *) ast)->unroll) );
+            } // else if
+
+            printf("while (");
+            print_ast(((WhileStatement *) ast)->expr);
+            printf(")\n");
+            for (i = 0; i < indent; i++) printf("    ");
+            printf("{\n");
+            indent++;
+            for (i = 0; i < indent; i++) printf("    ");
+            print_ast(((WhileStatement *) ast)->statement);
+            printf("\n");
+            indent--;
+            for (i = 0; i < indent; i++) printf("    ");
+            printf("}\n");
+            for (i = 0; i < indent; i++) printf("    ");
             print_ast(((Statement *) ast)->next);
-            break;  // !!! FIXME: write me.
+            break;
 
         case AST_STATEMENT_RETURN:
             printf("return");
@@ -2583,10 +2662,33 @@
             break;
 
         case AST_PACK_OFFSET:
+            printf(" : packoffset(%s%s%s)",
+                    ((PackOffset *) ast)->ident1,
+                    ((PackOffset *) ast)->ident2 ? "." : "",
+                    ((PackOffset *) ast)->ident2 ? ((PackOffset *) ast)->ident2 : "");
+            break;
+
         case AST_VARIABLE_LOWLEVEL:
+            print_ast(((VariableLowLevel *) ast)->packoffset);
+            if (((VariableLowLevel *) ast)->register_name)
+                printf(" : register(%s)", ((VariableLowLevel *) ast)->register_name);
+            break;
+
         case AST_ANNOTATION:
-            printf("[!!!]");
+        {
+            const Annotations *a = (Annotations *) ast;
+            printf("<");
+            while (a)
+            {
+                printf(" %s ", a->datatype);
+                print_ast(a->initializer);
+                if (a->next)
+                    printf(",");
+                a = a->next;
+            } // while
+            printf(" >");
             break;
+        } // case
 
         default:
             assert(0 && "unexpected type");
--- a/mojoshader_parser_hlsl.lemon	Mon Feb 22 12:43:55 2010 -0500
+++ b/mojoshader_parser_hlsl.lemon	Tue Feb 23 11:34:36 2010 -0500
@@ -509,7 +509,7 @@
 while_intro(A) ::= LBRACKET UNROLL LPAREN INT_CONSTANT(B) RPAREN RBRACKET WHILE. { A = (B.i64 < 0) ? 0 : B.i64; }
 while_intro(A) ::= LBRACKET UNROLL RBRACKET WHILE. { A = -1; }
 while_intro(A) ::= LBRACKET LOOP RBRACKET WHILE. { A = 0; }
-while_intro(A) ::= WHILE. { A = -1; }
+while_intro(A) ::= WHILE. { A = -2; }
 
 %type for_statement { Statement * }
 %destructor for_statement { delete_statement(ctx, $$); }
@@ -519,7 +519,7 @@
 for_intro(A) ::= LBRACKET UNROLL LPAREN INT_CONSTANT(B) RPAREN RBRACKET FOR. { A = (B.i64 < 0) ? 0 : B.i64; }
 for_intro(A) ::= LBRACKET UNROLL RBRACKET FOR. { A = -1; }
 for_intro(A) ::= LBRACKET LOOP RBRACKET FOR. { A = 0; }
-for_intro(A) ::= FOR. { A = -1; }
+for_intro(A) ::= FOR. { A = -2; }
 
 %type for_details { Statement * }
 %destructor for_details { delete_statement(ctx, $$); }
@@ -540,7 +540,7 @@
 do_intro(A) ::= LBRACKET UNROLL LPAREN INT_CONSTANT(B) RPAREN RBRACKET DO. { A = (B.i64 < 0) ? 0 : (int) B.i64; }
 do_intro(A) ::= LBRACKET UNROLL RBRACKET DO. { A = -1; }
 do_intro(A) ::= LBRACKET LOOP RBRACKET DO. { A = 0; }
-do_intro(A) ::= DO. { A = -1; }
+do_intro(A) ::= DO. { A = -2; }
 
 %type if_intro { int }
 if_intro(A) ::= LBRACKET BRANCH RBRACKET IF. { A = IFATTR_BRANCH; }