浏览代码

+ put guids in a constant pool as well

git-svn-id: trunk@24061 -
florian 12 年之前
父节点
当前提交
9375529430
共有 3 个文件被更改,包括 37 次插入19 次删除
  1. 2 1
      compiler/aasmdata.pas
  2. 27 13
      compiler/ncgcon.pas
  3. 8 5
      compiler/ncon.pas

+ 2 - 1
compiler/aasmdata.pas

@@ -89,7 +89,8 @@ interface
          sp_objcvartypes,
          sp_objcprotocolrefs,
          sp_varsets,
-         sp_floats
+         sp_floats,
+         sp_guids
       );
       
     const

+ 27 - 13
compiler/ncgcon.pas

@@ -525,21 +525,35 @@ implementation
 
     procedure tcgguidconstnode.pass_generate_code;
       var
-        tmplabel : TAsmLabel;
-        i : integer;
+         lastlabel   : tasmlabel;
+         i           : longint;
+         entry       : PHashSetItem;
       begin
         location_reset_ref(location,LOC_CREFERENCE,OS_NO,const_align(16));
-        { label for GUID }
-        current_asmdata.getdatalabel(tmplabel);
-        maybe_new_object_file(current_asmdata.asmlists[al_typedconsts]);
-        new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata_norel,tmplabel.name,const_align(16));
-        current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(tmplabel));
-        current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_32bit(longint(value.D1)));
-        current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_16bit(value.D2));
-        current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_16bit(value.D3));
-        for i:=low(value.D4) to high(value.D4) do
-          current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_8bit(value.D4[i]));
-        location.reference.symbol:=tmplabel;
+        lastlabel:=nil;
+        { const already used ? }
+        if not assigned(lab_set) then
+          begin
+            entry := current_asmdata.ConstPools[sp_guids].FindOrAdd(@value,sizeof(value));
+            lab_set := TAsmLabel(entry^.Data);  // is it needed anymore?
+
+             { :-(, we must generate a new entry }
+             if not assigned(entry^.Data) then
+               begin
+                 current_asmdata.getdatalabel(lastlabel);
+                 lab_set:=lastlabel;
+                 entry^.Data:=lastlabel;
+                 maybe_new_object_file(current_asmdata.asmlists[al_typedconsts]);
+                 new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata_norel,lastlabel.name,const_align(16));
+                 current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(lastlabel));
+                 current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_32bit(longint(value.D1)));
+                 current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_16bit(value.D2));
+                 current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_16bit(value.D3));
+                 for i:=low(value.D4) to high(value.D4) do
+                   current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_8bit(value.D4[i]));
+               end;
+          end;
+        location.reference.symbol:=lab_set;
       end;
 
 

+ 8 - 5
compiler/ncon.pas

@@ -168,6 +168,7 @@ interface
 
        tguidconstnode = class(tnode)
           value : tguid;
+          lab_set : tasmsymbol;
           constructor create(const g:tguid);virtual;
           constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
           procedure ppuwrite(ppufile:tcompilerppufile);override;
@@ -1144,6 +1145,7 @@ implementation
            value_set:=nil;
       end;
 
+
     destructor tsetconstnode.destroy;
       begin
         if assigned(value_set) then
@@ -1213,12 +1215,9 @@ implementation
       end;
 
 
-
     function tsetconstnode.dogetcopy : tnode;
-
       var
          n : tsetconstnode;
-
       begin
          n:=tsetconstnode(inherited dogetcopy);
          if assigned(value_set) then
@@ -1233,12 +1232,14 @@ implementation
          dogetcopy:=n;
       end;
 
+
     function tsetconstnode.pass_typecheck:tnode;
       begin
         result:=nil;
         resultdef:=typedef;
       end;
 
+
     function tsetconstnode.pass_1 : tnode;
       begin
          result:=nil;
@@ -1307,22 +1308,23 @@ implementation
 
 
     function tguidconstnode.dogetcopy : tnode;
-
       var
          n : tguidconstnode;
-
       begin
          n:=tguidconstnode(inherited dogetcopy);
          n.value:=value;
+         n.lab_set:=lab_set;
          dogetcopy:=n;
       end;
 
+
     function tguidconstnode.pass_typecheck:tnode;
       begin
         result:=nil;
         resultdef:=rec_tguid;
       end;
 
+
     function tguidconstnode.pass_1 : tnode;
       begin
          result:=nil;
@@ -1332,6 +1334,7 @@ implementation
           include(current_procinfo.flags,pi_needs_got);
       end;
 
+
     function tguidconstnode.docompare(p: tnode): boolean;
       begin
         docompare :=