Browse Source

+ introduced the wasm32_throw_fpcexception inline function, that emits a
'throw' instruction. This way we'll be able to emit this instruction from
RTL code (i.e. from fpc_raiseexception, when that is implemented for
WebAssembly)

Nikolay Nikolov 3 years ago
parent
commit
c2754eac3f

+ 2 - 1
compiler/wasm32/ccpuinnr.inc

@@ -14,5 +14,6 @@
 
   in_wasm32_memory_size = in_cpu_first,
   in_wasm32_memory_grow = in_cpu_first+1,
-  in_wasm32_unreachable = in_cpu_first+2
+  in_wasm32_unreachable = in_cpu_first+2,
+  in_wasm32_throw_fpcexception = in_cpu_first+3
 

+ 1 - 1
compiler/wasm32/itcpugas.pas

@@ -84,7 +84,7 @@ interface
       // additional memory
       'memory.grow 0', 'memory.size 0',
       // exceptions
-      'try','catch __FPC_exception','catch_all','delegate','throw','rethrow','end_try'
+      'try','catch __FPC_exception','catch_all','delegate','throw __FPC_exception','rethrow','end_try'
     );
 
     gas_wasm_basic_type_str : array [TWasmBasicType] of string = ('i32','i64','f32','f64');

+ 12 - 1
compiler/wasm32/nwasminl.pas

@@ -38,6 +38,7 @@ interface
         procedure second_memory_size;
         procedure second_memory_grow;
         procedure second_unreachable;
+        procedure second_throw_fpcexception;
       protected
         function first_sqr_real: tnode; override;
       public
@@ -155,6 +156,13 @@ implementation
       end;
 
 
+    procedure twasminlinenode.second_throw_fpcexception;
+      begin
+        location_reset(location,LOC_VOID,OS_NO);
+        current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_throw));
+      end;
+
+
     function twasminlinenode.first_sqr_real: tnode;
       begin
         expectloc:=LOC_FPUREGISTER;
@@ -194,7 +202,8 @@ implementation
           in_wasm32_memory_size,
           in_wasm32_memory_grow:
             expectloc:=LOC_REGISTER;
-          in_wasm32_unreachable:
+          in_wasm32_unreachable,
+          in_wasm32_throw_fpcexception:
             expectloc:=LOC_VOID;
           else
             Result:=inherited first_cpu;
@@ -211,6 +220,8 @@ implementation
             second_memory_grow;
           in_wasm32_unreachable:
             second_unreachable;
+          in_wasm32_throw_fpcexception:
+            second_throw_fpcexception;
           else
             inherited pass_generate_code_cpu;
         end;

+ 1 - 0
rtl/wasm32/cpuh.inc

@@ -20,3 +20,4 @@ const
 function fpc_wasm32_memory_size: longword;[internproc:fpc_in_wasm32_memory_size];
 function fpc_wasm32_memory_grow(n: longword): longword;[internproc:fpc_in_wasm32_memory_grow];
 procedure fpc_wasm32_unreachable;[internproc:fpc_in_wasm32_unreachable];
+procedure fpc_wasm32_throw_fpcexception;[internproc:fpc_in_wasm32_throw_fpcexception];

+ 1 - 1
rtl/wasm32/cpuinnr.inc

@@ -15,4 +15,4 @@
   fpc_in_wasm32_memory_size = fpc_in_cpu_first;
   fpc_in_wasm32_memory_grow = fpc_in_cpu_first+1;
   fpc_in_wasm32_unreachable = fpc_in_cpu_first+2;
-
+  fpc_in_wasm32_throw_fpcexception = fpc_in_cpu_first+3;