Browse Source

+ use of a dictionary object
for faster opcode searching in assembler readers
implemented by Kovacs Attila Zoltan

pierre 25 years ago
parent
commit
cff91a51a2
3 changed files with 51 additions and 20 deletions
  1. 11 1
      compiler/cpubase.pas
  2. 21 10
      compiler/ra386att.pas
  3. 19 9
      compiler/ra386int.pas

+ 11 - 1
compiler/cpubase.pas

@@ -196,6 +196,11 @@ type
 
 
   op2strtable=array[tasmop] of string[11];
   op2strtable=array[tasmop] of string[11];
 
 
+  pstr2opentry = ^tstr2opentry;
+  tstr2opentry = object(Tnamedindexobject)
+    op: TAsmOp;
+  end;
+
 const
 const
   firstop = low(tasmop);
   firstop = low(tasmop);
   lastop  = high(tasmop);
   lastop  = high(tasmop);
@@ -902,7 +907,12 @@ end;
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.28  2000-05-10 19:09:07  pierre
+  Revision 1.29  2000-05-12 21:57:02  pierre
+    + use of a dictionary object
+      for faster opcode searching in assembler readers
+      implemented by Kovacs Attila Zoltan
+
+  Revision 1.28  2000/05/10 19:09:07  pierre
     * op2strtable string length changed to 11
     * op2strtable string length changed to 11
       Thanks to Kovacs Attila Zoltan
       Thanks to Kovacs Attila Zoltan
       this should be set by nasmconv utility !
       this should be set by nasmconv utility !

+ 21 - 10
compiler/ra386att.pas

@@ -96,7 +96,7 @@ var
   actasmregister : tregister;
   actasmregister : tregister;
   actopsize      : topsize;
   actopsize      : topsize;
   actcondition   : tasmcond;
   actcondition   : tasmcond;
-  iasmops        : ^op2strtable;
+  iasmops        : Pdictionary;
   iasmregs       : ^reg2strtable;
   iasmregs       : ^reg2strtable;
 
 
 
 
@@ -105,11 +105,16 @@ Procedure SetupTables;
 var
 var
   i : tasmop;
   i : tasmop;
   j : tregister;
   j : tregister;
+  str2opentry: pstr2opentry;
 Begin
 Begin
   { opcodes }
   { opcodes }
-  new(iasmops);
+  new(iasmops,init);
   for i:=firstop to lastop do
   for i:=firstop to lastop do
-   iasmops^[i] := upper(att_op2str[i]);
+    begin
+      new(str2opentry,initname(upper(att_op2str[i])));
+      str2opentry^.op:=i;
+      iasmops^.insert(str2opentry);
+    end;
   { registers }
   { registers }
   new(iasmregs);
   new(iasmregs);
   for j:=firstreg to lastreg do
   for j:=firstreg to lastreg do
@@ -138,13 +143,13 @@ const
     S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_IL,S_IS,S_IQ,S_NO
     S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_IL,S_IS,S_IQ,S_NO
   );
   );
 var
 var
+  str2opentry: pstr2opentry;
   i    : tasmop;
   i    : tasmop;
   cond : string[4];
   cond : string[4];
   cnd  : tasmcond;
   cnd  : tasmcond;
   len,
   len,
   j,
   j,
   sufidx : longint;
   sufidx : longint;
-  hid  : string;
 Begin
 Begin
   is_asmopcode:=FALSE;
   is_asmopcode:=FALSE;
 
 
@@ -159,11 +164,12 @@ Begin
      if copy(s,len+1,length(att_sizesuffixstr[sufidx]))=att_sizesuffixstr[sufidx] then
      if copy(s,len+1,length(att_sizesuffixstr[sufidx]))=att_sizesuffixstr[sufidx] then
       begin
       begin
         { here we search the entire table... }
         { here we search the entire table... }
-        hid:=copy(s,1,len);
-        for i:=firstop to lastop do
-         if (length(hid) > 0) and (hid=iasmops^[i]) then
+        str2opentry:=nil;
+        if {(length(s)>0) and} (len>0) then
+          str2opentry:=pstr2opentry(iasmops^.search(copy(s,1,len)));
+        if assigned(str2opentry) then
           begin
           begin
-            actopcode:=i;
+            actopcode:=str2opentry^.op;
             if att_needsuffix[actopcode]=attsufFPU then
             if att_needsuffix[actopcode]=attsufFPU then
              actopsize:=att_sizefpusuffix[sufidx]
              actopsize:=att_sizefpusuffix[sufidx]
             else if att_needsuffix[actopcode]=attsufFPUint then
             else if att_needsuffix[actopcode]=attsufFPUint then
