+ generate the Z80 instruction enum and string table from z80ins.dat via a newly created tool

git-svn-id: branches/z80@44556 -
This commit is contained in:
nickysn 2020-04-04 01:36:07 +00:00
parent 6a2dbad8ca
commit 20eab5582f
10 changed files with 308 additions and 20 deletions

4
.gitattributes vendored
View File

@ -920,6 +920,7 @@ compiler/utils/mkx86inl.pp svneol=native#text/plain
compiler/utils/mkx86ins.pp svneol=native#text/plain
compiler/utils/mkx86reg.pp svneol=native#text/plain
compiler/utils/mkxtensareg.pp svneol=native#text/pascal
compiler/utils/mkz80ins.pp svneol=native#text/plain
compiler/utils/mkz80reg.pp svneol=native#text/plain
compiler/utils/msg2inc.pp svneol=native#text/plain
compiler/utils/msgdif.pp svneol=native#text/plain
@ -1080,7 +1081,10 @@ compiler/z80/rz80std.inc svneol=native#text/plain
compiler/z80/rz80sup.inc svneol=native#text/plain
compiler/z80/symcpu.pas svneol=native#text/plain
compiler/z80/z80ins.dat svneol=native#text/plain
compiler/z80/z80nop.inc svneol=native#text/plain
compiler/z80/z80op.inc svneol=native#text/plain
compiler/z80/z80reg.dat svneol=native#text/plain
compiler/z80/z80stdopnames.inc svneol=native#text/plain
/fpmake.pp svneol=native#text/plain
/fpmake_add1.inc svneol=native#text/plain
/fpmake_proc1.inc svneol=native#text/plain

View File

