浏览代码

* split up specifying the type of the section of a typed constant and whether
it should be put in a new section

git-svn-id: branches/hlcgllvm@28753 -

Jonas Maebe 10 年之前
父节点
当前提交
210b532832
共有 4 个文件被更改,包括 28 次插入20 次删除
  1. 21 13
      compiler/aasmcnst.pas
  2. 2 2
      compiler/llvm/nllvmtcon.pas
  3. 2 2
      compiler/ncgcon.pas
  4. 3 3
      compiler/ngtcon.pas

+ 21 - 13
compiler/aasmcnst.pas

@@ -98,6 +98,15 @@ type
       ofs: asizeint;
     end;
 
+   { flags for the finalisation of the typed const builder asmlist }
+   ttcasmlistoption = (
+     { the tasmsymbol is a tasmlabel }
+     tcalo_is_lab,
+     { start a new section }
+     tcalo_new_section
+   );
+   ttcasmlistoptions = set of ttcasmlistoption;
+
    { Warning: never directly create a ttai_typedconstbuilder instance,
      instead create a cai_typedconstbuilder (this class can be overridden) }
    ttai_lowleveltypedconstbuilder = class abstract
@@ -115,7 +124,7 @@ type
        platform }
      function aggregate_kind(def: tdef): ttypedconstkind; virtual;
      { finalize the asmlist: add the necessary symbols etc }
-     procedure finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; lab: boolean); virtual;
+     procedure finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions); virtual;
     public
      constructor create; virtual;
      destructor destroy; override;
@@ -186,7 +195,7 @@ type
        This asmlist will be freed when the builder is destroyed, so add its
        contents to another list first. This property should only be accessed
        once all data has been added. }
-     function get_final_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: longint; lab: boolean): tasmlist;
+     function get_final_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: longint; const options: ttcasmlistoptions): tasmlist;
 
      { returns the offset of the string data relative to ansi/unicode/widestring
        constant labels. On most platforms, this is 0 (with the header at a
@@ -413,19 +422,19 @@ implementation
      end;
 
 
-   procedure ttai_lowleveltypedconstbuilder.finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; lab: boolean);
+   procedure ttai_lowleveltypedconstbuilder.finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions);
      var
        prelist: tasmlist;
      begin
        prelist:=tasmlist.create_without_marker;
        { only now add items based on the symbolname, because it may be
          modified by the "section" specifier in case of a typed constant }
-       if section<>sec_none then
+       if tcalo_new_section in options then
          begin
            maybe_new_object_file(prelist);
            new_section(prelist,section,secname,const_align(alignment));
          end;
-       if not lab then
+       if not(tcalo_is_lab in options) then
          if sym.bind=AB_GLOBAL then
            prelist.concat(tai_symbol.Create_Global(sym,0))
          else
@@ -441,11 +450,11 @@ implementation
      end;
 
 
-   function ttai_lowleveltypedconstbuilder.get_final_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: longint; lab: boolean): tasmlist;
+   function ttai_lowleveltypedconstbuilder.get_final_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: longint; const options: ttcasmlistoptions): tasmlist;
      begin
        if not fasmlist_finalized then
          begin
-           finalize_asmlist(sym,def,section,secname,alignment,lab);
+           finalize_asmlist(sym,def,section,secname,alignment,options);
            fasmlist_finalized:=true;
          end;
        result:=fasmlist;
@@ -605,10 +614,10 @@ implementation
      var
        s: PChar;
        startlab: tasmlabel;
-       sectype: TAsmSectiontype;
        ansistrrecdef: trecorddef;
        datadef: tdef;
        datatcb: ttai_lowleveltypedconstbuilder;
+       options: ttcasmlistoptions;
      begin
        datatcb:=self.create;
        result:=datatcb.emit_string_const_common(list,st_ansistring,len,encoding,startlab);
@@ -622,11 +631,10 @@ implementation
        datatcb.emit_tai(tai_string.create_pchar(s,len+1),datadef);
        datatcb.maybe_end_aggregate(datadef);
        ansistrrecdef:=datatcb.end_anonymous_record;
+       options:=[tcalo_is_lab];
        if NewSection then
-         sectype:=sec_rodata_norel
-       else
-         sectype:=sec_none;
-       list.concatlist(datatcb.get_final_asmlist(startlab,ansistrrecdef,sectype,startlab.name,const_align(sizeof(pint)),true));
+         include(options,tcalo_new_section);
+       list.concatlist(datatcb.get_final_asmlist(startlab,ansistrrecdef,sec_rodata_norel,startlab.name,const_align(sizeof(pint)),options));
        datatcb.free;
      end;
 
