ref: 4fc15c50d106acfee86968ebe9d97757a0012483
parent: de47aaf07d23703824379f0a3b558a2e32eb502e
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Sep 27 02:01:25 EDT 2017
[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.
--- a/as/as.h
+++ b/as/as.h
@@ -24,12 +24,6 @@
FUNDEF = 1 << 7,
};
-enum args {
- AIMM = 1,
- AMAX,
- AREP = 1 << 7,
-};
-
enum endianess {
BIG_ENDIAN = -1,
LITTLE_ENDIAN = 1
@@ -78,6 +72,7 @@
char *name;
unsigned char flags;
char pass;
+ char argtype;
short desc;
TUINT value;
struct symbol *next;
@@ -114,6 +109,10 @@
/* expr.c */
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
--- a/as/main.c
+++ b/as/main.c
@@ -7,12 +7,6 @@
#include "../inc/scc.h"
#include "as.h"
-int
-match(Op *op, Node **args)
-{
- return 1;
-}
-
static int
cmp(const void *f1, const void *f2)
{
--- /dev/null
+++ b/as/target/amd64/proc.c
@@ -1,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;
+}
--- a/as/target/amd64/target.mk
+++ b/as/target/amd64/target.mk
@@ -13,4 +13,5 @@
OBJ-amd64 = $(OBJ) \
target/amd64/instbl.o \
- target/i386/ins.o
+ target/i386/ins.o \
+ target/amd64/proc.o
--- /dev/null
+++ b/as/target/i386/proc.c
@@ -1,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;
+}
--- a/as/target/i386/target.mk
+++ b/as/target/i386/target.mk
@@ -13,4 +13,5 @@
OBJ-i386 = $(OBJ) \
target/i386/instbl.o \
- target/i386/ins.o
+ target/i386/ins.o \
+ target/i386/proc.o
--- a/as/target/x86/args.h
+++ /dev/null
@@ -1,7 +1,0 @@
-
-enum args_x86 {
- AIMM8 = AMAX,
- AIMM16,
- AIMM32,
- AIMM64,
-};
--- a/as/target/x86/gen.awk
+++ b/as/target/x86/gen.awk
@@ -3,7 +3,7 @@
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
}
--- /dev/null
+++ b/as/target/x86/proc.h
@@ -1,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,
+};