ir_builder now has a vinstr_temp array, a bunch of temps (currently 1) which can be used for virtual instruction translation

This commit is contained in:
Wolfgang Bumiller 2013-08-26 10:23:03 +02:00
parent 95138b1e5b
commit 69cecb74df
2 changed files with 28 additions and 2 deletions

21
ir.c
View file

@ -312,6 +312,7 @@ static void ir_function_delete_quick(ir_function *self);
ir_builder* ir_builder_new(const char *modulename)
{
ir_builder* self;
size_t i;
self = (ir_builder*)mem_a(sizeof(*self));
if (!self)
@ -344,6 +345,15 @@ ir_builder* ir_builder_new(const char *modulename)
self->nil = ir_value_var("nil", store_value, TYPE_NIL);
self->nil->cvq = CV_CONST;
for (i = 0; i != IR_MAX_VINSTR_TEMPS; ++i) {
/* we write to them, but they're not supposed to be used outside the IR, so
* let's not allow the generation of ir_instrs which use these.
* So it's a constant noexpr.
*/
self->vinstr_temp[i] = ir_value_var("vinstr_temp", store_value, TYPE_NOEXPR);
self->vinstr_temp[i]->cvq = CV_CONST;
}
self->reserved_va_count = NULL;
self->code = code_init();
@ -374,6 +384,9 @@ void ir_builder_delete(ir_builder* self)
ir_value_delete(self->fields[i]);
}
ir_value_delete(self->nil);
for (i = 0; i != IR_MAX_VINSTR_TEMPS; ++i) {
ir_value_delete(self->vinstr_temp[i]);
}
vec_free(self->fields);
vec_free(self->filenames);
vec_free(self->filestrings);
@ -3652,6 +3665,14 @@ bool ir_builder_generate(ir_builder *self, const char *filename)
vec_push(self->code->globals, 0);
vec_push(self->code->globals, 0);
/* generate virtual-instruction temps */
for (i = 0; i < IR_MAX_VINSTR_TEMPS; ++i) {
ir_value_code_setaddr(self->vinstr_temp[i], vec_size(self->code->globals));
vec_push(self->code->globals, 0);
vec_push(self->code->globals, 0);
vec_push(self->code->globals, 0);
}
/* generate global temps */
self->first_common_globaltemp = vec_size(self->code->globals);
for (i = 0; i < self->max_globaltemps; ++i) {

5
ir.h
View file

@ -240,6 +240,7 @@ ir_block* ir_function_create_block(lex_ctx_t ctx, ir_function*, const char
/* builder */
#define IR_HT_SIZE 1024
#define IR_MAX_VINSTR_TEMPS 1
typedef struct ir_builder_s
{
char *name;
@ -267,6 +268,10 @@ typedef struct ir_builder_s
/* there should just be this one nil */
ir_value *nil;
ir_value *reserved_va_count;
/* some virtual instructions require temps, and their code is isolated
* so that we don't need to keep track of their liveness.
*/
ir_value *vinstr_temp[IR_MAX_VINSTR_TEMPS];
/* code generator */
code_t *code;