Browse Source

* Moved local label infrastructure into tasmreader, reduces number of global vars. Functionality is not changed.

git-svn-id: trunk@27477 -
sergei 11 years ago
parent
commit
5c48804240
5 changed files with 72 additions and 103 deletions
  1. 1 4
      compiler/m68k/ra68kmot.pas
  2. 2 5
      compiler/raatt.pas
  3. 67 2
      compiler/rasm.pas
  4. 0 87
      compiler/rautils.pas
  5. 2 5
      compiler/x86/rax86int.pas

+ 1 - 4
compiler/m68k/ra68kmot.pas

@@ -1732,8 +1732,6 @@ const
             _asmsorted := TRUE;
             _asmsorted := TRUE;
           end;
           end;
         curlist:=TAsmList.Create;
         curlist:=TAsmList.Create;
-        { setup label linked list }
-        LocalLabelList:=TLocalLabelList.Create;
         c:=current_scanner.asmgetchar;
         c:=current_scanner.asmgetchar;
         gettoken;
         gettoken;
         while actasmtoken<>AS_END do
         while actasmtoken<>AS_END do
@@ -1827,8 +1825,7 @@ const
           end; { end while }
           end; { end while }
 
 
         { Check LocalLabelList }
         { Check LocalLabelList }
-        LocalLabelList.CheckEmitted;
-        LocalLabelList.Free;
+        checklocallabels;
 
 
         assemble:=curlist;
         assemble:=curlist;
         //Message(asmr_d_finish_reading);
         //Message(asmr_d_finish_reading);

+ 2 - 5
compiler/raatt.pas

@@ -1002,8 +1002,6 @@ unit raatt;
         end;
         end;
        curlist:=TAsmList.Create;
        curlist:=TAsmList.Create;
        lasTSec:=sec_code;
        lasTSec:=sec_code;
-       { setup label linked list }
-       LocalLabelList:=TLocalLabelList.Create;
        { start tokenizer }
        { start tokenizer }
        c:=current_scanner.asmgetcharstart;
        c:=current_scanner.asmgetcharstart;
        gettoken;
        gettoken;
@@ -1256,9 +1254,8 @@ unit raatt;
              end;
              end;
          end;
          end;
        until false;
        until false;
-       { Check LocalLabelList }
-       LocalLabelList.CheckEmitted;
-       LocalLabelList.Free;
+       { check that all referenced local labels are defined }
+       checklocallabels;
        { are we back in the code section? }
        { are we back in the code section? }
        if lasTSec<>sec_code then
        if lasTSec<>sec_code then
         begin
         begin

+ 67 - 2
compiler/rasm.pas

@@ -28,6 +28,7 @@ unit rasm;
     uses
     uses
       cclasses,
       cclasses,
       rabase,
       rabase,
+      aasmbase,
       aasmtai,aasmdata,
       aasmtai,aasmdata,
       systems,
       systems,
       cpubase,
       cpubase,
@@ -44,25 +45,89 @@ unit rasm;
          actasmregister : tregister;
          actasmregister : tregister;
          actcondition   : tasmcond;
          actcondition   : tasmcond;
          iasmops        : TFPHashList;
          iasmops        : TFPHashList;
+         locallabels    : TFPHashObjectList;
          constructor create;override;
          constructor create;override;
          destructor destroy;override;
          destructor destroy;override;
+         function createlocallabel(const s: string; var hl: tasmlabel; emit: boolean): boolean;
+         procedure checklocallabels;
        end;
        end;
 
 
   implementation
   implementation
 
 
