* Refactor tasmlisttypedconstbuilder so it emits string/PChar data, if any, into a second asmlist, instead of appending it directly to global asmlist.

git-svn-id: trunk@29513 -
This commit is contained in:
sergei 2015-01-20 15:14:38 +00:00
parent ed4e876f4f
commit 6708b83a16
2 changed files with 22 additions and 14 deletions

View File

@ -81,6 +81,7 @@ interface
function parse_single_packed_const(def: tdef; var bp: tbitpackedval): boolean; function parse_single_packed_const(def: tdef; var bp: tbitpackedval): boolean;
protected protected
list: tasmlist; list: tasmlist;
datalist: tasmlist;
procedure parse_packed_array_def(def: tarraydef); procedure parse_packed_array_def(def: tarraydef);
procedure parse_arraydef(def:tarraydef);override; procedure parse_arraydef(def:tarraydef);override;
@ -97,7 +98,7 @@ interface
procedure tc_emit_stringdef(def: tstringdef; var node: tnode);override; procedure tc_emit_stringdef(def: tstringdef; var node: tnode);override;
public public
constructor create(sym: tstaticvarsym);virtual; constructor create(sym: tstaticvarsym);virtual;
function parse_into_asmlist: tasmlist; procedure parse_into_asmlist(out res, data: tasmlist);
end; end;
tasmlisttypedconstbuilderclass = class of tasmlisttypedconstbuilder; tasmlisttypedconstbuilderclass = class of tasmlisttypedconstbuilder;
@ -428,6 +429,7 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
begin begin
inherited; inherited;
list:=tasmlist.create; list:=tasmlist.create;
datalist:=tasmlist.create;
curoffset:=0; curoffset:=0;
end; end;
@ -545,7 +547,7 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
ll.ofs:=0; ll.ofs:=0;
end end
else else
ll:=emit_ansistring_const(current_asmdata.asmlists[al_const],strval,strlength,def.encoding); ll:=emit_ansistring_const(datalist,strval,strlength,def.encoding);
list.concat(Tai_const.Create_sym_offset(ll.lab,ll.ofs)); list.concat(Tai_const.Create_sym_offset(ll.lab,ll.ofs));
end; end;
st_unicodestring, st_unicodestring,
@ -560,7 +562,7 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
else else
begin begin
winlike:=(def.stringtype=st_widestring) and (tf_winlikewidestring in target_info.flags); winlike:=(def.stringtype=st_widestring) and (tf_winlikewidestring in target_info.flags);
ll:=emit_unicodestring_const(current_asmdata.asmlists[al_const], ll:=emit_unicodestring_const(datalist,
strval, strval,
def.encoding, def.encoding,
winlike); winlike);
@ -833,8 +835,8 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
else else
varalign:=0; varalign:=0;
varalign:=const_align(varalign); varalign:=const_align(varalign);
new_section(current_asmdata.asmlists[al_const], sec_rodata, ll.name, varalign); new_section(datalist, sec_rodata, ll.name, varalign);
current_asmdata.asmlists[al_const].concat(Tai_label.Create(ll)); datalist.concat(Tai_label.Create(ll));
if node.nodetype=stringconstn then if node.nodetype=stringconstn then
begin begin
len:=tstringconstnode(node).len; len:=tstringconstnode(node).len;
@ -844,11 +846,11 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
len:=255; len:=255;
getmem(ca,len+2); getmem(ca,len+2);
move(tstringconstnode(node).value_str^,ca^,len+1); move(tstringconstnode(node).value_str^,ca^,len+1);
current_asmdata.asmlists[al_const].concat(Tai_string.Create_pchar(ca,len+1)); datalist.concat(Tai_string.Create_pchar(ca,len+1));
end end
else else
if is_constcharnode(node) then if is_constcharnode(node) then
current_asmdata.asmlists[al_const].concat(Tai_string.Create(char(byte(tordconstnode(node).value.svalue))+#0)) datalist.concat(Tai_string.Create(char(byte(tordconstnode(node).value.svalue))+#0))
else else
IncompatibleTypes(node.resultdef, def); IncompatibleTypes(node.resultdef, def);
end end
@ -859,8 +861,8 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
begin begin
current_asmdata.getdatalabel(ll); current_asmdata.getdatalabel(ll);
list.concat(Tai_const.Create_sym(ll)); list.concat(Tai_const.Create_sym(ll));
new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata_norel,ll.name,const_align(sizeof(pint))); new_section(datalist,sec_rodata_norel,ll.name,const_align(sizeof(pint)));
current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(ll)); datalist.concat(Tai_label.Create(ll));
if (node.nodetype in [stringconstn,ordconstn]) then if (node.nodetype in [stringconstn,ordconstn]) then
begin begin
{ convert to unicodestring stringconstn } { convert to unicodestring stringconstn }
@ -870,9 +872,9 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
begin begin
pw:=pcompilerwidestring(tstringconstnode(node).value_str); pw:=pcompilerwidestring(tstringconstnode(node).value_str);
for i:=0 to tstringconstnode(node).len-1 do for i:=0 to tstringconstnode(node).len-1 do
current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_16bit(pw^.data[i])); datalist.concat(Tai_const.Create_16bit(pw^.data[i]));
{ ending #0 } { ending #0 }
current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_16bit(0)) datalist.concat(Tai_const.Create_16bit(0))
end; end;
end end
else else
@ -1671,10 +1673,11 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
end; end;
function tasmlisttypedconstbuilder.parse_into_asmlist: tasmlist; procedure tasmlisttypedconstbuilder.parse_into_asmlist(out res,data: tasmlist);
begin begin
read_typed_const_data(tcsym.vardef); read_typed_const_data(tcsym.vardef);
result:=list; res:=list;
data:=datalist;
end; end;

