Browse Source

+ added support for the handling of singleton record and array types in
defToWasmBasic

Nikolay Nikolov 3 years ago
parent
commit
df92d88f39
2 changed files with 40 additions and 1 deletions
  1. 1 1
      compiler/wasm32/cpupara.pas
  2. 39 0
      compiler/wasm32/tgcpu.pas

+ 1 - 1
compiler/wasm32/cpupara.pas

@@ -328,7 +328,7 @@ implementation
                   exit(false);
               end;
           end;
-        result:=true;
+        result:=(fields=1);
       end;
 
 

+ 39 - 0
compiler/wasm32/tgcpu.pas

@@ -97,6 +97,9 @@ unit tgcpu;
        hlcgobj,hlcgcpu, procinfo;
 
     function defToWasmBasic(def: tdef; var wbt: TWasmBasicType): Boolean;
+    var
+      fields, i: Integer;
+      wbt_candidate: TWasmBasicType;
     begin
       Result := assigned(def);
       if not Result then
@@ -120,6 +123,42 @@ unit tgcpu;
           else
             wbt := wbt_f64; // real/double/extended
         end
+      else if def.typ=recorddef then
+        begin
+          if not (def.size in [1,2,4,8]) then
+            exit(false);
+          fields:=0;
+          wbt_candidate:=Default(TWasmBasicType);
+          for i:=0 to trecorddef(def).symtable.symlist.count-1 do
+            begin
+              if (tsym(trecorddef(def).symtable.symlist[i]).typ<>fieldvarsym) or
+                 (sp_static in tsym(trecorddef(def).symtable.symlist[i]).symoptions) then
+                continue;
+              if assigned(tfieldvarsym(trecorddef(def).symtable.symlist[i]).vardef) then
+                begin
+                  Inc(fields);
+                  if fields>1 then
+                    exit(false);
+                  { search recursively }
+                  if not defToWasmBasic(tfieldvarsym(trecorddef(def).symtable.symlist[i]).vardef,wbt_candidate) then
+                    exit(false);
+                end;
+            end;
+          if fields=1 then
+            begin
+              wbt:=wbt_candidate;
+              result:=true;
+            end
+          else
+            result:=false;
+        end
+      else if def.typ=arraydef then
+        begin
+          if (def.size in [1,2,4,8]) and (tarraydef(def).elecount=1) then
+            result:=defToWasmBasic(tarraydef(def).elementdef,wbt)
+          else
+            result:=false;
+        end
       else
         Result := false;
     end;