* AsmSymbolDict changed to FPHashObjectList

git-svn-id: trunk@5139 -
This commit is contained in:
peter 2006-11-01 00:22:13 +00:00
parent 0909d46626
commit 05183ac829
8 changed files with 130 additions and 132 deletions

View File

@ -47,7 +47,7 @@ interface
TAsmLabelType = (alt_jump,alt_addr,alt_data,alt_dbgline,alt_dbgfile,alt_dbgtype,alt_dbgframe);
const
asmlabeltypeprefix : array[tasmlabeltype] of char = ('j','a','d','l','f','t','c');
asmlabeltypeprefix : array[TAsmLabeltype] of char = ('j','a','d','l','f','t','c');
type
TAsmSectiontype=(sec_none,
@ -79,7 +79,7 @@ interface
TAsmSectionOrder = (secorder_begin,secorder_default,secorder_end);
TAsmSymbol = class(TNamedIndexItem)
TAsmSymbol = class(TFPHashObject)
private
{ this need to be incremented with every symbol loading into the
TAsmList with loadsym/loadref/const_symbol (PFV) }
@ -92,8 +92,8 @@ interface
altsymbol : TAsmSymbol;
{ Cached objsymbol }
cachedobjsymbol : TObject;
constructor create(const s:string;_bind:TAsmsymbind;_typ:Tasmsymtype);
function getaltcopy(altnr: longint): tasmsymbol; virtual;
constructor Create(AList:TFPHashObjectList;const s:string;_bind:TAsmsymbind;_typ:Tasmsymtype);
function getaltcopy(AList:TFPHashObjectList;altnr: longint): TAsmSymbol; virtual;
function is_used:boolean;
procedure increfs;
procedure decrefs;
@ -102,13 +102,15 @@ interface
TAsmSymbolClass = class of TAsmSymbol;
TAsmLabel = class(TAsmSymbol)
protected
function getname:string;override;
public
labelnr : longint;
labeltype : TAsmLabelType;
is_set : boolean;
constructor createlocal(nr:longint;ltyp:TAsmLabelType);
constructor createglobal(const modulename:string;nr:longint;ltyp:TAsmLabelType);
function getaltcopy(altnr: longint): tasmsymbol; override;
function getname:string;override;
constructor Createlocal(AList:TFPHashObjectList;nr:longint;ltyp:TAsmLabelType);
constructor Createglobal(AList:TFPHashObjectList;const modulename:string;nr:longint;ltyp:TAsmLabelType);
function getaltcopy(AList:TFPHashObjectList;altnr: longint): TAsmSymbol; override;
end;
function use_smartlink_section:boolean;
@ -136,7 +138,7 @@ implementation
function maybe_smartlink_symbol:boolean;
begin
result:=(cs_create_smart in current_settings.moduleswitches) or
result:=(cs_Create_smart in current_settings.moduleswitches) or
use_smartlink_section;
end;
@ -248,9 +250,9 @@ implementation
TAsmSymbol
*****************************************************************************}
constructor tasmsymbol.create(const s:string;_bind:TAsmsymbind;_typ:Tasmsymtype);
constructor TAsmSymbol.Create(AList:TFPHashObjectList;const s:string;_bind:TAsmsymbind;_typ:Tasmsymtype);
begin;
inherited createname(s);
inherited Create(AList,s);
bind:=_bind;
typ:=_typ;
{ used to remove unused labels from the al_procedures }
@ -258,28 +260,25 @@ implementation
end;
function tasmsymbol.getaltcopy(altnr: longint): tasmsymbol;
function TAsmSymbol.getaltcopy(AList:TFPHashObjectList;altnr: longint): TAsmSymbol;
begin
result := TAsmSymbol(TAsmSymbolClass(classtype).createname(name+'_'+tostr(altnr)));
result.bind:=bind;
result.typ:=typ;
result.refs:=0;
result := TAsmSymbol(TAsmSymbolClass(classtype).Create(AList,name+'_'+tostr(altnr),bind,typ));
end;
function tasmsymbol.is_used:boolean;
function TAsmSymbol.is_used:boolean;
begin
is_used:=(refs>0);
end;
procedure tasmsymbol.increfs;
procedure TAsmSymbol.increfs;
begin
inc(refs);
end;
procedure tasmsymbol.decrefs;
procedure TAsmSymbol.decrefs;
begin
dec(refs);
if refs<0 then
@ -287,7 +286,7 @@ implementation
end;
function tasmsymbol.getrefs: longint;
function TAsmSymbol.getrefs: longint;
begin
getrefs := refs;
end;
@ -297,18 +296,18 @@ implementation
TAsmLabel
*****************************************************************************}
constructor tasmlabel.createlocal(nr:longint;ltyp:TAsmLabelType);
constructor TAsmLabel.Createlocal(AList:TFPHashObjectList;nr:longint;ltyp:TAsmLabelType);
begin
inherited create(target_asm.labelprefix+asmlabeltypeprefix[ltyp]+tostr(nr),AB_LOCAL,AT_LABEL);
inherited Create(AList,target_asm.labelprefix+asmlabeltypeprefix[ltyp]+tostr(nr),AB_LOCAL,AT_LABEL);
labelnr:=nr;
labeltype:=ltyp;
is_set:=false;
end;
constructor tasmlabel.createglobal(const modulename:string;nr:longint;ltyp:TAsmLabelType);
constructor TAsmLabel.Createglobal(AList:TFPHashObjectList;const modulename:string;nr:longint;ltyp:TAsmLabelType);
begin
inherited create('_$'+modulename+'$_L'+asmlabeltypeprefix[ltyp]+tostr(nr),AB_GLOBAL,AT_DATA);
inherited Create(AList,'_$'+modulename+'$_L'+asmlabeltypeprefix[ltyp]+tostr(nr),AB_GLOBAL,AT_DATA);
labelnr:=nr;
labeltype:=ltyp;
is_set:=false;
@ -317,12 +316,12 @@ implementation
end;
function tasmlabel.getaltcopy(altnr: longint): tasmsymbol;
function TAsmLabel.getaltcopy(AList:TFPHashObjectList;altnr: longint): TAsmSymbol;
begin;
result := inherited getaltcopy(altnr);
tasmlabel(result).labelnr:=labelnr;
tasmlabel(result).labeltype:=labeltype;
tasmlabel(result).is_set:=false;
result := inherited getaltcopy(AList,altnr);
TAsmLabel(result).labelnr:=labelnr;
TAsmLabel(result).labeltype:=labeltype;
TAsmLabel(result).is_set:=false;
case bind of
AB_GLOBAL:
result.increfs;
@ -334,7 +333,7 @@ implementation
end;
function tasmlabel.getname:string;
function TAsmLabel.getname:string;
begin
getname:=inherited getname;
increfs;

View File

@ -113,10 +113,10 @@ interface
TAsmData = class
private
{ Symbols }
FAsmSymbolDict : TDictionary;
FAsmSymbolDict : TFPHashObjectList;
FAltSymbolList : TFPObjectList;
FNextAltNr : longint;
FNextLabelNr : array[Tasmlabeltype] of longint;
FNextLabelNr : array[TAsmLabeltype] of longint;
{ Call Frame Information for stack unwinding}
FAsmCFI : TAsmCFI;
public
@ -129,18 +129,18 @@ interface
constructor create(const n:string);
destructor destroy;override;
{ asmsymbol }
function DefineAsmSymbol(const s : string;_bind:TAsmSymBind;_typ:Tasmsymtype) : tasmsymbol;
function RefAsmSymbol(const s : string) : tasmsymbol;
function getasmsymbol(const s : string) : tasmsymbol;
function DefineAsmSymbol(const s : string;_bind:TAsmSymBind;_typ:Tasmsymtype) : TAsmSymbol;
function RefAsmSymbol(const s : string) : TAsmSymbol;
function GetAsmSymbol(const s : string) : TAsmSymbol;
{ create new assembler label }
procedure getlabel(out l : tasmlabel;alt:tasmlabeltype);
procedure getjumplabel(out l : tasmlabel);
procedure getaddrlabel(out l : tasmlabel);
procedure getdatalabel(out l : tasmlabel);
procedure getlabel(out l : TAsmLabel;alt:TAsmLabeltype);
procedure getjumplabel(out l : TAsmLabel);
procedure getaddrlabel(out l : TAsmLabel);
procedure getdatalabel(out l : TAsmLabel);
{ generate an alternative (duplicate) symbol }
procedure GenerateAltSymbol(p:tasmsymbol);
procedure GenerateAltSymbol(p:TAsmSymbol);
procedure ResetAltSymbols;
property AsmSymbolDict:TDictionary read FAsmSymbolDict;
property AsmSymbolDict:TFPHashObjectList read FAsmSymbolDict;
property AsmCFI:TAsmCFI read FAsmCFI;
end;
@ -264,8 +264,7 @@ implementation
realname:=n;
name:=upper(n);
{ symbols }
FAsmSymbolDict:=TDictionary.create;
FAsmSymbolDict.usehash;
FAsmSymbolDict:=TFPHashObjectList.create(true);
FAltSymbolList:=TFPObjectList.Create(false);
{ labels }
FNextAltNr:=1;
@ -316,11 +315,11 @@ implementation
end;
function TAsmData.DefineAsmSymbol(const s : string;_bind:TAsmSymBind;_typ:Tasmsymtype) : tasmsymbol;
function TAsmData.DefineAsmSymbol(const s : string;_bind:TAsmSymBind;_typ:Tasmsymtype) : TAsmSymbol;
var
hp : tasmsymbol;
hp : TAsmSymbol;
begin
hp:=tasmsymbol(FAsmSymbolDict.search(s));
hp:=TAsmSymbol(FAsmSymbolDict.Find(s));
if assigned(hp) then
begin
{ Redefine is allowed, but the types must be the same. The redefine
@ -337,40 +336,31 @@ implementation
else
begin
{ Not found, insert it. }
hp:=tasmsymbol.create(s,_bind,_typ);
FAsmSymbolDict.insert(hp);
hp:=TAsmSymbol.create(AsmSymbolDict,s,_bind,_typ);
end;
result:=hp;
end;
function TAsmData.RefAsmSymbol(const s : string) : tasmsymbol;
var
hp : tasmsymbol;
function TAsmData.RefAsmSymbol(const s : string) : TAsmSymbol;
begin
hp:=tasmsymbol(FAsmSymbolDict.search(s));
if not assigned(hp) then
begin
{ Not found, insert it. }
hp:=tasmsymbol.create(s,AB_EXTERNAL,AT_NONE);
FAsmSymbolDict.insert(hp);
end;
result:=hp;
result:=TAsmSymbol(FAsmSymbolDict.Find(s));
if not assigned(result) then
result:=TAsmSymbol.create(AsmSymbolDict,s,AB_EXTERNAL,AT_NONE);
end;
function TAsmData.getasmsymbol(const s : string) : tasmsymbol;
function TAsmData.GetAsmSymbol(const s : string) : TAsmSymbol;
begin
getasmsymbol:=tasmsymbol(FAsmSymbolDict.search(s));
result:=TAsmSymbol(FAsmSymbolDict.Find(s));
end;
procedure TAsmData.GenerateAltSymbol(p:tasmsymbol);
procedure TAsmData.GenerateAltSymbol(p:TAsmSymbol);
begin
if not assigned(p.altsymbol) then
begin
p.altsymbol:=p.getaltcopy(FNextAltNr);
FAsmSymbolDict.insert(p.altsymbol);
p.altsymbol:=p.getaltcopy(AsmSymbolDict,FNextAltNr);
FAltSymbolList.Add(p);
end;
end;
@ -381,40 +371,36 @@ implementation
i : longint;
begin
for i:=0 to FAltSymbolList.Count-1 do
tasmsymbol(FAltSymbolList[i]).altsymbol:=nil;
TAsmSymbol(FAltSymbolList[i]).altsymbol:=nil;
FAltSymbolList.Clear;
end;
procedure TAsmData.getlabel(out l : tasmlabel;alt:tasmlabeltype);
procedure TAsmData.getlabel(out l : TAsmLabel;alt:TAsmLabeltype);
begin
l:=tasmlabel.createlocal(FNextLabelNr[alt],alt);
l:=TAsmLabel.createlocal(AsmSymbolDict,FNextLabelNr[alt],alt);
inc(FNextLabelNr[alt]);
FAsmSymbolDict.insert(l);
end;
procedure TAsmData.getjumplabel(out l : tasmlabel);
procedure TAsmData.getjumplabel(out l : TAsmLabel);
begin
l:=tasmlabel.createlocal(FNextLabelNr[alt_jump],alt_jump);
l:=TAsmLabel.createlocal(AsmSymbolDict,FNextLabelNr[alt_jump],alt_jump);
inc(FNextLabelNr[alt_jump]);
FAsmSymbolDict.insert(l);
end;
procedure TAsmData.getdatalabel(out l : tasmlabel);
procedure TAsmData.getdatalabel(out l : TAsmLabel);
begin
l:=tasmlabel.createglobal(name,FNextLabelNr[alt_data],alt_data);
l:=TAsmLabel.createglobal(AsmSymbolDict,name,FNextLabelNr[alt_data],alt_data);
inc(FNextLabelNr[alt_data]);
FAsmSymbolDict.insert(l);
end;
procedure TAsmData.getaddrlabel(out l : tasmlabel);
procedure TAsmData.getaddrlabel(out l : TAsmLabel);
begin
l:=tasmlabel.createlocal(FNextLabelNr[alt_addr],alt_addr);
l:=TAsmLabel.createlocal(AsmSymbolDict,FNextLabelNr[alt_addr],alt_addr);
inc(FNextLabelNr[alt_addr]);
FAsmSymbolDict.insert(l);
end;
begin

View File

@ -238,7 +238,7 @@ type
FCachedStr : pshortstring;
FStrIndex : Integer;
protected
function GetName:string;
function GetName:string;virtual;
public
constructor Create(HashObjectList:TFPHashObjectList;const s:string);
property Name:string read GetName;
@ -734,15 +734,24 @@ end;
function TFPList.Expand: TFPList; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
var
Power,
IncSize : Longint;
begin
if FCount < FCapacity then exit;
IncSize := 4;
if FCapacity > 3 then IncSize := IncSize + 4;
if FCapacity > 8 then IncSize := IncSize+8;
if FCapacity > 127 then Inc(IncSize, FCapacity shr 2);
SetCapacity(FCapacity + IncSize);
Result := Self;
if FCount < FCapacity then
exit;
nextpowerof2(FCapacity,Power);
if Power>=7 then
IncSize:=FCapacity shr (Power-6)
else if Power>=4 then
IncSize:=FCapacity shr (Power-3)
else if FCapacity > 8 then
IncSize:=16
else if FCapacity > 3 then
IncSize:=8
else
IncSize:=4;
SetCapacity(FCapacity + IncSize);
end;
function TFPList.First: Pointer;
@ -1326,18 +1335,23 @@ end;
function TFPHashList.Expand: TFPHashList;
var
Power,
IncSize : Longint;
begin
Result := Self;
if FCount < FCapacity then
exit;
IncSize := 4;
if FCapacity > 127 then
Inc(IncSize, FCapacity shr 2)
nextpowerof2(FCapacity,Power);
if Power>=7 then
IncSize:=FCapacity shr (Power-6)
else if Power>=4 then
IncSize:=FCapacity shr (Power-3)
else if FCapacity > 8 then
inc(IncSize,8)
IncSize:=16
else if FCapacity > 3 then
inc(IncSize,4);
IncSize:=8
else
IncSize:=4;
SetCapacity(FCapacity + IncSize);
{ Maybe expand hash also }
if FCount>FHashCapacity*MaxItemsPerHash then
@ -1346,14 +1360,17 @@ end;
procedure TFPHashList.StrExpand(MinIncSize:Integer);
var
Power,
IncSize : Longint;
begin
if FStrCount+MinIncSize < FStrCapacity then
exit;
IncSize := 64+MinIncSize;
if FStrCapacity > 255 then
Inc(IncSize, FStrCapacity shr 2);
SetStrCapacity(FStrCapacity + IncSize);
nextpowerof2(FCapacity,Power);
if Power>=7 then
IncSize:=FCapacity shr (Power-6)
else
IncSize:=64;
SetStrCapacity(FStrCapacity + IncSize + MinIncSize);
end;
function TFPHashList.IndexOf(Item: Pointer): Integer;

View File

@ -131,12 +131,12 @@ uses
function WriteValueString(p:pchar;len:longint):TasmLabel;
var
s : pchar;
reference: TAsmLabel;
referencelab: TAsmLabel;
begin
if (target_info.system in [system_powerpc_darwin,system_i386_darwin]) then
begin
current_asmdata.getdatalabel(reference);
current_asmdata.asmlists[al_const].concat(tai_label.create(reference));
current_asmdata.getdatalabel(referencelab);
current_asmdata.asmlists[al_const].concat(tai_label.create(referencelab));
end;
current_asmdata.getdatalabel(result);
current_asmdata.asmlists[al_const].concat(tai_align.create(const_align(sizeof(aint))));
@ -144,7 +144,7 @@ uses
current_asmdata.asmlists[al_const].concat(tai_const.create_aint(len));
current_asmdata.asmlists[al_const].concat(tai_label.create(result));
if (target_info.system in [system_powerpc_darwin,system_i386_darwin]) then
current_asmdata.asmlists[al_const].concat(tai_directive.create(asd_reference,reference.getname));
current_asmdata.asmlists[al_const].concat(tai_directive.create(asd_reference,referencelab.name));
getmem(s,len+1);
move(p^,s^,len);
s[len]:=#0;

View File

@ -1987,7 +1987,7 @@ end;
current_asmdata.getlabel(lbl,alt_dbgfile);
{ currently we create only 32 bit dwarf }
linelist.concat(tai_const.create_rel_sym(aitconst_32bit,
lbl,tasmsymbol.create('.Ledebug_line0',AB_COMMON,AT_DATA)));
lbl,current_asmdata.RefAsmSymbol('.Ledebug_line0')));
linelist.concat(tai_label.create(lbl));
@ -1998,7 +1998,7 @@ end;
current_asmdata.getlabel(lbl,alt_dbgfile);
{ currently we create only 32 bit dwarf }
linelist.concat(tai_const.create_rel_sym(aitconst_32bit,
lbl,tasmsymbol.create('.Lehdebug_line0',AB_COMMON,AT_DATA)));
lbl,current_asmdata.RefAsmSymbol('.Lehdebug_line0')));
linelist.concat(tai_label.create(lbl));
@ -2173,7 +2173,7 @@ end;
{ size }
{ currently we create only 32 bit dwarf }
current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(aitconst_32bit,
lenstartlabel,tasmsymbol.create('.Ledebug_info0',AB_COMMON,AT_DATA)));
lenstartlabel,current_asmdata.RefAsmSymbol('.Ledebug_info0')));
current_asmdata.asmlists[al_dwarf_info].concat(tai_label.create(lenstartlabel));
{ version }

