ast_test to build an IR

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-05-03 13:26:49 +02:00
parent 4c9c6ee5bd
commit 627ef279fd

View file

@ -14,6 +14,7 @@ VECTOR_MAKE(ast_function*, functions);
int main() int main()
{ {
/* AST */
ast_expression *exp; ast_expression *exp;
ast_value *gfoo = NULL; ast_value *gfoo = NULL;
ast_value *gbar = NULL; ast_value *gbar = NULL;
@ -24,6 +25,11 @@ int main()
ast_block *ba = NULL; ast_block *ba = NULL;
ast_value *li = NULL; ast_value *li = NULL;
/* IR */
ir_builder *ir = NULL;
/* common stuff */
size_t i; size_t i;
lex_ctx ctx; lex_ctx ctx;
ctx.file = NULL; ctx.file = NULL;
@ -99,6 +105,29 @@ int main()
/* Next up: Having the AST generate IR */ /* 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 */ /* cleanup */
/* Functions must be deleted FIRST since their expressions /* Functions must be deleted FIRST since their expressions
* reference global variables. * reference global variables.