scc

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

commit 03817ea82122c65ed529a36d448bebd3812e20be
parent fe63fe950ba61c141d0c8a37eaa2306b364966a8
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 27 Sep 2017 06:01:25 +0200

[as] Move match() to the target part

There are so many different addressing modes and so many register
classes that is impossible to write this function in a generic
form.

Diffstat:
Mas/as.h | 11+++++------
Mas/main.c | 6------
Aas/target/amd64/proc.c | 16++++++++++++++++
Mas/target/amd64/target.mk | 3++-
Aas/target/i386/proc.c | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mas/target/i386/target.mk | 3++-
Das/target/x86/args.h | 7-------
Mas/target/x86/gen.awk | 2+-
Aas/target/x86/proc.h | 38++++++++++++++++++++++++++++++++++++++
9 files changed, 144 insertions(+), 22 deletions(-)

diff --git a/as/as.h b/as/as.h @@ -24,12 +24,6 @@ enum symflags { FUNDEF = 1 << 7, }; -enum args { - AIMM = 1, - AMAX, - AREP = 1 << 7, -}; - enum endianess { BIG_ENDIAN = -1, LITTLE_ENDIAN = 1 @@ -78,6 +72,7 @@ struct symbol { char *name; unsigned char flags; char pass; + char argtype; short desc; TUINT value; struct symbol *next; @@ -115,6 +110,10 @@ extern int nextline(FILE *fp, struct line *linep); extern Node *expr(char *s); extern void deltree(Node *np); +/* proc.c */ +extern void iproc(void); +extern int match(Op *op, Node **args); + /* * Definition of global variables */ diff --git a/as/main.c b/as/main.c @@ -7,12 +7,6 @@ static char sccsid[] = "@(#) ./as/main.c"; #include "../inc/scc.h" #include "as.h" -int -match(Op *op, Node **args) -{ - return 1; -} - static int cmp(const void *f1, const void *f2) { diff --git a/as/target/amd64/proc.c b/as/target/amd64/proc.c @@ -0,0 +1,16 @@ +static char sccsid[] = "@(#) ./as/target/amd64/proc.c"; + +#include "../../../inc/scc.h" +#include "../../as.h" + + +void +iarch(void) +{ +} + +int +match(Op *op, Node **args) +{ + return 1; +} diff --git a/as/target/amd64/target.mk b/as/target/amd64/target.mk @@ -13,4 +13,5 @@ target/amd64/instbl.c: target/x86/gen.awk $(AMD64_TBL) OBJ-amd64 = $(OBJ) \ target/amd64/instbl.o \ - target/i386/ins.o + target/i386/ins.o \ + target/amd64/proc.o diff --git a/as/target/i386/proc.c b/as/target/i386/proc.c @@ -0,0 +1,80 @@ +static char sccsid[] = "@(#) ./as/target/i386/proc.c"; + +#include <stdlib.h> + +#include "../../../inc/scc.h" +#include "../../as.h" +#include "../x86/proc.h" + +void +iarch(void) +{ + static struct { + char *name; + char type; + } regs[] = { + "AX", AREG_AX, + "AL", AREG_AL, + "AH", AREG_AH, + "EAX", AREG_EAX, + + "BC", AREG_BC, + "BL", AREG_BL, + "BH", AREG_BH, + "EBX", AREG_EBX, + + "CX", AREG_CX, + "CL", AREG_CL, + "CH", AREG_CH, + "ECX", AREG_ECX, + + "DX", AREG_DX, + "DL", AREG_DL, + "DH", AREG_DH, + "EDX", AREG_EDX, + + "SI", AREG_SI, + "DI", AREG_DI, + + "SP", AREG_SP, + "ESP", AREG_ESP, + "EBP", AREG_EBP, + NULL + }, *bp; + + for (bp = regs; bp->name; ++bp) { + Symbol *sym = lookup(bp->name); + sym->argtype = bp->type; + } +} + +int +match(Op *op, Node **args) +{ + char *p; + int a, olda; + + if (!op->args) + return args == NULL; + + for (p = op->args; *p; ++p) { + if (*p != AREP) + a = *p; + else + --p; + + switch (a) { + case AIMM8: + case AIMM16: + case AIMM32: + case AIMM64: + case AREG_AL: + case AREG_AH: + case AREG_AX: + case AREG_EAX: + default: + abort(); + } + } + return 1; +} diff --git a/as/target/i386/target.mk b/as/target/i386/target.mk @@ -13,4 +13,5 @@ target/i386/instbl.c: target/x86/gen.awk $(I386_TBL) OBJ-i386 = $(OBJ) \ target/i386/instbl.o \ - target/i386/ins.o + target/i386/ins.o \ + target/i386/proc.o diff --git a/as/target/x86/args.h b/as/target/x86/args.h @@ -1,7 +0,0 @@ - -enum args_x86 { - AIMM8 = AMAX, - AIMM16, - AIMM32, - AIMM64, -}; diff --git a/as/target/x86/gen.awk b/as/target/x86/gen.awk @@ -3,7 +3,7 @@ BEGIN { FS = "\t" printf "#include \"../../../inc/scc.h\"\n"\ "#include \"../../as.h\"\n"\ - "#include \"../x86/args.h\"\n"\ + "#include \"../x86/proc.h\"\n"\ "#include \"ins.h\"\n\n" nop = 0; nvar = 0 } diff --git a/as/target/x86/proc.h b/as/target/x86/proc.h @@ -0,0 +1,38 @@ + +enum args { + AIMM = 1, + + AIMM8, + AIMM16, + AIMM32, + AIMM64, + + AREG_AX, + AREG_AL, + AREG_AH, + AREG_EAX, + + AREG_BC, + AREG_BL, + AREG_BH, + AREG_EBX, + + AREG_CX, + AREG_CL, + AREG_CH, + AREG_ECX, + + AREG_DX, + AREG_DL, + AREG_DH, + AREG_EDX, + + AREG_SI, + AREG_DI, + + AREG_SP, + AREG_ESP, + AREG_EBP, + + AREP, +};