]> git.mdlowis.com Git - proto/obnc.git/commitdiff
reporting if statements correctly now
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 30 Nov 2021 22:10:27 +0000 (17:10 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 30 Nov 2021 22:10:27 +0000 (17:10 -0500)
cerise/src/grammar.c
cerise/src/ssa.c

index 221ed7a55d3f1a46b20335328db633a73d5b7896..158a21e366e4e5960962da0cf96b1aae828f7547 100644 (file)
@@ -413,6 +413,7 @@ static SsaBlock* statement_seq(Parser* p)
             SsaNode* cond = expression(p);
             check_bool(p, cond);
             expect(p, THEN);
+            SsaNode* if_node = ssa_if(p, cond, NULL, NULL);
 
             SsaBlock* block = p->curr_block;
             block->links[0] = statement_seq(p);
@@ -423,13 +424,15 @@ static SsaBlock* statement_seq(Parser* p)
             {
                 block->links[1] = statement_seq(p);
                 block->links[1]->links[0] = p->curr_join;
-                /* reset vars to backup values */
             }
             else
             {
                 block->links[1] = p->curr_join;
             }
 
+            if_node->left.block = block->links[0];
+            if_node->right.block = block->links[1];
+
             /* pop the join node */
             p->curr_block = p->curr_join;
             p->curr_join = p->curr_join->next;
index c99bd5002764b4781991d6b96b2e5eb92ccf77a1..8c335dd2a52195229b01d7d7b65e551316b820f7 100644 (file)
@@ -184,9 +184,14 @@ void ssa_block_add(SsaBlock* blk, SsaNode* node)
 
 SsaNode* ssa_if(Parser* p, SsaNode* cond, SsaBlock* br1, SsaBlock* br2)
 {
-    (void)br1, (void)br2;
     cond = load(p, cond);
-    return NULL;
+    SsaNode* node = ssa_node(IF, MODE_CONTROL);
+    node->type = &VoidType;
+    node->left.block = br1;
+    node->right.block = br2;
+    node = load(p, node);
+    node->dest = cond->dest;
+    return node;
 }
 
 SsaNode* ssa_return(SsaNode* expr);
@@ -406,8 +411,11 @@ static void print_ident(Parser* p, SsaVar* var)
 
 static void print_dest(Parser* p, SsaNode* node)
 {
-    print_ident(p, &(node->dest));
-    printf(" = ");
+    if (node->mode != MODE_CONTROL)
+    {
+        print_ident(p, &(node->dest));
+        printf(" = ");
+    }
 }
 
 static void print_opcode(SsaNode* node)
@@ -427,19 +435,19 @@ static void print_opcode(SsaNode* node)
     }
     else if (op == EQ)
     {
-        printf("==");
+        printf(" == ");
     }
     else if (op == NEQ)
     {
-        printf("!=");
+        printf(" != ");
     }
     else if (op == LTEQ)
     {
-        printf("<=");
+        printf(" <= ");
     }
     else if (op == GTEQ)
     {
-        printf(">=");
+        printf(" >= ");
     }
      else
     {
@@ -468,6 +476,12 @@ void ssa_print(Parser* p, SsaNode* expr)
             printf("(Real)%f", ssa_asreal(expr));
             break;
 
+        case IF:
+            printf("if ");
+            print_ident(p, &(expr->dest));
+            printf(" then block%lu else block%lu", expr->left.block->id, expr->right.block->id);
+            break;
+
         default:
             if (expr->mode == MODE_VAR)
             {
@@ -560,7 +574,7 @@ void ssa_print_graph(Parser* p, SsaBlock* block)
     {
 
         /* print the phis */
-        for (SsaPhi* phi = block->phis; phi; phi = phi->next)
+        for (SsaPhi* phi = curr->phis; phi; phi = phi->next)
         {
             Symbol* s = symbol_getbyid(p, phi->symid);
             s->version++;