+ implemented exporting of functions for the win16 target

git-svn-id: trunk@31842 -
This commit is contained in:
nickysn 2015-09-27 00:48:35 +00:00
parent d144073299
commit 3e2248f41a
3 changed files with 119 additions and 3 deletions

View File

@ -148,6 +148,7 @@ interface
importlibfilename, { fullname of the import libraryfile }
staticlibfilename, { fullname of the static libraryfile }
sharedlibfilename, { fullname of the shared libraryfile }
exportfilename, { fullname of the export file }
mapfilename, { fullname of the mapfile }
exefilename, { fullname of the exefile }
dbgfilename, { fullname of the debug info file }
@ -626,6 +627,7 @@ uses
ppufilename:=p+n+target_info.unitext;
importlibfilename:=p+target_info.importlibprefix+n+target_info.importlibext;
staticlibfilename:=p+target_info.staticlibprefix+n+target_info.staticlibext;
exportfilename:=p+'exp'+n+target_info.objext;
{ output dir of exe can be specified separatly }
if AllowOutput and (OutputExeDir<>'') then

View File

@ -308,7 +308,8 @@ interface
system_i386_Netware,
system_i386_netwlibc,
system_arm_wince,
system_x86_64_win64]+systems_linux+systems_android;
system_x86_64_win64,
system_i8086_win16]+systems_linux+systems_android;
{ all systems for which weak linking has been tested/is supported }
systems_weak_linking = systems_darwin + systems_solaris + systems_linux + systems_android;

View File

@ -33,9 +33,10 @@ implementation
SysUtils,
cutils,cfileutl,cclasses,
globtype,globals,systems,verbose,script,
import,fmodule,i_win16,
import,export,fmodule,i_win16,
link,aasmbase,cpuinfo,
omfbase,ogbase,ogomf,owomflib;
omfbase,ogbase,ogomf,owbase,owomflib,
symconst,symdef,symsym;
type
@ -46,6 +47,18 @@ implementation
procedure generatelib;override;
end;
{ TExportLibWin16 }
TExportLibWin16=class(texportlib)
private
EList: TFPList;
public
destructor Destroy;override;
procedure preparelib(const s : string);override;
procedure exportprocedure(hp : texported_item);override;
procedure generatelib;override;
end;
{ the (Open) Watcom linker }
TExternalLinkerWin16WLink=class(texternallinker)
private
@ -96,6 +109,105 @@ begin
end;
{****************************************************************************
TExportLibWin16
****************************************************************************}
destructor TExportLibWin16.Destroy;
begin
EList.Free;
inherited Destroy;
end;
procedure TExportLibWin16.preparelib(const s: string);
begin
if EList=nil then
EList:=TFPList.Create;
end;
procedure TExportLibWin16.exportprocedure(hp: texported_item);
begin
if ((hp.options and eo_index)<>0) and ((hp.index<=0) or (hp.index>$ffff)) then
begin
message1(parser_e_export_invalid_index,tostr(hp.index));
exit;
end;
EList.Add(hp);
end;
procedure TExportLibWin16.generatelib;
var
ObjWriter: TObjectWriter;
ObjOutput: TOmfObjOutput;
RawRecord: TOmfRawRecord;
Header: TOmfRecord_THEADR;
i: Integer;
hp: texported_item;
ModEnd: TOmfRecord_MODEND;
DllExport_COMENT: TOmfRecord_COMENT;
expflag: Byte;
internal_name: TSymStr;
begin
if EList.Count=0 then
exit;
current_module.linkotherofiles.add(current_module.exportfilename,link_always);
ObjWriter:=TObjectWriter.Create;
ObjOutput:=TOmfObjOutput.Create(ObjWriter);
ObjWriter.createfile(current_module.exportfilename);
{ write header record }
RawRecord:=TOmfRawRecord.Create;
Header:=TOmfRecord_THEADR.Create;
Header.ModuleName:=current_module.exportfilename;
Header.EncodeTo(RawRecord);
RawRecord.WriteTo(ObjWriter);
Header.Free;
for i:=0 to EList.Count-1 do
begin
hp:=texported_item(EList[i]);
{ write EXPDEF record }
DllExport_COMENT:=TOmfRecord_COMENT.Create;
DllExport_COMENT.CommentClass:=CC_OmfExtension;
expflag:=0;
if (hp.options and eo_index)<>0 then
expflag:=expflag or $80;
if (hp.options and eo_resident)<>0 then
expflag:=expflag or $40;
if assigned(hp.sym) then
case hp.sym.typ of
staticvarsym:
internal_name:=tstaticvarsym(hp.sym).mangledname;
procsym:
internal_name:=tprocdef(tprocsym(hp.sym).ProcdefList[0]).mangledname;
else
internalerror(2015092701);
end
else
internal_name:=hp.name^;
DllExport_COMENT.CommentString:=#2+Chr(expflag)+Chr(Length(hp.name^))+hp.name^+Chr(Length(internal_name))+internal_name;
if (hp.options and eo_index)<>0 then
DllExport_COMENT.CommentString:=DllExport_COMENT.CommentString+Chr(Byte(hp.index))+Chr(Byte(hp.index shr 8));
DllExport_COMENT.EncodeTo(RawRecord);
RawRecord.WriteTo(ObjWriter);
DllExport_COMENT.Free;
end;
{ write MODEND record }
ModEnd:=TOmfRecord_MODEND.Create;
ModEnd.EncodeTo(RawRecord);
RawRecord.WriteTo(ObjWriter);
ModEnd.Free;
ObjWriter.closefile;
ObjOutput.Free;
ObjWriter.Free;
RawRecord.Free;
end;
{****************************************************************************
TExternalLinkerWin16WLink
****************************************************************************}
@ -203,5 +315,6 @@ end;
initialization
RegisterLinker(ld_win16,TExternalLinkerWin16WLink);
RegisterImport(system_i8086_win16,TImportLibWin16);
RegisterExport(system_i8086_win16,TExportLibWin16);
RegisterTarget(system_i8086_win16_info);
end.