[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:
nickysn 2020-08-03 13:00:08 +00:00
parent 6ae197c62c
commit 79e046adf1
2 changed files with 35 additions and 6 deletions

View File

@ -49,6 +49,7 @@ type
procedure WriteInstList(list: TWasmInstrList; ofsAddition: LongWord);
procedure WriteImportSect;
procedure WriteFuncTypeSect;
procedure WriteFuncSect;
procedure WriteExportSect;
@ -218,6 +219,12 @@ begin
inc(writeSec);
end;
// 02 import section
if m.ImportCount>0 then begin
WriteImportSect;
inc(writeSec);
end;
// 03 function section
if m.FuncCount>0 then begin
WriteFuncSect;
@ -474,6 +481,28 @@ begin
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);
begin
if st=nil then Exit;

View File

@ -98,7 +98,7 @@ type
public
LinkInfo : TLinkInfo;
id : string;
idInt : Integer; // reference number (after Normalization)
idNum : Integer; // reference number (after Normalization)
instr : TWasmInstrList;
functype : TWasmFuncType;
@ -500,7 +500,7 @@ begin
locals:=TList.Create;
instr:=TWasmInstrList.Create;
functype:=TWasmFuncType.Create;
idInt:=-1;
idNum:=-1;
end;
destructor TWasmFunc.Destroy;
@ -578,14 +578,14 @@ begin
for i:=0 to m.ImportCount-1 do begin
im:=m.GetImport(i);
if Assigned(im.fn) and (im.fn.id = funcIdx) then begin
Result:=im.fn.idInt;
Result:=im.fn.idNum;
Exit;
end;
end;
for i:=0 to m.FuncCount-1 do
if m.GetFunc(i).id = funcIdx then begin
Result:=m.GetFunc(i).idInt;
Result:=m.GetFunc(i).idNum;
Exit;
end;
end;
@ -659,7 +659,7 @@ begin
for i:=0 to m.ImportCount-1 do begin
im := m.GetImport(i);
if Assigned(im.fn) then begin
im.fn.idInt:=fnIdx;
im.fn.idNum:=fnIdx;
NormalizeFuncType(m, im.fn.functype);
inc(fnIdx);
end;
@ -679,7 +679,7 @@ begin
for i:=0 to m.FuncCount-1 do begin
f:=m.GetFunc(i);
f.idInt := fnIdx;
f.idNum := fnIdx;
NormalizeFuncType(m, f.functype);
// finding the reference in functions