mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-03-21 18:30:52 +00:00
ast_function generates parameter locals, ir_function_create_local now allows adding parameters as long as no local variables have been added yet
This commit is contained in:
parent
43897f6e8f
commit
a4617d0e61
4 changed files with 26 additions and 7 deletions
18
ast.c
18
ast.c
|
@ -557,7 +557,7 @@ error: /* clean up */
|
|||
return false;
|
||||
}
|
||||
|
||||
bool ast_local_codegen(ast_value *self, ir_function *func)
|
||||
bool ast_local_codegen(ast_value *self, ir_function *func, bool param)
|
||||
{
|
||||
ir_value *v = NULL;
|
||||
if (self->isconst && self->expression.vtype == TYPE_FUNCTION)
|
||||
|
@ -568,7 +568,7 @@ bool ast_local_codegen(ast_value *self, ir_function *func)
|
|||
return false;
|
||||
}
|
||||
|
||||
v = ir_function_create_local(func, self->name, self->expression.vtype);
|
||||
v = ir_function_create_local(func, self->name, self->expression.vtype, param);
|
||||
if (!v)
|
||||
return false;
|
||||
|
||||
|
@ -617,11 +617,23 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!self->builtin && self->vtype->params_count != self->params_count) {
|
||||
printf("ast_function's parameter variables doesn't match the declared parameter count\n");
|
||||
printf("%i != %i\n", self->vtype->params_count, self->params_count);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* fill the parameter list */
|
||||
for (i = 0; i < self->vtype->params_count; ++i)
|
||||
{
|
||||
if (!ir_function_params_add(irf, self->vtype->params[i]->expression.vtype))
|
||||
return false;
|
||||
}
|
||||
/* generate the parameter locals */
|
||||
for (i = 0; i < self->params_count; ++i) {
|
||||
if (!ast_local_codegen(self->params[i], self->ir_func, true))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (self->builtin) {
|
||||
irf->builtin = self->builtin;
|
||||
|
@ -682,7 +694,7 @@ bool ast_block_codegen(ast_block *self, ast_function *func, bool lvalue, ir_valu
|
|||
/* generate locals */
|
||||
for (i = 0; i < self->locals_count; ++i)
|
||||
{
|
||||
if (!ast_local_codegen(self->locals[i], func->ir_func))
|
||||
if (!ast_local_codegen(self->locals[i], func->ir_func, false))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
2
ast.h
2
ast.h
|
@ -125,7 +125,7 @@ void ast_value_delete(ast_value*);
|
|||
bool ast_value_set_name(ast_value*, const char *name);
|
||||
|
||||
bool ast_value_codegen(ast_value*, ast_function*, bool lvalue, ir_value**);
|
||||
bool ast_local_codegen(ast_value *self, ir_function *func);
|
||||
bool ast_local_codegen(ast_value *self, ir_function *func, bool isparam);
|
||||
bool ast_global_codegen(ast_value *self, ir_builder *ir);
|
||||
|
||||
/* Binary
|
||||
|
|
11
ir.c
11
ir.c
|
@ -311,14 +311,21 @@ ir_value* ir_function_get_local(ir_function *self, const char *name)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
ir_value* ir_function_create_local(ir_function *self, const char *name, int vtype)
|
||||
ir_value* ir_function_create_local(ir_function *self, const char *name, int vtype, bool param)
|
||||
{
|
||||
ir_value *ve = ir_function_get_local(self, name);
|
||||
if (ve) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ve = ir_value_var(name, store_local, vtype);
|
||||
if (param &&
|
||||
self->locals_count &&
|
||||
self->locals[self->locals_count-1]->store != store_param) {
|
||||
printf("cannot add parameters after adding locals\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ve = ir_value_var(name, (param ? store_param : store_local), vtype);
|
||||
if (!ir_function_locals_add(self, ve)) {
|
||||
ir_value_delete(ve);
|
||||
return NULL;
|
||||
|
|
2
ir.h
2
ir.h
|
@ -265,7 +265,7 @@ MEM_VECTOR_PROTO(ir_function, int, params);
|
|||
MEM_VECTOR_PROTO(ir_function, ir_block*, blocks);
|
||||
|
||||
ir_value* ir_function_get_local(ir_function *self, const char *name);
|
||||
ir_value* ir_function_create_local(ir_function *self, const char *name, int vtype);
|
||||
ir_value* ir_function_create_local(ir_function *self, const char *name, int vtype, bool param);
|
||||
|
||||
bool GMQCC_WARN ir_function_finalize(ir_function*);
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue