mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-28 12:10:25 +02:00
+ try to implement smartlink
git-svn-id: trunk@6867 -
This commit is contained in:
parent
63523e8a7f
commit
ce5037920a
@ -41,6 +41,7 @@ interface
|
|||||||
procedure WriteTree(p:TAsmList);override;
|
procedure WriteTree(p:TAsmList);override;
|
||||||
procedure WriteAsmList;override;
|
procedure WriteAsmList;override;
|
||||||
procedure WriteExternals;
|
procedure WriteExternals;
|
||||||
|
procedure WriteSmartExternals;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -253,6 +254,54 @@ interface
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
type
|
||||||
|
PExternChain = ^TExternChain;
|
||||||
|
|
||||||
|
TExternChain = Record
|
||||||
|
psym : pshortstring;
|
||||||
|
is_defined : boolean;
|
||||||
|
next : PExternChain;
|
||||||
|
end;
|
||||||
|
|
||||||
|
const
|
||||||
|
FEC : PExternChain = nil;
|
||||||
|
|
||||||
|
procedure AddSymbol(symname : string; defined : boolean);
|
||||||
|
var
|
||||||
|
EC : PExternChain;
|
||||||
|
begin
|
||||||
|
EC:=FEC;
|
||||||
|
while assigned(EC) do
|
||||||
|
begin
|
||||||
|
if EC^.psym^=symname then
|
||||||
|
begin
|
||||||
|
if defined then
|
||||||
|
EC^.is_defined:=true;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
EC:=EC^.next;
|
||||||
|
end;
|
||||||
|
New(EC);
|
||||||
|
EC^.next:=FEC;
|
||||||
|
FEC:=EC;
|
||||||
|
FEC^.psym:=stringdup(symname);
|
||||||
|
FEC^.is_defined := defined;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure FreeExternChainList;
|
||||||
|
var
|
||||||
|
EC : PExternChain;
|
||||||
|
begin
|
||||||
|
EC:=FEC;
|
||||||
|
while assigned(EC) do
|
||||||
|
begin
|
||||||
|
FEC:=EC^.next;
|
||||||
|
stringdispose(EC^.psym);
|
||||||
|
Dispose(EC);
|
||||||
|
EC:=FEC;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{****************************************************************************
|
{****************************************************************************
|
||||||
T386NasmAssembler
|
T386NasmAssembler
|
||||||
****************************************************************************}
|
****************************************************************************}
|
||||||
@ -270,6 +319,8 @@ interface
|
|||||||
if assigned(symbol) then
|
if assigned(symbol) then
|
||||||
begin
|
begin
|
||||||
AsmWrite(symbol.name);
|
AsmWrite(symbol.name);
|
||||||
|
if SmartAsm then
|
||||||
|
AddSymbol(symbol.name,false);
|
||||||
first:=false;
|
first:=false;
|
||||||
end;
|
end;
|
||||||
if (base<>NR_NO) then
|
if (base<>NR_NO) then
|
||||||
@ -325,7 +376,7 @@ interface
|
|||||||
if not ((opcode = A_LEA) or (opcode = A_LGS) or
|
if not ((opcode = A_LEA) or (opcode = A_LGS) or
|
||||||
(opcode = A_LSS) or (opcode = A_LFS) or
|
(opcode = A_LSS) or (opcode = A_LFS) or
|
||||||
(opcode = A_LES) or (opcode = A_LDS) or
|
(opcode = A_LES) or (opcode = A_LDS) or
|
||||||
(opcode = A_SHR) or (opcode = A_SHL) or
|
// (opcode = A_SHR) or (opcode = A_SHL) or
|
||||||
(opcode = A_SAR) or (opcode = A_SAL) or
|
(opcode = A_SAR) or (opcode = A_SAL) or
|
||||||
(opcode = A_OUT) or (opcode = A_IN)) then
|
(opcode = A_OUT) or (opcode = A_IN)) then
|
||||||
AsmWrite(sizestr(s,dest));
|
AsmWrite(sizestr(s,dest));
|
||||||
@ -336,6 +387,8 @@ interface
|
|||||||
asmwrite('dword ');
|
asmwrite('dword ');
|
||||||
if assigned(o.ref^.symbol) then
|
if assigned(o.ref^.symbol) then
|
||||||
begin
|
begin
|
||||||
|
if SmartAsm then
|
||||||
|
AddSymbol(o.ref^.symbol.name,false);
|
||||||
asmwrite(o.ref^.symbol.name);
|
asmwrite(o.ref^.symbol.name);
|
||||||
if o.ref^.offset=0 then
|
if o.ref^.offset=0 then
|
||||||
exit;
|
exit;
|
||||||
@ -373,6 +426,8 @@ interface
|
|||||||
) then
|
) then
|
||||||
AsmWrite('NEAR ');
|
AsmWrite('NEAR ');
|
||||||
AsmWrite(o.ref^.symbol.name);
|
AsmWrite(o.ref^.symbol.name);
|
||||||
|
if SmartAsm then
|
||||||
|
AddSymbol(o.ref^.symbol.name,false);
|
||||||
if o.ref^.offset>0 then
|
if o.ref^.offset>0 then
|
||||||
AsmWrite('+'+tostr(o.ref^.offset))
|
AsmWrite('+'+tostr(o.ref^.offset))
|
||||||
else
|
else
|
||||||
@ -387,6 +442,7 @@ interface
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var
|
var
|
||||||
LastSecType : TAsmSectiontype;
|
LastSecType : TAsmSectiontype;
|
||||||
|
|
||||||
@ -567,6 +623,8 @@ interface
|
|||||||
AsmWriteLn(tai_datablock(hp).sym.name);
|
AsmWriteLn(tai_datablock(hp).sym.name);
|
||||||
end;
|
end;
|
||||||
AsmWrite(PadTabs(tai_datablock(hp).sym.name,':'));
|
AsmWrite(PadTabs(tai_datablock(hp).sym.name,':'));
|
||||||
|
if SmartAsm then
|
||||||
|
AddSymbol(tai_datablock(hp).sym.name,true);
|
||||||
AsmWriteLn('RESB'#9+tostr(tai_datablock(hp).size));
|
AsmWriteLn('RESB'#9+tostr(tai_datablock(hp).size));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -600,6 +658,12 @@ interface
|
|||||||
repeat
|
repeat
|
||||||
if assigned(tai_const(hp).sym) then
|
if assigned(tai_const(hp).sym) then
|
||||||
begin
|
begin
|
||||||
|
if SmartAsm then
|
||||||
|
begin
|
||||||
|
AddSymbol(tai_const(hp).sym.name,false);
|
||||||
|
if assigned(tai_const(hp).endsym) then
|
||||||
|
AddSymbol(tai_const(hp).endsym.name,false);
|
||||||
|
end;
|
||||||
if assigned(tai_const(hp).endsym) then
|
if assigned(tai_const(hp).endsym) then
|
||||||
s:=tai_const(hp).endsym.name+'-'+tai_const(hp).sym.name
|
s:=tai_const(hp).endsym.name+'-'+tai_const(hp).sym.name
|
||||||
else
|
else
|
||||||
@ -807,6 +871,8 @@ interface
|
|||||||
begin
|
begin
|
||||||
if tai_label(hp).labsym.is_used then
|
if tai_label(hp).labsym.is_used then
|
||||||
AsmWriteLn(tai_label(hp).labsym.name+':');
|
AsmWriteLn(tai_label(hp).labsym.name+':');
|
||||||
|
if SmartAsm then
|
||||||
|
AddSymbol(tai_label(hp).labsym.name,true);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
ait_symbol :
|
ait_symbol :
|
||||||
@ -817,6 +883,8 @@ interface
|
|||||||
AsmWriteLn(tai_symbol(hp).sym.name);
|
AsmWriteLn(tai_symbol(hp).sym.name);
|
||||||
end;
|
end;
|
||||||
AsmWrite(tai_symbol(hp).sym.name);
|
AsmWrite(tai_symbol(hp).sym.name);
|
||||||
|
if SmartAsm then
|
||||||
|
AddSymbol(tai_symbol(hp).sym.name,true);
|
||||||
if assigned(hp.next) and not(tai(hp.next).typ in
|
if assigned(hp.next) and not(tai(hp.next).typ in
|
||||||
[ait_const,
|
[ait_const,
|
||||||
ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_string]) then
|
ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_string]) then
|
||||||
@ -883,12 +951,19 @@ interface
|
|||||||
ait_function_name : ;
|
ait_function_name : ;
|
||||||
|
|
||||||
ait_cutobject :
|
ait_cutobject :
|
||||||
|
begin
|
||||||
|
if SmartAsm then
|
||||||
begin
|
begin
|
||||||
{ only reset buffer if nothing has changed }
|
{ only reset buffer if nothing has changed }
|
||||||
if AsmSize=AsmStartSize then
|
if AsmSize=AsmStartSize then
|
||||||
AsmClear
|
AsmClear
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
|
if SmartAsm then
|
||||||
|
begin
|
||||||
|
WriteSmartExternals;
|
||||||
|
FreeExternChainList;
|
||||||
|
end;
|
||||||
AsmClose;
|
AsmClose;
|
||||||
DoAssemble;
|
DoAssemble;
|
||||||
AsmCreate(tai_cutobject(hp).place);
|
AsmCreate(tai_cutobject(hp).place);
|
||||||
@ -904,6 +979,7 @@ interface
|
|||||||
WriteSection(lasTSectype,'');
|
WriteSection(lasTSectype,'');
|
||||||
AsmStartSize:=AsmSize;
|
AsmStartSize:=AsmSize;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
ait_marker :
|
ait_marker :
|
||||||
if tai_marker(hp).kind=mark_InlineStart then
|
if tai_marker(hp).kind=mark_InlineStart then
|
||||||
@ -922,7 +998,13 @@ interface
|
|||||||
internalerror(200509191);
|
internalerror(200509191);
|
||||||
end;
|
end;
|
||||||
if assigned(tai_directive(hp).name) then
|
if assigned(tai_directive(hp).name) then
|
||||||
|
begin
|
||||||
|
|
||||||
|
if SmartAsm then
|
||||||
|
AddSymbol(tai_directive(hp).name^,false);
|
||||||
|
|
||||||
AsmWrite(tai_directive(hp).name^);
|
AsmWrite(tai_directive(hp).name^);
|
||||||
|
end;
|
||||||
AsmLn;
|
AsmLn;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -947,6 +1029,19 @@ interface
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure T386NasmAssembler.WriteSmartExternals;
|
||||||
|
var
|
||||||
|
EC : PExternChain;
|
||||||
|
begin
|
||||||
|
EC:=FEC;
|
||||||
|
while assigned(EC) do
|
||||||
|
begin
|
||||||
|
if not EC^.is_defined then
|
||||||
|
AsmWriteln('EXTERN'#9+EC^.psym^);
|
||||||
|
EC:=EC^.next;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure T386NasmAssembler.WriteAsmList;
|
procedure T386NasmAssembler.WriteAsmList;
|
||||||
var
|
var
|
||||||
@ -974,6 +1069,11 @@ interface
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
AsmLn;
|
AsmLn;
|
||||||
|
if SmartAsm then
|
||||||
|
begin
|
||||||
|
WriteSmartExternals;
|
||||||
|
FreeExternChainList;
|
||||||
|
end;
|
||||||
{$ifdef EXTDEBUG}
|
{$ifdef EXTDEBUG}
|
||||||
if assigned(current_module.mainsource) then
|
if assigned(current_module.mainsource) then
|
||||||
comment(v_info,'Done writing nasm-styled assembler output for '+current_module.mainsource^);
|
comment(v_info,'Done writing nasm-styled assembler output for '+current_module.mainsource^);
|
||||||
|
Loading…
Reference in New Issue
Block a user