From f6ca48a2660a16464e6b58078eedcd26375ecfca Mon Sep 17 00:00:00 2001 From: nickysn Date: Mon, 3 Aug 2020 12:59:32 +0000 Subject: [PATCH] [PATCH 045/188] updating wat parser From e7bcce53a1c94dabba3248fc64e6b3cd750777e4 Mon Sep 17 00:00:00 2001 From: Dmitry Boyarintsev Date: Thu, 21 Nov 2019 10:21:38 -0500 git-svn-id: branches/wasm@46041 - --- utils/wasmbin/wasmmodule.pas | 65 +++++++++++++++++++----------------- utils/wasmbin/watparser.pas | 8 ++--- 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/utils/wasmbin/wasmmodule.pas b/utils/wasmbin/wasmmodule.pas index 193a2f9768..bf1b181577 100644 --- a/utils/wasmbin/wasmmodule.pas +++ b/utils/wasmbin/wasmmodule.pas @@ -13,11 +13,17 @@ type { TWasmType } - TWasmType = class(TObject) + // function signature + + { TWasmFuncType } + + TWasmFuncType = class(TObject) private params : TList; results : TList; public + typeNum : Integer; // if Idx < 0 then type is declared from typeDef + typeIdx : string; // if typeID='' then type is declared from typeDef constructor Create; destructor Destroy; override; function AddResult(tp: byte = 0): TWasmParam; @@ -27,6 +33,8 @@ type function GetResult: TWasmParam; overload; function ResultCount: Integer; function ParamCount: Integer; + + function isExplicitRef: Boolean; end; TWasmInstr = class(TObject) @@ -54,16 +62,13 @@ type TWasmFunc = class(TObject) private - finlineType: TWasmType; locals: TList; public id : string; - typeIdx : Integer; // if Idx < 0 then type is declared from typeDef - typeId : string; // if tpyeID='' then type is declared from typeDef - instr : TWasmInstrList; + instr : TWasmInstrList; + functype : TWasmFuncType; constructor Create; destructor Destroy; override; - function GetInlineType: TWasmType; function AddLocal: TWasmParam; function LocalsCount: integer; end; @@ -92,8 +97,8 @@ type function GetFunc(i: integer): TWasmFunc; function FuncCount: integer; - function AddType: TWasmType; - function GetTypes(i: integer): TWasmType; + function AddType: TWasmFuncType; + function GetTypes(i: integer): TWasmFuncType; function TypesCount: integer; function AddExport: TWasmExport; @@ -147,16 +152,17 @@ begin Result:=items.Count; end; -{ TWasmType } +{ TWasmFuncType } -constructor TWasmType.Create; +constructor TWasmFuncType.Create; begin inherited Create; + typeNum:=-1; params:=Tlist.Create; results:=Tlist.Create; end; -destructor TWasmType.Destroy; +destructor TWasmFuncType.Destroy; begin ClearList(params); ClearList(results); @@ -165,14 +171,14 @@ begin inherited Destroy; end; -function TWasmType.AddResult(tp: byte): TWasmParam; +function TWasmFuncType.AddResult(tp: byte): TWasmParam; begin Result:=TWasmParam.Create; Result.tp:=tp; results.Add(Result); end; -function TWasmType.AddParam(tp: byte; const id: string): TWasmParam; +function TWasmFuncType.AddParam(tp: byte; const id: string): TWasmParam; begin Result:=TWasmParam.Create; Result.tp:=tp; @@ -180,7 +186,7 @@ begin params.Add(Result); end; -function TWasmType.GetParam(i: integer): TWasmParam; +function TWasmFuncType.GetParam(i: integer): TWasmParam; begin if (i>=0) and (i=0) and (i'') or (typeNum>=0); +end; + { TWasmModule } constructor TWasmModule.Create; @@ -238,9 +249,9 @@ begin funcs.Add(Result); end; -function TWasmModule.AddType: TWasmType; +function TWasmModule.AddType: TWasmFuncType; begin - Result:=TWasmType.Create; + Result:=TWasmFuncType.Create; types.Add(Result); end; @@ -257,10 +268,10 @@ begin Result:=funcs.Count; end; -function TWasmModule.GetTypes(i: integer): TWasmType; +function TWasmModule.GetTypes(i: integer): TWasmFuncType; begin if (i>=0) and (i=0 then dst.typeIdx:=nm - else dst.typeId:=id; + if nm>=0 then dst.functype.typeNum:=nm + else dst.functype.typeIdx:=id; ConsumeAnyOpenToken(sc, tk); end; while tk = weParam do begin - p:=dst.GetInlineType.AddParam; + p:=dst.functype.AddParam; sc.Next; ParseParam(sc, p.id, p.tp); ConsumeAnyOpenToken(sc, tk); end; while tk = weResult do begin - p:=dst.GetInlineType.AddResult; + p:=dst.functype.AddResult; sc.Next; ParseParam(sc, p.id, p.tp, false); ConsumeAnyOpenToken(sc, tk);