ir.c: importing ir_block

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-04-25 14:52:03 +02:00
parent 334e587c30
commit 2e0feca040

54
ir.c
View file

@ -193,3 +193,57 @@ ir_value* ir_function_create_local(ir_function *self, const char *name, int vtyp
ir_function_locals_add(self, ve);
return ve;
}
/***********************************************************************
*IR Block
*/
ir_block* ir_block_new(ir_function* owner, const char *name)
{
ir_block *self;
self = (ir_block*)malloc(sizeof(*self));
self->owner = owner;
self->context.file = "<@no context>";
self->context.line = 0;
self->final = ifalse;
VEC_INIT(self, instr);
VEC_INIT(self, entries);
VEC_INIT(self, exits);
self->_label = NULL;
ir_block_set_label(self, name);
self->eid = 0;
self->is_return = ifalse;
self->run_id = 0;
VEC_INIT(self, living);
return self;
}
MAKE_VEC_ADD(ir_block, ir_instr*, instr)
MAKE_VEC_REMOVE(ir_block, ir_instr*, instr)
MAKE_VEC_ADD(ir_block, ir_block*, entries)
MAKE_VEC_FIND(ir_block, ir_block*, entries)
MAKE_VEC_ADD(ir_block, ir_block*, exits)
MAKE_VEC_ADD(ir_block, ir_value*, living)
MAKE_VEC_REMOVE(ir_block, ir_value*, living)
MAKE_VEC_FIND(ir_block, ir_value*, living)
void ir_block_delete(ir_block* self)
{
size_t i;
free((void*)self->_label);
for (i = 0; i != self->instr_count; ++i)
ir_instr_delete(self->instr[i]);
VEC_CLEAR(self, instr);
VEC_CLEAR(self, entries);
VEC_CLEAR(self, exits);
VEC_CLEAR(self, living);
free(self);
}
void ir_block_set_label(ir_block *self, const char *name)
{
if (self->_label)
free((void*)self->_label);
self->_label = strdup(name);
}