mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-31 03:50:36 +00:00
TYPE_VARIANT in codegen, writing code from ast-test
This commit is contained in:
parent
61d3a9d1a0
commit
dfc0f6fab3
3 changed files with 14 additions and 3 deletions
9
ir.c
9
ir.c
|
@ -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
2
ir.h
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue