scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit e2c5b2c6dacc3a0c42fe14b79d05abc0acb42d1f
parent b90eb5f63f1264a37528244e8c2ce6a77a8da36a
Author: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
Date:   Mon, 25 Apr 2016 20:10:45 +0200

[cc2] Conver statement list into a double link

We need a double list because we are going to do some modifications
to the elements of the list, mainly in optimizations. Since stmt
operations are node operations is more logical if we move it to
node.c, where all the node functions live.

Diffstat:
Mcc2/cc2.h | 5+++--
Mcc2/node.c | 19+++++++++++++++++--
Mcc2/parser.c | 11-----------
3 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -138,7 +138,7 @@ struct symbol { char kind; union { TSIZE off; - Node *nlabel; + Node *stmt; Inst *ilabel; } u; Symbol *next; @@ -160,7 +160,7 @@ struct node { } u; Symbol *label; Node *left, *right; - Node *stmt; + Node *next, *prev; }; struct addr { @@ -208,6 +208,7 @@ extern void cleannodes(void); extern void delnode(Node *np); extern void deltree(Node *np); extern Node *newnode(void); +extern Node *addstmt(Node *np); /* symbol.c */ #define TMPSYM 0 diff --git a/cc2/node.c b/cc2/node.c @@ -18,7 +18,7 @@ struct arena { }; static struct arena *arena; -static Node *freep; +static Node *freep, *stmtp; static int inhome; Node * @@ -44,6 +44,20 @@ newnode(void) return memset(np, 0, sizeof(*np)); } +Node * +addstmt(Node *np) +{ + if (!curfun->u.stmt) + curfun->u.stmt = np; + else + stmtp->next = np; + np->next = NULL; + np->prev = stmtp; + stmtp = np; + + return np; +} + void delnode(Node *np) { @@ -73,6 +87,7 @@ cleannodes(void) } arena = NULL; freep = NULL; + stmtp = NULL; } void @@ -83,6 +98,6 @@ apply(Node *(*fun)(Node *)) if (!curfun) return; - for (np = curfun->u.nlabel; np; np = np->stmt) + for (np = curfun->u.stmt; np; np = np->next) (*fun)(np); } diff --git a/cc2/parser.c b/cc2/parser.c @@ -131,7 +131,6 @@ static struct decoc { }; static int sclass, inpars, ininit, endf, lineno; -static Node *stmtp; static void *stack[STACKSIZ], **sp = stack; static void @@ -569,16 +568,6 @@ flddecl(void) } static void -addstmt(Node *np) -{ - if (!curfun->u.nlabel) - curfun->u.nlabel = np; - else - stmtp->stmt = np; - stmtp = np; -} - -static void labeldcl(void) { Node *np;