self->vtype = vtype;
self->name = name ? util_strdup(name) : NULL;
MEM_VECTOR_INIT(self, blocks);
+ MEM_VECTOR_INIT(self, params);
self->labelcount = 0;
self->builtin = 0;
}
MEM_VEC_FUNCTIONS(ast_function, ast_block*, blocks)
+MEM_VEC_FUNCTIONS(ast_function, ast_value*, params)
void ast_function_delete(ast_function *self)
{
for (i = 0; i < self->blocks_count; ++i)
ast_delete(self->blocks[i]);
MEM_VECTOR_CLEAR(self, blocks);
+ /* ast_delete, not unref, there must only have been references
+ * to the parameter values inside the blocks deleted above.
+ */
+ for (i = 0; i < self->params_count; ++i)
+ ast_delete(self->params[i]);
+ MEM_VECTOR_CLEAR(self, params);
mem_d(self);
}
char labelbuf[64];
MEM_VECTOR_MAKE(ast_block*, blocks);
+
+ /* contrary to the params in ast_value, these are the parameter variables
+ * which are to be used in expressions.
+ * The ast_value for the function contains only the parameter types used
+ * to generate ast_calls, and ast_call contains the parameter values
+ * used in that call.
+ */
+ MEM_VECTOR_MAKE(ast_value*, params);
};
ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype);
/* This will NOT delete the underlying ast_value */
const char* ast_function_label(ast_function*, const char *prefix);
MEM_VECTOR_PROTO(ast_function, ast_block*, blocks);
+MEM_VECTOR_PROTO(ast_function, ast_value*, params);
bool ast_function_codegen(ast_function *self, ir_builder *builder);
enum store_types {
store_global,
store_local, /* local, assignable for now, should get promoted later */
+ store_param, /* parameters, they are locals with a fixed position */
store_value, /* unassignable */
store_return /* unassignable, at OFS_RETURN */
};
if (v->writes[w]->_ops[0] == v)
v->writes[w]->_ops[0] = instr->_ops[0];
- if (old->store != store_value && old->store != store_local)
+ if (old->store != store_value && old->store != store_local && old->store != store_param)
{
/* If it originally wrote to a global we need to store the value
* there as welli
value = instr->_ops[o];
/* We only care about locals */
+ /* we also calculate parameter liferanges so that locals
+ * can take up parameter slots */
if (value->store != store_value &&
- value->store != store_local)
+ value->store != store_local &&
+ value->store != store_param)
continue;
/* read operands */