@ -2,7 +2,7 @@
# Don't edit, this file is generated by FPCMake Version 2.0.0
#
default: all
MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian i386-nativent i386-iphonesim i386-android i386-aros m68k-linux m68k-netbsd m68k-amiga m68k-atari m68k-palmos m68k-macos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded powerpc-wii powerpc-aix sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-haiku x86_64-netbsd x86_64-solaris x86_64-openbsd x86_64-darwin x86_64-win64 x86_64-embedded x86_64-iphonesim x86_64-android x86_64-aros x86_64-dragonfly arm-linux arm-netbsd arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian arm-android arm-aros powerpc64-linux powerpc64-darwin powerpc64-embedded powerpc64-aix avr-embedded armeb-linux armeb-embedded mips-linux mipsel-linux mipsel-embedded mipsel-android jvm-java jvm-android i8086-embedded i8086-msdos i8086-win16 aarch64-linux aarch64-darwin aarch64-android wasm-wasm sparc64-linux riscv32-linux riscv32-embedded riscv64-linux riscv64-embedded xtensa-embedded xtensa-freertos
MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian i386-nativent i386-iphonesim i386-android i386-aros m68k-linux m68k-netbsd m68k-amiga m68k-atari m68k-palmos m68k-macos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded powerpc-wii powerpc-aix sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-haiku x86_64-netbsd x86_64-solaris x86_64-openbsd x86_64-darwin x86_64-win64 x86_64-embedded x86_64-iphonesim x86_64-android x86_64-aros x86_64-dragonfly arm-linux arm-netbsd arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian arm-android arm-aros powerpc64-linux powerpc64-darwin powerpc64-embedded powerpc64-aix avr-embedded armeb-linux armeb-embedded mips-linux mipsel-linux mipsel-embedded mipsel-android jvm-java jvm-android i8086-embedded i8086-msdos i8086-win16 aarch64-linux aarch64-darwin aarch64-android wasm-wasm sparc64-linux riscv32-linux riscv32-embedded riscv64-linux riscv64-embedded xtensa-linux xtensa-embedded xtensa-freertos
BSDs = freebsd netbsd openbsd darwin dragonfly
UNIXs = linux $(BSDs) solaris qnx haiku aix
LIMIT83fs = go32v2 os2 emx watcom msdos win16 atari
@ -890,6 +890,9 @@ endif
ifeq ($(FULL_TARGET),riscv64-embedded)
override TARGET_DIRS+=utils
endif
ifeq ($(FULL_TARGET),xtensa-linux)
override TARGET_DIRS+=utils
endif
ifeq ($(FULL_TARGET),xtensa-embedded)
override TARGET_DIRS+=utils
endif
@ -1172,6 +1175,9 @@ endif
ifeq ($(FULL_TARGET),riscv64-embedded)
override TARGET_PROGRAMS+=pp
endif
ifeq ($(FULL_TARGET),xtensa-linux)
override TARGET_PROGRAMS+=pp
endif
ifeq ($(FULL_TARGET),xtensa-embedded)
override TARGET_PROGRAMS+=pp
endif
@ -1455,6 +1461,9 @@ endif
ifeq ($(FULL_TARGET),riscv64-embedded)
override COMPILER_INCLUDEDIR+=$(CPC_TARGET)
endif
ifeq ($(FULL_TARGET),xtensa-linux)
override COMPILER_INCLUDEDIR+=$(CPC_TARGET)
endif
ifeq ($(FULL_TARGET),xtensa-embedded)
override COMPILER_INCLUDEDIR+=$(CPC_TARGET)
endif
@ -1737,6 +1746,9 @@ endif
ifeq ($(FULL_TARGET),riscv64-embedded)
override COMPILER_UNITDIR+=$(COMPILERSOURCEDIR)
endif
ifeq ($(FULL_TARGET),xtensa-linux)
override COMPILER_UNITDIR+=$(COMPILERSOURCEDIR)
endif
ifeq ($(FULL_TARGET),xtensa-embedded)
override COMPILER_UNITDIR+=$(COMPILERSOURCEDIR)
endif
@ -2019,6 +2031,9 @@ endif
ifeq ($(FULL_TARGET),riscv64-embedded)
override COMPILER_TARGETDIR+=$(CPU_UNITDIR)/bin/$(FULL_TARGET)
endif
ifeq ($(FULL_TARGET),xtensa-linux)
override COMPILER_TARGETDIR+=$(CPU_UNITDIR)/bin/$(FULL_TARGET)
endif
ifeq ($(FULL_TARGET),xtensa-embedded)
override COMPILER_TARGETDIR+=$(CPU_UNITDIR)/bin/$(FULL_TARGET)
endif
@ -2301,6 +2316,9 @@ endif
ifeq ($(FULL_TARGET),riscv64-embedded)
override COMPILER_UNITTARGETDIR+=$(CPU_UNITDIR)/units/$(FULL_TARGET)
endif
ifeq ($(FULL_TARGET),xtensa-linux)
override COMPILER_UNITTARGETDIR+=$(CPU_UNITDIR)/units/$(FULL_TARGET)
endif
ifeq ($(FULL_TARGET),xtensa-embedded)
override COMPILER_UNITTARGETDIR+=$(CPU_UNITDIR)/units/$(FULL_TARGET)
endif
@ -3250,6 +3268,9 @@ endif
ifeq ($(FULL_TARGET),riscv64-embedded)
REQUIRE_PACKAGES_RTL=1
endif
ifeq ($(FULL_TARGET),xtensa-linux)
REQUIRE_PACKAGES_RTL=1
endif
ifeq ($(FULL_TARGET),xtensa-embedded)
REQUIRE_PACKAGES_RTL=1
endif
@ -4185,6 +4206,9 @@ endif
ifeq ($(FULL_TARGET),riscv64-embedded)
TARGET_DIRS_UTILS=1
endif
ifeq ($(FULL_TARGET),xtensa-linux)
TARGET_DIRS_UTILS=1
endif
ifeq ($(FULL_TARGET),xtensa-embedded)
TARGET_DIRS_UTILS=1
endif
@ -4471,7 +4495,10 @@ insdatarm : arm/armins.dat
insdataarch64 : aarch64/a64ins.dat
$(COMPILER) -FE$(COMPILERUTILSDIR) $(COMPILERUTILSDIR)/mka64ins.pp
cd aarch64 && ..$(PATHSEP)utils$(PATHSEP)mka64ins$(SRCEXEEXT)
insdat: insdatx86 insdatarm insdataarch64
insdatz80 : z80/z80ins.dat
$(COMPILER) -FE$(COMPILERUTILSDIR) $(COMPILERUTILSDIR)/mkz80ins.pp
cd z80 && ..$(PATHSEP)utils$(PATHSEP)mkz80ins$(SRCEXEEXT)
insdat: insdatx86 insdatarm insdataarch64 insdatz80
regdatx86 : x86/x86reg.dat
$(COMPILER) -FE$(COMPILERUTILSDIR) $(COMPILERUTILSDIR)/mkx86reg.pp
cd x86 && ..$(PATHSEP)utils$(PATHSEP)mkx86reg$(SRCEXEEXT) i8086

View File

