]> git.mdlowis.com Git - proto/obnc.git/commitdiff
flat array indexing is functioning. nested arrays are broken. this is...progress
authorMichael D. Lowis <mike.lowis@gentex.com>
Wed, 21 Sep 2022 18:18:22 +0000 (14:18 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Wed, 21 Sep 2022 18:18:22 +0000 (14:18 -0400)
cerise/src/ssa.c
cerise/tests/Module.m

index 50eaa9512c985ea24e172ab52c02cfe9ead1b540..b9cbec464d55852e694b79d4c093d9bb0662a08b 100644 (file)
@@ -6,6 +6,7 @@ static SsaNode* unop(Parser* p, int op, SsaNode* operand);
 static SsaNode* const_binop(int op, SsaNode* left, SsaNode* right);
 static SsaNode* const_unop(int op, SsaNode* operand);
 static SsaNode* load(Parser* p, SsaNode* node);
+static SsaNode* loadmem(Parser* p, SsaNode* node);
 
 bool ssa_asbool(SsaNode* node)
 {
@@ -180,7 +181,12 @@ SsaNode* ssa_op(Parser* p, int op, SsaNode* left, SsaNode* right)
 
 SsaNode* ssa_store(Parser* p, SsaNode* dest, SsaNode* value)
 {
-    load(p, value);
+    value = load(p, value);
+    if (dest->mode == MODE_MEMORY && dest->code == '[')
+    {
+        dest = load(p, dest);
+    }
+
     SsaNode* node = ssa_node(STORE, MODE_MEMORY);
     node->type = dest->type;
     node->left = value;
@@ -188,7 +194,8 @@ SsaNode* ssa_store(Parser* p, SsaNode* dest, SsaNode* value)
 
     if (!symbol_getbyid(p, SSA_VAR(node).symid)->global)
     {
-        SSA_VAR(node).symver = phi_add(p, SSA_VAR(node));
+//        SSA_VAR(node).symver = phi_add(p, SSA_VAR(node));
+        (void)phi_add(p, SSA_VAR(node));
     }
     ssa_block_add(p->curr_block, node);
     node->loaded = 1;
@@ -204,7 +211,8 @@ SsaNode* ssa_fieldref(Parser* p, SsaNode* record, char* fname)
 
 SsaNode* ssa_index(Parser* p, SsaNode* array, SsaNode* index)
 {
-    load(p, index);
+//    array = load(p, array);
+    index = load(p, index);
     SsaNode* node = ssa_node('[', MODE_MEMORY);
     node->type = array->type->base;
     node->left = array;
@@ -299,8 +307,8 @@ static SsaNode* binop(Parser* p, int op, SsaNode* left, SsaNode* right)
     }
     else
     {
-        left = load(p, left);
-        right = load(p, right);
+        left = loadmem(p, left);
+        right = loadmem(p, right);
         node = ssa_node(op, MODE_BINOP);
         node->left = load(p, left);
         node->right = load(p, right);
@@ -482,11 +490,6 @@ static SsaNode* load(Parser* p, SsaNode* node)
 {
     if (!node->loaded && (node->mode != MODE_CONST))
     {
-//        if (node->mode == MODE_MEMORY && node->code == '[')
-//        {
-////            puts ("array!");
-//        }
-//        else
         if (node->mode == MODE_VAR)
         {
             node->left = ssa_ident(p, 0);
@@ -507,3 +510,16 @@ static SsaNode* load(Parser* p, SsaNode* node)
     }
     return node;
 }
+
+static SsaNode* loadmem(Parser* p, SsaNode* node)
+{
+    node = load(p, node);
+    if (node->mode == MODE_MEMORY && node->code == '[')
+    {
+        SsaNode* load_op = ssa_node(LOAD, MODE_MEMORY);
+        load_op->left = node;
+        load_op->type = node->type;
+        node = load(p, load_op);
+    }
+    return node;
+}
index 431fba049e100213543d349ae2b98e7b2964b315..322000ba122a4fd21300f9ddc039936f0bc18e86 100644 (file)
@@ -5,6 +5,7 @@ var
   vInt* : Int
   vReal : Real
   vIntArray : array 42 of Int
+  vIntArray2 : array 5 of array 5 of Int
 
 procedure TestReturnVoid()
 begin
@@ -54,102 +55,107 @@ begin
     vInt = 1 % vInt;
     vInt = vInt % vInt;
 end
-#
-#procedure TestIntCompOps()
-#begin
-#    vBool = vInt == 1;
-#    vBool = 1 == vInt;
-#    vBool = vInt == vInt;
-#
-#    vBool = vInt != 1;
-#    vBool = 1 != vInt;
-#    vBool = vInt != vInt;
-#
-#    vBool = vInt < 1;
-#    vBool = 1 < vInt;
-#    vBool = vInt < vInt;
-#
-#    vBool = vInt > 1;
-#    vBool = 1 > vInt;
-#    vBool = vInt > vInt;
-#
-#    vBool = vInt <= 1;
-#    vBool = 1 <= vInt;
-#    vBool = vInt <= vInt;
-#
-#    vBool = vInt >= 1;
-#    vBool = 1 >= vInt;
-#    vBool = vInt >= vInt;
-#end
-#
-#procedure TestRealArithOps()
-#begin
-#    vReal = vReal + 1.0;
-#    vReal = 1.0 + vReal;
-#    vReal = vReal + vReal;
-#
-#    vReal = vReal - 1.0;
-#    vReal = 1.0 - vReal;
-#    vReal = vReal - vReal;
-#
-#    vReal = vReal * 1.0;
-#    vReal = 1.0 * vReal;
-#    vReal = vReal * vReal;
-#
-#    vReal = vReal / 1.0;
-#    vReal = 1.0 / vReal;
-#    vReal = vReal / vReal;
-#
-#    vReal = vReal % 1.0;
-#    vReal = 1.0 % vReal;
-#    vReal = vReal % vReal;
-#end
-#
-#procedure TestRealCompOps()
-#begin
-#    vBool = vReal == 1.0;
-#    vBool = 1.0 == vReal;
-#    vBool = vReal == vReal;
-#
-#    vBool = vReal != 1.0;
-#    vBool = 1.0 != vReal;
-#    vBool = vReal != vReal;
-#
-#    vBool = vReal < 1.0;
-#    vBool = 1.0 < vReal;
-#    vBool = vReal < vReal;
-#
-#    vBool = vReal > 1.0;
-#    vBool = 1.0 > vReal;
-#    vBool = vReal > vReal;
-#
-#    vBool = vReal <= 1.0;
-#    vBool = 1.0 <= vReal;
-#    vBool = vReal <= vReal;
-#
-#    vBool = vReal >= 1.0;
-#    vBool = 1.0 >= vReal;
-#    vBool = vReal >= vReal;
-#end
-#
-#procedure TestIfStatements()
-#begin
-#  if vInt == 1 then
-#    vInt = 42;
-#  end
-#
-#  if vInt == 1 then
-#    vInt = 42;
-#  else
-#    vInt = 24;
-#  end
-#end
 
-procedure TestArrayAccess()
+procedure TestIntCompOps()
+begin
+    vBool = vInt == 1;
+    vBool = 1 == vInt;
+    vBool = vInt == vInt;
+
+    vBool = vInt != 1;
+    vBool = 1 != vInt;
+    vBool = vInt != vInt;
+
+    vBool = vInt < 1;
+    vBool = 1 < vInt;
+    vBool = vInt < vInt;
+
+    vBool = vInt > 1;
+    vBool = 1 > vInt;
+    vBool = vInt > vInt;
+
+    vBool = vInt <= 1;
+    vBool = 1 <= vInt;
+    vBool = vInt <= vInt;
+
+    vBool = vInt >= 1;
+    vBool = 1 >= vInt;
+    vBool = vInt >= vInt;
+end
+
+procedure TestRealArithOps()
+begin
+    vReal = vReal + 1.0;
+    vReal = 1.0 + vReal;
+    vReal = vReal + vReal;
+
+    vReal = vReal - 1.0;
+    vReal = 1.0 - vReal;
+    vReal = vReal - vReal;
+
+    vReal = vReal * 1.0;
+    vReal = 1.0 * vReal;
+    vReal = vReal * vReal;
+
+    vReal = vReal / 1.0;
+    vReal = 1.0 / vReal;
+    vReal = vReal / vReal;
+
+    vReal = vReal % 1.0;
+    vReal = 1.0 % vReal;
+    vReal = vReal % vReal;
+end
+
+procedure TestRealCompOps()
+begin
+    vBool = vReal == 1.0;
+    vBool = 1.0 == vReal;
+    vBool = vReal == vReal;
+
+    vBool = vReal != 1.0;
+    vBool = 1.0 != vReal;
+    vBool = vReal != vReal;
+
+    vBool = vReal < 1.0;
+    vBool = 1.0 < vReal;
+    vBool = vReal < vReal;
+
+    vBool = vReal > 1.0;
+    vBool = 1.0 > vReal;
+    vBool = vReal > vReal;
+
+    vBool = vReal <= 1.0;
+    vBool = 1.0 <= vReal;
+    vBool = vReal <= vReal;
+
+    vBool = vReal >= 1.0;
+    vBool = 1.0 >= vReal;
+    vBool = vReal >= vReal;
+end
+
+procedure TestIfStatements()
+begin
+  if vInt == 1 then
+    vInt = 42;
+  end
+
+  if vInt == 1 then
+    vInt = 42;
+  else
+    vInt = 24;
+  end
+end
+
+procedure TestFlatArrayAccess()
 begin
     vIntArray[0] = vIntArray[1] + vIntArray[2];
 end
 
+procedure TestNestedArrayAccess()
+begin
+    vIntArray2[0][1] = vIntArray2[1][1] + vIntArray2[2][1];
+end
+
 #procedure TestRecordAccess()
 #begin
 #end