]> git.mdlowis.com Git - proto/obnc.git/commitdiff
attempted to add in function blocks but return statements are not working at the...
authorMichael D. Lowis <mike.lowis@gentex.com>
Wed, 1 Dec 2021 21:38:14 +0000 (16:38 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Wed, 1 Dec 2021 21:38:14 +0000 (16:38 -0500)
cerise/inc/cerise.h
cerise/src/grammar.c
cerise/src/ssa.c
cerise/tests/Module.m

index bddaf0fb2b14f980101b7d2ef3a8a68e009e2fae..ad687020ba9535dd9329f4557ebd7e1911bd1e72 100644 (file)
@@ -270,7 +270,7 @@ SsaBlock* ssa_block(Parser* p);
 void ssa_block_add(SsaBlock* blk, SsaNode* stmt);
 
 SsaNode* ssa_if(Parser* p, SsaNode* cond, SsaBlock* br1, SsaBlock* br2);
-SsaNode* ssa_return(SsaNode* expr);
+SsaNode* ssa_return(Parser* p, SsaNode* expr);
 
 SsaNode* ssa_call(SsaNode* func);
 void ssa_call_add(SsaBlock* call, SsaNode* arg);
index 158a21e366e4e5960962da0cf96b1aae828f7547..b4766297c154b4e3de336a65174b4c381eda8f73 100644 (file)
@@ -438,11 +438,6 @@ static SsaBlock* statement_seq(Parser* p)
             p->curr_join = p->curr_join->next;
             expect(p, END);
         }
-//        else if (accept(p, END))
-//        {
-//            /* this is an empty block?? */
-//            break;
-//        }
         else /* assignments/expressions */
         {
             SsaNode* expr = expression(p);
@@ -574,6 +569,32 @@ void proc_decl(Parser* p)
         var_decl(p);
     }
 
+    expect(p, BEGIN);
+    SsaBlock* block = ssa_block(p);
+    p->curr_join = ssa_block(p);
+    block->links[1] = p->curr_join;
+
+    if (!matches(p, RETURN) && !matches(p, END))
+    {
+        block->links[0] = statement_seq(p);
+    }
+    else
+    {
+        block->links[0] = ssa_block(p);
+        p->curr_block = block->links[0];
+    }
+
+    if (proctype->base != &VoidType)
+    {
+        expect(p, RETURN);
+        SsaNode* retval = expression(p);
+        check_type(p, proctype->base, retval);
+        expect(p, ';');
+        ssa_return(p, retval);
+    }
+    expect(p, END);
+    ssa_print_graph(p, block);
+
 //    /* parse the body of the procedure */
 //    expect(p, BEGIN);
 //    proc->value = ast_block();
index 8c335dd2a52195229b01d7d7b65e551316b820f7..45b74f3e73880ccfc4a00f8e5efd59573cec89d9 100644 (file)
@@ -194,7 +194,15 @@ SsaNode* ssa_if(Parser* p, SsaNode* cond, SsaBlock* br1, SsaBlock* br2)
     return node;
 }
 
-SsaNode* ssa_return(SsaNode* expr);
+SsaNode* ssa_return(Parser* p, SsaNode* expr)
+{
+    load(p, expr);
+    SsaNode* node = ssa_node(RETURN, MODE_CONTROL);
+    node->type = expr->type;
+    node = load(p, node);
+    node->dest = expr->dest;
+    return node;
+}
 
 SsaNode* ssa_call(SsaNode* func);
 void ssa_call_add(SsaBlock* call, SsaNode* arg);
index 1b08561dcb1b61b9f4c9e221293566c571ca4067..92d535f5b128a4c6deb82aa6eee096ef1760aaa3 100644 (file)
@@ -54,11 +54,11 @@ var
 #  return z1;
 #end
 
-#procedure Bar*(a : Int) : Int
-#begin
-#    return a;
-#end
-#
+procedure Bar*(a : Int) : Int
+begin
+    return a;
+end
+
 #procedure Baz*(a : Int)
 #begin
 #    if (1 > 2) then
@@ -70,8 +70,8 @@ var
 
 begin
   b = 42;
-#  b = -b;
-#  c = b + 1;
+  b = -b;
+  c = b + 1;
 
   if c == b then
     c = 42;