Selaa lähdekoodia

* support specifying the alignment of the start of an anonymous record
in the typed const builder (packrecords is not enough in case there are
only fields smaller than the desired alignment)

git-svn-id: trunk@31250 -

Jonas Maebe 10 vuotta sitten
vanhempi
commit
6f4fe415e9
2 muutettua tiedostoa jossa 19 lisäystä ja 9 poistoa
  1. 14 4
      compiler/aasmcnst.pas
  2. 5 5
      compiler/ncgvmt.pas

+ 14 - 4
compiler/aasmcnst.pas

@@ -314,8 +314,17 @@ type
         a) it's definitely a record
         a) it's definitely a record
         b) the def of the record should be automatically constructed based on
         b) the def of the record should be automatically constructed based on
            the types of the emitted fields
            the types of the emitted fields
+
+        packrecords: same as "pacrecords x"
+        recordalign: specify the (minimum) alignment of the start of the record
+          (no equivalent in source code), used as an alternative for explicit
+          align statements. Use "1" if it should be calculated based on the
+          fields
+        recordalignmin: same as "codealign recordmin=x"
+        maxcrecordalign: specify maximum C record alignment (no equivalent in
+          source code)
      }
      }
-     function begin_anonymous_record(const optionalname: string; packrecords, recordalignmin, maxcrecordalign: shortint): trecorddef; virtual;
+     function begin_anonymous_record(const optionalname: string; packrecords, recordalign, recordalignmin, maxcrecordalign: shortint): trecorddef; virtual;
      function end_anonymous_record: trecorddef; virtual;
      function end_anonymous_record: trecorddef; virtual;
 
 
      { The next group of routines are for constructing complex expressions.
      { The next group of routines are for constructing complex expressions.
@@ -1079,7 +1088,7 @@ implementation
        result.ofs:=0;
        result.ofs:=0;
        { pack the data, so that we don't add unnecessary null bytes after the
        { pack the data, so that we don't add unnecessary null bytes after the
          constant string }
          constant string }
-       begin_anonymous_record('$'+get_dynstring_rec_name(stringtype,false,len),1,1,1);
+       begin_anonymous_record('$'+get_dynstring_rec_name(stringtype,false,len),1,sizeof(TConstPtrUInt),1,1);
        string_symofs:=get_string_symofs(stringtype,false);
        string_symofs:=get_string_symofs(stringtype,false);
        { encoding }
        { encoding }
        emit_tai(tai_const.create_16bit(encoding),u16inttype);
        emit_tai(tai_const.create_16bit(encoding),u16inttype);
@@ -1239,7 +1248,7 @@ implementation
          begin
          begin
            result.lab:=startlab;
            result.lab:=startlab;
            datatcb.begin_anonymous_record('$'+get_dynstring_rec_name(st_widestring,true,strlength),
            datatcb.begin_anonymous_record('$'+get_dynstring_rec_name(st_widestring,true,strlength),
-             4,
+             4,4,
              targetinfos[target_info.system]^.alignment.recordalignmin,
              targetinfos[target_info.system]^.alignment.recordalignmin,
              targetinfos[target_info.system]^.alignment.maxCrecordalign);
              targetinfos[target_info.system]^.alignment.maxCrecordalign);
            datatcb.emit_tai(Tai_const.Create_32bit(strlength*cwidechartype.size),s32inttype);
            datatcb.emit_tai(Tai_const.Create_32bit(strlength*cwidechartype.size),s32inttype);
@@ -1357,7 +1366,7 @@ implementation
      end;
      end;
 
 
 
 
-   function ttai_typedconstbuilder.begin_anonymous_record(const optionalname: string; packrecords, recordalignmin, maxcrecordalign: shortint): trecorddef;
+   function ttai_typedconstbuilder.begin_anonymous_record(const optionalname: string; packrecords, recordalign, recordalignmin, maxcrecordalign: shortint): trecorddef;
      var
      var
        anonrecorddef: trecorddef;
        anonrecorddef: trecorddef;
        typesym: ttypesym;
        typesym: ttypesym;
@@ -1379,6 +1388,7 @@ implementation
          end;
          end;
        { create skeleton def }
        { create skeleton def }
        anonrecorddef:=crecorddef.create_global_internal(optionalname,packrecords,recordalignmin,maxcrecordalign);
        anonrecorddef:=crecorddef.create_global_internal(optionalname,packrecords,recordalignmin,maxcrecordalign);
+       trecordsymtable(anonrecorddef.symtable).recordalignment:=recordalign;
        { generic aggregate housekeeping }
        { generic aggregate housekeeping }
        begin_aggregate_internal(anonrecorddef,true);
        begin_aggregate_internal(anonrecorddef,true);
        { mark as anonymous record }
        { mark as anonymous record }

+ 5 - 5
compiler/ncgvmt.pas

@@ -616,7 +616,7 @@ implementation
             { generate the class table }
             { generate the class table }
             tcb.start_internal_data_builder(current_asmdata.AsmLists[al_const],sec_rodata,'',datatcb,classtable);
             tcb.start_internal_data_builder(current_asmdata.AsmLists[al_const],sec_rodata,'',datatcb,classtable);
             datatcb.begin_anonymous_record('$fpc_intern_classtable_'+tostr(classtablelist.Count-1),
             datatcb.begin_anonymous_record('$fpc_intern_classtable_'+tostr(classtablelist.Count-1),
-              packrecords,
+              packrecords,1,
               targetinfos[target_info.system]^.alignment.recordalignmin,
               targetinfos[target_info.system]^.alignment.recordalignmin,
               targetinfos[target_info.system]^.alignment.maxCrecordalign);
               targetinfos[target_info.system]^.alignment.maxCrecordalign);
             datatcb.emit_tai(Tai_const.Create_16bit(classtablelist.count),u16inttype);
             datatcb.emit_tai(Tai_const.Create_16bit(classtablelist.count),u16inttype);
@@ -651,7 +651,7 @@ implementation
               lengths and their order would have to incorporated in the name,
               lengths and their order would have to incorporated in the name,
               plus there would be very little chance that it could actually be
               plus there would be very little chance that it could actually be
               reused }
               reused }
