diff --git a/compiler/wasm32/nwasmutil.pas b/compiler/wasm32/nwasmutil.pas index 5c908c07dd..a02ecca0dd 100644 --- a/compiler/wasm32/nwasmutil.pas +++ b/compiler/wasm32/nwasmutil.pas @@ -58,6 +58,33 @@ implementation list.Concat(tai_import_name.create(proc.mangledname,proc.import_name^)); end; + procedure InsertUnitInfo(list : TAsmList;cur_unit: tused_unit); + var + i: Integer; + def : tdef; + proc : tprocdef; + begin + if (cur_unit.u.moduleflags * [mf_init,mf_finalize])<>[] then + begin + if mf_init in cur_unit.u.moduleflags then + list.Concat(tai_functype.create(make_mangledname('INIT$',cur_unit.u.globalsymtable,''),TWasmFuncType.Create([],[]))); + if mf_finalize in cur_unit.u.moduleflags then + list.Concat(tai_functype.create(make_mangledname('FINALIZE$',cur_unit.u.globalsymtable,''),TWasmFuncType.Create([],[]))); + end; + for i:=0 to cur_unit.u.deflist.Count-1 do + begin + def:=tdef(cur_unit.u.deflist[i]); + if assigned(def) and (tdef(def).typ = procdef) then + begin + proc := tprocdef(def); + if (po_external in proc.procoptions) and (po_has_importdll in proc.procoptions) then + WriteImportDll(list,proc) + else if not proc.owner.iscurrentunit or (po_external in proc.procoptions) then + thlcgwasm(hlcg).g_procdef(list,proc); + end; + end; + end; + var i : integer; def : tdef; @@ -94,25 +121,13 @@ implementation cur_unit:=tused_unit(usedunits.First); while assigned(cur_unit) do begin - if (cur_unit.u.moduleflags * [mf_init,mf_finalize])<>[] then - begin - if mf_init in cur_unit.u.moduleflags then - list.Concat(tai_functype.create(make_mangledname('INIT$',cur_unit.u.globalsymtable,''),TWasmFuncType.Create([],[]))); - if mf_finalize in cur_unit.u.moduleflags then - list.Concat(tai_functype.create(make_mangledname('FINALIZE$',cur_unit.u.globalsymtable,''),TWasmFuncType.Create([],[]))); - end; - for i:=0 to cur_unit.u.deflist.Count-1 do - begin - def:=tdef(cur_unit.u.deflist[i]); - if assigned(def) and (tdef(def).typ = procdef) then - begin - proc := tprocdef(def); - if (po_external in proc.procoptions) and (po_has_importdll in proc.procoptions) then - WriteImportDll(list,proc) - else if not proc.owner.iscurrentunit or (po_external in proc.procoptions) then - thlcgwasm(hlcg).g_procdef(list,proc); - end; - end; + InsertUnitInfo(list,cur_unit); + cur_unit:=tused_unit(cur_unit.Next); + end; + cur_unit:=tused_unit(current_module.used_units.First); + while assigned(cur_unit) do + begin + InsertUnitInfo(list,cur_unit); cur_unit:=tused_unit(cur_unit.Next); end; end; diff --git a/tests/webtbs/tw39543.pp b/tests/webtbs/tw39543.pp new file mode 100644 index 0000000000..3403ca6131 --- /dev/null +++ b/tests/webtbs/tw39543.pp @@ -0,0 +1,10 @@ +program tw39543; + +{$MODE objfpc} + +uses + uw39543a; + +begin + +end. \ No newline at end of file diff --git a/tests/webtbs/uw39543a.pp b/tests/webtbs/uw39543a.pp new file mode 100644 index 0000000000..750270d50c --- /dev/null +++ b/tests/webtbs/uw39543a.pp @@ -0,0 +1,19 @@ +unit uw39543a; + +interface + +{$MODE objfpc} + +uses + uw39543b; + +function Test: TVector4; + +implementation + +function Test: TVector4; +begin + Result := Vector4(1, 2, 3, 4); +end; + +end. \ No newline at end of file diff --git a/tests/webtbs/uw39543b.pp b/tests/webtbs/uw39543b.pp new file mode 100644 index 0000000000..ee791fd25d --- /dev/null +++ b/tests/webtbs/uw39543b.pp @@ -0,0 +1,27 @@ +unit uw39543b; + +interface + +{$MODE objfpc} + +type + TVector4 = record + X, Y, Z, W: Single; + end; + +function Vector4(X, Y, Z, W: Single): TVector4; + +implementation + +uses + uw39543a; + +function Vector4(X, Y, Z, W: Single): TVector4; +begin + Result.X := X; + Result.Y := Y; + Result.Z := Z; + Result.W := W; +end; + +end. \ No newline at end of file