]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
ast_entfield_codegen
authorWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 3 May 2012 10:19:33 +0000 (12:19 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 3 May 2012 10:19:33 +0000 (12:19 +0200)
ast.c

diff --git a/ast.c b/ast.c
index 4b439d4eabb10b67db259c2300d0d1ee964adeab..cf2aa026846166d57e13ee4e86b7ed7f88cb90ea 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -623,7 +623,35 @@ bool ast_binary_codegen(ast_binary *self, ast_function *func, bool lvalue, ir_va
 
 bool ast_entfield_codegen(ast_entfield *self, ast_function *func, bool lvalue, ir_value **out)
 {
-    return false;
+    ast_expression_codegen *cgen;
+    ir_value *ent, *field;
+
+    /* This function needs to take the 'lvalue' flag into account!
+     * As lvalue we provide a field-pointer, as rvalue we provide the
+     * value in a temp.
+     */
+
+    cgen = self->entity->expression.codegen;
+    if (!(*cgen)((ast_expression*)(self->entity), func, false, &ent))
+        return false;
+
+    cgen = self->field->expression.codegen;
+    if (!(*cgen)((ast_expression*)(self->field), func, false, &field))
+        return false;
+
+    if (lvalue) {
+        /* address! */
+        *out = ir_block_create_fieldaddress(func->curblock, ast_function_label(func),
+                                            ent, field);
+    } else {
+        *out = ir_block_create_load_from_ent(func->curblock, ast_function_label(func),
+                                             ent, field, self->expression.vtype);
+    }
+    if (!*out)
+        return false;
+
+    /* Hm that should be it... */
+    return true;
 }
 
 bool ast_ifthen_codegen(ast_ifthen *self, ast_function *func, bool lvalue, ir_value **out)