]> git.mdlowis.com Git - proto/obnc.git/commitdiff
start defining CFG links for blocks
authorMichael D. Lowis <mike.lowis@gentex.com>
Mon, 26 Jul 2021 21:01:47 +0000 (17:01 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Mon, 26 Jul 2021 21:01:47 +0000 (17:01 -0400)
cerise/inc/cerise.h
cerise/src/grammar.c
cerise/src/ssa.c

index 97f628634d0e006fdc89002978ae28f145d6c295..e9b5c1281dd91f63c15cc91ff5c2f193fc8ed9e5 100644 (file)
@@ -110,9 +110,12 @@ typedef union {
     char* s;
 } SsaConst;
 
+struct SsaBlock;
+
 typedef union {
     SsaVar var;
     SsaConst val;
+    struct SsaBlock* block;
 } SsaValue;
 
 typedef struct SsaNode {
@@ -138,11 +141,12 @@ typedef struct SsaPhi {
     SsaPhiVar* vars;
 } SsaPhi;
 
-typedef struct {
+typedef struct SsaBlock {
     size_t id;
     SsaPhi* phis;
     SsaNode* head;
     SsaNode* tail;
+    struct SsaBlock* links[2];
 } SsaBlock;
 
 enum {
index e3961db82551f8b2b4fe98081c55b7787d790256..17b2921c7c3e32232784c8b3abd1969e78afc7be 100644 (file)
@@ -478,6 +478,7 @@ static void const_decl(Parser* p)
     bool export = false;
     Symbol* sym = NULL;
 
+    p->curr_block = ssa_block(p);
     do
     {
         name = expect_text(p, IDENT);
@@ -492,6 +493,7 @@ static void const_decl(Parser* p)
         }
     }
     while (matches(p, IDENT));
+    p->curr_block = NULL;
 
     EXIT_RULE();
 }
@@ -504,7 +506,6 @@ void proc_decl(Parser* p)
     char* name = expect_text(p, IDENT);
     bool export = accept(p, '*');
     Symbol* proc = symbol_new(p, 0, name, SYM_PROC, export);
-//    Type* proctype = calloc(1, sizeof(Type));
     Type* proctype = symbol_newtype(p);
     proctype->form = FORM_PROC;
     proc->type = proctype;
@@ -625,16 +626,19 @@ static void module(Parser* p)
 
     if (accept(p, BEGIN))
     {
-        p->curr_block = ssa_block(p);
+        //proc_start();
+        SsaBlock* block = ssa_block(p);
         p->curr_join = ssa_block(p);
+        block->links[1] = p->curr_join;
+
         if (!matches(p, END))
         {
-            SsaBlock* block = statement_seq(p);
-            ssa_print_block(p, block);
-            ssa_print_block(p, p->curr_join);
-            (void)block;
+            block->links[0] = statement_seq(p);
         }
         expect(p, END);
+
+        ssa_print_block(p, block);
+        //proc_end();
     }
 
     if (!matches(p, END_FILE))
index e24695b45033034d7af9911b76bf604114bcf497..232c0254614a6f99cd635df2fad74ad4fb8b9867 100644 (file)
@@ -188,7 +188,6 @@ SsaNode* ssa_return(SsaNode* expr);
 SsaNode* ssa_call(SsaNode* func);
 void ssa_call_add(SsaBlock* call, SsaNode* arg);
 
-
 static SsaNode* binop(Parser* p, int op, SsaNode* left, SsaNode* right)
 {
     SsaNode* node = NULL;