scc

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

commit 1fa83f138d13af191704b2bf3504091c6c92a57a
parent 57ca51bc90319ba7b58eefac227b3dfa8c671032
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed,  6 May 2015 19:28:36 +0200

Convert emitswitch into private of code.c

Diffstat:
Mcc1/cc1.h | 26+++++++++++++++++---------
Mcc1/code.c | 14+++++++++-----
Mcc1/stmt.c | 14+-------------
3 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -28,6 +28,8 @@ enum { typedef struct ctype Type; typedef struct symbol Symbol; +typedef struct caselist Caselist; +typedef struct node Node; struct ctype { uint8_t op; /* type builder operator */ @@ -79,7 +81,17 @@ extern Symbol extern void pushctx(void), popctx(void); -typedef struct caselist Caselist; +struct scase { + Symbol *label; + Node *expr; + struct scase *next; +}; + +struct caselist { + short nr; + Symbol *deflabel; + struct scase *head; +}; extern void compound(Symbol *lbreak, Symbol *lcont, Caselist *lswitch); @@ -136,7 +148,7 @@ extern uint8_t yytoken; extern uint8_t next(void); extern void expect(uint8_t tok); -typedef struct node { +struct node { uint8_t op; Type *type; Symbol *sym; @@ -144,7 +156,7 @@ typedef struct node { bool symbol: 1; bool constant : 1; struct node *left, *right; -} Node; +}; enum { OPTR = 1, OADD, OSIZE, OMUL, OSUB, @@ -155,7 +167,7 @@ enum { OCOMMA, OCAST, OSYM, OASK, OFIELD, OTYP, OLABEL, ODEFAULT, OCASE, OSTRUCT, OJUMP, OBRANCH, OEXPR, OEFUN, OESTRUCT, OELOOP, OBLOOP, OPRINT, - OFUN, ORET, ODECL, + OFUN, ORET, ODECL, OSWITCH, /* TODO: This order is important, but must be changed */ OAND, OOR, /* @@ -165,11 +177,7 @@ enum { OEQ = 0x40, ONE, OLT, OGE, OLE, OGT }; -/*TODO: clean these declarations */ -extern void - emit(uint8_t, void *), - emitswitch(short); - +extern void emit(uint8_t, void *); extern Node *node(uint8_t op, Type *tp, Node *left, Node *rigth); extern Node *symbol(Symbol *sym); extern void freetree(Node *np); diff --git a/cc1/code.c b/cc1/code.c @@ -13,7 +13,8 @@ static void emitbin(uint8_t, void *), emitunary(uint8_t, void *), emitsizeof(uint8_t, void *), emitexp(uint8_t, void *), emitsymid(uint8_t, void *), emittext(uint8_t, void *), emitprint(uint8_t, void *), emitfun(uint8_t, void *), - emitret(uint8_t, void *), emitdcl(uint8_t, void *); + emitret(uint8_t, void *), emitdcl(uint8_t, void *), + emitswitch(uint8_t, void *); char *optxt[] = { [OADD] = "+", @@ -121,7 +122,8 @@ void (*opcode[])(uint8_t, void *) = { [OPRINT] = emitprint, [OFUN] = emitfun, [ORET] = emitret, - [ODECL] = emitdcl + [ODECL] = emitdcl, + [OSWITCH] = emitswitch }; void @@ -303,10 +305,12 @@ emitsymid(uint8_t op, void *arg) printf(optxt[op], sym->id); } -void -emitswitch(short nr) +static void +emitswitch(uint8_t op, void *arg) { - printf("\teI\t#%0x", nr); + Caselist *lcase = arg; + + printf("\teI\t#%0x", lcase->nr); } void diff --git a/cc1/stmt.c b/cc1/stmt.c @@ -7,18 +7,6 @@ #include "../inc/cc.h" #include "cc1.h" -struct scase { - Symbol *label; - Node *expr; - struct scase *next; -}; - -struct caselist { - short nr; - Symbol *deflabel; - struct scase *head; -}; - Symbol *curfun; extern Node *convert(Node *np, Type *tp1, char iscast); @@ -249,7 +237,7 @@ Switch(Symbol *lbreak, Symbol *lcont, Caselist *lswitch) emit(OJUMP, lcond); stmt(lbreak, lcont, &lcase); emit(OLABEL, lcond); - emitswitch(lcase.nr); + emit(OSWITCH, &lcase); emit(OEXPR, cond); for (p = lcase.head; p; p = next) { emit(OCASE, p->label);