shithub: scc

Download patch

ref: b7e1cae8e53b2a4d9cbaf505927d1abdca22f13d
parent: 7592b0fad1cfe071e67746bfa132adf34ea00c75
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Jan 25 07:56:27 EST 2018

[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.

--- a/as/as.h
+++ b/as/as.h
@@ -166,11 +166,14 @@
 
 /* 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);
--- a/as/expr.c
+++ b/as/expr.c
@@ -25,7 +25,7 @@
 
 #define accept(t) (yytoken == (t) ? next() : 0)
 
-static Node *
+Node *
 node(int op, Node *l, Node *r)
 {
 	struct arena *ap;
@@ -351,32 +351,6 @@
 	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 @@
 	return np;
 }
 
-static Node *
+Node *
 expr(void)
 {
 	int op;
@@ -548,7 +522,7 @@
 		break;
 	case '(':
 		next();
-		np = zilog();
+		np = addrmode();
 		expect(')');
 		break;
 	case REG:
--- a/as/target/x80/ins.c
+++ b/as/target/x80/ins.c
@@ -148,6 +148,30 @@
 	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)
 {
--- a/as/target/x86/ins.c
+++ b/as/target/x86/ins.c
@@ -36,3 +36,8 @@
 	}
 	return 1;
 }
+
+Node *
+addrmode(void)
+{
+}