Browse Source

+ introduced decode_wasm_basic_type function

Nikolay Nikolov 1 year ago
parent
commit
2626b85984
1 changed files with 27 additions and 0 deletions
  1. 27 0
      compiler/wasm32/cpubase.pas

+ 27 - 0
compiler/wasm32/cpubase.pas

@@ -391,6 +391,7 @@ uses
 
     function natural_alignment_for_load_store(op: TAsmOp): shortint;
     function encode_wasm_basic_type(wbt: TWasmBasicType): Byte;
+    function decode_wasm_basic_type(b: Byte; out wbt: TWasmBasicType): Boolean;
 
 implementation
 
@@ -595,6 +596,32 @@ uses
         end;
       end;
 
+    function decode_wasm_basic_type(b: Byte; out wbt: TWasmBasicType): Boolean;
+      begin
+        result:=true;
+        case b of
+          $7F:
+            wbt:=wbt_i32;
+          $7E:
+            wbt:=wbt_i64;
+          $7D:
+            wbt:=wbt_f32;
+          $7C:
+            wbt:=wbt_f64;
+          $7B:
+            wbt:=wbt_v128;
+          $70:
+            wbt:=wbt_funcref;
+          $6F:
+            wbt:=wbt_externref;
+          else
+            begin
+              result:=false;
+              wbt:=default(TWasmBasicType);
+            end;
+        end;
+      end;
+
 {*****************************************************************************
                                   TWasmFuncType
 *****************************************************************************}