Przeglądaj źródła

+ wrap block nodes with exit in a_block..a_end_block instructions. This fixes
'exit' in inlined procedures on the WebAssembly target.

Nikolay Nikolov 3 lat temu
rodzic
commit
bb30958665
2 zmienionych plików z 70 dodań i 1 usunięć
  1. 1 1
      compiler/wasm32/cpunode.pas
  2. 69 0
      compiler/wasm32/nwasmbas.pas

+ 1 - 1
compiler/wasm32/cpunode.pas

@@ -33,7 +33,7 @@ implementation
     ncgbas,ncgflw,ncgcnv,ncgld,ncgmem,ncgcon,ncgset,
     ncgadd, ncgcal,ncgmat,ncginl,
     
-    nwasmadd,nwasmcal,nwasmmat,nwasmflw,nwasmcon,nwasmcnv,nwasmset,nwasminl,
+    nwasmbas,nwasmadd,nwasmcal,nwasmmat,nwasmflw,nwasmcon,nwasmcnv,nwasmset,nwasminl,
     { these are not really nodes }
     nwasmutil,
     { symtable }

+ 69 - 0
compiler/wasm32/nwasmbas.pas

@@ -0,0 +1,69 @@
+{
+    Copyright (c) 2021 by Nikolay Nikolov
+
+    This unit implements code generation for some basic nodes on the
+    WebAssembly target.
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit nwasmbas;
+
+{$i fpcdefs.inc}
+
+interface
+
+    uses
+      nbas,ncgbas;
+
+    type
+
+      { twasmblocknode }
+
+      twasmblocknode=class(tcgblocknode)
+        procedure pass_generate_code; override;
+      end;
+
+implementation
+
+    uses
+      aasmdata,aasmcpu,
+      cpubase,
+      hlcgobj,hlcgcpu,
+      node;
+
+    { twasmblocknode }
+
+    procedure twasmblocknode.pass_generate_code;
+      begin
+        if nf_block_with_exit in flags then
+          begin
+            current_asmdata.CurrAsmList.concat(taicpu.op_none(a_block));
+            thlcgwasm(hlcg).incblock;
+          end;
+
+        inherited pass_generate_code;
+
+        if nf_block_with_exit in flags then
+          begin
+            current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_block));
+            thlcgwasm(hlcg).decblock;
+          end;
+      end;
+
+begin
+  cblocknode:=twasmblocknode;
+end.