scc

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

commit f88e9e2cd64fa2907c4f9e66747ea78c6f9a24c2
parent f10d4f047da4eb78ccb7d102e5757a97aa6a7120
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 14 Sep 2017 14:32:50 +0100

[cc2] Use the new generic arena allocator

Diffstat:
Mcc2/node.c | 39++++++++-------------------------------
1 file changed, 8 insertions(+), 31 deletions(-)

diff --git a/cc2/node.c b/cc2/node.c @@ -11,13 +11,8 @@ static char sccsid[] = "@(#) ./cc2/node.c"; Node *curstmt; Symbol *curfun; -struct arena { - Node *mem; - struct arena *next; -}; +static Alloc *arena; -static struct arena *arena; -static Node *freep; Node * newnode(int op) @@ -25,21 +20,9 @@ newnode(int op) struct arena *ap; Node *np; - if (!freep) { - ap = xmalloc(sizeof(*ap)); - ap->mem = xcalloc(NNODES, sizeof(Node)); - ap->next = arena; - arena = ap; - for (np = ap->mem; np < &ap->mem[NNODES-1]; ++np) - np->left = np+1; - np->left = NULL; - freep = np; - } - - np = freep; - freep = np->left; - - memset(np, 0, sizeof(*np)); + if (!arena) + arena = alloc(sizeof(Node), NNODES); + np = memset(new(arena), 0, sizeof(*np)); np->op = op; return np; @@ -125,8 +108,7 @@ nextstmt(void) void delnode(Node *np) { - np->left = freep; - freep = np; + delete(arena, np); } void @@ -142,15 +124,10 @@ deltree(Node *np) void cleannodes(void) { - struct arena *ap, *next; - - for (ap = arena; ap; ap = next) { - next = ap->next; - free(ap->mem); - free(ap); + if (arena) { + dealloc(arena); + arena = NULL; } - arena = NULL; - freep = NULL; curstmt = NULL; }