+    uses
+      verbose;
+
+    type
+      TLocalLabel = class(TFPHashObject)
+        emitted: boolean;
+        lab: tasmlabel;
+        function Gettasmlabel: tasmlabel;
+      end;
+
+
+    function TLocalLabel.Gettasmlabel:tasmlabel;
+      begin
+        if not assigned(lab) then
+         begin
+           current_asmdata.getjumplabel(lab);
+           { this label is forced to be used so it's always written }
+           lab.increfs;
+         end;
+        result:=lab;
+      end;
+
+
     constructor tasmreader.create;
     constructor tasmreader.create;
       begin
       begin
         inherited create;
         inherited create;
         firsttoken:=true;
         firsttoken:=true;
+        locallabels:=TFPHashObjectList.create;
       end;
       end;
 
 
 
 
     destructor tasmreader.destroy;
     destructor tasmreader.destroy;
       begin
       begin
-        if assigned(iasmops) then
-          iasmops.Free;
+        locallabels.Free;
+        iasmops.Free;
         inherited destroy;
         inherited destroy;
       end;
       end;
 
 
 
 
+    function tasmreader.createlocallabel(const s: string; var hl: tasmlabel; emit:boolean):boolean;
+      var
+        lab: TLocalLabel;
+      begin
+        result:=true;
+        { Check if it already is defined }
+        lab:=TLocalLabel(locallabels.Find(s));
+        if not assigned(lab) then
+          lab:=TLocalLabel.Create(locallabels,s);
+        { set emitted flag and check for dup syms }
+        if emit then
+          begin
+            if lab.Emitted then
+              begin
+                Message1(asmr_e_dup_local_sym,lab.Name);
+                result:=false;
+              end;
+            lab.Emitted:=true;
+          end;
+        hl:=lab.Gettasmlabel;
+      end;
+
+
+    procedure tasmreader.checklocallabels;
+      var
+        i: longint;
+        lab: TLocalLabel;
+      begin
+        for i:=0 to locallabels.Count-1 do
+          begin
+            lab:=TLocalLabel(locallabels[i]);
+            if not lab.emitted then
+              Message1(asmr_e_unknown_label_identifier,lab.name);
+          end;
+        locallabels.Clear;
+      end;
+
 end.
 end.

+ 0 - 87
compiler/rautils.pas

@@ -41,28 +41,6 @@ Const
   {$define MAX_OPER_3}
   {$define MAX_OPER_3}
 {$endif}
 {$endif}
 
 
-{---------------------------------------------------------------------
-                       Local Label Management
----------------------------------------------------------------------}
-
-Type
-  { Each local label has this structure associated with it }
-  TLocalLabel = class(TFPHashObject)
-    Emitted : boolean;
-    constructor Create(AList:TFPHashObjectList;const n:string);
-    function  Gettasmlabel:tasmlabel;
-  private
-    lab : tasmlabel;
-  end;
-
-  TLocalLabelList = class(TFPHashObjectList)
-    procedure CheckEmitted;
-  end;
-
-var
-  LocalLabelList : TLocalLabelList;
-
-function CreateLocalLabel(const s: string; var hl: tasmlabel; emit:boolean):boolean;
 Function SearchLabel(const s: string; var hl: tasmlabel;emit:boolean): boolean;
 Function SearchLabel(const s: string; var hl: tasmlabel;emit:boolean): boolean;
 
 
 
 
@@ -1150,71 +1128,6 @@ end;
     end;
     end;
 
 
 
 
-{***************************************************************************
-                                 TLocalLabel
-***************************************************************************}
-
-constructor TLocalLabel.create(AList:TFPHashObjectList;const n:string);
-begin
-  inherited Create(AList,n);
-  lab:=nil;
-  emitted:=false;
-end;
-
-
-function TLocalLabel.Gettasmlabel:tasmlabel;
-begin
-  if not assigned(lab) then
-   begin
-     current_asmdata.getjumplabel(lab);
-     { this label is forced to be used so it's always written }
-     lab.increfs;
-   end;
-  Gettasmlabel:=lab;
-end;
-
-
-{***************************************************************************
-                             TLocalLabelList
-***************************************************************************}
-
-procedure TLocalLabelList.CheckEmitted;
-var
-  i : longint;
-  lab : TLocalLabel;
-begin
-  for i:=0 to LocalLabelList.Count-1 do
-    begin
-      lab:=TLocalLabel(LocalLabelList[i]);
-      if not lab.emitted then
-        Message1(asmr_e_unknown_label_identifier,lab.name);
-    end;
-end;
-
-
-function CreateLocalLabel(const s: string; var hl: tasmlabel; emit:boolean):boolean;
-var
-  lab : TLocalLabel;
-Begin
-  CreateLocalLabel:=true;
-{ Check if it already is defined }
-  lab:=TLocalLabel(LocalLabellist.Find(s));
-  if not assigned(lab) then
-    lab:=TLocalLabel.Create(LocalLabellist,s);
-{ set emitted flag and check for dup syms }
-  if emit then
-   begin
-     if lab.Emitted then
-      begin
-        Message1(asmr_e_dup_local_sym,lab.Name);
-        CreateLocalLabel:=false;
-      end;
-     lab.Emitted:=true;
-   end;
-  hl:=lab.Gettasmlabel;
-end;
-
-
 {****************************************************************************
 {****************************************************************************
                       Symbol table helper routines
                       Symbol table helper routines
 ****************************************************************************}
 ****************************************************************************}

+ 2 - 5
compiler/x86/rax86int.pas

@@ -2227,8 +2227,6 @@ Unit Rax86int;
        end;
        end;
       }
       }
       curlist:=TAsmList.Create;
       curlist:=TAsmList.Create;
-      { setup label linked list }
-      LocalLabelList:=TLocalLabelList.Create;
       { we might need to know which parameters are passed in registers }
       { we might need to know which parameters are passed in registers }
       if not parse_generic then
       if not parse_generic then
         current_procinfo.generate_parameter_info;
         current_procinfo.generate_parameter_info;
@@ -2329,9 +2327,8 @@ Unit Rax86int;
             end;
             end;
         end; { end case }
         end; { end case }
       until false;
       until false;
-      { Check LocalLabelList }
-      LocalLabelList.CheckEmitted;
-      LocalLabelList.Free;
+      { check that all referenced local labels are defined }
+      checklocallabels;
       { Return the list in an asmnode }
       { Return the list in an asmnode }
       assemble:=curlist;
       assemble:=curlist;
       Message1(asmr_d_finish_reading,'intel');
       Message1(asmr_d_finish_reading,'intel');