ref: a69a08db850e632d1809320b6abbaca181354216
parent: b3eaabc77b314248434e707001fd2d0d3087471c
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Sep 27 17:54:26 EDT 2017
[as] Propagate AIMM property in + Two added AIMM become a new AIMM even if the symbol cannot be resolved.
--- a/as/as.h
+++ b/as/as.h
@@ -31,6 +31,18 @@
LITTLE_ENDIAN = 1
};
+enum common_args {
+ AIMM = 1,
+ ASTR,
+ AREG,
+ AIMM8,
+ AIMM16,
+ AIMM32,
+ AIMM64,
+ AMAX,
+ AREP = 128
+};
+
#define MAXSYM 63
typedef struct ins Ins;
@@ -82,6 +94,7 @@
struct node {
unsigned char op;
+ unsigned char addr;
struct symbol *sym;
struct node *left;
struct node *right;
--- a/as/expr.c
+++ b/as/expr.c
@@ -63,13 +63,11 @@
}
static Node *
-binary(int op, Node *l, Node *r)
+fold(int op, Node *l, Node *r)
{
Node *np;
TUINT val, lv, rv;
- if (l->op != NUMBER || r->op != NUMBER)
- return node(op, l, r);
lv = l->sym->value;
rv = r->sym->value;
@@ -130,6 +128,7 @@
np = node(NUMBER, NULL, NULL);
np->sym = tmpsym(val);
+ np->addr = AIMM;
return np;
division_by_zero:
@@ -137,6 +136,24 @@
}
static Node *
+binary(int op, Node *l, Node *r)
+{
+ int addr;
+ Node *np;
+
+ if (l->op == NUMBER || r->op == NUMBER)
+ return fold(op, l, r);
+ if (l->addr == AIMM && r->addr == AIMM)
+ addr = AIMM;
+ else
+ error("incorrect operand");
+ np = node(op, l, r);
+ np->addr = addr;
+
+ return np;
+}
+
+static Node *
unary(int op, Node *np)
{
if (op != '!')
@@ -317,27 +334,23 @@
static Node *
primary(void)
{
+ int addr;
Node *np;
switch (yytoken) {
case REG:
- case NUMBER:
+ addr = AREG;
+ goto basic_atom;
case IDEN:
+ case NUMBER:
+ addr = AIMM;
+ goto basic_atom;
case STRING:
+ addr = ASTR;
+ basic_atom:
np = node(yytoken, NULL, NULL);
np->sym = yylval.sym;
next();
- break;
- case '[':
- next();
- np = or();
- expect(']');
- np = node('@', np, NULL);
- break;
- case '(':
- next();
- np = or();
- expect(')');
break;
default:
unexpected();
--- a/as/target/x80/proc.h
+++ b/as/target/x80/proc.h
@@ -1,13 +1,6 @@
enum args {
- AIMM = 1,
-
- AIMM8,
- AIMM16,
- AIMM32,
- AIMM64,
-
- AREG_AF,
+ AREG_AF = AMAX,
AREG_A,
AREG_F,
@@ -34,6 +27,4 @@
AREG_R,
AREG_I,
AREG_AF_,
-
- AREP,
};
--- a/as/target/x86/proc.h
+++ b/as/target/x86/proc.h
@@ -1,13 +1,6 @@
enum args {
- AIMM = 1,
-
- AIMM8,
- AIMM16,
- AIMM32,
- AIMM64,
-
- AREG_CS,
+ AREG_CS = AMAX,
AREG_DS,
AREG_SS,
AREG_ES,
@@ -153,6 +146,4 @@
AREG_YMM15,
AREG_MXCSR,
-
- AREP,
};