space idnentation, macros, strdup again

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-04-25 14:49:29 +02:00
parent 9b6cfcb80f
commit 9343936082

112
ir.c
View file

@ -34,11 +34,11 @@ void ir_builder_delete(ir_builder* self)
for (i = 0; i != self->functions_count; ++i) {
ir_function_delete(self->functions[i]);
}
VEC_CLEAR(self, functions);
MEM_VECTOR_CLEAR(self, functions);
for (i = 0; i != self->globals_count; ++i) {
ir_value_delete(self->globals[i]);
}
VEC_CLEAR(self, globals);
MEM_VECTOR_CLEAR(self, globals);
mem_d(self);
}
@ -104,92 +104,92 @@ void ir_function_calculate_liferanges(ir_function*);
ir_function* ir_function_new(ir_builder* owner)
{
ir_function *self;
self = (ir_function*)malloc(sizeof(*self));
self->owner = owner;
self->context.file = "<@no context>";
self->context.line = 0;
self->retype = qc_void;
VEC_INIT(self, params);
VEC_INIT(self, blocks);
VEC_INIT(self, values);
VEC_INIT(self, locals);
ir_function_set_name(self, "<@unnamed>");
ir_function *self;
self = (ir_function*)mem_a(sizeof(*self));
self->owner = owner;
self->context.file = "<@no context>";
self->context.line = 0;
self->retype = qc_void;
MEM_VECTOR_INIT(self, params);
MEM_VECTOR_INIT(self, blocks);
MEM_VECTOR_INIT(self, values);
MEM_VECTOR_INIT(self, locals);
ir_function_set_name(self, "<@unnamed>");
self->run_id = 0;
return self;
self->run_id = 0;
return self;
}
MAKE_VEC_ADD(ir_function, ir_value*, values)
MAKE_VEC_ADD(ir_function, ir_block*, blocks)
MAKE_VEC_ADD(ir_function, ir_value*, locals)
MEM_VECTOR_FUNCTIONS(ir_function, ir_value*, values)
MEM_VECTOR_FUNCTIONS(ir_function, ir_block*, blocks)
MEM_VECTOR_FUNCTIONS(ir_function, ir_value*, locals)
void ir_function_set_name(ir_function *self, const char *name)
{
if (self->_name)
free((void*)self->_name);
self->_name = strdup(name);
if (self->name)
mem_d((void*)self->name);
self->name = util_strdup(name);
}
void ir_function_delete(ir_function *self)
{
size_t i;
free((void*)self->_name);
size_t i;
mem_d((void*)self->name);
for (i = 0; i != self->blocks_count; ++i)
ir_block_delete(self->blocks[i]);
VEC_CLEAR(self, blocks);
for (i = 0; i != self->blocks_count; ++i)
ir_block_delete(self->blocks[i]);
MEM_VECTOR_CLEAR(self, blocks);
VEC_CLEAR(self, params);
MEM_VECTOR_CLEAR(self, params);
for (i = 0; i != self->values_count; ++i)
ir_value_delete(self->values[i]);
VEC_CLEAR(self, values);
for (i = 0; i != self->values_count; ++i)
ir_value_delete(self->values[i]);
MEM_VECTOR_CLEAR(self, values);
for (i = 0; i != self->locals_count; ++i)
ir_value_delete(self->locals[i]);
VEC_CLEAR(self, locals);
for (i = 0; i != self->locals_count; ++i)
ir_value_delete(self->locals[i]);
MEM_VECTOR_CLEAR(self, locals);
free(self);
mem_d(self);
}
void ir_function_collect_value(ir_function *self, ir_value *v)
{
ir_function_values_add(self, v);
ir_function_values_add(self, v);
}
ir_block* ir_function_create_block(ir_function *self, const char *label)
{
ir_block* bn = ir_block_new(self, label);
memcpy(&bn->context, &self->context, sizeof(self->context));
ir_function_blocks_add(self, bn);
return bn;
ir_block* bn = ir_block_new(self, label);
memcpy(&bn->context, &self->context, sizeof(self->context));
ir_function_blocks_add(self, bn);
return bn;
}
void ir_function_finalize(ir_function *self)
{
ir_function_naive_phi(self);
ir_function_enumerate(self);
ir_function_calculate_liferanges(self);
ir_function_naive_phi(self);
ir_function_enumerate(self);
ir_function_calculate_liferanges(self);
}
ir_value* ir_function_get_local(ir_function *self, const char *name)
{
size_t i;
for (i = 0; i < self->locals_count; ++i) {
if (!strcmp(self->locals[i]->_name, name))
return self->locals[i];
}
return NULL;
size_t i;
for (i = 0; i < self->locals_count; ++i) {
if (!strcmp(self->locals[i]->name, name))
return self->locals[i];
}
return NULL;
}
ir_value* ir_function_create_local(ir_function *self, const char *name, ir_type_t vtype)
ir_value* ir_function_create_local(ir_function *self, const char *name, int vtype)
{
ir_value *ve = ir_function_get_local(self, name);
if (ve) {
return NULL;
}
ir_value *ve = ir_function_get_local(self, name);
if (ve) {
return NULL;
}
ve = ir_value_var(name, qc_localvar, vtype);
ir_function_locals_add(self, ve);
return ve;
ve = ir_value_var(name, qc_localvar, vtype);
ir_function_locals_add(self, ve);
return ve;
}