self->left = left;
self->right = right;
+ if (op >= INSTR_EQ_F && op <= INSTR_GT)
+ self->expression.vtype = TYPE_FLOAT;
+ else if (op == INSTR_AND || op == INSTR_OR ||
+ op == INSTR_BITAND || op == INSTR_BITOR)
+ self->expression.vtype = TYPE_FLOAT;
+ else if (op == INSTR_MUL_VF || op == INSTR_MUL_FV)
+ self->expression.vtype = TYPE_VECTOR;
+ else if (op == INSTR_MUL_V)
+ self->expression.vtype = TYPE_FLOAT;
+ else
+ self->expression.vtype = left->expression.vtype;
+
return self;
}
MEM_VECTOR_INIT(self, params);
+ self->func = funcexpr;
+
return self;
}
+MEM_VEC_FUNCTIONS(ast_call, ast_expression*, params)
void ast_call_delete(ast_call *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);
* and the ast-user should take care of ast_global_codegen to be used
* on all the globals.
*/
- if (!self->ir_v)
+ if (!self->ir_v) {
+ printf("ast_value used before generated (%s)\n", self->name);
return false;
+ }
*out = self->ir_v;
return true;
}
return false;
self->constval.vfunc->ir_func = func;
+ self->ir_v = func->value;
/* The function is filled later on ast_function_codegen... */
return true;
}
v = ir_builder_create_global(ir, self->name, self->expression.vtype);
- if (!v)
+ if (!v) {
+ printf("ir_builder_create_global failed\n");
return false;
+ }
if (self->isconst) {
switch (self->expression.vtype)
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;
}
- for (i = 0; i < self->params_count; ++i)
+ 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", (int)self->vtype->params_count, (int)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->params[i]->expression.vtype))
+ 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->vtype->expression.next ||
self->vtype->expression.next->expression.vtype == TYPE_VOID)
+ {
return ir_block_create_return(self->curblock, NULL);
+ }
else
{
/* error("missing return"); */
/* 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_call_codegen(ast_call *self, ast_function *func, bool lvalue, ir_value **out)
{
- /* TODO: call ir codegen */
ast_expression_codegen *cgen;
ir_value_vector params;
ir_instr *callinstr;