Skip to content

Commit

Permalink
typed block ins done right
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-s168 committed May 28, 2024
1 parent ed6ff3a commit cf60a80
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
7 changes: 5 additions & 2 deletions ir/builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ void vx_IrBlock_make_root(vx_IrBlock *block,
}

void vx_IrBlock_add_in(vx_IrBlock *block,
const vx_IrVar var)
const vx_IrVar var,
vx_IrType *ty)
{
block->ins = realloc(block->ins, sizeof(vx_IrTypedVar) * (block->ins_len + 1));
block->ins[block->ins_len ++].var = var;
vx_IrTypedVar* v = &block->ins[block->ins_len ++];
v->var = var;
v->type = ty;
}

static void root_block_put_var(vx_IrBlock *root, vx_IrVar var, vx_IrOp *decl) {
Expand Down
6 changes: 4 additions & 2 deletions ir/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,10 @@ void vx_IrBlock_dump(const vx_IrBlock *block, FILE *out, const size_t indent) {

fputs("BLOCK", out);
for (size_t i = 0; i < block->ins_len; i ++) {
const vx_IrVar in = block->ins[i].var;
fprintf(out, " %%%zu", in);
if (i > 0)
fputc(',', out);
vx_IrTypedVar in = block->ins[i];
fprintf(out, " %s %%%zu", in.type->debugName, in.var);
}
fputc('\n', out);

Expand Down
2 changes: 1 addition & 1 deletion ir/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ vx_IrBlock *vx_IrBlock_init_heap(vx_IrBlock *parent, size_t parent_index);
void vx_IrBlock_init(vx_IrBlock *block, vx_IrBlock *parent, size_t parent_index);
/** run AFTER you finished building it! */
void vx_IrBlock_make_root(vx_IrBlock *block, size_t total_vars);
void vx_IrBlock_add_in(vx_IrBlock *block, vx_IrVar var);
void vx_IrBlock_add_in(vx_IrBlock *block, vx_IrVar var, vx_IrType *type);
void vx_IrBlock_add_op(vx_IrBlock *block, const vx_IrOp *op);
/** WARNING: DON'T REF VARS IN OP THAT ARE NOT ALREADY INDEXED ROOT */
vx_IrOp *vx_IrBlock_add_op_building(vx_IrBlock *block);
Expand Down
8 changes: 4 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ void eq(int a, int b, int c, int d) {
vx_IrBlock *block = vx_IrBlock_init_heap(NULL, 0);
vx_IrVar a = 0, b = 1, c = 2, d = 3, temp0 = 4, temp1 = 5, temp2 = 6;

vx_IrBlock_add_in(block, a);
vx_IrBlock_add_in(block, b);
vx_IrBlock_add_in(block, c);
vx_IrBlock_add_in(block, d);
vx_IrBlock_add_in(block, a, ty_int);
vx_IrBlock_add_in(block, b, ty_int);
vx_IrBlock_add_in(block, c, ty_int);
vx_IrBlock_add_in(block, d, ty_int);

vx_IrOp iff;
vx_IrOp_init(&iff, VX_IR_OP_IF, block);
Expand Down

0 comments on commit cf60a80

Please sign in to comment.