mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 02:59:13 +02:00
[PATCH 045/188] updating wat parser
From e7bcce53a1c94dabba3248fc64e6b3cd750777e4 Mon Sep 17 00:00:00 2001 From: Dmitry Boyarintsev <skalogryz.lists@gmail.com> Date: Thu, 21 Nov 2019 10:21:38 -0500 git-svn-id: branches/wasm@46041 -
This commit is contained in:
parent
d47696380e
commit
f6ca48a266
@ -13,11 +13,17 @@ type
|
|||||||
|
|
||||||
{ TWasmType }
|
{ TWasmType }
|
||||||
|
|
||||||
TWasmType = class(TObject)
|
// function signature
|
||||||
|
|
||||||
|
{ TWasmFuncType }
|
||||||
|
|
||||||
|
TWasmFuncType = class(TObject)
|
||||||
private
|
private
|
||||||
params : TList;
|
params : TList;
|
||||||
results : TList;
|
results : TList;
|
||||||
public
|
public
|
||||||
|
typeNum : Integer; // if Idx < 0 then type is declared from typeDef
|
||||||
|
typeIdx : string; // if typeID='' then type is declared from typeDef
|
||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function AddResult(tp: byte = 0): TWasmParam;
|
function AddResult(tp: byte = 0): TWasmParam;
|
||||||
@ -27,6 +33,8 @@ type
|
|||||||
function GetResult: TWasmParam; overload;
|
function GetResult: TWasmParam; overload;
|
||||||
function ResultCount: Integer;
|
function ResultCount: Integer;
|
||||||
function ParamCount: Integer;
|
function ParamCount: Integer;
|
||||||
|
|
||||||
|
function isExplicitRef: Boolean;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TWasmInstr = class(TObject)
|
TWasmInstr = class(TObject)
|
||||||
@ -54,16 +62,13 @@ type
|
|||||||
|
|
||||||
TWasmFunc = class(TObject)
|
TWasmFunc = class(TObject)
|
||||||
private
|
private
|
||||||
finlineType: TWasmType;
|
|
||||||
locals: TList;
|
locals: TList;
|
||||||
public
|
public
|
||||||
id : string;
|
id : string;
|
||||||
typeIdx : Integer; // if Idx < 0 then type is declared from typeDef
|
instr : TWasmInstrList;
|
||||||
typeId : string; // if tpyeID='' then type is declared from typeDef
|
functype : TWasmFuncType;
|
||||||
instr : TWasmInstrList;
|
|
||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function GetInlineType: TWasmType;
|
|
||||||
function AddLocal: TWasmParam;
|
function AddLocal: TWasmParam;
|
||||||
function LocalsCount: integer;
|
function LocalsCount: integer;
|
||||||
end;
|
end;
|
||||||
@ -92,8 +97,8 @@ type
|
|||||||
function GetFunc(i: integer): TWasmFunc;
|
function GetFunc(i: integer): TWasmFunc;
|
||||||
function FuncCount: integer;
|
function FuncCount: integer;
|
||||||
|
|
||||||
function AddType: TWasmType;
|
function AddType: TWasmFuncType;
|
||||||
function GetTypes(i: integer): TWasmType;
|
function GetTypes(i: integer): TWasmFuncType;
|
||||||
function TypesCount: integer;
|
function TypesCount: integer;
|
||||||
|
|
||||||
function AddExport: TWasmExport;
|
function AddExport: TWasmExport;
|
||||||
@ -147,16 +152,17 @@ begin
|
|||||||
Result:=items.Count;
|
Result:=items.Count;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TWasmType }
|
{ TWasmFuncType }
|
||||||
|
|
||||||
constructor TWasmType.Create;
|
constructor TWasmFuncType.Create;
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
|
typeNum:=-1;
|
||||||
params:=Tlist.Create;
|
params:=Tlist.Create;
|
||||||
results:=Tlist.Create;
|
results:=Tlist.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TWasmType.Destroy;
|
destructor TWasmFuncType.Destroy;
|
||||||
begin
|
begin
|
||||||
ClearList(params);
|
ClearList(params);
|
||||||
ClearList(results);
|
ClearList(results);
|
||||||
@ -165,14 +171,14 @@ begin
|
|||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TWasmType.AddResult(tp: byte): TWasmParam;
|
function TWasmFuncType.AddResult(tp: byte): TWasmParam;
|
||||||
begin
|
begin
|
||||||
Result:=TWasmParam.Create;
|
Result:=TWasmParam.Create;
|
||||||
Result.tp:=tp;
|
Result.tp:=tp;
|
||||||
results.Add(Result);
|
results.Add(Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TWasmType.AddParam(tp: byte; const id: string): TWasmParam;
|
function TWasmFuncType.AddParam(tp: byte; const id: string): TWasmParam;
|
||||||
begin
|
begin
|
||||||
Result:=TWasmParam.Create;
|
Result:=TWasmParam.Create;
|
||||||
Result.tp:=tp;
|
Result.tp:=tp;
|
||||||
@ -180,7 +186,7 @@ begin
|
|||||||
params.Add(Result);
|
params.Add(Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TWasmType.GetParam(i: integer): TWasmParam;
|
function TWasmFuncType.GetParam(i: integer): TWasmParam;
|
||||||
begin
|
begin
|
||||||
if (i>=0) and (i<params.Count) then
|
if (i>=0) and (i<params.Count) then
|
||||||
Result:=TWasmParam(params[i])
|
Result:=TWasmParam(params[i])
|
||||||
@ -188,7 +194,7 @@ begin
|
|||||||
Result:=nil;
|
Result:=nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TWasmType.GetResult(i: integer): TWasmParam;
|
function TWasmFuncType.GetResult(i: integer): TWasmParam;
|
||||||
begin
|
begin
|
||||||
if (i>=0) and (i<results.Count) then
|
if (i>=0) and (i<results.Count) then
|
||||||
Result:=TWasmParam(results[i])
|
Result:=TWasmParam(results[i])
|
||||||
@ -196,21 +202,26 @@ begin
|
|||||||
Result:=nil;
|
Result:=nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TWasmType.GetResult: TWasmParam;
|
function TWasmFuncType.GetResult: TWasmParam;
|
||||||
begin
|
begin
|
||||||
Result:=GetResult(0);
|
Result:=GetResult(0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TWasmType.ResultCount: Integer;
|
function TWasmFuncType.ResultCount: Integer;
|
||||||
begin
|
begin
|
||||||
Result:=results.Count;
|
Result:=results.Count;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TWasmType.ParamCount: Integer;
|
function TWasmFuncType.ParamCount: Integer;
|
||||||
begin
|
begin
|
||||||
Result:=params.Count;
|
Result:=params.Count;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TWasmFuncType.isExplicitRef: Boolean;
|
||||||
|
begin
|
||||||
|
Result:=(typeIdx<>'') or (typeNum>=0);
|
||||||
|
end;
|
||||||
|
|
||||||
{ TWasmModule }
|
{ TWasmModule }
|
||||||
|
|
||||||
constructor TWasmModule.Create;
|
constructor TWasmModule.Create;
|
||||||
@ -238,9 +249,9 @@ begin
|
|||||||
funcs.Add(Result);
|
funcs.Add(Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TWasmModule.AddType: TWasmType;
|
function TWasmModule.AddType: TWasmFuncType;
|
||||||
begin
|
begin
|
||||||
Result:=TWasmType.Create;
|
Result:=TWasmFuncType.Create;
|
||||||
types.Add(Result);
|
types.Add(Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -257,10 +268,10 @@ begin
|
|||||||
Result:=funcs.Count;
|
Result:=funcs.Count;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TWasmModule.GetTypes(i: integer): TWasmType;
|
function TWasmModule.GetTypes(i: integer): TWasmFuncType;
|
||||||
begin
|
begin
|
||||||
if (i>=0) and (i<types.Count) then
|
if (i>=0) and (i<types.Count) then
|
||||||
Result:=TWasmType(types[i])
|
Result:=TWasmFuncType(types[i])
|
||||||
else
|
else
|
||||||
Result:=nil;
|
Result:=nil;
|
||||||
end;
|
end;
|
||||||
@ -294,26 +305,20 @@ end;
|
|||||||
constructor TWasmFunc.Create;
|
constructor TWasmFunc.Create;
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
typeIdx:=-1;
|
|
||||||
locals:=TList.Create;
|
locals:=TList.Create;
|
||||||
instr:=TWasmInstrList.Create;
|
instr:=TWasmInstrList.Create;
|
||||||
|
functype:=TWasmFuncType.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TWasmFunc.Destroy;
|
destructor TWasmFunc.Destroy;
|
||||||
begin
|
begin
|
||||||
ClearList(locals);
|
ClearList(locals);
|
||||||
locals.Free;
|
locals.Free;
|
||||||
finlineType.Free;
|
functype.Free;
|
||||||
instr.Free;
|
instr.Free;
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TWasmFunc.GetInlineType: TWasmType;
|
|
||||||
begin
|
|
||||||
if not Assigned(fInlineType) then finlineType:=TWasmType.Create;
|
|
||||||
Result:=finlineType;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TWasmFunc.AddLocal: TWasmParam;
|
function TWasmFunc.AddLocal: TWasmParam;
|
||||||
begin
|
begin
|
||||||
Result:=TWasmParam.Create;
|
Result:=TWasmParam.Create;
|
||||||
|
@ -228,20 +228,20 @@ begin
|
|||||||
|
|
||||||
if tk = weType then begin
|
if tk = weType then begin
|
||||||
if not ParseNumOfId(sc, nm, id) then Exit;
|
if not ParseNumOfId(sc, nm, id) then Exit;
|
||||||
if nm>=0 then dst.typeIdx:=nm
|
if nm>=0 then dst.functype.typeNum:=nm
|
||||||
else dst.typeId:=id;
|
else dst.functype.typeIdx:=id;
|
||||||
ConsumeAnyOpenToken(sc, tk);
|
ConsumeAnyOpenToken(sc, tk);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
while tk = weParam do begin
|
while tk = weParam do begin
|
||||||
p:=dst.GetInlineType.AddParam;
|
p:=dst.functype.AddParam;
|
||||||
sc.Next;
|
sc.Next;
|
||||||
ParseParam(sc, p.id, p.tp);
|
ParseParam(sc, p.id, p.tp);
|
||||||
ConsumeAnyOpenToken(sc, tk);
|
ConsumeAnyOpenToken(sc, tk);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
while tk = weResult do begin
|
while tk = weResult do begin
|
||||||
p:=dst.GetInlineType.AddResult;
|
p:=dst.functype.AddResult;
|
||||||
sc.Next;
|
sc.Next;
|
||||||
ParseParam(sc, p.id, p.tp, false);
|
ParseParam(sc, p.id, p.tp, false);
|
||||||
ConsumeAnyOpenToken(sc, tk);
|
ConsumeAnyOpenToken(sc, tk);
|
||||||
|
Loading…
Reference in New Issue
Block a user