Sfoglia il codice sorgente

* when adding WebAssembly object info, traverse through current_module.used_units,
as well as the usedunits global. This resolves #39543

Nikolay Nikolov 3 anni fa
parent
commit
2c0f10d988
4 ha cambiato i file con 90 aggiunte e 19 eliminazioni
  1. 34 19
      compiler/wasm32/nwasmutil.pas
  2. 10 0
      tests/webtbs/tw39543.pp
  3. 19 0
      tests/webtbs/uw39543a.pp
  4. 27 0
      tests/webtbs/uw39543b.pp

+ 34 - 19
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;

+ 10 - 0
tests/webtbs/tw39543.pp

@@ -0,0 +1,10 @@
+program tw39543;
+
+{$MODE objfpc}
+
+uses
+  uw39543a;
+
+begin
+
+end.

+ 19 - 0
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.

+ 27 - 0
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.