mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 04:06:08 +02:00
[PATCH 080/188] update writing binary modules
From cab7a9d25f515abe3d0859893b7d19bfba224261 Mon Sep 17 00:00:00 2001 From: Dmitry Boyarintsev <skalogryz.lists@gmail.com> Date: Mon, 9 Mar 2020 10:28:41 -0400 git-svn-id: branches/wasm@46076 -
This commit is contained in:
parent
6ae197c62c
commit
79e046adf1
@ -49,6 +49,7 @@ type
|
|||||||
|
|
||||||
procedure WriteInstList(list: TWasmInstrList; ofsAddition: LongWord);
|
procedure WriteInstList(list: TWasmInstrList; ofsAddition: LongWord);
|
||||||
|
|
||||||
|
procedure WriteImportSect;
|
||||||
procedure WriteFuncTypeSect;
|
procedure WriteFuncTypeSect;
|
||||||
procedure WriteFuncSect;
|
procedure WriteFuncSect;
|
||||||
procedure WriteExportSect;
|
procedure WriteExportSect;
|
||||||
@ -218,6 +219,12 @@ begin
|
|||||||
inc(writeSec);
|
inc(writeSec);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// 02 import section
|
||||||
|
if m.ImportCount>0 then begin
|
||||||
|
WriteImportSect;
|
||||||
|
inc(writeSec);
|
||||||
|
end;
|
||||||
|
|
||||||
// 03 function section
|
// 03 function section
|
||||||
if m.FuncCount>0 then begin
|
if m.FuncCount>0 then begin
|
||||||
WriteFuncSect;
|
WriteFuncSect;
|
||||||
@ -474,6 +481,28 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TBinWriter.WriteImportSect;
|
||||||
|
var
|
||||||
|
sc : TSectionRec;
|
||||||
|
i : integer;
|
||||||
|
im : TWasmImport;
|
||||||
|
begin
|
||||||
|
SectionBegin(SECT_IMPORT, sc);
|
||||||
|
|
||||||
|
WriteU32(dst, module.ImportCount);
|
||||||
|
for i:=0 to module.ImportCount-1 do begin
|
||||||
|
im:=module.GetImport(i);
|
||||||
|
|
||||||
|
WriteString(im.module);
|
||||||
|
WriteString(im.name);
|
||||||
|
if Assigned(im.fn) then begin
|
||||||
|
dst.WriteByte(IMPDESC_FUNC);
|
||||||
|
WriteU32(dst, im.fn.functype.typeNum);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
SectionEnd(sc);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TBinWriter.pushStream(st: TStream);
|
procedure TBinWriter.pushStream(st: TStream);
|
||||||
begin
|
begin
|
||||||
if st=nil then Exit;
|
if st=nil then Exit;
|
||||||
|
@ -98,7 +98,7 @@ type
|
|||||||
public
|
public
|
||||||
LinkInfo : TLinkInfo;
|
LinkInfo : TLinkInfo;
|
||||||
id : string;
|
id : string;
|
||||||
idInt : Integer; // reference number (after Normalization)
|
idNum : Integer; // reference number (after Normalization)
|
||||||
instr : TWasmInstrList;
|
instr : TWasmInstrList;
|
||||||
functype : TWasmFuncType;
|
functype : TWasmFuncType;
|
||||||
|
|
||||||
@ -500,7 +500,7 @@ begin
|
|||||||
locals:=TList.Create;
|
locals:=TList.Create;
|
||||||
instr:=TWasmInstrList.Create;
|
instr:=TWasmInstrList.Create;
|
||||||
functype:=TWasmFuncType.Create;
|
functype:=TWasmFuncType.Create;
|
||||||
idInt:=-1;
|
idNum:=-1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TWasmFunc.Destroy;
|
destructor TWasmFunc.Destroy;
|
||||||
@ -578,14 +578,14 @@ begin
|
|||||||
for i:=0 to m.ImportCount-1 do begin
|
for i:=0 to m.ImportCount-1 do begin
|
||||||
im:=m.GetImport(i);
|
im:=m.GetImport(i);
|
||||||
if Assigned(im.fn) and (im.fn.id = funcIdx) then begin
|
if Assigned(im.fn) and (im.fn.id = funcIdx) then begin
|
||||||
Result:=im.fn.idInt;
|
Result:=im.fn.idNum;
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
for i:=0 to m.FuncCount-1 do
|
for i:=0 to m.FuncCount-1 do
|
||||||
if m.GetFunc(i).id = funcIdx then begin
|
if m.GetFunc(i).id = funcIdx then begin
|
||||||
Result:=m.GetFunc(i).idInt;
|
Result:=m.GetFunc(i).idNum;
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -659,7 +659,7 @@ begin
|
|||||||
for i:=0 to m.ImportCount-1 do begin
|
for i:=0 to m.ImportCount-1 do begin
|
||||||
im := m.GetImport(i);
|
im := m.GetImport(i);
|
||||||
if Assigned(im.fn) then begin
|
if Assigned(im.fn) then begin
|
||||||
im.fn.idInt:=fnIdx;
|
im.fn.idNum:=fnIdx;
|
||||||
NormalizeFuncType(m, im.fn.functype);
|
NormalizeFuncType(m, im.fn.functype);
|
||||||
inc(fnIdx);
|
inc(fnIdx);
|
||||||
end;
|
end;
|
||||||
@ -679,7 +679,7 @@ begin
|
|||||||
|
|
||||||
for i:=0 to m.FuncCount-1 do begin
|
for i:=0 to m.FuncCount-1 do begin
|
||||||
f:=m.GetFunc(i);
|
f:=m.GetFunc(i);
|
||||||
f.idInt := fnIdx;
|
f.idNum := fnIdx;
|
||||||
|
|
||||||
NormalizeFuncType(m, f.functype);
|
NormalizeFuncType(m, f.functype);
|
||||||
// finding the reference in functions
|
// finding the reference in functions
|
||||||
|
Loading…
Reference in New Issue
Block a user