From e965ffb9dfac38923c811d2a1bd9ba02b0d3fa76 Mon Sep 17 00:00:00 2001
From: Wolfgang Bumiller <wolfgang.linux@bumiller.com>
Date: Tue, 3 Jul 2012 22:47:01 +0200
Subject: [PATCH] basic CALL translation: to be refined

---
 ir.c | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/ir.c b/ir.c
index 48c4ccf..ff87a80 100644
--- a/ir.c
+++ b/ir.c
@@ -2210,7 +2210,42 @@ tailcall:
              *      generation already. This would even include later
              *      reuse.... probably... :)
              */
-            printf("TODO: call instruction\n");
+            size_t p;
+            ir_value *retvalue;
+
+            for (p = 0; p < instr->params_count; ++p)
+            {
+                ir_value *param = instr->params[p];
+
+                stmt.opcode = INSTR_STORE_F;
+                stmt.o3.u1 = 0;
+
+                stmt.opcode = type_store_instr[param->vtype];
+                stmt.o1.u1 = param->code.globaladdr;
+                stmt.o2.u1 = OFS_PARM0 + 3 * p;
+                if (code_statements_add(stmt) < 0)
+                    return false;
+            }
+            stmt.opcode = INSTR_CALL0 + instr->params_count;
+            if (stmt.opcode > INSTR_CALL8)
+                stmt.opcode = INSTR_CALL8;
+            stmt.o1.u1 = instr->_ops[1]->code.globaladdr;
+            stmt.o2.u1 = 0;
+            stmt.o3.u1 = 0;
+            if (code_statements_add(stmt) < 0)
+                return false;
+
+            retvalue = instr->_ops[0];
+            if (retvalue && retvalue->store != store_return && retvalue->life_count)
+            {
+                /* not to be kept in OFS_RETURN */
+                stmt.opcode = type_store_instr[retvalue->vtype];
+                stmt.o1.u1 = OFS_RETURN;
+                stmt.o2.u1 = retvalue->code.globaladdr;
+                stmt.o3.u1 = 0;
+                if (code_statements_add(stmt) < 0)
+                    return false;
+            }
             return false;
         }
 
-- 
2.39.5