]> git.mdlowis.com Git - proto/obnc.git/commitdiff
fixed null pointer issues but code generation is still wrong
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 8 Mar 2022 16:21:06 +0000 (11:21 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 8 Mar 2022 16:21:06 +0000 (11:21 -0500)
cerise/backend/ssa/codegen.c
cerise/src/ssa.c
cerise/tests/Module.m

index cd427b6399959081c2c07366f60343d8efb19b6a..da2486d29234739bd25830f5e6d0b8610ca9c974 100644 (file)
@@ -293,8 +293,11 @@ void print_op(Parser* p, SsaNode* expr)
             {
                 printf("    ret ");
                 emit_type(expr->ret_type);
-                printf(" ");
-                print_ident(p, &(expr->dest));
+                if (expr->ret_type->form != FORM_VOID)
+                {
+                    printf(" ");
+                    print_ident(p, &(expr->dest));
+                }
                 puts("");
             }
             break;
@@ -323,7 +326,7 @@ void print_op(Parser* p, SsaNode* expr)
             printf(" = %s ", binop_name(expr));
             emit_type(expr->ret_type);
             printf(" ");
-            print_const(expr->ret_type, &(expr->left));
+            print_const(expr->arg_type, &(expr->left));
             printf(", ");
             print_ident(p, &(expr->right.var));
             printf("\n");
@@ -337,7 +340,7 @@ void print_op(Parser* p, SsaNode* expr)
             printf(" ");
             print_ident(p, &(expr->left.var));
             printf(", ");
-            print_const(expr->ret_type, &(expr->right));
+            print_const(expr->arg_type, &(expr->right));
             printf("\n");
             break;
 
index 0ae1aff9aa79d5f4a58b872ad385800793238fb1..23aa3f10473cc3a1ae50f11b9a05116149e1c404 100644 (file)
@@ -137,6 +137,7 @@ SsaNode* ssa_ident(Parser* p, long long index)
     {
         node = ssa_node(IDENT, MODE_VAR);
         node->ret_type = sym->type;
+        node->arg_type = sym->type;
         node->loaded = !sym->global;
         node->dest.symid = index;
         node->dest.symver = sym->version;
@@ -151,6 +152,7 @@ SsaNode* ssa_bool(Parser* p, bool val)
     (void)p;
     SsaNode* node = ssa_node(BOOL, MODE_CONST);
     node->ret_type = &BoolType;
+    node->arg_type = &BoolType;
     node->left.val.i = val;
     return node;
 }
@@ -160,6 +162,7 @@ SsaNode* ssa_int(Parser* p, long long val)
     (void)p;
     SsaNode* node = ssa_node(INT, MODE_CONST);
     node->ret_type = &IntType;
+    node->arg_type = &IntType;
     node->left.val.i = val;
     return node;
 }
@@ -169,6 +172,7 @@ SsaNode* ssa_real(Parser* p, double val)
     (void)p;
     SsaNode* node = ssa_node(REAL, MODE_CONST);
     node->ret_type = &RealType;
+    node->arg_type = &RealType;
     node->left.val.f = val;
     return node;
 }
@@ -185,6 +189,7 @@ SsaNode* ssa_store(Parser* p, SsaNode* dest, SsaNode* value)
     load(p, value);
     SsaNode* node = ssa_node(STORE, MODE_MEMORY);
     node->ret_type = dest->ret_type;
+    node->arg_type = dest->ret_type;
     node->dest = dest->left.var;
     node->left.var = value->dest;
     node->dest.symver = phi_add(p, node->dest);
@@ -234,6 +239,7 @@ SsaNode* ssa_if(Parser* p, SsaNode* cond, SsaBlock* br1, SsaBlock* br2)
     cond = load(p, cond);
     SsaNode* node = ssa_node(IF, MODE_CONTROL);
     node->ret_type = &VoidType;
+    node->arg_type = &BoolType;
     node->left.block = br1;
     node->right.block = br2;
     node = load(p, node);
@@ -248,12 +254,14 @@ SsaNode* ssa_return(Parser* p, SsaNode* expr)
     {
         load(p, expr);
         node->ret_type = expr->ret_type;
+        node->arg_type = expr->ret_type;
         node = load(p, node);
         node->dest = expr->dest;
     }
     else
     {
         node->ret_type = &VoidType;
+        node->arg_type = &VoidType;
         node = load(p, node);
     }
     return node;
@@ -325,6 +333,7 @@ static SsaNode* unop(Parser* p, int op, SsaNode* operand)
         operand = load(p, operand);
         node = ssa_node(op, MODE_UNOP);
         node->ret_type = operand->ret_type;
+        node->arg_type = operand->ret_type;
         node->left.var = operand->dest;
     }
     return node;
@@ -428,6 +437,8 @@ static SsaNode* const_binop(int op, SsaNode* a, SsaNode* b)
     {
         assert(!"not a left.valid form");
     }
+
+    a->arg_type = a->ret_type;
     return a;
 }
 
index 31112387dd398f440feb2491ad225a0ade3dc75d..46e2024358fc0b2dad5aa0bc7abcdf98e0c8c01f 100644 (file)
@@ -98,14 +98,28 @@ begin
 
 #  # Comparison ops
   a = b == 1;
+  a = 1 == b;
+#  a = b == b;
+
 #  a = b != 1;
+#  a = 1 != b;
+#  a = b != b;
+#
 #  a = b < 1;
+#  a = 1 < b;
+#  a = b < b;
+#
 #  a = b > 1;
+#  a = 1 > b;
+#  a = b > b;
+#
 #  a = b <= 1;
+#  a = 1 <= b;
+#  a = b <= b;
+#
 #  a = b >= 1;
-
-
-
+#  a = 1 >= b;
+#  a = b >= b;
 
 #  b = 1;
 #  if c == b then