scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit b09facc71149bd600d32d2c063c762e78340bda9
parent 5be6d06570908e1574813c3f9b0f0f6d8a7cc34b
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 24 Apr 2014 16:57:24 +0200

Add Caselist type

This type is going to be used for the switch implementation,
so we need keep a track of all the elements of the switch.

Diffstat:
cc1.h | 5+++--
stmt.c | 23+++++++++++++++++------
symbol.c | 2+-
3 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/cc1.h b/cc1.h @@ -125,11 +125,12 @@ extern Symbol *lookup(char *s, unsigned char ns), *install(char *s, unsigned char ns); -typedef void Ctxfun(Symbol *, Symbol *, Symbol *); +typedef struct caselist Caselist; +typedef void Ctxfun(Symbol *, Symbol *, Caselist *); extern Ctxfun compound; extern void context(Ctxfun *fun, - Symbol *lbreak, Symbol *lcont, Symbol *lswitch); + Symbol *lbreak, Symbol *lcont, Caselist *lswitch); extern Type *typename(void); diff --git a/stmt.c b/stmt.c @@ -5,11 +5,22 @@ #include "cc1.h" +struct scase { + int val; + Symbol *label; + struct scase *next; +}; + +struct caselist { + short nr; + struct scase *head; +}; + Symbol *curfun; extern Node *convert(Node *np, Type *tp1, char iscast); extern Node *iszero(Node *np), *eval(Node *np); -static void stmt(Symbol *lbreak, Symbol *lcont, Symbol *lswitch); +static void stmt(Symbol *lbreak, Symbol *lcont, Caselist *lswitch); static Symbol * label(char *s, char define) @@ -54,7 +65,7 @@ condition(void) } static void -While(Symbol *lswitch) +While(Caselist *lswitch) { Symbol *begin, *cond, *end; Node *np; @@ -76,7 +87,7 @@ While(Symbol *lswitch) } static void -For(Symbol *lswitch) +For(Caselist *lswitch) { Symbol *begin, *cond, *end; Node *econd = NULL, *einc = NULL; @@ -109,7 +120,7 @@ For(Symbol *lswitch) } static void -Dowhile(Symbol *lswitch) +Dowhile(Caselist *lswitch) { Symbol *begin= label(NULL, 1), *end = label(NULL, 1); @@ -189,7 +200,7 @@ Goto(void) } void -compound(Symbol *lbreak, Symbol *lcont, Symbol *lswitch) +compound(Symbol *lbreak, Symbol *lcont, Caselist *lswitch) { expect('{'); for (;;) { @@ -207,7 +218,7 @@ compound(Symbol *lbreak, Symbol *lcont, Symbol *lswitch) } static void -stmt(Symbol *lbreak, Symbol *lcont, Symbol *lswitch) +stmt(Symbol *lbreak, Symbol *lcont, Caselist *lswitch) { repeat: diff --git a/symbol.c b/symbol.c @@ -47,7 +47,7 @@ freesyms(uint8_t ns) } void -context(Ctxfun *fun, Symbol *lbreak, Symbol *lcont, Symbol *lswitch) +context(Ctxfun *fun, Symbol *lbreak, Symbol *lcont, Caselist *lswitch) { uint8_t ns;