From 92a4431c86e273f447e82ba980154b43d8eef5cc Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Wed, 2 May 2012 18:34:24 +0200 Subject: [PATCH] ast_local_codegen - similar structure to global_codegen obviously... --- ast.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/ast.c b/ast.c index af64e08..96e419d 100644 --- a/ast.c +++ b/ast.c @@ -297,7 +297,10 @@ void ast_function_delete(ast_function *self) } /*********************************************************************/ -/* AST codegen aprt +/* AST codegen part + * by convention you must never pass NULL to the 'ir_value **out' + * parameter. If you really don't care about the output, pass a dummy. + * But I can't imagine a pituation where the output is truly unnecessary. */ bool ast_value_codegen(ast_value *self, ast_function *func, bool lvalue, ir_value **out) @@ -368,6 +371,54 @@ error: /* clean up */ return false; } +bool ast_local_codegen(ast_value *self, ir_function *func) +{ + ir_value *v = NULL; + if (self->isconst && self->vtype == TYPE_FUNCTION) + { + /* Do we allow local functions? I think not... + * this is NOT a function pointer atm. + */ + return false; + } + + v = ir_function_create_local(func, self->name, self->vtype); + if (!v) + return false; + + /* A constant local... hmmm... + * I suppose the IR will have to deal with this + */ + if (self->isconst) { + switch (self->vtype) + { + case TYPE_FLOAT: + if (!ir_value_set_float(v, self->constval.vfloat)) + goto error; + break; + case TYPE_VECTOR: + if (!ir_value_set_vector(v, self->constval.vvec)) + goto error; + break; + case TYPE_STRING: + if (!ir_value_set_string(v, self->constval.vstring)) + goto error; + break; + default: + printf("TODO: global constant type %i\n", self->vtype); + break; + } + } + + /* link us to the ir_value */ + self->ir_v = v; + return true; + +error: /* clean up */ + ir_value_delete(v); + return false; +} + bool ast_function_codegen(ast_function *self, ir_builder *ir) { if (!self->ir_func) {