@ -699,7 +699,11 @@ insdataarch64 : aarch64/a64ins.dat
$(COMPILER) -FE$(COMPILERUTILSDIR) $(COMPILERUTILSDIR)/mka64ins.pp
cd aarch64 && ..$(PATHSEP)utils$(PATHSEP)mka64ins$(SRCEXEEXT)
insdat: insdatx86 insdatarm insdataarch64
insdatz80 : z80/z80ins.dat
$(COMPILER) -FE$(COMPILERUTILSDIR) $(COMPILERUTILSDIR)/mkz80ins.pp
cd z80 && ..$(PATHSEP)utils$(PATHSEP)mkz80ins$(SRCEXEEXT)
insdat: insdatx86 insdatarm insdataarch64 insdatz80
regdatx86 : x86/x86reg.dat
$(COMPILER) -FE$(COMPILERUTILSDIR) $(COMPILERUTILSDIR)/mkx86reg.pp

View File

@ -2,7 +2,7 @@
# Don't edit, this file is generated by FPCMake Version 2.0.0
#
default: all
MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian i386-nativent i386-iphonesim i386-android i386-aros m68k-linux m68k-netbsd m68k-amiga m68k-atari m68k-palmos m68k-macos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded powerpc-wii powerpc-aix sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-haiku x86_64-netbsd x86_64-solaris x86_64-openbsd x86_64-darwin x86_64-win64 x86_64-embedded x86_64-iphonesim x86_64-android x86_64-aros x86_64-dragonfly arm-linux arm-netbsd arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian arm-android arm-aros powerpc64-linux powerpc64-darwin powerpc64-embedded powerpc64-aix avr-embedded armeb-linux armeb-embedded mips-linux mipsel-linux mipsel-embedded mipsel-android jvm-java jvm-android i8086-embedded i8086-msdos i8086-win16 aarch64-linux aarch64-darwin aarch64-android wasm-wasm sparc64-linux riscv32-linux riscv32-embedded riscv64-linux riscv64-embedded xtensa-embedded xtensa-freertos
MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian i386-nativent i386-iphonesim i386-android i386-aros m68k-linux m68k-netbsd m68k-amiga m68k-atari m68k-palmos m68k-macos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded powerpc-wii powerpc-aix sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-haiku x86_64-netbsd x86_64-solaris x86_64-openbsd x86_64-darwin x86_64-win64 x86_64-embedded x86_64-iphonesim x86_64-android x86_64-aros x86_64-dragonfly arm-linux arm-netbsd arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian arm-android arm-aros powerpc64-linux powerpc64-darwin powerpc64-embedded powerpc64-aix avr-embedded armeb-linux armeb-embedded mips-linux mipsel-linux mipsel-embedded mipsel-android jvm-java jvm-android i8086-embedded i8086-msdos i8086-win16 aarch64-linux aarch64-darwin aarch64-android wasm-wasm sparc64-linux riscv32-linux riscv32-embedded riscv64-linux riscv64-embedded xtensa-linux xtensa-embedded xtensa-freertos
BSDs = freebsd netbsd openbsd darwin dragonfly
UNIXs = linux $(BSDs) solaris qnx haiku aix
LIMIT83fs = go32v2 os2 emx watcom msdos win16 atari
@ -605,6 +605,9 @@ endif
ifeq ($(FULL_TARGET),riscv64-embedded)
override TARGET_PROGRAMS+=fpc ppufiles ppudump ppumove mka64ins mkarmins mkx86ins
endif
ifeq ($(FULL_TARGET),xtensa-linux)
override TARGET_PROGRAMS+=fpc ppufiles ppudump ppumove mka64ins mkarmins mkx86ins
endif
ifeq ($(FULL_TARGET),xtensa-embedded)
override TARGET_PROGRAMS+=fpc ppufiles ppudump ppumove mka64ins mkarmins mkx86ins
endif
@ -887,6 +890,9 @@ endif
ifeq ($(FULL_TARGET),riscv64-embedded)
override CLEAN_UNITS+=ppu crc
endif
ifeq ($(FULL_TARGET),xtensa-linux)
override CLEAN_UNITS+=ppu crc
endif
ifeq ($(FULL_TARGET),xtensa-embedded)
override CLEAN_UNITS+=ppu crc
endif
@ -1170,6 +1176,9 @@ endif
ifeq ($(FULL_TARGET),riscv64-embedded)
override COMPILER_UNITDIR+=..
endif
ifeq ($(FULL_TARGET),xtensa-linux)
override COMPILER_UNITDIR+=..
endif
ifeq ($(FULL_TARGET),xtensa-embedded)
override COMPILER_UNITDIR+=..
endif
@ -1452,6 +1461,9 @@ endif
ifeq ($(FULL_TARGET),riscv64-embedded)
override COMPILER_SOURCEDIR+=..
endif
ifeq ($(FULL_TARGET),xtensa-linux)
override COMPILER_SOURCEDIR+=..
endif
ifeq ($(FULL_TARGET),xtensa-embedded)
override COMPILER_SOURCEDIR+=..
endif
@ -2403,6 +2415,9 @@ endif
ifeq ($(FULL_TARGET),riscv64-embedded)
REQUIRE_PACKAGES_RTL=1
endif
ifeq ($(FULL_TARGET),xtensa-linux)
REQUIRE_PACKAGES_RTL=1
endif
ifeq ($(FULL_TARGET),xtensa-embedded)
REQUIRE_PACKAGES_RTL=1
endif