View File

@ -773,19 +773,17 @@ interface
end;
var
currentasmlist : TExternalAssembler;
procedure writeexternal(p:tnamedindexitem;arg:pointer);
begin
if tasmsymbol(p).bind=AB_EXTERNAL then
currentasmlist.AsmWriteln('EXTERN'#9+p.name);
end;
procedure T386NasmAssembler.WriteExternals;
var
sym : TAsmSymbol;
i : longint;
begin
currentasmlist:=self;
current_asmdata.AsmSymbolDict.foreach_static(@writeexternal,nil);
for i:=0 to current_asmdata.AsmSymbolDict.Count-1 do
begin
sym:=TAsmSymbol(current_asmdata.AsmSymbolDict[i]);
if sym.bind=AB_EXTERNAL then
AsmWriteln('EXTERN'#9+sym.name);
end;
end;

View File

@ -497,7 +497,7 @@ implementation
defined:=true;
current_asmdata.getjumplabel(asmblocklabel);
end;
result:=asmblocklabel.getname;
result:=asmblocklabel.name;
end;
{****************************************************************************

View File

@ -818,32 +818,30 @@ implementation
end;
end;
var
currentasmlist : TExternalAssembler;
procedure writeexternal(p:tnamedindexitem;arg:pointer);
procedure tx86intelassembler.WriteExternals;
var
sym : TAsmSymbol;
i : longint;
begin
if tasmsymbol(p).bind=AB_EXTERNAL then
for i:=0 to current_asmdata.AsmSymbolDict.Count-1 do
begin
case target_asm.id of
as_i386_masm,as_i386_wasm:
currentasmlist.AsmWriteln(#9'EXTRN'#9+p.name
+': NEAR');
as_x86_64_masm:
currentasmlist.AsmWriteln(#9'EXTRN'#9+p.name
+': PROC');
else
currentasmlist.AsmWriteln(#9'EXTRN'#9+p.name);
end;
sym:=TAsmSymbol(current_asmdata.AsmSymbolDict[i]);
if sym.bind=AB_EXTERNAL then
begin
case target_asm.id of
as_i386_masm,
as_i386_wasm :
AsmWriteln(#9'EXTRN'#9+sym.name+': NEAR');
as_x86_64_masm :
AsmWriteln(#9'EXTRN'#9+sym.name+': PROC');
else
AsmWriteln(#9'EXTRN'#9+sym.name);
end;
end;
end;
end;
procedure tx86IntelAssembler.WriteExternals;
begin
currentasmlist:=self;
current_asmdata.AsmSymbolDict.foreach_static(@writeexternal,nil);
end;
function tx86intelassembler.DoAssemble : boolean;
var