TYPE_VARIANT in codegen, writing code from ast-test

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-05-09 17:30:08 +02:00
parent 61d3a9d1a0
commit dfc0f6fab3
3 changed files with 14 additions and 3 deletions

9
ir.c
View file

@ -2052,6 +2052,12 @@ static bool ir_builder_gen_global(ir_builder *self, ir_value *global)
if (code_defs_add(def) < 0)
return false;
return gen_global_function(self, global);
case TYPE_VARIANT:
/* assume biggest type */
global->code.globaladdr = code_globals_add(0);
code_globals_add(0);
code_globals_add(0);
return true;
default:
/* refuse to create 'void' type or any other fancy business. */
printf("Invalid type for global variable %s\n", global->name);
@ -2075,8 +2081,7 @@ bool ir_builder_generate(ir_builder *self, const char *filename)
return false;
}
code_write(filename);
return false;
return code_write(filename);
}
/***********************************************************************

2
ir.h
View file

@ -275,6 +275,8 @@ ir_function* ir_builder_create_function(ir_builder*, const char *name);
ir_value* ir_builder_get_global(ir_builder*, const char *fun);
ir_value* ir_builder_create_global(ir_builder*, const char *name, int vtype);
bool ir_builder_generate(ir_builder *self, const char *filename);
void ir_builder_dump(ir_builder*, int (*oprintf)(const char*, ...));
/* This code assumes 32 bit floats while generating binary */

View file

@ -192,7 +192,7 @@ STATE(ASSIGN(STORE_F, vi, BIN(ADD_F, vi, f1)));
ENDWHILE();
ENDFUNCTION(main);
ir = ir_builder_new("ast_test");
assert(ir);
@ -216,6 +216,10 @@ ENDFUNCTION(main);
/* dump */
ir_builder_dump(ir, printf);
/* Now create a file */
if (!ir_builder_generate(ir, "test_ast.dat"))
printf("*** failed to generate code\n");
/* ir cleanup */
ir_builder_delete(ir);