Răsfoiți Sursa

+ added strict validation for the param types in z80ins.dat

git-svn-id: branches/z80@44557 -
nickysn 5 ani în urmă
părinte
comite
4027ad18e0
2 a modificat fișierele cu 67 adăugiri și 2 ștergeri
  1. 60 1
      compiler/utils/mkz80ins.pp
  2. 7 1
      compiler/z80/z80ins.dat

+ 60 - 1
compiler/utils/mkz80ins.pp

@@ -24,6 +24,50 @@ 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 }';
 
+  ParamTypes: array [0..40] of string = (
+    'void',
+    'r',
+    'r''',
+    'b',
+    'n',
+    'p',
+    'e',
+    'nn',
+    '0',
+    '1',
+    '2',
+    'cc',
+    'C',
+    'NC',
+    'Z',
+    'NZ',
+    'dd',
+    'qq',
+    'pp',
+    'rr',
+    'A',
+    'I',
+    'R',
+    'IX',
+    'IY',
+    'SP',
+    'DE',
+    'HL',
+    'AF',
+    'AF''',
+    '(C)',
+    '(n)',
+    '(nn)',
+    '(BC)',
+    '(DE)',
+    '(HL)',
+    '(SP)',
+    '(IX)',
+    '(IY)',
+    '(IX+d)',
+    '(IY+d)'
+  );
+
 type
 
   { TZ80InsDatOutputFiles }
@@ -61,12 +105,23 @@ destructor TZ80InsDatOutputFiles.Destroy;
     inherited Destroy;
   end;
 
+function FindParamType(const ParamTypeStr: string): Integer;
+var
+  I: Integer;
+begin
+  for I:=Low(ParamTypes) to High(ParamTypes) do
+    if ParamTypes[I]=ParamTypeStr then
+      exit(I);
+  raise Exception.Create('Invalid param type: '''+ParamTypeStr+'''');
+end;
+
 var
   InsDatFile: TextFile;
   OutputFiles: TZ80InsDatOutputFiles=nil;
-  S, op: string;
+  S, op, ParamsStr, S_Param: string;
   FirstIns: Boolean=true;
   OpCount: Integer=0;
+  S_Split, S_Params: TStringArray;
 begin
   writeln('FPC Z80 Instruction Table Converter Version ',Version);
   AssignFile(InsDatFile,'../z80/z80ins.dat');
@@ -94,6 +149,10 @@ begin
         else if S<>'' then
           begin
             Inc(OpCount);
+            S_Split:=S.Split(' ',TStringSplitOptions.ExcludeEmpty);
+            S_Params:=S_Split[0].Split(',',TStringSplitOptions.ExcludeEmpty);
+            for S_Param in S_Params do
+              FindParamType(S_Param);
           end;
       end;
     Writeln(OutputFiles.OpFile,');');

+ 7 - 1
compiler/z80/z80ins.dat

@@ -6,6 +6,9 @@
 ; p      - immediate value in [$00,$08,$10,$18,$20,$28,$30,$38]
 ; e      - 8-bit relative jump offset
 ; nn     - 16-bit immediate value
+; 0      - the immediate value 0
+; 1      - the immediate value 1
+; 2      - the immediate value 2
 ; cc     - condition: NZ/Z/NC/C/PO/PE/P/M
 ; C      - condition C
 ; NC     - condition NC
@@ -26,13 +29,16 @@
 ; AF     - 16-bit register pair AF
 ; AF'    - alternate register set, 16-bit register pair AF'
 ; (C)    - implied parameter of the IN and OUT instructions
+; (n)    - 8-bit immediate port number for the IN and OUT instructions
 ; (nn)   - memory contents at address (nn = 16-bit immediate address)
 ; (BC)   - memory contents at address in register BC
 ; (DE)   - memory contents at address in register DE
 ; (HL)   - memory contents at address in register HL
 ; (SP)   - memory contents at address in register SP
+; (IX)   - memory contents at address in register IX
+; (IY)   - memory contents at address in register IY
 ; (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]
+; (IY+d) - memory contents at address in register IY+d, d is in [-128..127]
 
 [None]
 void