107
compiler/utils/mkz80ins.pp Normal file
View File

@ -0,0 +1,107 @@
{
Copyright (c) 2020 by Nikolay Nikolov
Convert z80ins.dat to a set of .inc files for usage with
the Free pascal compiler
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
program mkz80ins;
{$mode objfpc}{$H+}
uses
SysUtils,StrUtils;
const
Version = '1.0.0';
HeaderStr = '{ don''t edit, this file is generated from z80ins.dat; to regenerate, run ''make insdat'' in the compiler directory }';
type
{ TZ80InsDatOutputFiles }
TZ80InsDatOutputFiles = class
public
OpFile: TextFile;
NOpFile: TextFile;
StdOpNames: TextFile;
constructor Create;
destructor Destroy;override;
end;
constructor TZ80InsDatOutputFiles.Create;
begin
AssignFile(OpFile,'z80op.inc');
Rewrite(OpFile);
Writeln(OpFile,HeaderStr);
Writeln(OpFile,'(');
AssignFile(NOpFile,'z80nop.inc');
Rewrite(NOpFile);
Writeln(NOpFile,HeaderStr);
AssignFile(StdOpNames,'z80stdopnames.inc');
Rewrite(StdOpNames);
Writeln(StdOpNames,HeaderStr);
Writeln(StdOpNames,'(');
end;
destructor TZ80InsDatOutputFiles.Destroy;
begin
CloseFile(OpFile);
CloseFile(NOpFile);
CloseFile(StdOpNames);
inherited Destroy;
end;
var
InsDatFile: TextFile;
OutputFiles: TZ80InsDatOutputFiles=nil;
S, op: string;
FirstIns: Boolean=true;
OpCount: Integer=0;
begin
writeln('FPC Z80 Instruction Table Converter Version ',Version);
AssignFile(InsDatFile,'../z80/z80ins.dat');
Reset(InsDatFile);
try
OutputFiles:=TZ80InsDatOutputFiles.Create;
while not EoF(InsDatFile) do
begin
Readln(InsDatFile,S);
S:=Trim(S);
if AnsiStartsStr(';',S) then
continue
else if AnsiStartsStr('[',S) then
begin
op:=Copy(S,2,Length(S)-2);
if not FirstIns then
begin
Writeln(OutputFiles.OpFile,',');
Writeln(OutputFiles.StdOpNames,',');
end;
FirstIns:=False;
Write(OutputFiles.OpFile,'A_'+op);
Write(OutputFiles.StdOpNames,''''+LowerCase(op)+'''');
end
else if S<>'' then
begin
Inc(OpCount);
end;
end;
Writeln(OutputFiles.OpFile,');');
Writeln(OutputFiles.StdOpNames,');');
Writeln(OutputFiles.NOpFile,OpCount,';');
finally
FreeAndNil(OutputFiles);
CloseFile(InsDatFile);
end;
end.

View File

@ -43,14 +43,7 @@ unit cpubase;
*****************************************************************************}
type
TAsmOp=(A_None,
A_ADD,A_ADC,A_AND,A_BIT,A_CALL,A_CCF,A_CP,A_CPD,A_CPDR,
A_CPI,A_CPIR,A_CPL,A_DAA,A_DEC,A_DI,A_DJNZ,A_EI,A_EX,
A_EXX,A_HALT,A_IM,A_IN,A_INC,A_IND,A_INDR,A_INI,A_INIR,
A_JP,A_JR,A_LD,A_LDD,A_LDDR,A_LDI,A_LDIR,A_NEG,A_NOP,A_OR,
A_OTDR,A_OTIR,A_OUT,A_OUTD,A_OUTI,A_POP,A_PUSH,A_RES,A_RET,A_RETI,
A_RETN,A_RL,A_RLA,A_RLC,A_RLCA,A_RLD,A_RR,A_RRA,A_RRC,
A_RRCA,A_RRD,A_RST,A_SBC,A_SCF,A_SET,A_SLA,A_SRA,A_SRL,A_SUB,A_XOR);
TAsmOp={$i z80op.inc}
{ This should define the array of instructions as string }
@ -62,14 +55,7 @@ unit cpubase;
{ Last value of opcode enumeration }
lastop = high(tasmop);
std_op2str:op2strtable=('',
'add','adc','and','bit','call','ccf','cp','cpd','cpdr',
'cpi','cpir','cpl','daa','dec','di','djnz','ei','ex',
'exx','halt','im','in','inc','ind','indr','ini','inir',
'jp','jr','ld','ldd','lddr','ldi','ldir','neg','nop','or',
'otdr','otir','out','outd','outi','pop','push','res','ret','reti',
'retn','rl','rla','rlc','rlca','rld','rr','rra','rrc',
'rrca','rrd','rst','sbc','scf','set','sla','sra','srl','sub','xor');
std_op2str:op2strtable={$i z80stdopnames.inc}
{ call/reg instructions are not considered as jmp instructions for the usage cases of
this set }

View File

@ -34,6 +34,9 @@
; (IX+d) - memory contents at address in register IX+d, d is in [-128..127]
; (IY+d) - memory contents at address in register IX+d, d is in [-128..127]
[None]
void
[ADC]
A,r
A,n

2
compiler/z80/z80nop.inc Normal file
View File

@ -0,0 +1,2 @@
{ don't edit, this file is generated from z80ins.dat; to regenerate, run 'make insdat' in the compiler directory }
203;

70
compiler/z80/z80op.inc Normal file
View File

@ -0,0 +1,70 @@
{ don't edit, this file is generated from z80ins.dat; to regenerate, run 'make insdat' in the compiler directory }
(
A_None,
A_ADC,
A_ADD,
A_AND,
A_BIT,
A_CALL,
A_CCF,
A_CP,
A_CPD,
A_CPDR,
A_CPI,
A_CPIR,
A_CPL,
A_DAA,
A_DEC,
A_DI,
A_DJNZ,
A_EI,
A_EX,
A_EXX,
A_HALT,
A_IM,
A_IN,
A_INC,
A_IND,
A_INDR,
A_INI,
A_INIR,
A_JP,
A_JR,
A_LD,
A_LDD,
A_LDDR,
A_LDI,
A_LDIR,
A_NEG,
A_NOP,
A_OR,
A_OTDR,
A_OTIR,
A_OUT,
A_OUTD,
A_OUTI,
A_POP,
A_PUSH,
A_RES,
A_RET,
A_RETI,
A_RETN,
A_RL,
A_RLA,
A_RLC,
A_RLCA,
A_RLD,
A_RR,
A_RRA,
A_RRC,
A_RRCA,
A_RRD,
A_RST,
A_SBC,
A_SCF,
A_SET,
A_SLA,
A_SRA,
A_SRL,
A_SUB,
A_XOR);

View File

@ -0,0 +1,70 @@
{ don't edit, this file is generated from z80ins.dat; to regenerate, run 'make insdat' in the compiler directory }
(
'none',
'adc',
'add',
'and',
'bit',
'call',
'ccf',
'cp',
'cpd',
'cpdr',
'cpi',
'cpir',
'cpl',
'daa',
'dec',
'di',
'djnz',
'ei',
'ex',
'exx',
'halt',
'im',
'in',
'inc',
'ind',
'indr',
'ini',
'inir',
'jp',
'jr',
'ld',
'ldd',
'lddr',
'ldi',
'ldir',
'neg',
'nop',
'or',
'otdr',
'otir',
'out',
'outd',
'outi',
'pop',
'push',
'res',
'ret',
'reti',
'retn',
'rl',
'rla',
'rlc',
'rlca',
'rld',
'rr',
'rra',
'rrc',
'rrca',
'rrd',
'rst',
'sbc',
'scf',
'set',
'sla',
'sra',
'srl',
'sub',
'xor');