From: Michael D. Lowis Date: Mon, 26 Jul 2021 21:01:47 +0000 (-0400) Subject: start defining CFG links for blocks X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=5b0653af8787e211ddde3a2d886c829fc08888ba;p=proto%2Fobnc.git start defining CFG links for blocks --- diff --git a/cerise/inc/cerise.h b/cerise/inc/cerise.h index 97f6286..e9b5c12 100644 --- a/cerise/inc/cerise.h +++ b/cerise/inc/cerise.h @@ -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 { diff --git a/cerise/src/grammar.c b/cerise/src/grammar.c index e3961db..17b2921 100644 --- a/cerise/src/grammar.c +++ b/cerise/src/grammar.c @@ -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)) diff --git a/cerise/src/ssa.c b/cerise/src/ssa.c index e24695b..232c025 100644 --- a/cerise/src/ssa.c +++ b/cerise/src/ssa.c @@ -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;