ir_value *v = NULL;
if (self->isconst && self->expression.vtype == TYPE_FUNCTION)
{
- ir_function *func = ir_builder_create_function(ir, self->name);
+ ir_function *func = ir_builder_create_function(ir, self->name, self->expression.next->expression.vtype);
if (!func)
return false;
return NULL;
}
-ir_function* ir_builder_create_function(ir_builder *self, const char *name)
+ir_function* ir_builder_create_function(ir_builder *self, const char *name, int outtype)
{
ir_function *fn = ir_builder_get_function(self, name);
if (fn) {
return NULL;
}
- fn = ir_function_new(self);
+ fn = ir_function_new(self, outtype);
if (!ir_function_set_name(fn, name) ||
!ir_builder_functions_add(self, fn) )
{
bool ir_function_calculate_liferanges(ir_function*);
bool ir_function_allocate_locals(ir_function*);
-ir_function* ir_function_new(ir_builder* owner)
+ir_function* ir_function_new(ir_builder* owner, int outtype)
{
ir_function *self;
self = (ir_function*)mem_a(sizeof(*self));
self->owner = owner;
self->context.file = "<@no context>";
self->context.line = 0;
- self->retype = TYPE_VOID;
+ self->outtype = outtype;
MEM_VECTOR_INIT(self, params);
MEM_VECTOR_INIT(self, blocks);
MEM_VECTOR_INIT(self, values);
typedef struct ir_function_s
{
char *name;
- int retype;
+ int outtype;
MEM_VECTOR_MAKE(int, params);
MEM_VECTOR_MAKE(ir_block*, blocks);
struct ir_builder_s *owner;
} ir_function;
-ir_function* ir_function_new(struct ir_builder_s *owner);
+ir_function* ir_function_new(struct ir_builder_s *owner, int returntype);
void ir_function_delete(ir_function*);
bool GMQCC_WARN ir_function_collect_value(ir_function*, ir_value *value);
MEM_VECTOR_PROTO(ir_builder, ir_value*, globals);
ir_function* ir_builder_get_function(ir_builder*, const char *fun);
-ir_function* ir_builder_create_function(ir_builder*, const char *name);
+ir_function* ir_builder_create_function(ir_builder*, const char *name, int outtype);
ir_value* ir_builder_get_global(ir_builder*, const char *fun);
ir_value* ir_builder_create_global(ir_builder*, const char *name, int vtype);
STATE(loop); \
} while(0)
-#define FUNCTION(name) \
-do { \
- ast_function *func_##name; \
- ast_block *my_funcblock; \
- DEFVAR(var_##name); \
- VARnamed(TYPE_FUNCTION, var_##name, name); \
- MKGLOBAL(var_##name); \
- func_##name = ast_function_new(ctx, #name, var_##name); \
- assert(functions_add(func_##name) >= 0); \
- my_funcblock = ast_block_new(ctx); \
- assert(my_funcblock); \
- assert(ast_function_blocks_add(func_##name, my_funcblock)); \
+#define FUNCTION(name, outtype) \
+do { \
+ ast_function *func_##name; \
+ ast_block *my_funcblock; \
+ DEFVAR(var_##name); \
+ DEFVAR(return_##name); \
+ VARnamed(TYPE_FUNCTION, var_##name, name); \
+ VARnamed(outtype, return_##name, "#returntype"); \
+ var_##name->expression.next = (ast_expression*)return_##name; \
+ MKGLOBAL(var_##name); \
+ func_##name = ast_function_new(ctx, #name, var_##name); \
+ assert(functions_add(func_##name) >= 0); \
+ my_funcblock = ast_block_new(ctx); \
+ assert(my_funcblock); \
+ assert(ast_function_blocks_add(func_##name, my_funcblock)); \
curblock = my_funcblock;
#define MKLOCAL(var) \
MKCONSTFLOAT(f1, 1.0);
MKCONSTFLOAT(f5, 5.0);
-FUNCTION(main);
+FUNCTION(main, TYPE_VOID);
VAR(TYPE_FLOAT, vi);
VAR(TYPE_FLOAT, vx);