scc

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

commit 48a6fc29693471ca6a56e6691fed7ffb154a1b58
parent 647295531ad0b58e8460ce06e471047fbba80f2f
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 25 Jan 2018 12:56:27 +0100

[as] Generalize zilog() to addrmode()

Zilog() was intended for complex addressing modes, and this is
something that is going to be too much arch dependant, so it is
better to give this work to the arch code.

Diffstat:
Mas/as.h | 3+++
Mas/expr.c | 32+++-----------------------------
Mas/target/x80/ins.c | 24++++++++++++++++++++++++
Mas/target/x86/ins.c | 5+++++
4 files changed, 35 insertions(+), 29 deletions(-)

diff --git a/as/as.h b/as/as.h @@ -166,11 +166,14 @@ extern int nextline(FILE *fp, struct line *linep); /* expr.c */ extern Node *operand(char **s); +extern Node *expr(void); extern void deltree(Node *np); +extern Node *node(int op, Node *l, Node *r); /* proc.c */ extern void iarch(void); extern int match(Op *op, Node **args); +extern Node *addrmode(void); /* ins.c */ extern char *tobytes(TUINT v, int n, int inc); diff --git a/as/expr.c b/as/expr.c @@ -25,7 +25,7 @@ static int regmode; #define accept(t) (yytoken == (t) ? next() : 0) -static Node * +Node * node(int op, Node *l, Node *r) { struct arena *ap; @@ -351,32 +351,6 @@ expect(int token) next(); } -static Node *expr(void); - -Node * -zilog(void) -{ - int op; - Node *np = expr(); - - switch (np->addr) { - case AREG: - op = AINDIR; - break; - case AREG_OFF: - op = AINDEX; - break; - case ANUMBER: - op = ADIRECT; - break; - default: - abort(); - } - np = node(op, np, NULL); - np->addr = op; - return np; -} - /*************************************************************************/ /* grammar functions */ /*************************************************************************/ @@ -513,7 +487,7 @@ and(void) return np; } -static Node * +Node * expr(void) { int op; @@ -548,7 +522,7 @@ operand(char **strp) break; case '(': next(); - np = zilog(); + np = addrmode(); expect(')'); break; case REG: diff --git a/as/target/x80/ins.c b/as/target/x80/ins.c @@ -148,6 +148,30 @@ match(Op *op, Node **args) return *args == NULL; } +Node * +addrmode(void) +{ + int op; + Node *np = expr(); + + switch (np->addr) { + case AREG: + op = AINDIR; + break; + case AREG_OFF: + op = AINDEX; + break; + case ANUMBER: + op = ADIRECT; + break; + default: + abort(); + } + np = node(op, np, NULL); + np->addr = op; + return np; +} + int getclass(Node *np) { diff --git a/as/target/x86/ins.c b/as/target/x86/ins.c @@ -36,3 +36,8 @@ match(Op *op, Node **args) } return 1; } + +Node * +addrmode(void) +{ +}