Browse Source

+ implemented pass1 (calcsize) of the instruction encoding for the Z80 internal asm

git-svn-id: trunk@45247 -
nickysn 5 years ago
parent
commit
27e9dde81a
1 changed files with 71 additions and 0 deletions
  1. 71 0
      compiler/z80/aasmcpu.pas

+ 71 - 0
compiler/z80/aasmcpu.pas

@@ -109,9 +109,12 @@ uses
          { next fields are filled in pass1, so pass2 is faster }
          { next fields are filled in pass1, so pass2 is faster }
          insentry  : PInsEntry;
          insentry  : PInsEntry;
          inssize   : shortint;
          inssize   : shortint;
+         insoffset : longint;
+         LastInsOffset : longint;
 
 
          function Matches(p:PInsEntry):boolean;
          function Matches(p:PInsEntry):boolean;
          function FindInsentry(objdata:TObjData):boolean;
          function FindInsentry(objdata:TObjData):boolean;
+         function calcsize(p:PInsEntry):shortint;
       public
       public
          constructor op_none(op : tasmop);
          constructor op_none(op : tasmop);
 
 
@@ -137,6 +140,10 @@ uses
          { register spilling code }
          { register spilling code }
          function spilling_get_operation_type(opnr: longint): topertype;override;
          function spilling_get_operation_type(opnr: longint): topertype;override;
 
 
+         procedure ResetPass1;override;
+         procedure ResetPass2;override;
+         function  Pass1(objdata:TObjData):longint;override;
+         procedure Pass2(objdata:TObjData);override;
          function CheckIfValid:boolean;
          function CheckIfValid:boolean;
          function GetString:string;
          function GetString:string;
       end;
       end;
@@ -401,6 +408,17 @@ implementation
       end;
       end;
 
 
 
 
+    function taicpu.calcsize(p: PInsEntry): shortint;
+      var
+        c: Char;
+      begin
+        result:=1;
+        for c in p^.code do
+          if c=',' then
+            inc(result);
+      end;
+
+
     constructor taicpu.op_none(op : tasmop);
     constructor taicpu.op_none(op : tasmop);
       begin
       begin
          inherited create(op);
          inherited create(op);
@@ -558,6 +576,59 @@ implementation
       end;
       end;
 
 
 
 
+    procedure taicpu.ResetPass1;
+      begin
+        { we need to reset everything here, because the choosen insentry
+          can be invalid for a new situation where the previously optimized
+          insentry is not correct }
+        InsEntry:=nil;
+        InsSize:=0;
+        LastInsOffset:=-1;
+      end;
+
+
+    procedure taicpu.ResetPass2;
+      begin
+        { we are here in a second pass, check if the instruction can be optimized }
+        {if assigned(InsEntry) and
+           (IF_PASS2 in InsEntry^.flags) then
+         begin
+           InsEntry:=nil;
+           InsSize:=0;
+         end;}
+        LastInsOffset:=-1;
+      end;
+
+
+    function taicpu.Pass1(objdata: TObjData): longint;
+      begin
+        Pass1:=0;
+        { Save the old offset and set the new offset }
+        InsOffset:=ObjData.CurrObjSec.Size;
+        { Error? }
+        if (Insentry=nil) and (InsSize=-1) then
+          exit;
+        { set the file postion }
+        current_filepos:=fileinfo;
+        { Get InsEntry }
+        if FindInsEntry(ObjData) then
+          begin
+            { Calculate instruction size }
+            InsSize:=calcsize(insentry);
+            LastInsOffset:=InsOffset;
+            Pass1:=InsSize;
+            exit;
+          end;
+        LastInsOffset:=-1;
+      end;
+
+
+    procedure taicpu.Pass2(objdata: TObjData);
+      begin
+        inherited Pass2(objdata);
+      end;
+
+
     function taicpu.CheckIfValid: boolean;
     function taicpu.CheckIfValid: boolean;
       begin
       begin
         result:=FindInsEntry(nil);
         result:=FindInsEntry(nil);