mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-24 11:09:15 +02:00
* changed getarraydef() into a tarraydef.getreusable() class method
git-svn-id: trunk@31147 -
This commit is contained in:
parent
ef00cefa0a
commit
f40ea04540
@ -661,7 +661,7 @@ implementation
|
||||
if fvalues.count<>1 then
|
||||
internalerror(2014070105);
|
||||
tai_simpletypedconst(fvalues[0]).fdef:=
|
||||
getarraydef(cansichartype,
|
||||
carraydef.getreusable(cansichartype,
|
||||
tai_string(tai_simpletypedconst(fvalues[0]).val).len);
|
||||
end;
|
||||
end;
|
||||
@ -1165,7 +1165,7 @@ implementation
|
||||
move(data^,s^,len);
|
||||
s[len]:=#0;
|
||||
{ terminating zero included }
|
||||
datadef:=getarraydef(cansichartype,len+1);
|
||||
datadef:=carraydef.getreusable(cansichartype,len+1);
|
||||
datatcb.maybe_begin_aggregate(datadef);
|
||||
datatcb.emit_tai(tai_string.create_pchar(s,len+1),datadef);
|
||||
datatcb.maybe_end_aggregate(datadef);
|
||||
@ -1214,7 +1214,7 @@ implementation
|
||||
end;
|
||||
if cwidechartype.size = 2 then
|
||||
begin
|
||||
datadef:=getarraydef(cwidechartype,strlength+1);
|
||||
datadef:=carraydef.getreusable(cwidechartype,strlength+1);
|
||||
datatcb.maybe_begin_aggregate(datadef);
|
||||
for i:=0 to strlength-1 do
|
||||
datatcb.emit_tai(Tai_const.Create_16bit(pcompilerwidestring(data)^.data[i]),cwidechartype);
|
||||
@ -1242,11 +1242,11 @@ implementation
|
||||
functionality in place yet to reuse shortstringdefs of the same length
|
||||
and neither the lowlevel nor the llvm typedconst builder cares about
|
||||
this difference }
|
||||
result:=getarraydef(cansichartype,length(str)+1);
|
||||
result:=carraydef.getreusable(cansichartype,length(str)+1);
|
||||
maybe_begin_aggregate(result);
|
||||
emit_tai(Tai_const.Create_8bit(length(str)),u8inttype);
|
||||
if str<>'' then
|
||||
emit_tai(Tai_string.Create(str),getarraydef(cansichartype,length(str)));
|
||||
emit_tai(Tai_string.Create(str),carraydef.getreusable(cansichartype,length(str)));
|
||||
maybe_end_aggregate(result);
|
||||
end;
|
||||
|
||||
|
@ -473,7 +473,7 @@ unit cpupara;
|
||||
{ LOC_REFERENCE always contains everything that's left }
|
||||
paraloc^.loc:=LOC_REFERENCE;
|
||||
paraloc^.size:=int_cgsize(paralen);
|
||||
paraloc^.def:=getarraydef(u8inttype,paralen);
|
||||
paraloc^.def:=carraydef.getreusable(u8inttype,paralen);
|
||||
if (side=callerside) then
|
||||
paraloc^.reference.index:=NR_STACK_POINTER_REG;
|
||||
paraloc^.reference.offset:=stack_offset;
|
||||
@ -547,7 +547,7 @@ unit cpupara;
|
||||
{ LOC_REFERENCE always contains everything that's left }
|
||||
paraloc^.loc:=LOC_REFERENCE;
|
||||
paraloc^.size:=int_cgsize(paralen);
|
||||
paraloc^.def:=getarraydef(u8inttype,paralen);
|
||||
paraloc^.def:=carraydef.getreusable(u8inttype,paralen);
|
||||
if (side=callerside) then
|
||||
paraloc^.reference.index:=NR_STACK_POINTER_REG;
|
||||
paraloc^.reference.offset:=stack_offset;
|
||||
|
@ -228,7 +228,7 @@ implementation
|
||||
arreledef:=cpointerdef.getreusable(orgparadef)
|
||||
else
|
||||
arreledef:=parasym.vardef;
|
||||
arrdef:=getarraydef(arreledef,1+ord(cs_check_var_copyout in current_settings.localswitches));
|
||||
arrdef:=carraydef.getreusable(arreledef,1+ord(cs_check_var_copyout in current_settings.localswitches));
|
||||
{ the -1 means "use the array's element count to determine the number
|
||||
of elements" in the JVM temp generator }
|
||||
arraytemp:=ctempcreatenode.create(arrdef,-1,tt_persistent,true);
|
||||
|
@ -72,13 +72,13 @@ implementation
|
||||
constants (-> excludes terminating #0) and pchars (-> includes
|
||||
terminating #0). The resultdef excludes the #0 while the data
|
||||
includes it -> insert typecast from datadef to resultdef }
|
||||
datadef:=getarraydef(cansichartype,len+1);
|
||||
datadef:=carraydef.getreusable(cansichartype,len+1);
|
||||
cst_shortstring:
|
||||
{ the resultdef of the string constant is the type of the
|
||||
string to which it is assigned, which can be longer or shorter
|
||||
than the length of the string itself -> typecast it to the
|
||||
correct string type }
|
||||
datadef:=getarraydef(cansichartype,min(len,255)+1);
|
||||
datadef:=carraydef.getreusable(cansichartype,min(len,255)+1);
|
||||
else
|
||||
internalerror(2014071203);
|
||||
end;
|
||||
|
@ -129,7 +129,7 @@ implementation
|
||||
size for extended, which is usually larger) into an extended }
|
||||
if (llvmfielddef.typ=floatdef) and
|
||||
(tfloatdef(llvmfielddef).floattype=s80real) then
|
||||
hlcg.g_ptrtypecast_ref(current_asmdata.CurrAsmList,cpointerdef.getreusable(getarraydef(u8inttype,10)),cpointerdef.getreusable(s80floattype),location.reference);
|
||||
hlcg.g_ptrtypecast_ref(current_asmdata.CurrAsmList,cpointerdef.getreusable(carraydef.getreusable(u8inttype,10)),cpointerdef.getreusable(s80floattype),location.reference);
|
||||
{ if it doesn't match the requested field exactly (variant record),
|
||||
adjust the type of the pointer }
|
||||
if (vs.offsetfromllvmfield<>0) or
|
||||
@ -168,7 +168,7 @@ implementation
|
||||
10 bytes) }
|
||||
if (resultdef.typ=floatdef) and
|
||||
(tfloatdef(resultdef).floattype=s80real) then
|
||||
arrptrelementdef:=cpointerdef.getreusable(getarraydef(u8inttype,10))
|
||||
arrptrelementdef:=cpointerdef.getreusable(carraydef.getreusable(u8inttype,10))
|
||||
else
|
||||
arrptrelementdef:=cpointerdef.getreusable(resultdef);
|
||||
end;
|
||||
|
@ -778,7 +778,7 @@ implementation
|
||||
{ don't increase/decrease the reference count here, will be done by
|
||||
the callee (see (*) above) -> typecast to array of byte
|
||||
for the assignment to the temp }
|
||||
temparraydef:=getarraydef(u8inttype,left.resultdef.size);
|
||||
temparraydef:=carraydef.getreusable(u8inttype,left.resultdef.size);
|
||||
paratemp:=ctempcreatenode.create(temparraydef,temparraydef.size,tt_persistent,false);
|
||||
addstatement(initstat,paratemp);
|
||||
addstatement(initstat,
|
||||
|
@ -377,7 +377,7 @@ implementation
|
||||
move(value_str^,pc[1],l);
|
||||
pc[0]:=chr(l);
|
||||
pc[l+1]:=#0;
|
||||
datadef:=getarraydef(cansichartype,l+1);
|
||||
datadef:=carraydef.getreusable(cansichartype,l+1);
|
||||
datatcb.maybe_begin_aggregate(datadef);
|
||||
datatcb.emit_tai(Tai_string.Create_pchar(pc,l+1),datadef);
|
||||
datatcb.maybe_end_aggregate(datadef);
|
||||
@ -397,7 +397,7 @@ implementation
|
||||
string can be used for pchar assignments (but it's
|
||||
also used for array-of-char assignments, in which
|
||||
case the terminating #0 is not part of the data) }
|
||||
datadef:=getarraydef(cansichartype,len+1);
|
||||
datadef:=carraydef.getreusable(cansichartype,len+1);
|
||||
datatcb.maybe_begin_aggregate(datadef);
|
||||
datatcb.emit_tai(Tai_string.Create_pchar(pc,len+1),datadef);
|
||||
datatcb.maybe_end_aggregate(datadef);
|
||||
|
@ -240,14 +240,14 @@ implementation
|
||||
writenames(tcb,p^.l);
|
||||
tcb.start_internal_data_builder(current_asmdata.AsmLists[al_const],sec_rodata_norel,'',datatcb,p^.nl);
|
||||
len:=length(p^.data.messageinf.str^);
|
||||
datatcb.maybe_begin_aggregate(getarraydef(cansichartype,len+1));
|
||||
datatcb.maybe_begin_aggregate(carraydef.getreusable(cansichartype,len+1));
|
||||
datatcb.emit_tai(tai_const.create_8bit(len),cansichartype);
|
||||
getmem(ca,len+1);
|
||||
move(p^.data.messageinf.str^[1],ca^,len);
|
||||
ca[len]:=#0;
|
||||
datatcb.emit_tai(Tai_string.Create_pchar(ca,len),getarraydef(cansichartype,len));
|
||||
datatcb.maybe_end_aggregate(getarraydef(cansichartype,len+1));
|
||||
tcb.finish_internal_data_builder(datatcb,p^.nl,getarraydef(cansichartype,len+1),sizeof(pint));
|
||||
datatcb.emit_tai(Tai_string.Create_pchar(ca,len),carraydef.getreusable(cansichartype,len));
|
||||
datatcb.maybe_end_aggregate(carraydef.getreusable(cansichartype,len+1));
|
||||
tcb.finish_internal_data_builder(datatcb,p^.nl,carraydef.getreusable(cansichartype,len+1),sizeof(pint));
|
||||
if assigned(p^.r) then
|
||||
writenames(tcb,p^.r);
|
||||
end;
|
||||
@ -259,7 +259,7 @@ implementation
|
||||
|
||||
{ write name label }
|
||||
tcb.maybe_begin_aggregate(entrydef);
|
||||
tcb.emit_tai(Tai_const.Create_sym(p^.nl),cpointerdef.getreusable(getarraydef(cansichartype,length(p^.data.messageinf.str^)+1)));
|
||||
tcb.emit_tai(Tai_const.Create_sym(p^.nl),cpointerdef.getreusable(carraydef.getreusable(cansichartype,length(p^.data.messageinf.str^)+1)));
|
||||
tcb.queue_init(voidcodepointertype);
|
||||
tcb.queue_emit_proc(p^.data);
|
||||
tcb.maybe_end_aggregate(entrydef);
|
||||
@ -774,7 +774,7 @@ implementation
|
||||
current_asmdata.RefAsmSymbol(
|
||||
make_mangledname('IIDSTR',AImplIntf.IntfDef.owner,AImplIntf.IntfDef.objname^),
|
||||
AT_DATA),
|
||||
cpointerdef.getreusable(getarraydef(cansichartype,length(AImplIntf.IntfDef.iidstr^)+1)));
|
||||
cpointerdef.getreusable(carraydef.getreusable(cansichartype,length(AImplIntf.IntfDef.iidstr^)+1)));
|
||||
{ IType }
|
||||
tcb.emit_ord_const(aint(AImplIntf.VtblImplIntf.IType),interfaceentrytypedef);
|
||||
tcb.maybe_end_aggregate(interfaceentrydef);
|
||||
@ -815,7 +815,7 @@ implementation
|
||||
datatcb.emit_tai(Tai_const.Create_pint(_class.ImplementedInterfaces.count),search_system_type('SIZEUINT').typedef);
|
||||
interfaceentrydef:=search_system_type('TINTERFACEENTRY').typedef;
|
||||
interfaceentrytypedef:=search_system_type('TINTERFACEENTRYTYPE').typedef;
|
||||
interfacearray:=getarraydef(interfaceentrydef,_class.ImplementedInterfaces.count);
|
||||
interfacearray:=carraydef.getreusable(interfaceentrydef,_class.ImplementedInterfaces.count);
|
||||
datatcb.maybe_begin_aggregate(interfacearray);
|
||||
{ Write vtbl references }
|
||||
for i:=0 to _class.ImplementedInterfaces.count-1 do
|
||||
|
@ -552,7 +552,7 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
|
||||
fillchar(ca[strlength],def.size-strlength-1,' ');
|
||||
ca[strlength]:=#0;
|
||||
ca[def.size-1]:=#0;
|
||||
ftcb.emit_tai(Tai_string.Create_pchar(ca,def.size-1),getarraydef(cansichartype,def.size-1));
|
||||
ftcb.emit_tai(Tai_string.Create_pchar(ca,def.size-1),carraydef.getreusable(cansichartype,def.size-1));
|
||||
ftcb.maybe_end_aggregate(def);
|
||||
end;
|
||||
st_ansistring:
|
||||
@ -830,14 +830,14 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
|
||||
len:=255;
|
||||
getmem(ca,len+1);
|
||||
move(tstringconstnode(node).value_str^,ca^,len+1);
|
||||
datadef:=getarraydef(cansichartype,len+1);
|
||||
datadef:=carraydef.getreusable(cansichartype,len+1);
|
||||
datatcb.maybe_begin_aggregate(datadef);
|
||||
datatcb.emit_tai(Tai_string.Create_pchar(ca,len+1),datadef);
|
||||
datatcb.maybe_end_aggregate(datadef);
|
||||
end
|
||||
else if is_constcharnode(node) then
|
||||
begin
|
||||
datadef:=getarraydef(cansichartype,2);
|
||||
datadef:=carraydef.getreusable(cansichartype,2);
|
||||
datatcb.maybe_begin_aggregate(datadef);
|
||||
datatcb.emit_tai(Tai_string.Create(char(byte(tordconstnode(node).value.svalue))+#0),datadef);
|
||||
datatcb.maybe_end_aggregate(datadef);
|
||||
@ -845,7 +845,7 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
|
||||
else
|
||||
begin
|
||||
IncompatibleTypes(node.resultdef, def);
|
||||
datadef:=getarraydef(cansichartype,1);
|
||||
datadef:=carraydef.getreusable(cansichartype,1);
|
||||
end;
|
||||
ftcb.finish_internal_data_builder(datatcb,ll,datadef,varalign);
|
||||
{ we now emit the address of the first element of the array
|
||||
@ -876,7 +876,7 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
|
||||
datatcb:=ctai_typedconstbuilder.create([tcalo_is_lab,tcalo_make_dead_strippable]);
|
||||
pw:=pcompilerwidestring(tstringconstnode(node).value_str);
|
||||
{ include terminating #0 }
|
||||
datadef:=getarraydef(cwidechartype,tstringconstnode(node).len+1);
|
||||
datadef:=carraydef.getreusable(cwidechartype,tstringconstnode(node).len+1);
|
||||
datatcb.maybe_begin_aggregate(datadef);
|
||||
for i:=0 to tstringconstnode(node).len-1 do
|
||||
datatcb.emit_tai(Tai_const.Create_16bit(pw^.data[i]),cwidechartype);
|
||||
|
@ -621,7 +621,7 @@ implementation
|
||||
else if restlen in [1,2,4,8] then
|
||||
result:=cgsize_orddef(int_cgsize(restlen))
|
||||
else
|
||||
result:=getarraydef(u8inttype,restlen);
|
||||
result:=carraydef.getreusable(u8inttype,restlen);
|
||||
end;
|
||||
|
||||
|
||||
|
@ -570,7 +570,7 @@ unit cpupara;
|
||||
if paraloc^.size<>OS_NO then
|
||||
paraloc^.def:=cgsize_orddef(paraloc^.size)
|
||||
else
|
||||
paraloc^.def:=getarraydef(u8inttype,paralen);
|
||||
paraloc^.def:=carraydef.getreusable(u8inttype,paralen);
|
||||
end;
|
||||
else
|
||||
internalerror(2006011101);
|
||||
|
@ -490,6 +490,7 @@ interface
|
||||
function elecount : asizeuint;
|
||||
constructor create_from_pointer(def:tpointerdef);virtual;
|
||||
constructor create(l,h:asizeint;def:tdef);virtual;
|
||||
class function getreusable(def: tdef; elems: asizeint): tarraydef; virtual;
|
||||
constructor ppuload(ppufile:tcompilerppufile);
|
||||
destructor destroy; override;
|
||||
function getcopy : tstoreddef;override;
|
||||
@ -1125,10 +1126,6 @@ interface
|
||||
|
||||
function use_vectorfpu(def : tdef) : boolean;
|
||||
|
||||
{ returns an arraydef for an array containing a single array of def, resuing
|
||||
an existing one in case it exists in the current module }
|
||||
function getsingletonarraydef(def: tdef): tarraydef;
|
||||
function getarraydef(def: tdef; elecount: asizeint): tarraydef;
|
||||
{ returns a procvardef that represents the address of a procdef }
|
||||
function getprocaddressprocvar(def: tabstractprocdef): tprocvardef;
|
||||
|
||||
@ -3423,6 +3420,39 @@ implementation
|
||||
symtable:=tarraysymtable.create(self);
|
||||
end;
|
||||
|
||||
|
||||
class function tarraydef.getreusable(def: tdef; elems: asizeint): tarraydef;
|
||||
var
|
||||
res: PHashSetItem;
|
||||
oldsymtablestack: tsymtablestack;
|
||||
arrdesc: packed record
|
||||
def: tdef;
|
||||
elecount: asizeint;
|
||||
end;
|
||||
begin
|
||||
if not assigned(current_module) then
|
||||
internalerror(2011081301);
|
||||
arrdesc.def:=def;
|
||||
arrdesc.elecount:=elems;
|
||||
res:=current_module.arraydefs.FindOrAdd(@arrdesc,sizeof(arrdesc));
|
||||
if not assigned(res^.Data) then
|
||||
begin
|
||||
{ since these arraydef can be reused anywhere in the current
|
||||
unit, add them to the global/staticsymtable }
|
||||
oldsymtablestack:=symtablestack;
|
||||
symtablestack:=nil;
|
||||
res^.Data:=carraydef.create(0,elems-1,ptrsinttype);
|
||||
tarraydef(res^.Data).elementdef:=def;
|
||||
if assigned(current_module.localsymtable) then
|
||||
current_module.localsymtable.insertdef(tdef(res^.Data))
|
||||
else
|
||||
current_module.globalsymtable.insertdef(tdef(res^.Data));
|
||||
symtablestack:=oldsymtablestack;
|
||||
end;
|
||||
result:=tarraydef(res^.Data);
|
||||
end;
|
||||
|
||||
|
||||
destructor tarraydef.destroy;
|
||||
begin
|
||||
symtable.free;
|
||||
@ -7631,44 +7661,6 @@ implementation
|
||||
end;
|
||||
|
||||
|
||||
function getsingletonarraydef(def: tdef): tarraydef;
|
||||
begin
|
||||
result:=getarraydef(def,1);
|
||||
end;
|
||||
|
||||
|
||||
function getarraydef(def: tdef; elecount: asizeint): tarraydef;
|
||||
var
|
||||
res: PHashSetItem;
|
||||
oldsymtablestack: tsymtablestack;
|
||||
arrdesc: packed record
|
||||
def: tdef;
|
||||
elecount: asizeint;
|
||||
end;
|
||||
begin
|
||||
if not assigned(current_module) then
|
||||
internalerror(2011081301);
|
||||
arrdesc.def:=def;
|
||||
arrdesc.elecount:=elecount;
|
||||
res:=current_module.arraydefs.FindOrAdd(@arrdesc,sizeof(arrdesc));
|
||||
if not assigned(res^.Data) then
|
||||
begin
|
||||
{ since these arraydef can be reused anywhere in the current
|
||||
unit, add them to the global/staticsymtable }
|
||||
oldsymtablestack:=symtablestack;
|
||||
symtablestack:=nil;
|
||||
res^.Data:=carraydef.create(0,elecount-1,ptrsinttype);
|
||||
tarraydef(res^.Data).elementdef:=def;
|
||||
if assigned(current_module.localsymtable) then
|
||||
current_module.localsymtable.insertdef(tdef(res^.Data))
|
||||
else
|
||||
current_module.globalsymtable.insertdef(tdef(res^.Data));
|
||||
symtablestack:=oldsymtablestack;
|
||||
end;
|
||||
result:=tarraydef(res^.Data);
|
||||
end;
|
||||
|
||||
|
||||
function getprocaddressprocvar(def: tabstractprocdef): tprocvardef;
|
||||
var
|
||||
res: PHashSetItem;
|
||||
|
@ -2360,7 +2360,7 @@ implementation
|
||||
if assigned(def) then
|
||||
constdef:=def
|
||||
else
|
||||
constdef:=getarraydef(cansichartype,l);
|
||||
constdef:=carraydef.getreusable(cansichartype,l);
|
||||
value.len:=l;
|
||||
end;
|
||||
|
||||
@ -2371,7 +2371,7 @@ implementation
|
||||
fillchar(value, sizeof(value), #0);
|
||||
consttyp:=t;
|
||||
pcompilerwidestring(value.valueptr):=pw;
|
||||
constdef:=getarraydef(cwidechartype,getlengthwidestring(pw));
|
||||
constdef:=carraydef.getreusable(cwidechartype,getlengthwidestring(pw));
|
||||
value.len:=getlengthwidestring(pw);
|
||||
end;
|
||||
|
||||
|
@ -288,7 +288,7 @@ unit cpupara;
|
||||
else
|
||||
result:=class2;
|
||||
result.typ:=X86_64_SSE_CLASS;
|
||||
result.def:=getarraydef(s32floattype,2)
|
||||
result.def:=carraydef.getreusable(s32floattype,2)
|
||||
end;
|
||||
|
||||
|
||||
@ -401,7 +401,7 @@ unit cpupara;
|
||||
(classes[i-1].typ<>X86_64_SSEUP_CLASS) then
|
||||
begin
|
||||
classes[i].typ:=X86_64_SSE_CLASS;
|
||||
classes[i].def:=getarraydef(s32floattype,2);
|
||||
classes[i].def:=carraydef.getreusable(s32floattype,2);
|
||||
end;
|
||||
|
||||
(* If X86_64_X87UP_CLASS isn't preceded by X86_64_X87_CLASS,
|
||||
@ -443,7 +443,7 @@ unit cpupara;
|
||||
X86_64_SSESF_CLASS:
|
||||
begin
|
||||
classes[0].typ:=X86_64_SSE_CLASS;
|
||||
classes[0].def:=getarraydef(s32floattype,2);
|
||||
classes[0].def:=carraydef.getreusable(s32floattype,2);
|
||||
end;
|
||||
end;
|
||||
{ 2) the second part is 32 bit, but the total size is > 12 bytes }
|
||||
@ -457,7 +457,7 @@ unit cpupara;
|
||||
X86_64_SSESF_CLASS:
|
||||
begin
|
||||
classes[1].typ:=X86_64_SSE_CLASS;
|
||||
classes[1].def:=getarraydef(s32floattype,2);
|
||||
classes[1].def:=carraydef.getreusable(s32floattype,2);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -613,7 +613,7 @@ unit cpupara;
|
||||
{ if we have e.g. a record with two successive "single"
|
||||
fields, we need a 64 bit rather than a 32 bit load }
|
||||
classes[0].typ:=X86_64_SSE_CLASS;
|
||||
classes[0].def:=getarraydef(s32floattype,2);
|
||||
classes[0].def:=carraydef.getreusable(s32floattype,2);
|
||||
end;
|
||||
result:=1;
|
||||
end;
|
||||
@ -639,9 +639,9 @@ unit cpupara;
|
||||
s128real:
|
||||
begin
|
||||
classes[0].typ:=X86_64_SSE_CLASS;
|
||||
classes[0].def:=getarraydef(s32floattype,2);
|
||||
classes[0].def:=carraydef.getreusable(s32floattype,2);
|
||||
classes[1].typ:=X86_64_SSEUP_CLASS;
|
||||
classes[1].def:=getarraydef(s32floattype,2);
|
||||
classes[1].def:=carraydef.getreusable(s32floattype,2);
|
||||
result:=2;
|
||||
end;
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user