@@ -1982,7 +1988,7 @@ var
 procedure ra386att_exit;{$ifndef FPC}far;{$endif}
 procedure ra386att_exit;{$ifndef FPC}far;{$endif}
 begin
 begin
   if assigned(iasmops) then
   if assigned(iasmops) then
-    dispose(iasmops);
+    dispose(iasmops,done);
   if assigned(iasmregs) then
   if assigned(iasmregs) then
     dispose(iasmregs);
     dispose(iasmregs);
   exitproc:=old_exit;
   exitproc:=old_exit;
@@ -1995,7 +2001,12 @@ begin
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.77  2000-05-11 09:56:21  pierre
+  Revision 1.78  2000-05-12 21:57:02  pierre
+    + use of a dictionary object
+      for faster opcode searching in assembler readers
+      implemented by Kovacs Attila Zoltan
+
+  Revision 1.77  2000/05/11 09:56:21  pierre
     * fixed several compare problems between longints and
     * fixed several compare problems between longints and
       const > $80000000 that are treated as int64 constanst
       const > $80000000 that are treated as int64 constanst
       by Delphi reported by Kovacs Attila Zoltan
       by Delphi reported by Kovacs Attila Zoltan

+ 19 - 9
compiler/ra386int.pas

@@ -113,7 +113,7 @@ var
   actopcode      : tasmop;
   actopcode      : tasmop;
   actopsize      : topsize;
   actopsize      : topsize;
   actcondition   : tasmcond;
   actcondition   : tasmcond;
-  iasmops        : ^op2strtable;
+  iasmops        : Pdictionary;
   iasmregs       : ^reg2strtable;
   iasmregs       : ^reg2strtable;
 
 
 
 
@@ -122,11 +122,16 @@ Procedure SetupTables;
 var
 var
   i : tasmop;
   i : tasmop;
   j : tregister;
   j : tregister;
+  str2opentry: pstr2opentry;
 Begin
 Begin
   { opcodes }
   { opcodes }
-  new(iasmops);
+  new(iasmops,init);
   for i:=firstop to lastop do
   for i:=firstop to lastop do
-   iasmops^[i] := upper(int_op2str[i]);
+    begin
+      new(str2opentry,initname(upper(int_op2str[i])));
+      str2opentry^.op:=i;
+      iasmops^.insert(str2opentry);
+    end;
   { registers }
   { registers }
   new(iasmregs);
   new(iasmregs);
   for j:=firstreg to lastreg do
   for j:=firstreg to lastreg do
@@ -141,7 +146,7 @@ end;
 
 
    function is_asmopcode(const s: string):boolean;
    function is_asmopcode(const s: string):boolean;
    var
    var
-     i: tasmop;
+     str2opentry: pstr2opentry;
      cond : string[4];
      cond : string[4];
      cnd : tasmcond;
      cnd : tasmcond;
      j: longint;
      j: longint;
@@ -152,10 +157,10 @@ end;
      actcondition:=C_None;
      actcondition:=C_None;
      actopsize:=S_NO;
      actopsize:=S_NO;
 
 
-     for i:=firstop to lastop do
-      if s=iasmops^[i] then
+     str2opentry:=pstr2opentry(iasmops^.search(s));
+     if assigned(str2opentry) then
        begin
        begin
-         actopcode:=i;
+         actopcode:=str2opentry^.op;
          actasmtoken:=AS_OPCODE;
          actasmtoken:=AS_OPCODE;
          is_asmopcode:=TRUE;
          is_asmopcode:=TRUE;
          exit;
          exit;
@@ -1815,7 +1820,7 @@ var
 procedure ra386int_exit;{$ifndef FPC}far;{$endif}
 procedure ra386int_exit;{$ifndef FPC}far;{$endif}
 begin
 begin
   if assigned(iasmops) then
   if assigned(iasmops) then
-    dispose(iasmops);
+    dispose(iasmops,done);
   if assigned(iasmregs) then
   if assigned(iasmregs) then
     dispose(iasmregs);
     dispose(iasmregs);
   exitproc:=old_exit;
   exitproc:=old_exit;
@@ -1828,7 +1833,12 @@ begin
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.68  2000-05-12 21:26:23  pierre
+  Revision 1.69  2000-05-12 21:57:02  pierre
+    + use of a dictionary object
+      for faster opcode searching in assembler readers
+      implemented by Kovacs Attila Zoltan
+
+  Revision 1.68  2000/05/12 21:26:23  pierre
     * fix the FDIV FDIVR FSUB FSUBR and popping equivalent
     * fix the FDIV FDIVR FSUB FSUBR and popping equivalent
       simply by swapping from reverse to normal and vice-versa
       simply by swapping from reverse to normal and vice-versa
       when passing from one syntax to the other !
       when passing from one syntax to the other !