mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2024-12-18 00:11:06 +00:00
ast_test to build an IR
This commit is contained in:
parent
4c9c6ee5bd
commit
627ef279fd
1 changed files with 29 additions and 0 deletions
|
@ -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.
|
||||||
|
|
Loading…
Reference in a new issue