scc

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

commit 89acdb2f73c67385406cf52242f46ba0ef021dec
parent 06dd27e58615dac53f3c5ea5e375f596f9b4c373
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 29 Dec 2017 09:12:42 +0000

[as-z80] Add indirect jumps

Diffstat:
Mas/target/x80/ins.c | 21++++++++++-----------
Mas/target/x80/proc.h | 2++
Mas/target/x80/rules.dat | 2++
Mas/target/x80/x80.dat | 20+++++++++++---------
Mas/target/z80/proc.c | 6++++++
Mas/target/z80/test.s | 6+++---
6 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/as/target/x80/ins.c b/as/target/x80/ins.c @@ -485,15 +485,20 @@ im(Op *op, Node **args) } void -cc(Op *op, Node **args) +branch(Op *op, Node **args) { unsigned char buf[4]; Node *flag, *imm; int n = op->size, i = n; unsigned val; - flag = args[0]; - imm = args[1]; + flag = imm = NULL; + if (args[0]->addr == AREG) { + flag = args[0]; + imm = args[1]; + } else if (args[0]->addr == AIMM) { + imm = args[0]; + } memcpy(buf, op->bytes, n); if (imm) { @@ -501,19 +506,13 @@ cc(Op *op, Node **args) buf[--i] = val >> 8; buf[--i] = val; } - buf[--i] |= flag2int(flag->sym->argtype) << 3; + if (flag) + buf[--i] |= flag2int(flag->sym->argtype) << 3; emit(buf, n); } void -jr(Op *op, Node **args) -{ - /* TODO */ - abort(); -} - -void rst(Op *op, Node **args) { unsigned char buf[1]; diff --git a/as/target/x80/proc.h b/as/target/x80/proc.h @@ -55,6 +55,8 @@ enum args { AINDER_BC, /* (BC) */ AINDER_SP, /* (SP) */ AINDER_C, /* (C) */ + AINDER_IX, /* (IX) */ + AINDER_IY, /* (IY) */ AIMM3, /* 3 bit immediate */ AZERO, /* a literal 0 */ diff --git a/as/target/x80/rules.dat b/as/target/x80/rules.dat @@ -21,6 +21,8 @@ R AREG_R \(HL\) AINDER_HL \(SP\) AINDER_SP \(C\) AINDER_C +\(IX\) AINDER_IX +\(IY\) AINDER_IY SP AREG_SP HL AREG_HL DE AREG_DE diff --git a/as/target/x80/x80.dat b/as/target/x80/x80.dat @@ -332,18 +332,20 @@ OUTD none 2 0xed,0xab noargs Z80,R800 OTDR none 2 0xed,0xbb noargs Z80,R800 # Jump group -JP imm16 3 0xc3 imm16 Z80,R800,GB80 -JP cc,imm16 3 0xc2 cc Z80,R800,GB80 -JR imm8 2 0x18 jr Z80,R800,GB80 -JR ss,imm8 2 0x00 jr Z80,R800,GB80 -JP IY 2 0xfd,0xe9 noargs Z80,R800 -DJNZ imm8 2 0x10 jr Z80,R800,GB80 +JP imm16 3 0xc3 branch Z80,R800,GB80 +JP cc,imm16 3 0xc2 branch Z80,R800,GB80 +JR imm8 2 0x18 branch Z80,R800,GB80 +JR ss,imm8 2 0x00 branch Z80,R800,GB80 +JP (HL) 1 0xe9 branch Z80,R800,GB80 +JP (IX) 2 0xdd,0xe9 branch Z80,R800 +JP (IY) 2 0xfd,0xe9 branch Z80,R800 +DJNZ imm8 2 0x10 branch Z80,R800,GB80 # Call and return group -CALL imm16 3 0xcd imm16 Z80,R800,GB80 -CALL cc,imm16 3 0xc4 cc Z80,R800 +CALL imm16 3 0xcd branch Z80,R800,GB80 +CALL cc,imm16 3 0xc4 branch Z80,R800 RET none 1 0xc9 noargs Z80,R800,GB80 -RET cc 1 0xc0 cc Z80,R800 +RET cc 1 0xc0 branch Z80,R800 RETI none 2 0xed,0x4d noargs Z80,R800 RETN none 2 0xed,0x45 noargs Z80,R800 RST rst 1 0xc7 rst Z80,R800,GB80 diff --git a/as/target/z80/proc.c b/as/target/z80/proc.c @@ -91,6 +91,12 @@ match(Op *op, Node **args) case AINDER_BC: arg = AREG_BC; goto indirect; + case AINDER_IX: + arg = AREG_IX; + goto indirect; + case AINDER_IY: + arg = AREG_IY; + goto indirect; case AINDER_SP: arg = AREG_SP; indirect: diff --git a/as/target/z80/test.s b/as/target/z80/test.s @@ -757,7 +757,7 @@ POP %IX / DD E1 EX (%SP),%IX / DD E3 PUSH %IX / DD E5 -/ JP (%IX) / DD E9 + JP (%IX) / DD E9 LD %SP,%IX / DD F9 SBC %A,64 / DE 40 RST 24 / DF @@ -770,7 +770,7 @@ AND %A,16 / E6 10 RST 32 / E7 RET %PE / E8 -/E9 JP (HL) + JP (%HL) / E9 JP %PE,16384 / EA 00 40 EX %DE,%HL / EB CALL %PE,16384 / EC 00 40 @@ -1130,7 +1130,7 @@ POP %IY / FD E1 EX (%SP),%IY / FD E3 PUSH %IY / FD E5 -/FDE9 JP (IY) + JP (%IY) / FD E9 LD %SP,%IY / FD F9 CP %A,32 / FE 20 RST 56 / FF