cache filenames as such instead of using code_cachedstring

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-08-24 19:44:29 +02:00
parent bdffa662b6
commit 74cb075665
2 changed files with 37 additions and 5 deletions

33
ir.c
View file

@ -166,6 +166,8 @@ ir_builder* ir_builder_new(const char *modulename)
MEM_VECTOR_INIT(self, functions);
MEM_VECTOR_INIT(self, globals);
MEM_VECTOR_INIT(self, fields);
MEM_VECTOR_INIT(self, filenames);
MEM_VECTOR_INIT(self, filestrings);
self->name = NULL;
if (!ir_builder_set_name(self, modulename)) {
mem_d(self);
@ -175,9 +177,11 @@ ir_builder* ir_builder_new(const char *modulename)
return self;
}
MEM_VEC_FUNCTIONS(ir_builder, ir_value*, globals)
MEM_VEC_FUNCTIONS(ir_builder, ir_value*, fields)
MEM_VEC_FUNCTIONS(ir_builder, ir_value*, globals)
MEM_VEC_FUNCTIONS(ir_builder, ir_value*, fields)
MEM_VEC_FUNCTIONS(ir_builder, ir_function*, functions)
MEM_VEC_FUNCTIONS(ir_builder, const char*, filenames)
MEM_VEC_FUNCTIONS(ir_builder, qcint, filestrings)
void ir_builder_delete(ir_builder* self)
{
@ -195,6 +199,8 @@ void ir_builder_delete(ir_builder* self)
ir_value_delete(self->fields[i]);
}
MEM_VECTOR_CLEAR(self, fields);
MEM_VECTOR_CLEAR(self, filenames);
MEM_VECTOR_CLEAR(self, filestrings);
mem_d(self);
}
@ -2549,6 +2555,27 @@ static bool gen_function_code(ir_function *self)
return true;
}
static qcint ir_builder_filestring(ir_builder *ir, const char *filename)
{
/* NOTE: filename pointers are copied, we never strdup them,
* thus we can use pointer-comparison to find the string.
*/
size_t i;
qcint str;
for (i = 0; i < ir->filenames_count; ++i) {
if (ir->filenames[i] == filename)
return ir->filestrings[i];
}
str = code_genstring(filename);
if (!ir_builder_filenames_add(ir, filename))
return 0;
if (!ir_builder_filestrings_add(ir, str))
ir->filenames_count--;
return str;
}
static bool gen_global_function(ir_builder *ir, ir_value *global)
{
prog_section_function fun;
@ -2566,7 +2593,7 @@ static bool gen_global_function(ir_builder *ir, ir_value *global)
irfun = global->constval.vfunc;
fun.name = global->code.name;
fun.file = code_cachedstring(global->context.file);
fun.file = ir_builder_filestring(ir, global->context.file);
fun.profile = 0; /* always 0 */
fun.nargs = irfun->params_count;

9
ir.h
View file

@ -305,6 +305,9 @@ typedef struct ir_builder_s
MEM_VECTOR_MAKE(ir_function*, functions);
MEM_VECTOR_MAKE(ir_value*, globals);
MEM_VECTOR_MAKE(ir_value*, fields);
MEM_VECTOR_MAKE(const char*, filenames);
MEM_VECTOR_MAKE(qcint, filestrings);
} ir_builder;
ir_builder* ir_builder_new(const char *modulename);
@ -313,8 +316,10 @@ void ir_builder_delete(ir_builder*);
bool ir_builder_set_name(ir_builder *self, const char *name);
MEM_VECTOR_PROTO(ir_builder, ir_function*, functions);
MEM_VECTOR_PROTO(ir_builder, ir_value*, globals);
MEM_VECTOR_PROTO(ir_builder, ir_value*, fields);
MEM_VECTOR_PROTO(ir_builder, ir_value*, globals);
MEM_VECTOR_PROTO(ir_builder, ir_value*, fields);
MEM_VECTOR_PROTO(ir_builder, const char*, filenames);
MEM_VECTOR_PROTO(ir_builder, qcint, filestrings);
ir_function* ir_builder_get_function(ir_builder*, const char *fun);
ir_function* ir_builder_create_function(ir_builder*, const char *name, int outtype);