mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-18 22:31:36 +00:00
function in the ast now MUST have an output type in their 'next' ast_expression pointer, the IR's outtype of functions is now filled
This commit is contained in:
parent
67fa4ce07b
commit
c1ea9cc409
5 changed files with 24 additions and 21 deletions
2
ast.c
2
ast.c
|
@ -493,7 +493,7 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir)
|
||||||
ir_value *v = NULL;
|
ir_value *v = NULL;
|
||||||
if (self->isconst && self->expression.vtype == TYPE_FUNCTION)
|
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)
|
if (!func)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
8
ir.c
8
ir.c
|
@ -110,14 +110,14 @@ ir_function* ir_builder_get_function(ir_builder *self, const char *name)
|
||||||
return NULL;
|
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);
|
ir_function *fn = ir_builder_get_function(self, name);
|
||||||
if (fn) {
|
if (fn) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn = ir_function_new(self);
|
fn = ir_function_new(self, outtype);
|
||||||
if (!ir_function_set_name(fn, name) ||
|
if (!ir_function_set_name(fn, name) ||
|
||||||
!ir_builder_functions_add(self, fn) )
|
!ir_builder_functions_add(self, fn) )
|
||||||
{
|
{
|
||||||
|
@ -161,7 +161,7 @@ void ir_function_enumerate(ir_function*);
|
||||||
bool ir_function_calculate_liferanges(ir_function*);
|
bool ir_function_calculate_liferanges(ir_function*);
|
||||||
bool ir_function_allocate_locals(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;
|
ir_function *self;
|
||||||
self = (ir_function*)mem_a(sizeof(*self));
|
self = (ir_function*)mem_a(sizeof(*self));
|
||||||
|
@ -177,7 +177,7 @@ ir_function* ir_function_new(ir_builder* owner)
|
||||||
self->owner = owner;
|
self->owner = owner;
|
||||||
self->context.file = "<@no context>";
|
self->context.file = "<@no context>";
|
||||||
self->context.line = 0;
|
self->context.line = 0;
|
||||||
self->retype = TYPE_VOID;
|
self->outtype = outtype;
|
||||||
MEM_VECTOR_INIT(self, params);
|
MEM_VECTOR_INIT(self, params);
|
||||||
MEM_VECTOR_INIT(self, blocks);
|
MEM_VECTOR_INIT(self, blocks);
|
||||||
MEM_VECTOR_INIT(self, values);
|
MEM_VECTOR_INIT(self, values);
|
||||||
|
|
6
ir.h
6
ir.h
|
@ -224,7 +224,7 @@ void ir_block_dump(ir_block*, char *ind, int (*oprintf)(const char*,...));
|
||||||
typedef struct ir_function_s
|
typedef struct ir_function_s
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
int retype;
|
int outtype;
|
||||||
MEM_VECTOR_MAKE(int, params);
|
MEM_VECTOR_MAKE(int, params);
|
||||||
MEM_VECTOR_MAKE(ir_block*, blocks);
|
MEM_VECTOR_MAKE(ir_block*, blocks);
|
||||||
|
|
||||||
|
@ -250,7 +250,7 @@ typedef struct ir_function_s
|
||||||
struct ir_builder_s *owner;
|
struct ir_builder_s *owner;
|
||||||
} ir_function;
|
} 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*);
|
void ir_function_delete(ir_function*);
|
||||||
|
|
||||||
bool GMQCC_WARN ir_function_collect_value(ir_function*, ir_value *value);
|
bool GMQCC_WARN ir_function_collect_value(ir_function*, ir_value *value);
|
||||||
|
@ -290,7 +290,7 @@ MEM_VECTOR_PROTO(ir_builder, ir_function*, functions);
|
||||||
MEM_VECTOR_PROTO(ir_builder, ir_value*, globals);
|
MEM_VECTOR_PROTO(ir_builder, ir_value*, globals);
|
||||||
|
|
||||||
ir_function* ir_builder_get_function(ir_builder*, const char *fun);
|
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_get_global(ir_builder*, const char *fun);
|
||||||
ir_value* ir_builder_create_global(ir_builder*, const char *name, int vtype);
|
ir_value* ir_builder_create_global(ir_builder*, const char *name, int vtype);
|
||||||
|
|
|
@ -56,18 +56,21 @@ do { \
|
||||||
STATE(loop); \
|
STATE(loop); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define FUNCTION(name) \
|
#define FUNCTION(name, outtype) \
|
||||||
do { \
|
do { \
|
||||||
ast_function *func_##name; \
|
ast_function *func_##name; \
|
||||||
ast_block *my_funcblock; \
|
ast_block *my_funcblock; \
|
||||||
DEFVAR(var_##name); \
|
DEFVAR(var_##name); \
|
||||||
VARnamed(TYPE_FUNCTION, var_##name, name); \
|
DEFVAR(return_##name); \
|
||||||
MKGLOBAL(var_##name); \
|
VARnamed(TYPE_FUNCTION, var_##name, name); \
|
||||||
func_##name = ast_function_new(ctx, #name, var_##name); \
|
VARnamed(outtype, return_##name, "#returntype"); \
|
||||||
assert(functions_add(func_##name) >= 0); \
|
var_##name->expression.next = (ast_expression*)return_##name; \
|
||||||
my_funcblock = ast_block_new(ctx); \
|
MKGLOBAL(var_##name); \
|
||||||
assert(my_funcblock); \
|
func_##name = ast_function_new(ctx, #name, var_##name); \
|
||||||
assert(ast_function_blocks_add(func_##name, my_funcblock)); \
|
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;
|
curblock = my_funcblock;
|
||||||
|
|
||||||
#define MKLOCAL(var) \
|
#define MKLOCAL(var) \
|
||||||
|
|
|
@ -36,7 +36,7 @@ MKCONSTFLOAT(f0, 0.0);
|
||||||
MKCONSTFLOAT(f1, 1.0);
|
MKCONSTFLOAT(f1, 1.0);
|
||||||
MKCONSTFLOAT(f5, 5.0);
|
MKCONSTFLOAT(f5, 5.0);
|
||||||
|
|
||||||
FUNCTION(main);
|
FUNCTION(main, TYPE_VOID);
|
||||||
|
|
||||||
VAR(TYPE_FLOAT, vi);
|
VAR(TYPE_FLOAT, vi);
|
||||||
VAR(TYPE_FLOAT, vx);
|
VAR(TYPE_FLOAT, vx);
|
||||||
|
|
Loading…
Reference in a new issue