From 7e53fecd092c55b7675af5e6bf5dfafbe9e74da0 Mon Sep 17 00:00:00 2001 From: Nikolay Nikolov Date: Sat, 25 Sep 2021 16:00:09 +0300 Subject: [PATCH] + handle tai_local in the internal asm writer and store the locals in the wasm obj extra symbol data object --- compiler/assemble.pas | 2 ++ compiler/ogwasm.pas | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/compiler/assemble.pas b/compiler/assemble.pas index 45e79b1656..925f137653 100644 --- a/compiler/assemble.pas +++ b/compiler/assemble.pas @@ -1841,6 +1841,8 @@ Implementation TWasmObjData(ObjData).DeclareImportModule(tai_import_module(hp)); ait_import_name: TWasmObjData(ObjData).DeclareImportName(tai_import_name(hp)); + ait_local: + TWasmObjData(ObjData).DeclareLocal(tai_local(hp)); {$endif WASM} else ; diff --git a/compiler/ogwasm.pas b/compiler/ogwasm.pas index cae44ab9da..d92bdbc8e0 100644 --- a/compiler/ogwasm.pas +++ b/compiler/ogwasm.pas @@ -46,7 +46,9 @@ interface TypeIdx: Integer; ImportModule: string; ImportName: string; + Locals: array of TWasmBasicType; constructor Create(HashObjectList: TFPHashObjectList; const s: TSymStr); + procedure AddLocal(bastyp: TWasmBasicType); end; { TWasmObjSection } @@ -65,6 +67,7 @@ interface private FFuncTypes: array of TWasmFuncType; FObjSymbolsExtraDataList: TFPHashObjectList; + FLastFuncName: string; function is_smart_section(atype:TAsmSectiontype):boolean; function sectionname_gas(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string; @@ -78,6 +81,7 @@ interface procedure DeclareFuncType(ft: tai_functype); procedure DeclareImportModule(aim: tai_import_module); procedure DeclareImportName(ain: tai_import_name); + procedure DeclareLocal(al: tai_local); end; { TWasmObjOutput } @@ -124,6 +128,12 @@ implementation TypeIdx:=-1; end; + procedure TWasmObjSymbolExtraData.AddLocal(bastyp: TWasmBasicType); + begin + SetLength(Locals,Length(Locals)+1); + Locals[High(Locals)]:=bastyp; + end; + {**************************************************************************** TWasmObjSection ****************************************************************************} @@ -343,8 +353,8 @@ implementation i: Integer; ObjSymExtraData: TWasmObjSymbolExtraData; begin + FLastFuncName:=ft.funcname; i:=AddFuncType(ft.functype); - ObjSymExtraData:=AddOrCreateObjSymbolExtraData(ft.funcname); ObjSymExtraData.TypeIdx:=i; end; @@ -365,6 +375,14 @@ implementation ObjSymExtraData.ImportName:=ain.importname; end; + procedure TWasmObjData.DeclareLocal(al: tai_local); + var + ObjSymExtraData: TWasmObjSymbolExtraData; + begin + ObjSymExtraData:=TWasmObjSymbolExtraData(FObjSymbolsExtraDataList.Find(FLastFuncName)); + ObjSymExtraData.AddLocal(al.bastyp); + end; + {**************************************************************************** TWasmObjOutput ****************************************************************************}