scc

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

commit 30f54b9eb7c68cb7d92366ba146ae2f7c6390c40
parent 382b2e36815f494dd95bba35651907da248ffd97
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 29 Dec 2017 13:41:30 +0000

[as-z80] Remove class functions

It is better to have a function that returns a flag field with the
different different classes of the register. It makes the code shorter
and faster.

Diffstat:
Mas/target/x80/ins.c | 123+++++++++++++++++--------------------------------------------------------------
Mas/target/x80/proc.h | 20++++++++++++--------
Mas/target/z80/proc.c | 45++++++++++++++++++++++++---------------------
3 files changed, 62 insertions(+), 126 deletions(-)

diff --git a/as/target/x80/ins.c b/as/target/x80/ins.c @@ -8,125 +8,54 @@ static char sccsid[] = "@(#) ./as/target/z80/ins.c"; #include "proc.h" int -rclass(int reg) +getclass(Node *np) { - switch (reg) { - case AREG_B: - case AREG_C: - case AREG_D: - case AREG_E: - case AREG_H: - case AREG_L: - case AREG_A: - return 1; - default: + if (np->addr != AREG) return 0; - } -} -int -pclass(int reg) -{ - switch (reg) { - case AREG_B: + switch (np->sym->value) { case AREG_C: - case AREG_D: - case AREG_E: - case AREG_IXH: - case AREG_IXL: + return RCLASS | PCLASS | QCLASS | CCCLASS; case AREG_A: - return 1; - default: - return 0; - } -} - -int -qclass(int reg) -{ - switch (reg) { case AREG_B: - case AREG_C: case AREG_D: case AREG_E: - case AREG_IYH: + return RCLASS | PCLASS | QCLASS; + case AREG_H: + case AREG_L: + return RCLASS; + break; + case AREG_IXL: + case AREG_IXH: + return PCLASS; case AREG_IYL: - case AREG_A: - return 1; - default: - return 0; - } -} - -int -ddclass(int reg) -{ - switch (reg) { - case AREG_BC: - case AREG_DE: + case AREG_IYH: + return QCLASS; case AREG_HL: - case AREG_SP: - return 1; - default: - return 0; - } -} - -int -qqclass(int reg) -{ - switch (reg) { + return DDCLASS | QQCLASS; + break; case AREG_BC: case AREG_DE: - case AREG_HL: + return DDCLASS | QQCLASS | PPCLASS | RRCLASS; + break; + case AREG_SP: + return DDCLASS | PPCLASS | RRCLASS; + break; case AREG_AF: - return 1; - default: - return 0; - } -} - -int -ppclass(int reg) -{ - switch (reg) { - case AREG_BC: - case AREG_DE: + return QQCLASS; case AREG_IX: - case AREG_SP: - return 1; - default: - return 0; - } -} - -int -rrclass(int reg) -{ - switch (reg) { - case AREG_BC: - case AREG_DE: + return PPCLASS; + break; case AREG_IY: - case AREG_SP: - return 1; - default: - return 0; - } -} - -int -ccclass(int reg) -{ - switch (reg) { + return RRCLASS; case AREG_NZ: case AREG_Z: case AREG_NC: - case AREG_C: case AREG_PO: case AREG_PE: case AREG_P: case AREG_M: - return 1; + return CCCLASS; default: return 0; } diff --git a/as/target/x80/proc.h b/as/target/x80/proc.h @@ -63,11 +63,15 @@ enum args { ARST, /* 0h, 08h, 10h, 18h, 20h, 28h, 30h, 38h */ }; -extern int rclass(int reg); -extern int pclass(int reg); -extern int qclass(int reg); -extern int ddclass(int reg); -extern int qqclass(int reg); -extern int ppclass(int reg); -extern int rrclass(int reg); -extern int ccclass(int reg); +enum { + RCLASS = 1 << 0, + PCLASS = 1 << 1, + QCLASS = 1 << 2, + DDCLASS = 1 << 3, + QQCLASS = 1 << 4, + PPCLASS = 1 << 5, + RRCLASS = 1 << 6, + CCCLASS = 1 << 7, +}; + +extern int getclass(Node *np); diff --git a/as/target/z80/proc.c b/as/target/z80/proc.c @@ -64,9 +64,8 @@ int match(Op *op, Node **args) { unsigned char *p; - int arg; + int arg, class; Node *np; - int (*class)(int); if (!op->args) return args == NULL; @@ -76,6 +75,7 @@ match(Op *op, Node **args) --p; if ((np = *args++) == NULL) return (arg & (AREP|AOPT)) != 0; + class = getclass(np); arg &= ~(AREP|AOPT); switch (arg) { @@ -119,32 +119,35 @@ match(Op *op, Node **args) return 0; break; case AREG_RCLASS: - class = rclass; - goto register_class; + if ((class & RCLASS) == 0) + return 0; + break; case AREG_PCLASS: - class = pclass; - goto register_class; + if ((class & PCLASS) == 0) + return 0; + break; case AREG_QCLASS: - class = qclass; - goto register_class; + if ((class & QCLASS) == 0) + return 0; + break; case AREG_QQCLASS: - class = qqclass; - goto register_class; + if ((class & QQCLASS) == 0) + return 0; + break; case AREG_PPCLASS: - class = ppclass; - goto register_class; + if ((class & PPCLASS) == 0) + return 0; + break; case AREG_RRCLASS: - class = rrclass; - goto register_class; + if ((class & RRCLASS) == 0) + return 0; + break; case AREG_CCCLASS: - class = ccclass; - goto register_class; - case AREG_DDCLASS: - class = ddclass; - register_class: - if (np->addr != AREG) + if ((class & CCCLASS) == 0) return 0; - if (!(*class)(np->sym->value)) + break; + case AREG_DDCLASS: + if ((class & DDCLASS) == 0) return 0; break; case AINDEX_IY: