scc

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

commit 967951ff9fb1901301a9f4bf2cc54ec36b52d599
parent 474ced6ed3e9334fb952e6503db2eb39f33bccef
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 27 Sep 2017 21:54:26 +0200

[as] Propagate AIMM property in +

Two added AIMM become a new AIMM even if the symbol cannot
be resolved.

Diffstat:
Mas/as.h | 13+++++++++++++
Mas/expr.c | 43++++++++++++++++++++++++++++---------------
Mas/target/x80/proc.h | 11+----------
Mas/target/x86/proc.h | 11+----------
4 files changed, 43 insertions(+), 35 deletions(-)

diff --git a/as/as.h b/as/as.h @@ -31,6 +31,18 @@ enum endianess { 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 symbol { struct node { unsigned char op; + unsigned char addr; struct symbol *sym; struct node *left; struct node *right; diff --git a/as/expr.c b/as/expr.c @@ -63,13 +63,11 @@ deltree(Node *np) } 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 @@ binary(int op, Node *l, Node *r) np = node(NUMBER, NULL, NULL); np->sym = tmpsym(val); + np->addr = AIMM; return np; division_by_zero: @@ -137,6 +136,24 @@ division_by_zero: } 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,28 +334,24 @@ static Node *or(void); 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(); } diff --git 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 @@ enum args { AREG_R, AREG_I, AREG_AF_, - - AREP, }; diff --git 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 @@ enum args { AREG_YMM15, AREG_MXCSR, - - AREP, };