scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 8cc7f57a951c9807a7d55cbb7ed1a9cb456930e2
parent 8d0d2c097a87b8d96e107bab9b0c9176e75f89ef
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 21 Mar 2015 04:06:52 -0400

Add BAND, BOR and BXOR operations

These are exactly the same than add operation, so they were really easy.

Diffstat:
Mcc2/cc2.h | 5++++-
Mcc2/cgen.c | 36+++++++++++++++++++++++++++++++-----
Mcc2/code.c | 10++++++++--
3 files changed, 43 insertions(+), 8 deletions(-)

diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -136,7 +136,10 @@ enum { INC, SUB, DEC, - JP + JP, + AND, + OR, + XOR }; enum { diff --git a/cc2/cgen.c b/cc2/cgen.c @@ -252,6 +252,9 @@ move(Node *np, Node *parent) break; case OADD: case OSUB: + case OBAND: + case OBOR: + case OBXOR: switch (np->op) { case PAR: case AUTO: @@ -286,12 +289,13 @@ static void add(Node *np) { Node *lp = np->left, *rp = np->right, *a; + uint8_t op; switch (np->type.size) { case 1: a = reguse[A]; if (a == lp) - goto add1; + goto update_a; if (a == rp) goto conmute1; if (lp->op == CONST) { @@ -299,13 +303,32 @@ add(Node *np) goto conmute1; } accum(lp); - goto add1; + goto update_a; conmute1: conmute(np); lp = np->left, rp = np->right; - add1: + update_a: move(rp, np); - code((np->op == OADD) ? ADD : SUB, lp, rp); + switch (np->op) { + case OADD: + op = ADD; + break; + case OSUB: + op = SUB; + break; + case OBAND: + op = AND; + break; + case OBOR: + op = OR; + break; + case OBXOR: + op = XOR; + break; + default: + abort(); + } + code(op, lp, rp); lp->used = rp->used = 1; np->op = REG; np->reg = A; @@ -380,7 +403,10 @@ static void (*opnodes[])(Node *) = { [REG] = nop, [AUTO] = nop, [CONST] = nop, - [PAR] = nop + [PAR] = nop, + [OBOR] = add, + [OBAND] = add, + [OBXOR] = add }; static void diff --git a/cc2/code.c b/cc2/code.c @@ -34,7 +34,10 @@ static void (*instcode[])(void) = { [INC] = inst1, [SUB] = inst2, [DEC] = inst1, - [JP] = inst1 + [JP] = inst1, + [AND] = inst2, + [OR] = inst2, + [XOR] = inst2 }; static char *insttext[] = { @@ -51,7 +54,10 @@ static char *insttext[] = { [INC] = "INC", [SUB] = "SUB", [DEC] = "DEC", - [JP] = "JP" + [JP] = "JP", + [AND] = "AND", + [OR] = "OR", + [XOR] = "XOR" }; Inst *pc, *prog;