Browse Source

+ emit a size directive for the internal dynarray const label. This fixes
WebAssembly dynarray consts with the llvm-mc external asm.

Nikolay Nikolov 11 months ago
parent
commit
28b080d9bc
2 changed files with 5 additions and 3 deletions
  1. 4 2
      compiler/aasmcnst.pas
  2. 1 1
      compiler/ngtcon.pas

+ 4 - 2
compiler/aasmcnst.pas

@@ -360,7 +360,7 @@ type
      { starts a dynamic array constant so that its data can be emitted directly afterwards }
      function begin_dynarray_const(arrdef:tdef;var startlab:tasmlabel;out arrlengthloc:ttypedconstplaceholder):tasmlabofs;virtual;
      { ends a dynamic array constant by updating the count field; the arrlengthloc will be freed }
-     function end_dynarray_const(arrdef:tdef;arrlength:asizeint;arrlengthloc:ttypedconstplaceholder):tdef;virtual;
+     function end_dynarray_const(arrdef:tdef;arrlength:asizeint;arrlengthloc:ttypedconstplaceholder;llofs:tasmlabofs):tdef;virtual;
 
      { emit a shortstring constant, and return its def }
      function emit_shortstring_const(const str: shortstring): tdef;
@@ -1817,11 +1817,13 @@ implementation
      end;
 
 
-   function ttai_typedconstbuilder.end_dynarray_const(arrdef:tdef;arrlength:asizeint;arrlengthloc:ttypedconstplaceholder):tdef;
+   function ttai_typedconstbuilder.end_dynarray_const(arrdef:tdef;arrlength:asizeint;arrlengthloc:ttypedconstplaceholder;llofs:tasmlabofs):tdef;
      begin
        { we emit the high value, not the count }
        arrlengthloc.replace(tai_const.Create_sizeint(arrlength-1),sizesinttype);
        arrlengthloc.free;
+       if get_dynarray_symofs=0 then
+         emit_tai(tai_symbol_end.create(llofs.lab),arrdef);
        result:=end_anonymous_record;
      end;
 

+ 1 - 1
compiler/ngtcon.pas

@@ -1298,7 +1298,7 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
                       end;
                     ftcb:=oldtcb;
 
-                    dynarrdef:=datatcb.end_dynarray_const(def,dyncount,dyncountloc);
+                    dynarrdef:=datatcb.end_dynarray_const(def,dyncount,dyncountloc,llofs);
 
                     ftcb.finish_internal_data_builder(datatcb,ll,dynarrdef,sizeof(pint));