mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-17 02:39:27 +02:00
* moved the import name handling entirely to hlcgobj so it can be
overridden git-svn-id: trunk@31053 -
This commit is contained in:
parent
54dd25b448
commit
b39bc5888a
compiler
@ -563,6 +563,7 @@ unit hlcgobj;
|
||||
|
||||
procedure gen_proc_symbol(list:TAsmList);virtual;
|
||||
procedure gen_proc_symbol_end(list:TAsmList);virtual;
|
||||
procedure handle_external_proc(list: TAsmList; pd: tprocdef; const importname: TSymStr); virtual;
|
||||
|
||||
procedure gen_initialize_code(list:TAsmList);virtual;
|
||||
procedure gen_finalize_code(list:TAsmList);virtual;
|
||||
@ -4377,6 +4378,40 @@ implementation
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure thlcgobj.handle_external_proc(list: TAsmList; pd: tprocdef; const importname: TSymStr);
|
||||
begin
|
||||
{ External declared in implementation, and there was already a
|
||||
forward (or interface) declaration then we need to generate
|
||||
a stub that calls the external routine }
|
||||
if (not pd.forwarddef) and
|
||||
(pd.hasforward) then
|
||||
begin
|
||||
if importname<>'' then
|
||||
begin
|
||||
{ add the procedure to the al_procedures }
|
||||
maybe_new_object_file(list);
|
||||
new_section(list,sec_code,lower(pd.mangledname),current_settings.alignment.procalign);
|
||||
if (po_global in pd.procoptions) then
|
||||
list.concat(Tai_symbol.createname_global(pd.mangledname,AT_FUNCTION,0))
|
||||
else
|
||||
list.concat(Tai_symbol.createname(pd.mangledname,AT_FUNCTION,0));
|
||||
|
||||
g_external_wrapper(list,pd,importname);
|
||||
end;
|
||||
{ remove the external stuff, so that the interface crc
|
||||
doesn't change. This makes the function calls less
|
||||
efficient, but it means that the interface doesn't
|
||||
change if the function is ever redirected to another
|
||||
function or implemented in the unit. }
|
||||
pd.procoptions:=pd.procoptions-[po_external,po_has_importname,po_has_importdll];
|
||||
stringdispose(pd.import_name);
|
||||
stringdispose(pd.import_dll);
|
||||
pd.import_nr:=0;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure thlcgobj.gen_initialize_code(list: TAsmList);
|
||||
begin
|
||||
{ initialize local data like ansistrings }
|
||||
|
@ -84,8 +84,6 @@ interface
|
||||
procedure gen_restore_used_regs(list:TAsmList);
|
||||
procedure gen_load_para_value(list:TAsmList);
|
||||
|
||||
procedure gen_external_stub(list:TAsmList;pd:tprocdef;const externalname:string);
|
||||
|
||||
procedure get_used_regvars(n: tnode; var rv: tusedregvars);
|
||||
{ adds the regvars used in n and its children to rv.allregvars,
|
||||
those which were already in rv.allregvars to rv.commonregvars and
|
||||
@ -1489,25 +1487,6 @@ implementation
|
||||
end;
|
||||
|
||||
|
||||
{****************************************************************************
|
||||
External handling
|
||||
****************************************************************************}
|
||||
|
||||
procedure gen_external_stub(list:TAsmList;pd:tprocdef;const externalname:string);
|
||||
begin
|
||||
create_hlcodegen;
|
||||
{ add the procedure to the al_procedures }
|
||||
maybe_new_object_file(list);
|
||||
new_section(list,sec_code,lower(pd.mangledname),current_settings.alignment.procalign);
|
||||
if (po_global in pd.procoptions) then
|
||||
list.concat(Tai_symbol.createname_global(pd.mangledname,AT_FUNCTION,0))
|
||||
else
|
||||
list.concat(Tai_symbol.createname(pd.mangledname,AT_FUNCTION,0));
|
||||
|
||||
hlcg.g_external_wrapper(list,pd,externalname);
|
||||
destroy_hlcodegen;
|
||||
end;
|
||||
|
||||
{****************************************************************************
|
||||
Const Data
|
||||
****************************************************************************}
|
||||
|
@ -2157,33 +2157,12 @@ implementation
|
||||
current_module.dllscannerinputlist.Add(proc_get_importname(pd),pd);
|
||||
end;
|
||||
|
||||
{ External declared in implementation, and there was already a
|
||||
forward (or interface) declaration then we need to generate
|
||||
a stub that calls the external routine }
|
||||
if (not pd.forwarddef) and
|
||||
(pd.hasforward)
|
||||
{ it is unclear to me what's the use of the following condition,
|
||||
so commented out, see also issue #18371 (FK)
|
||||
and
|
||||
not(
|
||||
assigned(pd.import_dll) and
|
||||
(target_info.system in [system_i386_wdosx,
|
||||
system_arm_wince,system_i386_wince])
|
||||
) } then
|
||||
begin
|
||||
s:=proc_get_importname(pd);
|
||||
if s<>'' then
|
||||
gen_external_stub(current_asmdata.asmlists[al_procedures],pd,s);
|
||||
{ remove the external stuff, so that the interface crc
|
||||
doesn't change. This makes the function calls less
|
||||
efficient, but it means that the interface doesn't
|
||||
change if the function is ever redirected to another
|
||||
function or implemented in the unit. }
|
||||
pd.procoptions:=pd.procoptions-[po_external,po_has_importname,po_has_importdll];
|
||||
stringdispose(pd.import_name);
|
||||
stringdispose(pd.import_dll);
|
||||
pd.import_nr:=0;
|
||||
end;
|
||||
create_hlcodegen;
|
||||
hlcg.handle_external_proc(
|
||||
current_asmdata.asmlists[al_procedures],
|
||||
pd,
|
||||
proc_get_importname(pd));
|
||||
destroy_hlcodegen;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user