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)
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;
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;
/* 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;
}
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
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;
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*);
/*