scc

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

commit 7de77b9d418a975b358d701e26452c80819d6042
parent 222655d71caa72a961f0a1573b42f48a891c5808
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 10 Aug 2014 23:11:25 +0200

Add modulo operator in cc2

Diffstat:
cc1/code.c | 2+-
cc2/cc2.h | 1+
cc2/cgen.c | 4++--
cc2/parser.c | 1+
4 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/cc1/code.c b/cc1/code.c @@ -19,7 +19,7 @@ char *opcodes[] = { [ODEC] = ";-", [OSIZE] = "#", [OPTR] = "@", - [OMOD] = "*", + [OMOD] = "%", [ODIV] = "/", [OSHL] = "l", [OSHR] = "r", diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -69,6 +69,7 @@ enum nerrors { #define OSUB '-' #define OASSIG ':' #define OINC ';' +#define OMOD '%' extern void error(unsigned nerror, ...); extern void genaddable(Node *list[]); diff --git a/cc2/cgen.c b/cc2/cgen.c @@ -125,7 +125,7 @@ xcgen(Node *np) switch (np->op) { case OINC: - case OADD: case OASSIG: + case OADD: case OASSIG: case OMOD: break; default: abort(); @@ -191,7 +191,7 @@ xaddable(Node *np) np->addable = 20; break; case OINC: - case OASSIG: case OADD: case OSUB: + case OASSIG: case OADD: case OSUB: case OMOD: xaddable(lp); xaddable(rp); break; diff --git a/cc2/parser.c b/cc2/parser.c @@ -248,6 +248,7 @@ increment(char *token) static void (*optbl[])(char *) = { ['+'] = operator, + ['%'] = operator, ['-'] = operator, ['*'] = operator, ['/'] = operator,