scc

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

commit a90c987aa4bf133d6b484e26684919f482ffad73
parent b5fe10c6fb6606d271bc75e2245a801286f91bb4
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 18 Mar 2015 10:31:41 +0000

Add prev pointer in Inst

We are going to add and remove elements from the list, so it is a good
idea to have a pointer to the previous element, because with this data
structure is easy to remove elements from it.

Diffstat:
Mcc2/cc2.h | 22++++++++++++++++++++--
Mcc2/code.c | 22+++-------------------
2 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -85,6 +85,25 @@ struct node { struct node *left, *right; }; +typedef struct inst Inst; +typedef struct addr Addr; + +struct addr { + char kind; + union { + uint8_t reg; + TINT i; + Inst *pc; + Symbol *sym; + } u; +}; + +struct inst { + char op; + Addr from, to; + Inst *next, *prev; +}; + enum nerrors { EINTNUM, /* too much internal identifiers */ EEXTNUM, /* too much external identifiers */ @@ -101,8 +120,6 @@ enum nerrors { ENUMERR }; - - enum { LDW, LDL, @@ -124,6 +141,7 @@ enum { }; extern Symbol *curfun; +extern Inst *prog, *pc; /* main.c */ extern void error(unsigned nerror, ...); diff --git a/cc2/code.c b/cc2/code.c @@ -48,25 +48,7 @@ static char *insttext[] = { [INC] = "INC" }; -typedef struct inst Inst; -typedef struct addr Addr; - -struct addr { - char kind; - union { - uint8_t reg; - TINT i; - Inst *pc; - Symbol *sym; - } u; -}; - -struct inst { - char op; - Addr from, to; - Inst *next; -}; -Inst *prog, *pc; +Inst *pc, *prog; Inst * nextpc(void) @@ -74,6 +56,8 @@ nextpc(void) Inst *new; new = xmalloc(sizeof(*new)); + new->prev = pc; + if (!pc) prog = new; else