View File

@ -47,6 +47,7 @@ implementation
cursectype : TAsmSectionType; cursectype : TAsmSectionType;
section : ansistring; section : ansistring;
tcbuilder : ttypedconstbuilder; tcbuilder : ttypedconstbuilder;
datalist,
reslist : tasmlist; reslist : tasmlist;
restree, restree,
previnit : tnode; previnit : tnode;
@ -66,7 +67,7 @@ implementation
begin begin
maybe_new_object_file(list); maybe_new_object_file(list);
tcbuilder:=tasmlisttypedconstbuilderclass(ctypedconstbuilder).create(sym); tcbuilder:=tasmlisttypedconstbuilderclass(ctypedconstbuilder).create(sym);
reslist:=tasmlisttypedconstbuilder(tcbuilder).parse_into_asmlist; tasmlisttypedconstbuilder(tcbuilder).parse_into_asmlist(reslist,datalist);
{ Certain types like windows WideString are initialized at runtime and cannot { Certain types like windows WideString are initialized at runtime and cannot
be placed into readonly memory } be placed into readonly memory }
if (sym.varspez=vs_const) and not (vo_force_finalize in sym.varoptions) then if (sym.varspez=vs_const) and not (vo_force_finalize in sym.varoptions) then
@ -89,6 +90,7 @@ implementation
current_module.tcinitcode:=restree; current_module.tcinitcode:=restree;
tcbuilder.free; tcbuilder.free;
reslist:=nil; reslist:=nil;
datalist:=nil;
cursectype:=sec_none; cursectype:=sec_none;
end; end;
@ -160,6 +162,9 @@ implementation
list.concatlist(reslist); list.concatlist(reslist);
reslist.free; reslist.free;
list.concat(tai_symbol_end.Createname(sym.mangledname)); list.concat(tai_symbol_end.Createname(sym.mangledname));
{ and pointed data, if any }
current_asmdata.asmlists[al_const].concatlist(datalist);
datalist.free;
end end
else else
begin begin