]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
ast_test to build an IR
authorWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 3 May 2012 11:26:49 +0000 (13:26 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 3 May 2012 11:26:49 +0000 (13:26 +0200)
test/ast-test.c

index afe90077190b2ab3a8ee102bbe4b7214f2483d29..00e8c052e3220dba789651fde674f7473099ef97 100644 (file)
@@ -14,6 +14,7 @@ VECTOR_MAKE(ast_function*, functions);
 
 int main()
 {
+    /* AST */
     ast_expression *exp;
     ast_value      *gfoo    = NULL;
     ast_value      *gbar    = NULL;
@@ -24,6 +25,11 @@ int main()
     ast_block      *ba      = NULL;
     ast_value      *li      = NULL;
 
+    /* IR */
+    ir_builder     *ir = NULL;
+
+    /* common stuff */
+
     size_t i;
     lex_ctx ctx;
     ctx.file = NULL;
@@ -99,6 +105,29 @@ int main()
 
     /* Next up: Having the AST generate IR */
 
+    ir = ir_builder_new("ast_test");
+    assert(ir);
+
+    /* gen globals */
+    for (i = 0; i < globals_elements; ++i) {
+        if (!ast_global_codegen(globals_data[i], ir)) {
+            assert(!"failed to generate global");
+        }
+    }
+
+    /* gen functions */
+    for (i = 0; i < functions_elements; ++i) {
+        if (!ast_function_codegen(functions_data[i], ir)) {
+            assert(!"failed to generate function");
+        }
+    }
+
+    /* dump */
+    ir_builder_dump(ir, printf);
+
+    /* ir cleanup */
+    ir_builder_delete(ir);
+
     /* cleanup */
     /* Functions must be deleted FIRST since their expressions
      * reference global variables.