]> git.mdlowis.com Git - proto/obnc.git/commitdiff
fixed up loads and stores
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 8 Mar 2022 21:18:31 +0000 (16:18 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 8 Mar 2022 21:18:31 +0000 (16:18 -0500)
cerise/backend/ssa/codegen.c
cerise/inc/cerise.h
cerise/src/ssa.c
cerise/tests/Module.m

index 539942c4d2905af140611a5127d4377e6dd1ccb0..6da63e2ce379a3fa0cbe12d4a052ad7d87204f41 100644 (file)
@@ -240,6 +240,19 @@ char* binop_name(SsaNode* node)
     return name;
 }
 
+void print_operand(Parser* p, SsaNode* expr, int is_const, SsaValue* value)
+{
+    if (is_const)
+    {
+        print_const(expr->arg_type, value);
+    }
+    else
+    {
+        printf(" ");
+        print_ident(p, &(value->var));
+    }
+}
+
 void print_op(Parser* p, SsaNode* expr)
 {
     switch(expr->mode)
@@ -261,8 +274,7 @@ void print_op(Parser* p, SsaNode* expr)
             {
                 printf("    store ");
                 emit_type(expr->arg_type);
-                printf(" ");
-                print_ident(p, &(expr->left.var));
+                print_operand(p, expr, expr->lconst, &(expr->left));
                 printf(", ");
                 emit_type(expr->ret_type);
                 printf("* ");
@@ -301,40 +313,15 @@ void print_op(Parser* p, SsaNode* expr)
             printf(" = %s ", binop_name(expr));
             emit_type(expr->arg_type);
             printf(" ");
-            print_ident(p, &(expr->left.var));
-            printf(", ");
-            print_ident(p, &(expr->right.var));
-            printf("\n");
-            break;
-
-        case MODE_BINOP_LC:
-            printf("    ");
-            print_ident(p, &(expr->dest));
-            printf(" = %s ", binop_name(expr));
-            emit_type(expr->arg_type);
-            printf(" ");
-            print_const(expr->arg_type, &(expr->left));
-            printf(", ");
-            print_ident(p, &(expr->right.var));
-            printf("\n");
-            break;
-
-        case MODE_BINOP_RC:
-            printf("    ");
-            print_ident(p, &(expr->dest));
-            printf(" = %s ", binop_name(expr));
-            emit_type(expr->arg_type);
-            printf(" ");
-            print_ident(p, &(expr->left.var));
+            print_operand(p, expr, expr->lconst, &(expr->left));
             printf(", ");
-            print_const(expr->arg_type, &(expr->right));
+            print_operand(p, expr, expr->rconst, &(expr->right));
             printf("\n");
             break;
 
         case MODE_VAR:
         case MODE_CONST:
         default:
-            printf("OP ????\n");
             assert(!"not implemented");
             break;
     }
index 0bc318009500e6827b9c6c1900520351998a09ef..be905397f9ef06b8f5f03a4adf941b456d17d0b5 100644 (file)
@@ -127,9 +127,11 @@ typedef union {
 
 typedef struct SsaNode {
     struct SsaNode* next;
-    int code : 27;
-    int mode : 4;
-    int loaded : 1;
+    unsigned int code : 25;
+    unsigned int mode : 4;
+    unsigned int loaded : 1;
+    unsigned int lconst : 1;
+    unsigned int rconst : 1;
     Type* ret_type;
     Type* arg_type;
     SsaVar dest;
@@ -166,9 +168,7 @@ enum {
     MODE_CONTROL  = 2,
     MODE_UNOP     = 3,
     MODE_BINOP    = 4,
-    MODE_BINOP_LC = 5,
-    MODE_BINOP_RC = 6,
-    MODE_MEMORY   = 7,
+    MODE_MEMORY   = 5,
 };
 
 typedef struct Symbol {
index 23aa3f10473cc3a1ae50f11b9a05116149e1c404..bef2c36b740e4d334b1037cafe955a7007101c54 100644 (file)
@@ -191,7 +191,17 @@ SsaNode* ssa_store(Parser* p, SsaNode* dest, SsaNode* value)
     node->ret_type = dest->ret_type;
     node->arg_type = dest->ret_type;
     node->dest = dest->left.var;
-    node->left.var = value->dest;
+
+    if (value->mode == MODE_CONST)
+    {
+        node->lconst = 1;
+        node->left = value->left;
+    }
+    else
+    {
+        node->left.var = value->dest;
+    }
+
     node->dest.symver = phi_add(p, node->dest);
     ssa_block_add(p->curr_block, node);
     node->loaded = 1;
@@ -281,22 +291,22 @@ static SsaNode* binop(Parser* p, int op, SsaNode* left, SsaNode* right)
     {
         left = load(p, left);
         right = load(p, right);
+        node = ssa_node(op, MODE_BINOP);
 
         if (left->mode == MODE_CONST)
         {
-            node = ssa_node(op, MODE_BINOP_LC);
+            node->lconst = 1;
             node->left = left->left;
             node->right.var = right->dest;
         }
         else if (right->mode == MODE_CONST)
         {
-            node = ssa_node(op, MODE_BINOP_RC);
+            node->rconst = 1;
             node->left.var = left->dest;
             node->right = right->left;
         }
         else
         {
-            node = ssa_node(op, MODE_BINOP);
             node->left.var = left->dest;
             node->right.var = right->dest;
         }
index 67a6d146a761c8f76be6109dbae31c51134636ce..8086199c0521f94ff7efa8b983e84348a89e3e1a 100644 (file)
@@ -73,7 +73,7 @@ var
 begin
   # Global variables
   i = 42;
-#  b = i;
+  b = i;
 
 #  # Arithmetic ops
 #  c = b + 1;