mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 06:26:10 +02:00
[PATCH 175/188] update normalization of imported units
From b2e45d583af68ff11052b29125b00331ad7a4359 Mon Sep 17 00:00:00 2001 From: Dmitry Boyarintsev <skalogryz.lists@gmail.com> Date: Wed, 8 Apr 2020 10:32:10 -0400 git-svn-id: branches/wasm@46171 -
This commit is contained in:
parent
50b84edd27
commit
e13fb1fd1b
@ -165,18 +165,31 @@ begin
|
|||||||
fn.typeNum:=RegisterFuncType(m, fn);
|
fn.typeNum:=RegisterFuncType(m, fn);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure NormalizeImport(m: TWasmModule; var fnIdx: Integer);
|
procedure NormalizeImport(m: TWasmModule; out fnIdx: Integer;
|
||||||
|
out memIdx: Integer; out globIdx: Integer; out tblIdx : Integer);
|
||||||
var
|
var
|
||||||
i : integer;
|
i : integer;
|
||||||
im : TWasmImport;
|
im : TWasmImport;
|
||||||
begin
|
begin
|
||||||
fnIdx := 0;
|
fnIdx := 0;
|
||||||
|
memIdx := 0;
|
||||||
|
globIdx := 0;
|
||||||
|
tblIdx := 0;
|
||||||
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.idNum:=fnIdx;
|
im.fn.idNum:=fnIdx;
|
||||||
NormalizeFuncType(m, im.fn.functype);
|
NormalizeFuncType(m, im.fn.functype);
|
||||||
inc(fnIdx);
|
inc(fnIdx);
|
||||||
|
end else if Assigned(im.mem) then begin
|
||||||
|
im.mem.id.idNum := memIdx;
|
||||||
|
inc(memIdx);
|
||||||
|
end else if Assigned(im.glob) then begin
|
||||||
|
im.glob.id.idNum := globIdx;
|
||||||
|
inc(globIdx);
|
||||||
|
end else if Assigned(im.table) then begin
|
||||||
|
im.table.id.idNum := tblIdx;
|
||||||
|
inc(tblIdx);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -258,16 +271,20 @@ end;
|
|||||||
// normalizing reference
|
// normalizing reference
|
||||||
procedure Normalize(m: TWasmModule);
|
procedure Normalize(m: TWasmModule);
|
||||||
var
|
var
|
||||||
i : integer;
|
i : integer;
|
||||||
f : TWasmFunc;
|
f : TWasmFunc;
|
||||||
x : TWasmExport;
|
x : TWasmExport;
|
||||||
fnIdx : Integer;
|
fnIdx : Integer;
|
||||||
|
memIdx : Integer;
|
||||||
|
globIdx : Integer;
|
||||||
|
tblIdx : Integer;
|
||||||
|
g : TWasmGlobal;
|
||||||
begin
|
begin
|
||||||
fnIdx := 0;
|
fnIdx := 0;
|
||||||
NormalizeGlobals(m);
|
NormalizeGlobals(m);
|
||||||
NormalizeTable(m);
|
NormalizeTable(m);
|
||||||
NormalizeElems(m);
|
NormalizeElems(m);
|
||||||
NormalizeImport(m, fnIdx);
|
NormalizeImport(m, fnIdx, memIdx, globIdx, tblIdx);
|
||||||
NormalizeTableLimit(m);
|
NormalizeTableLimit(m);
|
||||||
|
|
||||||
for i:=0 to m.FuncCount-1 do begin
|
for i:=0 to m.FuncCount-1 do begin
|
||||||
@ -280,7 +297,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
for i:=0 to m.GlobalCount-1 do
|
for i:=0 to m.GlobalCount-1 do
|
||||||
NormalizeInst(m, nil, m.GetGlobal(i).StartValue);
|
begin
|
||||||
|
g := m.GetGlobal(i);
|
||||||
|
g.id.idNum := globIdx;
|
||||||
|
inc(globIdx);
|
||||||
|
NormalizeInst(m, nil, g.StartValue);
|
||||||
|
end;
|
||||||
|
|
||||||
// normalizing function body
|
// normalizing function body
|
||||||
for i:=0 to m.FuncCount-1 do begin
|
for i:=0 to m.FuncCount-1 do begin
|
||||||
|
Loading…
Reference in New Issue
Block a user