scc

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

commit 73ea23b4798899eeb1aec7d9e19b594f8000c016
parent 53e36437d86d46131b359596f1e62ff9f3166a0b
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 10 Aug 2014 23:46:33 +0200

Add bit logical operations to cc2

Diffstat:
Mcc2/cc2.h | 3+++
Mcc2/cgen.c | 4+++-
Mcc2/parser.c | 24+++++++++++++++++++++++-
3 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -73,6 +73,9 @@ enum nerrors { #define ODIV '/' #define OSHL 'l' #define OSHR 'r' +#define OBAND '&' +#define OBOR '|' +#define OBXOR '^' extern void error(unsigned nerror, ...); extern void genaddable(Node *list[]); diff --git a/cc2/cgen.c b/cc2/cgen.c @@ -125,8 +125,9 @@ xcgen(Node *np) switch (np->op) { case OINC: - case OADD: case OASSIG: case OMOD: case ODIV: + case OADD: case OSUB: case OASSIG: case OMOD: case ODIV: case OSHL: case OSHR: + case OBAND: case OBOR: case OBXOR: break; default: abort(); @@ -194,6 +195,7 @@ xaddable(Node *np) case OINC: case OASSIG: case OADD: case OSUB: case OMOD: case ODIV: case OSHL: case OSHR: + case OBAND: case OBOR: case OBXOR: xaddable(lp); xaddable(rp); break; diff --git a/cc2/parser.c b/cc2/parser.c @@ -243,15 +243,37 @@ increment(char *token) } } +static void +assignment(char *token) +{ + Node *np = newnode(); + + np->right = pop(); + np->left = pop(); + np->op = *token; + switch (*++token) { + case OADD: case OSUB: case OINC: case OMOD: case ODIV: + case OSHL: case OSHR: case OBAND: case OBOR: case OBXOR: + np->subop = *++token; + default: + np->type = gettype(token); + break; + } + push(np); +} + static void (*optbl[])(char *) = { ['+'] = operator, ['%'] = operator, ['-'] = operator, ['*'] = operator, ['/'] = operator, - [':'] = operator, ['l'] = operator, ['r'] = operator, + ['&'] = operator, + ['|'] = operator, + ['^'] = operator, + [':'] = assignment, [';'] = increment, ['A'] = variable, ['T'] = variable,