[PATCH 174/188] update parsing of import entity

From ce1266c4fb4a1c99ca4c8463989cdb7b4baeaacd Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <skalogryz.lists@gmail.com>
Date: Wed, 8 Apr 2020 10:25:27 -0400

git-svn-id: branches/wasm@46170 -
This commit is contained in:
nickysn 2020-08-03 13:02:05 +00:00
parent b710b84191
commit 50b84edd27
2 changed files with 86 additions and 40 deletions

View File

@ -192,16 +192,6 @@ type
constructor Create;
end;
{ TWasmImport }
TWasmImport = class(TObject)
LinkInfo : TLinkInfo;
module : string;
name : string;
fn : TWasmFunc;
function AddFunc: TWasmFunc;
end;
{ TWasmTable }
TWasmTable = class(TObject)
@ -235,6 +225,23 @@ type
exportInfo : TExportInfo;
end;
{ TWasmImport }
TWasmImport = class(TObject)
LinkInfo : TLinkInfo;
module : string;
name : string;
fn : TWasmFunc;
mem : TWasmMemory;
glob : TWasmGlobal;
table : TWasmTable;
destructor Destroy; override;
function AddFunc: TWasmFunc;
function AddMemory: TWasmMemory;
function AddGlobal: TWasmGlobal;
function AddTable: TWasmTable;
end;
{ TWasmModule }
TWasmModule = class(TObject)
@ -490,12 +497,42 @@ end;
{ TWasmImport }
destructor TWasmImport.Destroy;
begin
mem.Free;
fn.Free;
glob.Free;
table.Free;
inherited Destroy;
end;
function TWasmImport.AddFunc: TWasmFunc;
begin
if not Assigned(fn) then fn:= TWasmFunc.Create;
Result:=fn;
end;
function TWasmImport.AddMemory: TWasmMemory;
begin
if not Assigned(mem) then
mem := TWasmMemory.Create;
Result := mem;
end;
function TWasmImport.AddGlobal: TWasmGlobal;
begin
if not Assigned(glob) then
glob := TWasmGlobal.Create;
Result := glob;
end;
function TWasmImport.AddTable: TWasmTable;
begin
if not Assigned(table) then
table := TWasmTable.Create;
Result := table;
end;
{ TWasmExport }
constructor TWasmExport.Create;

View File

@ -578,36 +578,6 @@ begin
ConsumeToken(sc, weCloseBrace);
end;
procedure ParseImport(sc: TWatScanner; dst: TWasmImport);
var
tk : TWatToken;
begin
if sc.token=weImport then
sc.Next;
if sc.token<>weString then
ErrorExpectButFound(sc, 'string');
dst.module := sc.resWasmString;
sc.Next;
if sc.token<>weString then
ErrorExpectButFound(sc, 'string');
dst.name := sc.resWasmString;
sc.Next;
ConsumeAnyOpenToken(sc, tk);
case tk of
weAsmSymbol: ;
weFunc: begin
ParseFunc(sc, dst.AddFunc);
end;
else
ErrorExpectButFound(sc, 'importdesc', TokenStr[sc.token]);
end;
ConsumeToken(sc, weCloseBrace);
end;
procedure ConsumeAsmSym(sc: TWatScanner; dst: TAsmSymList);
begin
dst.Push(sc.asmCmd, sc.resText);
@ -662,6 +632,45 @@ begin
ConsumeToken(sc, weCloseBrace);
end;
procedure ParseImport(sc: TWatScanner; dst: TWasmImport);
var
tk : TWatToken;
begin
if sc.token=weImport then
sc.Next;
if sc.token<>weString then
ErrorExpectButFound(sc, 'string');
dst.module := sc.resWasmString;
sc.Next;
if sc.token<>weString then
ErrorExpectButFound(sc, 'string');
dst.name := sc.resWasmString;
sc.Next;
ConsumeAnyOpenToken(sc, tk);
case tk of
weAsmSymbol: ;
weFunc: begin
ParseFunc(sc, dst.AddFunc);
end;
weMemory: begin
ParseMemory(sc, dst.AddMemory);
end;
weTable: begin
ParseTable(sc, dst.AddTable);
end;
weGlobal: begin
ParseGlobal(sc, dst.AddGlobal);
end;
else
ErrorExpectButFound(sc, 'importdesc', TokenStr[sc.token]);
end;
ConsumeToken(sc, weCloseBrace);
end;
procedure ParseModuleInt(sc: TWatScanner; dst: TWasmModule);
var
tk : TWatToken;