void testast()
{
ast_expression *exp;
+ ast_value *gfoo = NULL;
+ ast_value *gbar = NULL;
+ ast_value *const_3 = NULL;
+ ast_value *const_4 = NULL;
+ ast_value *vmain = NULL;
+ ast_function *fmain = NULL;
+ ast_block *ba = NULL;
+ ast_value *li = NULL;
+
size_t i;
lex_ctx ctx;
ctx.file = NULL;
ctx.line = 1;
/* globals */
- ast_value *gfoo = ast_value_new(ctx, "foo", TYPE_FLOAT);
+ gfoo = ast_value_new(ctx, "foo", TYPE_FLOAT);
assert(gfoo);
assert(globals_add(gfoo) >= 0);
- ast_value *gbar = ast_value_new(ctx, "bar", TYPE_FLOAT);
+ gbar = ast_value_new(ctx, "bar", TYPE_FLOAT);
assert(gbar);
assert(globals_add(gbar) >= 0);
- ast_value *const_3 = ast_value_new(ctx, "3", TYPE_FLOAT);
+ const_3 = ast_value_new(ctx, "3", TYPE_FLOAT);
assert(const_3);
assert(globals_add(const_3) >= 0);
const_3->isconst = true;
const_3->constval.vfloat = 3.0;
- ast_value *const_4 = ast_value_new(ctx, "4", TYPE_FLOAT);
+ const_4 = ast_value_new(ctx, "4", TYPE_FLOAT);
assert(const_4);
assert(globals_add(const_4) >= 0);
const_4->isconst = true;
const_4->constval.vfloat = 4.0;
/* defining a function */
- ast_value *vmain = ast_value_new(ctx, "main", TYPE_FUNCTION);
+ vmain = ast_value_new(ctx, "main", TYPE_FUNCTION);
assert(vmain);
assert(globals_add(vmain) >= 0);
/* This happens in ast_function_new:
*/
/* creating a function body */
- ast_function *fmain = ast_function_new(ctx, "main", vmain);
+ fmain = ast_function_new(ctx, "main", vmain);
assert(fmain);
assert(functions_add(fmain) >= 0);
/* { block */
- ast_block *ba = ast_block_new(ctx);
+ ba = ast_block_new(ctx);
assert(ba);
assert(ast_function_blocks_add(fmain, ba));
/* local variable i */
- ast_value *li = ast_value_new(ctx, "i", TYPE_FLOAT);
+ li = ast_value_new(ctx, "i", TYPE_FLOAT);
assert(li);
assert(ast_block_locals_add(ba, li));
+#include "gmqcc.h"
#include "ir.h"
void builder1()
{
- ir_builder *b = ir_builder_new("test");
- ir_value *va = ir_builder_create_global(b, "a", TYPE_FLOAT);
- ir_value *v3 = ir_builder_create_global(b, "const_f_3", TYPE_FLOAT);
- ir_value *vb = ir_builder_create_global(b, "b", TYPE_FLOAT);
- ir_value *vc = ir_builder_create_global(b, "c", TYPE_FLOAT);
- ir_value *vd = ir_builder_create_global(b, "d", TYPE_FLOAT);
+ ir_builder *b = ir_builder_new("test");
+ ir_value *va = ir_builder_create_global(b, "a", TYPE_FLOAT);
+ ir_value *v3 = ir_builder_create_global(b, "const_f_3", TYPE_FLOAT);
+ ir_value *vb = ir_builder_create_global(b, "b", TYPE_FLOAT);
+ ir_value *vc = ir_builder_create_global(b, "c", TYPE_FLOAT);
+ ir_value *vd = ir_builder_create_global(b, "d", TYPE_FLOAT);
+
+ ir_function *fmain = NULL;
+ ir_value *la = NULL;
+ ir_block *bmain = NULL;
+ ir_block *blt = NULL;
+ ir_block *bge = NULL;
+ ir_block *bend = NULL;
+ ir_value *sum = NULL;
+ ir_value *prd = NULL;
+ ir_value *less = NULL;
+ ir_value *x1 = NULL;
+ ir_value *vig = NULL;
+ ir_value *x2 = NULL;
+ ir_instr *retphi = NULL;
+ ir_value *retval = NULL;
if (!ir_value_set_float(v3, 3.0f) ||
!ir_value_set_float(vb, 4.0f) ||
!ir_value_set_float(vd, 20.0f) )
abort();
- ir_function *fmain = ir_builder_create_function(b, "main");
+ fmain = ir_builder_create_function(b, "main");
- ir_value *la = ir_function_create_local(fmain, "loc1", TYPE_FLOAT);
+ la = ir_function_create_local(fmain, "loc1", TYPE_FLOAT);
(void)la;
- ir_block *bmain = ir_function_create_block(fmain, "top");
- ir_block *blt = ir_function_create_block(fmain, "less");
- ir_block *bge = ir_function_create_block(fmain, "greaterequal");
- ir_block *bend = ir_function_create_block(fmain, "end");
+ bmain = ir_function_create_block(fmain, "top");
+ blt = ir_function_create_block(fmain, "less");
+ bge = ir_function_create_block(fmain, "greaterequal");
+ bend = ir_function_create_block(fmain, "end");
if (!ir_block_create_store_op(bmain, INSTR_STORE_F, va, v3)) abort();
- ir_value *sum = ir_block_create_add(bmain, "%sum", va, vb);
- ir_value *prd = ir_block_create_mul(bmain, "%mul", sum, vc);
- ir_value *less = ir_block_create_binop(bmain, "%less",
+ sum = ir_block_create_add(bmain, "%sum", va, vb);
+ prd = ir_block_create_mul(bmain, "%mul", sum, vc);
+ less = ir_block_create_binop(bmain, "%less",
INSTR_LT, prd, vd);
if (!ir_block_create_if(bmain, less, blt, bge)) abort();
- ir_value *x1 = ir_block_create_binop(blt, "%x1", INSTR_ADD_F, sum, v3);
+ x1 = ir_block_create_binop(blt, "%x1", INSTR_ADD_F, sum, v3);
if (!ir_block_create_goto(blt, bend)) abort();
- ir_value *vig = ir_block_create_binop(bge, "%ignore", INSTR_ADD_F, va, vb);
+ vig = ir_block_create_binop(bge, "%ignore", INSTR_ADD_F, va, vb);
if (!ir_block_create_store_op(bge, INSTR_STORE_F, la, vig)) abort();
- ir_value *x2 = ir_block_create_binop(bge, "%x2", INSTR_ADD_F, sum, v3);
+ x2 = ir_block_create_binop(bge, "%x2", INSTR_ADD_F, sum, v3);
if (!ir_block_create_goto(bge, bend)) abort();
- ir_instr *retphi = ir_block_create_phi(bend, "%retval", TYPE_FLOAT);
+ retphi = ir_block_create_phi(bend, "%retval", TYPE_FLOAT);
if (!ir_phi_add(retphi, blt, x1) ||
!ir_phi_add(retphi, bge, x2) )
abort();
- ir_value *retval = ir_phi_value(retphi);
+ retval = ir_phi_value(retphi);
if (!ir_block_create_return(bend, retval)) abort();
/*