-            datatcb.begin_anonymous_record('',packrecords,
+            datatcb.begin_anonymous_record('',packrecords,1,
               targetinfos[target_info.system]^.alignment.recordalignmin,
               targetinfos[target_info.system]^.alignment.recordalignmin,
               targetinfos[target_info.system]^.alignment.maxCrecordalign);
               targetinfos[target_info.system]^.alignment.maxCrecordalign);
             datatcb.emit_tai(Tai_const.Create_16bit(fieldcount),u16inttype);
             datatcb.emit_tai(Tai_const.Create_16bit(fieldcount),u16inttype);
@@ -674,7 +674,7 @@ implementation
                         Name: ShortString;
                         Name: ShortString;
                       end;
                       end;
                     }
                     }
-                    datatcb.begin_anonymous_record('$fpc_intern_fieldinfo_'+tostr(length(tfieldvarsym(sym).realname)),packrecords,
+                    datatcb.begin_anonymous_record('$fpc_intern_fieldinfo_'+tostr(length(tfieldvarsym(sym).realname)),packrecords,1,
                       targetinfos[target_info.system]^.alignment.recordalignmin,
                       targetinfos[target_info.system]^.alignment.recordalignmin,
                       targetinfos[target_info.system]^.alignment.maxCrecordalign);
                       targetinfos[target_info.system]^.alignment.maxCrecordalign);
                     datatcb.emit_tai(Tai_const.Create_pint(tfieldvarsym(sym).fieldoffset),ptruinttype);
                     datatcb.emit_tai(Tai_const.Create_pint(tfieldvarsym(sym).fieldoffset),ptruinttype);
@@ -711,7 +711,7 @@ implementation
         i  : longint;
         i  : longint;
       begin
       begin
         tcb.start_internal_data_builder(current_asmdata.AsmLists[al_const],sec_rodata,'',datatcb,fintfvtablelabels[intfindex]);
         tcb.start_internal_data_builder(current_asmdata.AsmLists[al_const],sec_rodata,'',datatcb,fintfvtablelabels[intfindex]);
-        datatcb.begin_anonymous_record('',0,
+        datatcb.begin_anonymous_record('',0,1,
           targetinfos[target_info.system]^.alignment.recordalignmin,
           targetinfos[target_info.system]^.alignment.recordalignmin,
           targetinfos[target_info.system]^.alignment.maxCrecordalign);
           targetinfos[target_info.system]^.alignment.maxCrecordalign);
         if assigned(AImplIntf.procdefs) then
         if assigned(AImplIntf.procdefs) then
@@ -809,7 +809,7 @@ implementation
           end;
           end;
 
 
         tcb.start_internal_data_builder(current_asmdata.AsmLists[al_const],sec_rodata,'',datatcb,lab);
         tcb.start_internal_data_builder(current_asmdata.AsmLists[al_const],sec_rodata,'',datatcb,lab);
-        datatcb.begin_anonymous_record('',default_settings.packrecords,
+        datatcb.begin_anonymous_record('',default_settings.packrecords,1,
           targetinfos[target_info.system]^.alignment.recordalignmin,
           targetinfos[target_info.system]^.alignment.recordalignmin,
           targetinfos[target_info.system]^.alignment.maxCrecordalign);
           targetinfos[target_info.system]^.alignment.maxCrecordalign);
         datatcb.emit_tai(Tai_const.Create_pint(_class.ImplementedInterfaces.count),search_system_type('SIZEUINT').typedef);
         datatcb.emit_tai(Tai_const.Create_pint(_class.ImplementedInterfaces.count),search_system_type('SIZEUINT').typedef);