scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit ad4c75716e7da7fb0c247f8a71fd4e7511c19778
parent 2a449ac877e295ab2b7c9e4179470db355f71bb8
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 29 Dec 2017 11:38:20 +0000

[as-z80] Simplify 8 bit load group

There were too many functions, and they could be merged in
more generic functions.

Diffstat:
Mas/target/x80/ins.c | 107+++++++++++++++----------------------------------------------------------------
Mas/target/x80/x80.dat | 20++++++++++----------
2 files changed, 30 insertions(+), 97 deletions(-)

diff --git a/as/target/x80/ins.c b/as/target/x80/ins.c @@ -176,44 +176,15 @@ flag2int(int flag) } void -r8_imm8(Op *op, Node **args) -{ - Node *par1, *par2; - unsigned char buf[3]; - int n = op->size; - - par1 = args[0]; - par2 = args[1]; - - memcpy(buf, op->bytes, n); - buf[n-1] = par2->sym->value; - buf[n-2] |= reg2int(par1->sym->argtype) << 3; - emit(buf, n); -} - -void -imm8(Op *op, Node **args) -{ - Node *par1, *par2; - unsigned char buf[3]; - int n = op->size; - - par2 = args[1]; - - memcpy(buf, op->bytes, n); - buf[n-1] = par2->sym->value; - emit(buf, n); -} - -void -imm16(Op *op, Node **args) +dir(Op *op, Node **args) { Node *imm; unsigned char buf[4]; unsigned val; int n = op->size; - imm = (args[1]) ? args[1] : args[0]; + imm = (args[1]->addr == ADIRECT) ? args[1] : args[0]; + imm = imm->left; memcpy(buf, op->bytes, n); val = imm->sym->value; buf[n-1] = val >> 8; @@ -222,60 +193,23 @@ imm16(Op *op, Node **args) } void -dir(Op *op, Node **args) -{ - Node *dir; - - dir = (args[1]->addr == ADIRECT) ? args[1] : args[0]; - args[1] = dir->left; - imm16(op, args); -} - -void -r8_r8(Op *op, Node **args) -{ - Node *par1, *par2; - unsigned char buf[3]; - int n = op->size; - - par1 = args[0]; - par2 = args[1]; - memcpy(buf, op->bytes, n); - buf[n-1] |= reg2int(par1->sym->argtype) << 3 | - reg2int(par2->sym->argtype); - emit(buf, n); -} - -void -r8(Op *op, Node **args) +ld8(Op *op, Node **args) { - Node *par; - unsigned char buf[3]; - int n = op->size; + Node *par1 = args[0], *par2 = args[1]; + int n = op->size, i = n;; + unsigned regval = 0; + unsigned char buf[4]; - par = args[0]; memcpy(buf, op->bytes, n); - buf[n-1] |= reg2int(par->sym->argtype); - emit(buf, n); -} -void -xx_r8(Op *op, Node **args) -{ - args[0] = args[1]; - r8(op, args); -} + if (par1->addr == AREG) + regval |= reg2int(par1->sym->argtype) << 3; + if (par2->addr == AREG) + regval |= reg2int(par2->sym->argtype); + else if (par2->addr == AIMM) + buf[--i] = par2->sym->value; -void -r8_xx(Op *op, Node **args) -{ - Node *par; - unsigned char buf[3]; - int n = op->size; - - par = args[0]; - memcpy(buf, op->bytes, n); - buf[n-1] |= reg2int(par->sym->argtype) << 3; + buf[--i] |= regval; emit(buf, n); } @@ -379,12 +313,11 @@ idx(Op *op, Node **args) } idx = args[0]->left->right; - if (args[1]) { - if (args[1]->addr == AREG) - reg = args[1]; - else - imm = args[1]; - } + if (args[1]->addr == AREG) + reg = args[1]; + else + imm = args[1]; + memcpy(buf, op->bytes, n); if (imm) diff --git a/as/target/x80/x80.dat b/as/target/x80/x80.dat @@ -46,23 +46,23 @@ # ss is any flag from C, NC, Z, NZ # 8 bit load group -LD r,imm8 2 0x06 r8_imm8 Z80,R800,GB80 -LD p,imm8 3 0xdd,0x06 r8_imm8 Z80,R800 -LD q,imm8 3 0xfd,0x06 r8_imm8 Z80,R800 -LD (HL),imm8 2 0x36 imm8 Z80,R800,GB80 +LD r,imm8 2 0x06 ld8 Z80,R800,GB80 +LD p,imm8 3 0xdd,0x06 ld8 Z80,R800 +LD q,imm8 3 0xfd,0x06 ld8 Z80,R800 +LD (HL),imm8 2 0x36 ld8 Z80,R800,GB80 -LD r,r 1 0x40 r8_r8 Z80,R800,GB80 -LD p,p 2 0xdd,0x40 r8_r8 Z80,R800 -LD q,q 2 0xfd,0x40 r8_r8 Z80,R800 -LD (HL),r 1 0x70 xx_r8 Z80,R800,GB80 -LD r,(HL) 1 0x46 r8_xx Z80,R800,GB80 +LD r,r 1 0x40 ld8 Z80,R800,GB80 +LD p,p 2 0xdd,0x40 ld8 Z80,R800 +LD q,q 2 0xfd,0x40 ld8 Z80,R800 +LD (HL),r 1 0x70 ld8 Z80,R800,GB80 +LD r,(HL) 1 0x46 ld8 Z80,R800,GB80 LD r,(IX+n) 3 0xdd,0x46 idx Z80,R800 LD r,(IY+n) 3 0xfd,0x46 idx Z80,R800 LD (IX+n),r 3 0xdd,0x70 idx Z80,R800 LD (IY+n),r 3 0xfd,0x70 idx Z80,R800 -LD (HL),imm8 2 0x36 imm8 Z80,R800,GB80 +LD (HL),imm8 2 0x36 ld8 Z80,R800,GB80 LD (IX+n),imm8 4 0xdd,0x36 idx Z80,R800 LD (IY+n),imm8 4 0xfd,0x36 idx Z80,R800