@@ -677,7 +685,7 @@ implementation
        else
          { code generation for other sizes must be written }
          internalerror(200904271);
-       list.concatlist(datatcb.get_final_asmlist(startlab,uniwidestrrecdef,sec_rodata_norel,startlab.name,const_align(sizeof(pint)),true));
+       list.concatlist(datatcb.get_final_asmlist(startlab,uniwidestrrecdef,sec_rodata_norel,startlab.name,const_align(sizeof(pint)),[tcalo_is_lab,tcalo_new_section]));
        datatcb.free;
      end;
 

+ 2 - 2
compiler/llvm/nllvmtcon.pas

@@ -43,7 +43,7 @@ interface
       flast_added_tai: tai;
       fqueued_tai_opidx: longint;
 
-      procedure finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; lab: boolean); override;
+      procedure finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions); override;
       { outerai: the ai that should become fqueued_tai in case it's still nil,
           or that should be filled in the fqueued_tai_opidx of the current
           fqueued_tai if it's not nil
@@ -87,7 +87,7 @@ implementation
     cpubase,llvmbase,
     symbase,symtable,llvmdef,defutil;
 
-  procedure tllvmtai_typedconstbuilder.finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; lab: boolean);
+  procedure tllvmtai_typedconstbuilder.finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions);
     var
       newasmlist: tasmlist;
     begin

+ 2 - 2
compiler/ncgcon.pas

@@ -376,7 +376,7 @@ implementation
                           datatcb.emit_tai(Tai_string.Create_pchar(pc,l+1),datadef);
                           datatcb.maybe_end_aggregate(datadef);
                           current_asmdata.asmlists[al_typedconsts].concatList(
-                            datatcb.get_final_asmlist(lastlabel.lab,datadef,sec_rodata_norel,lastlabel.lab.name,const_align(sizeof(pint)),true)
+                            datatcb.get_final_asmlist(lastlabel.lab,datadef,sec_rodata_norel,lastlabel.lab.name,const_align(sizeof(pint)),[tcalo_is_lab,tcalo_new_section])
                           );
                           datatcb.free;
                         end;
@@ -398,7 +398,7 @@ implementation
                           datatcb.emit_tai(Tai_string.Create_pchar(pc,len+1),datadef);
                           datatcb.maybe_end_aggregate(datadef);
                           current_asmdata.asmlists[al_typedconsts].concatList(
-                            datatcb.get_final_asmlist(lastlabel.lab,datadef,sec_rodata_norel,lastlabel.lab.name,const_align(sizeof(pint)),true)
+                            datatcb.get_final_asmlist(lastlabel.lab,datadef,sec_rodata_norel,lastlabel.lab.name,const_align(sizeof(pint)),[tcalo_is_lab,tcalo_new_section])
                           );
                           datatcb.free;
                         end;

+ 3 - 3
compiler/ngtcon.pas

@@ -875,7 +875,7 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
                   IncompatibleTypes(node.resultdef, def);
                   datadef:=getarraydef(cansichartype,1);
                 end;
-              current_asmdata.asmlists[al_const].concatlist(datatcb.get_final_asmlist(ll,datadef,sec_rodata,ll.name,varalign,true));
+              current_asmdata.asmlists[al_const].concatlist(datatcb.get_final_asmlist(ll,datadef,sec_rodata,ll.name,varalign,[tcalo_is_lab,tcalo_new_section]));
               datatcb.free;
               { we now emit the address of the first element of the array
                 containing the string data }
@@ -913,7 +913,7 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
                      datatcb.emit_tai(Tai_const.Create_16bit(0),cwidechartype);
                      datatcb.maybe_end_aggregate(datadef);
                      { concat add the string data to the al_const asmlist }
-                     current_asmdata.asmlists[al_const].concatlist(datatcb.get_final_asmlist(ll,datadef,sec_rodata,ll.name,const_align(sizeof(pint)),true));
+                     current_asmdata.asmlists[al_const].concatlist(datatcb.get_final_asmlist(ll,datadef,sec_rodata,ll.name,const_align(sizeof(pint)),[tcalo_is_lab,tcalo_new_section]));
                      datatcb.free;
                      { we now emit the address of the first element of the array
                        containing the string data }
@@ -1136,7 +1136,7 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
               sec:=sec_data;
             secname:=asmsym.Name;
           end;
-        result:=ftcb.get_final_asmlist(asmsym,fsym.vardef,sec,secname,fsym.vardef.alignment,false);
+        result:=ftcb.get_final_asmlist(asmsym,fsym.vardef,sec,secname,fsym.vardef.alignment,[tcalo_new_section]);
         if addstabx then
           begin
             { see same code in ncgutil.insertbssdata }