From 6f4fe415e95a93335eb026cc928f9b10902e4da1 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Thu, 30 Jul 2015 16:58:01 +0000 Subject: [PATCH] * 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 - --- compiler/aasmcnst.pas | 18 ++++++++++++++---- compiler/ncgvmt.pas | 10 +++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/compiler/aasmcnst.pas b/compiler/aasmcnst.pas index 4b148b1504..25502fdb67 100644 --- a/compiler/aasmcnst.pas +++ b/compiler/aasmcnst.pas @@ -314,8 +314,17 @@ type a) it's definitely a record b) the def of the record should be automatically constructed based on 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; { The next group of routines are for constructing complex expressions. @@ -1079,7 +1088,7 @@ implementation result.ofs:=0; { pack the data, so that we don't add unnecessary null bytes after the 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); { encoding } emit_tai(tai_const.create_16bit(encoding),u16inttype); @@ -1239,7 +1248,7 @@ implementation begin result.lab:=startlab; 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.maxCrecordalign); datatcb.emit_tai(Tai_const.Create_32bit(strlength*cwidechartype.size),s32inttype); @@ -1357,7 +1366,7 @@ implementation 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 anonrecorddef: trecorddef; typesym: ttypesym; @@ -1379,6 +1388,7 @@ implementation end; { create skeleton def } anonrecorddef:=crecorddef.create_global_internal(optionalname,packrecords,recordalignmin,maxcrecordalign); + trecordsymtable(anonrecorddef.symtable).recordalignment:=recordalign; { generic aggregate housekeeping } begin_aggregate_internal(anonrecorddef,true); { mark as anonymous record } diff --git a/compiler/ncgvmt.pas b/compiler/ncgvmt.pas index 2ad3ee7863..4e14d95798 100644 --- a/compiler/ncgvmt.pas +++ b/compiler/ncgvmt.pas @@ -616,7 +616,7 @@ implementation { generate the class table } 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), - packrecords, + packrecords,1, targetinfos[target_info.system]^.alignment.recordalignmin, targetinfos[target_info.system]^.alignment.maxCrecordalign); 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, plus there would be very little chance that it could actually be reused } - datatcb.begin_anonymous_record('',packrecords, + datatcb.begin_anonymous_record('',packrecords,1, targetinfos[target_info.system]^.alignment.recordalignmin, targetinfos[target_info.system]^.alignment.maxCrecordalign); datatcb.emit_tai(Tai_const.Create_16bit(fieldcount),u16inttype); @@ -674,7 +674,7 @@ implementation Name: ShortString; 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.maxCrecordalign); datatcb.emit_tai(Tai_const.Create_pint(tfieldvarsym(sym).fieldoffset),ptruinttype); @@ -711,7 +711,7 @@ implementation i : longint; begin 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.maxCrecordalign); if assigned(AImplIntf.procdefs) then @@ -809,7 +809,7 @@ implementation end; 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.maxCrecordalign); datatcb.emit_tai(Tai_const.Create_pint(_class.ImplementedInterfaces.count),search_system_type('SIZEUINT').typedef);