Browse Source

* check for valid asm instructions

peter 24 years ago
parent
commit
00c901b3c1
2 changed files with 63 additions and 22 deletions
  1. 54 20
      compiler/i386/cpuasm.pas
  2. 9 2
      compiler/i386/ra386.pas

+ 54 - 20
compiler/i386/cpuasm.pas

@@ -122,6 +122,7 @@ type
   public
   public
      { the next will reset all instructions that can change in pass 2 }
      { the next will reset all instructions that can change in pass 2 }
      procedure ResetPass2;
      procedure ResetPass2;
+     function  CheckIfValid:boolean;
      function  Pass1(offset:longint):longint;virtual;
      function  Pass1(offset:longint):longint;virtual;
      procedure Pass2;virtual;
      procedure Pass2;virtual;
   private
   private
@@ -949,20 +950,15 @@ begin
 end;
 end;
 
 
 
 
-function taicpu.Pass1(offset:longint):longint;
+function taicpu.CheckIfValid:boolean;
 var
 var
   m,i : longint;
   m,i : longint;
 begin
 begin
-  Pass1:=0;
-{ Save the old offset and set the new offset }
-  InsOffset:=Offset;
+  CheckIfValid:=false;
 { Things which may only be done once, not when a second pass is done to
 { Things which may only be done once, not when a second pass is done to
   optimize }
   optimize }
   if Insentry=nil then
   if Insentry=nil then
    begin
    begin
-     { Check if error last time then InsSize=-1 }
-     if InsSize=-1 then
-      exit;
      { We need intel style operands }
      { We need intel style operands }
      SwapOperands;
      SwapOperands;
      { create the .ot fields }
      { create the .ot fields }
@@ -972,23 +968,20 @@ begin
    end
    end
   else
   else
    begin
    begin
-{$ifdef PASS2FLAG}
-     { we are here in a second pass, check if the instruction can be optimized }
-     if (InsEntry^.flags and IF_PASS2)=0 then
-      begin
-        Pass1:=InsSize;
-        exit;
-      end;
-     { update the .ot fields, some top_const can be updated }
-     create_ot;
-{$endif}
+     { we've already an insentry so it's valid }
+     CheckIfValid:=true;
+     exit;
    end;
    end;
 { Lookup opcode in the table }
 { Lookup opcode in the table }
   InsSize:=-1;
   InsSize:=-1;
   i:=instabcache^[opcode];
   i:=instabcache^[opcode];
   if i=-1 then
   if i=-1 then
    begin
    begin
+{$ifdef TP}
+     Message1(asmw_e_opcode_not_in_table,'');
+{$else}
      Message1(asmw_e_opcode_not_in_table,att_op2str[opcode]);
      Message1(asmw_e_opcode_not_in_table,att_op2str[opcode]);
+{$endif}
      exit;
      exit;
    end;
    end;
   insentry:=@instab[i];
   insentry:=@instab[i];
@@ -1000,8 +993,7 @@ begin
         InsSize:=calcsize(insentry);
         InsSize:=calcsize(insentry);
         if (segprefix<>R_NO) then
         if (segprefix<>R_NO) then
          inc(InsSize);
          inc(InsSize);
-        Pass1:=InsSize;
-        LastInsOffset:=InsOffset;
+        CheckIfValid:=true;
         exit;
         exit;
       end;
       end;
      inc(i);
      inc(i);
@@ -1012,6 +1004,45 @@ begin
 { No instruction found, set insentry to nil and inssize to -1 }
 { No instruction found, set insentry to nil and inssize to -1 }
   insentry:=nil;
   insentry:=nil;
   inssize:=-1;
   inssize:=-1;
+end;
+
+
+
+function taicpu.Pass1(offset:longint):longint;
+begin
+  Pass1:=0;
+{ Save the old offset and set the new offset }
+  InsOffset:=Offset;
+{ Things which may only be done once, not when a second pass is done to
+  optimize }
+  if Insentry=nil then
+   begin
+     { Check if error last time then InsSize=-1 }
+     if InsSize=-1 then
+      exit;
+     { set the file postion }
+     aktfilepos:=fileinfo;
+   end
+  else
+   begin
+{$ifdef PASS2FLAG}
+     { we are here in a second pass, check if the instruction can be optimized }
+     if (InsEntry^.flags and IF_PASS2)=0 then
+      begin
+        Pass1:=InsSize;
+        exit;
+      end;
+     { update the .ot fields, some top_const can be updated }
+     create_ot;
+{$endif}
+   end;
+{ Check if it's a valid instruction }
+  if CheckIfValid then
+   begin
+     LastInsOffset:=InsOffset;
+     Pass1:=InsSize;
+     exit;
+   end;
   LastInsOffset:=-1;
   LastInsOffset:=-1;
 end;
 end;
 
 
@@ -1690,7 +1721,10 @@ end;
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.8  2001-01-07 15:48:56  jonas
+  Revision 1.9  2001-01-12 19:18:42  peter
+    * check for valid asm instructions
+
+  Revision 1.8  2001/01/07 15:48:56  jonas
     * references to symbols were only decreased in taicpu.done for jmps, fixed
     * references to symbols were only decreased in taicpu.done for jmps, fixed
 
 
   Revision 1.7  2000/12/26 15:56:17  peter
   Revision 1.7  2000/12/26 15:56:17  peter

+ 9 - 2
compiler/i386/ra386.pas

@@ -506,7 +506,11 @@ begin
 
 
  { Concat the opcode or give an error }
  { Concat the opcode or give an error }
   if assigned(ai) then
   if assigned(ai) then
-   p.concat(ai)
+   begin
+     { Check the instruction if it's valid }
+     ai.CheckIfValid;
+     p.concat(ai);
+   end
   else
   else
    Message(asmr_e_invalid_opcode_and_operand);
    Message(asmr_e_invalid_opcode_and_operand);
 end;
 end;
@@ -514,7 +518,10 @@ end;
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.4  2000-12-25 00:07:34  peter
+  Revision 1.5  2001-01-12 19:18:42  peter
+    * check for valid asm instructions
+
+  Revision 1.4  2000/12/25 00:07:34  peter
     + new tlinkedlist class (merge of old tstringqueue,tcontainer and
     + new tlinkedlist class (merge of old tstringqueue,tcontainer and
       tlinkedlist objects)
       tlinkedlist objects)