Michael Ferris 8 лет назад
Родитель
Сommit
086583e5c0

+ 12 - 11
lib/wabt/chakra/wabtapi.cc

@@ -61,6 +61,16 @@ namespace ChakraWabt
     };
 }
 
+Features GetWabtFeatures(const ChakraContext& ctx)
+{
+    Features features;
+    if (ctx.features.sign_extends || ctx.features.threads)
+    {
+        features.enable_threads();
+    }
+    return features;
+}
+
 uint TruncSizeT(size_t value)
 {
     if (value > 0xffffffff)
@@ -265,7 +275,8 @@ Js::Var create_module(Context* ctx, const Module* module, bool validate = true)
     }
     if (validate)
     {
-        ValidateModule(ctx->lexer, module, ctx->errorHandler);
+        ValidateOptions options(GetWabtFeatures(*ctx->chakra));
+        ValidateModule(ctx->lexer, module, ctx->errorHandler, &options);
     }
     MemoryStream stream;
     WriteBinaryOptions s_write_binary_options;
@@ -464,16 +475,6 @@ void CheckResult(Result result, const char* errorMessage)
     }
 }
 
-Features GetWabtFeatures(ChakraContext& ctx)
-{
-    Features features;
-    if (ctx.features.sign_extends || ctx.features.threads)
-    {
-        features.enable_threads();
-    }
-    return features;
-}
-
 Js::Var ChakraWabt::ConvertWast2Wasm(ChakraContext& chakraCtx, char* buffer, uint bufferSize, bool isSpecText)
 {
     Validate(chakraCtx, isSpecText);

+ 147 - 104
lib/wabt/chakra/windows/config.h

@@ -1,18 +1,18 @@
 /*
- * Copyright 2016 WebAssembly Community Group participants
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2016 WebAssembly Community Group participants
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
 
 #ifndef WABT_CONFIG_H_
 #define WABT_CONFIG_H_
@@ -40,16 +40,13 @@
 /* Whether ENABLE_VIRTUAL_TERMINAL_PROCESSING is defined by windows.h */
 #define HAVE_WIN32_VT100 1
 
-#define COMPILER_IS_CLANG 1
+#define COMPILER_IS_CLANG 0
 #define COMPILER_IS_GNU 0
-#define COMPILER_IS_MSVC 0
+#define COMPILER_IS_MSVC 1
 
 #define WITH_EXCEPTIONS 0
 
 #define SIZEOF_SIZE_T 4
-#define SIZEOF_INT 4
-#define SIZEOF_LONG 4
-#define SIZEOF_LONG_LONG 8
 
 #if HAVE_ALLOCA_H
 #include <alloca.h>
@@ -96,30 +93,6 @@
 #define WABT_STATIC_ASSERT(x) _Static_assert((x), #x)
 #endif
 
-#if SIZEOF_INT == 4
-#define wabt_clz_u32(x) __builtin_clz(x)
-#define wabt_ctz_u32(x) __builtin_ctz(x)
-#define wabt_popcount_u32(x) __builtin_popcount(x)
-#elif SIZEOF_LONG == 4
-#define wabt_clz_u32(x) __builtin_clzl(x)
-#define wabt_ctz_u32(x) __builtin_ctzl(x)
-#define wabt_popcount_u32(x) __builtin_popcountl(x)
-#else
-#error "don't know how to define 32-bit builtins"
-#endif
-
-#if SIZEOF_LONG == 8
-#define wabt_clz_u64(x) __builtin_clzl(x)
-#define wabt_ctz_u64(x) __builtin_ctzl(x)
-#define wabt_popcount_u64(x) __builtin_popcountl(x)
-#elif SIZEOF_LONG_LONG == 8
-#define wabt_clz_u64(x) __builtin_clzll(x)
-#define wabt_ctz_u64(x) __builtin_ctzll(x)
-#define wabt_popcount_u64(x) __builtin_popcountll(x)
-#else
-#error "don't know how to define 64-bit builtins"
-#endif
-
 #define WABT_UNREACHABLE __builtin_unreachable()
 
 #elif COMPILER_IS_MSVC
@@ -137,76 +110,136 @@
 
 #define WABT_UNREACHABLE __assume(0)
 
-__inline unsigned long wabt_clz_u32(unsigned long mask) {
-  unsigned long index;
-  _BitScanReverse(&index, mask);
-  return sizeof(unsigned long) * 8 - (index + 1);
+#else
+
+#error unknown compiler
+
+#endif
+
+
+namespace wabt
+{
+
+#if COMPILER_IS_CLANG || COMPILER_IS_GNU
+
+inline int Clz(unsigned x) { return x ? __builtin_clz(x) : sizeof(x) * 8; }
+inline int Clz(unsigned long x) { return x ? __builtin_clzl(x) : sizeof(x) * 8; }
+inline int Clz(unsigned long long x) { return x ? __builtin_clzll(x) : sizeof(x) * 8; }
+
+inline int Ctz(unsigned x) { return x ? __builtin_ctz(x) : sizeof(x) * 8; }
+inline int Ctz(unsigned long x) { return x ? __builtin_ctzl(x) : sizeof(x) * 8; }
+inline int Ctz(unsigned long long x) { return x ? __builtin_ctzll(x) : sizeof(x) * 8; }
+
+inline int Popcount(unsigned x) { return __builtin_popcount(x); }
+inline int Popcount(unsigned long x) { return __builtin_popcountl(x); }
+inline int Popcount(unsigned long long x) { return __builtin_popcountll(x); }
+
+#elif COMPILER_IS_MSVC
+
+#if _M_IX86
+inline unsigned long LowDword(unsigned __int64 value)
+{
+    return (unsigned long)value;
+}
+
+inline unsigned long HighDword(unsigned __int64 value)
+{
+    unsigned long high;
+    memcpy(&high, (unsigned char*)&value + sizeof(high), sizeof(high));
+    return high;
+}
+#endif
+
+inline int Clz(unsigned long mask)
+{
+    if (mask == 0)
+        return 32;
+
+    unsigned long index;
+    _BitScanReverse(&index, mask);
+    return sizeof(unsigned long) * 8 - (index + 1);
 }
 
-__inline unsigned long wabt_clz_u64(unsigned __int64 mask) {
+inline int Clz(unsigned int mask)
+{
+    return Clz((unsigned long)mask);
+}
+
+inline int Clz(unsigned __int64 mask)
+{
 #if _M_X64
-  unsigned long index;
-  _BitScanReverse64(&index, mask);
-  return sizeof(unsigned __int64) * 8 - (index + 1);
+    if (mask == 0)
+        return 64;
+
+    unsigned long index;
+    _BitScanReverse64(&index, mask);
+    return sizeof(unsigned __int64) * 8 - (index + 1);
 #elif _M_IX86
-  unsigned long index;
-  unsigned long high_mask;
-  memcpy(&high_mask, (unsigned char*)&mask + sizeof(unsigned long),
-         sizeof(unsigned long));
-  if (_BitScanReverse(&index, high_mask)) {
-    return sizeof(unsigned long) * 8 - (index + 1);
-  }
+    int result = Clz(HighDword(mask));
+    if (result == 32)
+        result += Clz(LowDword(mask));
 
-  unsigned long low_mask;
-  memcpy(&low_mask, &mask, sizeof(unsigned long));
-  _BitScanReverse(&index, low_mask);
-  return sizeof(unsigned __int64) * 8 - (index + 1);
+    return result;
 #else
 #error unexpected architecture
 #endif
 }
 
-__inline unsigned long wabt_ctz_u32(unsigned long mask) {
+inline int Ctz(unsigned long mask)
+{
+    if (mask == 0)
+        return 32;
+
     unsigned long index;
     _BitScanForward(&index, mask);
     return index;
 }
 
-__inline unsigned long wabt_ctz_u64(unsigned __int64 mask) {
+inline int Ctz(unsigned int mask)
+{
+    return Ctz((unsigned long)mask);
+}
+
+inline int Ctz(unsigned __int64 mask)
+{
 #if _M_X64
+    if (mask == 0)
+        return 64;
+
     unsigned long index;
     _BitScanForward64(&index, mask);
     return index;
 #elif _M_IX86
-    unsigned long low_mask = (unsigned long)mask;
-    if (low_mask) {
-        return wabt_ctz_u32(low_mask);
-    }
-    unsigned long high_mask;
-    memcpy(&high_mask, (unsigned char*)&mask + sizeof(unsigned long),
-           sizeof(unsigned long));
-    return sizeof(unsigned long) * 8 + wabt_ctz_u32(high_mask);
+    int result = Ctz(LowDword(mask));
+    if (result == 32)
+        result += Ctz(HighDword(mask));
+
+    return result;
 #else
 #error unexpected architecture
 #endif
 }
 
+inline int Popcount(unsigned long value)
+{
+    return __popcnt(value);
+}
+
+inline int Popcount(unsigned int value)
+{
+    return Popcount((unsigned long)value);
+}
 
-#define wabt_popcount_u32 __popcnt
+inline int Popcount(unsigned __int64 value)
+{
 #if _M_X64
+    return __popcnt64(value);
 #elif _M_IX86
-__inline unsigned __int64 __popcnt64(unsigned __int64 value) {
-    unsigned long high_value;
-    unsigned long low_value;
-    memcpy(&high_value, (unsigned char*)&value + sizeof(unsigned long),
-           sizeof(unsigned long));
-    memcpy(&low_value, &value, sizeof(unsigned long));
-    return wabt_popcount_u32(high_value) + wabt_popcount_u32(low_value);
-}
+    return Popcount(HighDword(value)) + Popcount(LowDword(value));
 #else
 #error unexpected architecture
 #endif
-#define wabt_popcount_u64 __popcnt64
+}
 
 #else
 
@@ -214,10 +247,12 @@ __inline unsigned __int64 __popcnt64(unsigned __int64 value) {
 
 #endif
 
+} // namespace wabt
+
 
 #if COMPILER_IS_MSVC
 
-/* print format specifier for size_t */
+  /* print format specifier for size_t */
 #if SIZEOF_SIZE_T == 4
 #define PRIzd "d"
 #define PRIzx "x"
@@ -230,7 +265,7 @@ __inline unsigned __int64 __popcnt64(unsigned __int64 value) {
 
 #elif COMPILER_IS_CLANG || COMPILER_IS_GNU
 
-/* print format specifier for size_t */
+  /* print format specifier for size_t */
 #define PRIzd "zd"
 #define PRIzx "zx"
 
@@ -244,7 +279,7 @@ __inline unsigned __int64 __popcnt64(unsigned __int64 value) {
 #if HAVE_SNPRINTF
 #define wabt_snprintf snprintf
 #elif COMPILER_IS_MSVC
-/* can't just use _snprintf because it doesn't always null terminate */
+  /* can't just use _snprintf because it doesn't always null terminate */
 #include <cstdarg>
 int wabt_snprintf(char* str, size_t size, const char* format, ...);
 #else
@@ -252,7 +287,7 @@ int wabt_snprintf(char* str, size_t size, const char* format, ...);
 #endif
 
 #if COMPILER_IS_MSVC
-/* can't just use vsnprintf because it doesn't always null terminate */
+  /* can't just use vsnprintf because it doesn't always null terminate */
 int wabt_vsnprintf(char* str, size_t size, const char* format, va_list ap);
 #else
 #define wabt_vsnprintf vsnprintf
@@ -274,26 +309,34 @@ typedef int ssize_t;
 // MSVC on x64 generates uint64 -> float conversions but doesn't do
 // round-to-nearest-ties-to-even, which is required by WebAssembly.
 #include <emmintrin.h>
-__inline double wabt_convert_uint64_to_double(unsigned __int64 x) {
-  __m128d result = _mm_setzero_pd();
-  if (x & 0x8000000000000000ULL) {
-    result = _mm_cvtsi64_sd(result, (x >> 1) | (x & 1));
-    result = _mm_add_sd(result, result);
-  } else {
-    result = _mm_cvtsi64_sd(result, x);
-  }
-  return _mm_cvtsd_f64(result);
+__inline double wabt_convert_uint64_to_double(unsigned __int64 x)
+{
+    __m128d result = _mm_setzero_pd();
+    if (x & 0x8000000000000000ULL)
+    {
+        result = _mm_cvtsi64_sd(result, (x >> 1) | (x & 1));
+        result = _mm_add_sd(result, result);
+    }
+    else
+    {
+        result = _mm_cvtsi64_sd(result, x);
+    }
+    return _mm_cvtsd_f64(result);
 }
 
-__inline float wabt_convert_uint64_to_float(unsigned __int64 x) {
-  __m128 result = _mm_setzero_ps();
-  if (x & 0x8000000000000000ULL) {
-    result = _mm_cvtsi64_ss(result, (x >> 1) | (x & 1));
-    result = _mm_add_ss(result, result);
-  } else {
-    result = _mm_cvtsi64_ss(result, x);
-  }
-  return _mm_cvtss_f32(result);
+__inline float wabt_convert_uint64_to_float(unsigned __int64 x)
+{
+    __m128 result = _mm_setzero_ps();
+    if (x & 0x8000000000000000ULL)
+    {
+        result = _mm_cvtsi64_ss(result, (x >> 1) | (x & 1));
+        result = _mm_add_ss(result, result);
+    }
+    else
+    {
+        result = _mm_cvtsi64_ss(result, x);
+    }
+    return _mm_cvtss_f32(result);
 }
 
 #else

+ 2 - 0
lib/wabt/wabt.vcxproj

@@ -58,6 +58,7 @@
     <ClCompile Include="$(MSBuildThisFileDirectory)src\feature.cc" />
     <ClCompile Include="$(MSBuildThisFileDirectory)src\generate-names.cc" />
     <ClCompile Include="$(MSBuildThisFileDirectory)src\hash-util.cc" />
+    <ClCompile Include="$(MSBuildThisFileDirectory)src\filenames.cc" />
     <ClCompile Include="$(MSBuildThisFileDirectory)src\ir.cc" />
     <ClCompile Include="$(MSBuildThisFileDirectory)src\leb128.cc" />
     <ClCompile Include="$(MSBuildThisFileDirectory)src\lexer-source-line-finder.cc" />
@@ -102,6 +103,7 @@
     <ClInclude Include="src\feature.h" />
     <ClInclude Include="src\generate-names.h" />
     <ClInclude Include="src\hash-util.h" />
+    <ClInclude Include="src\filenames.h" />
     <ClInclude Include="src\intrusive-list.h" />
     <ClInclude Include="src\ir.h" />
     <ClInclude Include="src\leb128.h" />

+ 4 - 4
test/WasmSpec/testsuite/core/br.wast

@@ -147,7 +147,7 @@
   (table anyfunc (elem $f))
   (func (export "as-call_indirect-func") (result i32)
     (block (result i32)
-      (call_indirect $sig
+      (call_indirect (type $sig)
         (br 0 (i32.const 20))
         (i32.const 1) (i32.const 2) (i32.const 3)
       )
@@ -155,7 +155,7 @@
   )
   (func (export "as-call_indirect-first") (result i32)
     (block (result i32)
-      (call_indirect $sig
+      (call_indirect (type $sig)
         (i32.const 0)
         (br 0 (i32.const 21)) (i32.const 2) (i32.const 3)
       )
@@ -163,7 +163,7 @@
   )
   (func (export "as-call_indirect-mid") (result i32)
     (block (result i32)
-      (call_indirect $sig
+      (call_indirect (type $sig)
         (i32.const 0)
         (i32.const 1) (br 0 (i32.const 22)) (i32.const 3)
       )
@@ -171,7 +171,7 @@
   )
   (func (export "as-call_indirect-last") (result i32)
     (block (result i32)
-      (call_indirect $sig
+      (call_indirect (type $sig)
         (i32.const 0)
         (i32.const 1) (i32.const 2) (br 0 (i32.const 23))
       )

+ 4 - 4
test/WasmSpec/testsuite/core/br_table.wast

@@ -989,7 +989,7 @@
   (table anyfunc (elem $f))
   (func (export "as-call_indirect-first") (result i32)
     (block (result i32)
-      (call_indirect $sig
+      (call_indirect (type $sig)
         (br_table 0 (i32.const 20) (i32.const 1)) (i32.const 1) (i32.const 2)
         (i32.const 3)
       )
@@ -997,7 +997,7 @@
   )
   (func (export "as-call_indirect-mid") (result i32)
     (block (result i32)
-      (call_indirect $sig
+      (call_indirect (type $sig)
         (i32.const 0) (br_table 0 (i32.const 21) (i32.const 1)) (i32.const 2)
         (i32.const 3)
       )
@@ -1005,7 +1005,7 @@
   )
   (func (export "as-call_indirect-last") (result i32)
     (block (result i32)
-      (call_indirect $sig
+      (call_indirect (type $sig)
         (i32.const 0) (i32.const 1) (br_table 0 (i32.const 22) (i32.const 1))
         (i32.const 3)
       )
@@ -1013,7 +1013,7 @@
   )
   (func (export "as-call_indirect-func") (result i32)
     (block (result i32)
-      (call_indirect $sig
+      (call_indirect (type $sig)
         (i32.const 0) (i32.const 1) (i32.const 2)
         (br_table 0 (i32.const 23) (i32.const 1))
       )

+ 38 - 38
test/WasmSpec/testsuite/core/call_indirect.wast

@@ -54,49 +54,49 @@
 
   ;; Typing
 
-  (func (export "type-i32") (result i32) (call_indirect $out-i32 (i32.const 0)))
-  (func (export "type-i64") (result i64) (call_indirect $out-i64 (i32.const 1)))
-  (func (export "type-f32") (result f32) (call_indirect $out-f32 (i32.const 2)))
-  (func (export "type-f64") (result f64) (call_indirect $out-f64 (i32.const 3)))
+  (func (export "type-i32") (result i32) (call_indirect (type $out-i32) (i32.const 0)))
+  (func (export "type-i64") (result i64) (call_indirect (type $out-i64) (i32.const 1)))
+  (func (export "type-f32") (result f32) (call_indirect (type $out-f32) (i32.const 2)))
+  (func (export "type-f64") (result f64) (call_indirect (type $out-f64) (i32.const 3)))
 
   (func (export "type-index") (result i64)
-    (call_indirect $over-i64 (i64.const 100) (i32.const 5))
+    (call_indirect (type $over-i64) (i64.const 100) (i32.const 5))
   )
 
   (func (export "type-first-i32") (result i32)
-    (call_indirect $over-i32 (i32.const 32) (i32.const 4))
+    (call_indirect (type $over-i32) (i32.const 32) (i32.const 4))
   )
   (func (export "type-first-i64") (result i64)
-    (call_indirect $over-i64 (i64.const 64) (i32.const 5))
+    (call_indirect (type $over-i64) (i64.const 64) (i32.const 5))
   )
   (func (export "type-first-f32") (result f32)
-    (call_indirect $over-f32 (f32.const 1.32) (i32.const 6))
+    (call_indirect (type $over-f32) (f32.const 1.32) (i32.const 6))
   )
   (func (export "type-first-f64") (result f64)
-    (call_indirect $over-f64 (f64.const 1.64) (i32.const 7))
+    (call_indirect (type $over-f64) (f64.const 1.64) (i32.const 7))
   )
 
   (func (export "type-second-i32") (result i32)
-    (call_indirect $f32-i32 (f32.const 32.1) (i32.const 32) (i32.const 8))
+    (call_indirect (type $f32-i32) (f32.const 32.1) (i32.const 32) (i32.const 8))
   )
   (func (export "type-second-i64") (result i64)
-    (call_indirect $i32-i64 (i32.const 32) (i64.const 64) (i32.const 9))
+    (call_indirect (type $i32-i64) (i32.const 32) (i64.const 64) (i32.const 9))
   )
   (func (export "type-second-f32") (result f32)
-    (call_indirect $f64-f32 (f64.const 64) (f32.const 32) (i32.const 10))
+    (call_indirect (type $f64-f32) (f64.const 64) (f32.const 32) (i32.const 10))
   )
   (func (export "type-second-f64") (result f64)
-    (call_indirect $i64-f64 (i64.const 64) (f64.const 64.1) (i32.const 11))
+    (call_indirect (type $i64-f64) (i64.const 64) (f64.const 64.1) (i32.const 11))
   )
 
   ;; Dispatch
 
   (func (export "dispatch") (param i32 i64) (result i64)
-    (call_indirect $over-i64 (get_local 1) (get_local 0))
+    (call_indirect (type $over-i64) (get_local 1) (get_local 0))
   )
 
   (func (export "dispatch-structural") (param i32) (result i64)
-    (call_indirect $over-i64-duplicate (i64.const 9) (get_local 0))
+    (call_indirect (type $over-i64-duplicate) (i64.const 9) (get_local 0))
   )
 
   ;; Recursion
@@ -107,7 +107,7 @@
       (else
         (i64.mul
           (get_local 0)
-          (call_indirect $over-i64
+          (call_indirect (type $over-i64)
             (i64.sub (get_local 0) (i64.const 1))
             (i32.const 12)
           )
@@ -121,11 +121,11 @@
       (then (i64.const 1))
       (else
         (i64.add
-          (call_indirect $over-i64
+          (call_indirect (type $over-i64)
             (i64.sub (get_local 0) (i64.const 2))
             (i32.const 13)
           )
-          (call_indirect $over-i64
+          (call_indirect (type $over-i64)
             (i64.sub (get_local 0) (i64.const 1))
             (i32.const 13)
           )
@@ -138,7 +138,7 @@
     (if (result i32) (i32.eqz (get_local 0))
       (then (i32.const 44))
       (else
-        (call_indirect $over-i32
+        (call_indirect (type $over-i32)
           (i32.sub (get_local 0) (i32.const 1))
           (i32.const 15)
         )
@@ -149,7 +149,7 @@
     (if (result i32) (i32.eqz (get_local 0))
       (then (i32.const 99))
       (else
-        (call_indirect $over-i32
+        (call_indirect (type $over-i32)
           (i32.sub (get_local 0) (i32.const 1))
           (i32.const 14)
         )
@@ -166,10 +166,10 @@
   ;; implementations and be incompatible with implementations that don't do
   ;; it (or don't do it under the same circumstances).
 
-  (func $runaway (export "runaway") (call_indirect $proc (i32.const 16)))
+  (func $runaway (export "runaway") (call_indirect (type $proc) (i32.const 16)))
 
-  (func $mutual-runaway1 (export "mutual-runaway") (call_indirect $proc (i32.const 18)))
-  (func $mutual-runaway2 (call_indirect $proc (i32.const 17)))
+  (func $mutual-runaway1 (export "mutual-runaway") (call_indirect (type $proc) (i32.const 18)))
+  (func $mutual-runaway2 (call_indirect (type $proc) (i32.const 17)))
 )
 
 (assert_return (invoke "type-i32") (i32.const 0x132))
@@ -236,7 +236,7 @@
 (assert_invalid
   (module
     (type (func))
-    (func $no-table (call_indirect 0 (i32.const 0)))
+    (func $no-table (call_indirect (type 0) (i32.const 0)))
   )
   "unknown table"
 )
@@ -245,7 +245,7 @@
   (module
     (type (func))
     (table 0 anyfunc)
-    (func $type-void-vs-num (i32.eqz (call_indirect 0 (i32.const 0))))
+    (func $type-void-vs-num (i32.eqz (call_indirect (type 0) (i32.const 0))))
   )
   "type mismatch"
 )
@@ -253,7 +253,7 @@
   (module
     (type (func (result i64)))
     (table 0 anyfunc)
-    (func $type-num-vs-num (i32.eqz (call_indirect 0 (i32.const 0))))
+    (func $type-num-vs-num (i32.eqz (call_indirect (type 0) (i32.const 0))))
   )
   "type mismatch"
 )
@@ -262,7 +262,7 @@
   (module
     (type (func (param i32)))
     (table 0 anyfunc)
-    (func $arity-0-vs-1 (call_indirect 0 (i32.const 0)))
+    (func $arity-0-vs-1 (call_indirect (type 0) (i32.const 0)))
   )
   "type mismatch"
 )
@@ -270,7 +270,7 @@
   (module
     (type (func (param f64 i32)))
     (table 0 anyfunc)
-    (func $arity-0-vs-2 (call_indirect 0 (i32.const 0)))
+    (func $arity-0-vs-2 (call_indirect (type 0) (i32.const 0)))
   )
   "type mismatch"
 )
@@ -278,7 +278,7 @@
   (module
     (type (func))
     (table 0 anyfunc)
-    (func $arity-1-vs-0 (call_indirect 0 (i32.const 1) (i32.const 0)))
+    (func $arity-1-vs-0 (call_indirect (type 0) (i32.const 1) (i32.const 0)))
   )
   "type mismatch"
 )
@@ -287,7 +287,7 @@
     (type (func))
     (table 0 anyfunc)
     (func $arity-2-vs-0
-      (call_indirect 0 (f64.const 2) (i32.const 1) (i32.const 0))
+      (call_indirect (type 0) (f64.const 2) (i32.const 1) (i32.const 0))
     )
   )
   "type mismatch"
@@ -297,7 +297,7 @@
   (module
     (type (func (param i32)))
     (table 0 anyfunc)
-    (func $type-func-void-vs-i32 (call_indirect 0 (i32.const 1) (nop)))
+    (func $type-func-void-vs-i32 (call_indirect (type 0) (i32.const 1) (nop)))
   )
   "type mismatch"
 )
@@ -305,7 +305,7 @@
   (module
     (type (func (param i32)))
     (table 0 anyfunc)
-    (func $type-func-num-vs-i32 (call_indirect 0 (i32.const 0) (i64.const 1)))
+    (func $type-func-num-vs-i32 (call_indirect (type 0) (i32.const 0) (i64.const 1)))
   )
   "type mismatch"
 )
@@ -315,7 +315,7 @@
     (type (func (param i32 i32)))
     (table 0 anyfunc)
     (func $type-first-void-vs-num
-      (call_indirect 0 (nop) (i32.const 1) (i32.const 0))
+      (call_indirect (type 0) (nop) (i32.const 1) (i32.const 0))
     )
   )
   "type mismatch"
@@ -325,7 +325,7 @@
     (type (func (param i32 i32)))
     (table 0 anyfunc)
     (func $type-second-void-vs-num
-      (call_indirect 0 (i32.const 1) (nop) (i32.const 0))
+      (call_indirect (type 0) (i32.const 1) (nop) (i32.const 0))
     )
   )
   "type mismatch"
@@ -335,7 +335,7 @@
     (type (func (param i32 f64)))
     (table 0 anyfunc)
     (func $type-first-num-vs-num
-      (call_indirect 0 (f64.const 1) (i32.const 1) (i32.const 0))
+      (call_indirect (type 0) (f64.const 1) (i32.const 1) (i32.const 0))
     )
   )
   "type mismatch"
@@ -345,7 +345,7 @@
     (type (func (param f64 i32)))
     (table 0 anyfunc)
     (func $type-second-num-vs-num
-      (call_indirect 0 (i32.const 1) (f64.const 1) (i32.const 0))
+      (call_indirect (type 0) (i32.const 1) (f64.const 1) (i32.const 0))
     )
   )
   "type mismatch"
@@ -357,14 +357,14 @@
 (assert_invalid
   (module
     (table 0 anyfunc)
-    (func $unbound-type (call_indirect 1 (i32.const 0)))
+    (func $unbound-type (call_indirect (type 1) (i32.const 0)))
   )
   "unknown type"
 )
 (assert_invalid
   (module
     (table 0 anyfunc)
-    (func $large-type (call_indirect 1012321300 (i32.const 0)))
+    (func $large-type (call_indirect (type 1012321300) (i32.const 0)))
   )
   "unknown type"
 )

+ 7 - 7
test/WasmSpec/testsuite/core/elem.wast

@@ -20,10 +20,10 @@
   (func $const-i32-a (type $out-i32) (i32.const 65))
   (func $const-i32-b (type $out-i32) (i32.const 66))
   (func (export "call-7") (type $out-i32)
-    (call_indirect $out-i32 (i32.const 7))
+    (call_indirect (type $out-i32) (i32.const 7))
   )
   (func (export "call-9") (type $out-i32)
-    (call_indirect $out-i32 (i32.const 9))
+    (call_indirect (type $out-i32) (i32.const 9))
   )
 )
 
@@ -40,7 +40,7 @@
   (func $const-i32-a (type $out-i32) (i32.const 65))
   (func $const-i32-b (type $out-i32) (i32.const 66))
   (func (export "call-overwritten-element") (type $out-i32)
-    (call_indirect $out-i32 (i32.const 9))
+    (call_indirect (type $out-i32) (i32.const 9))
   )
 )
 
@@ -108,7 +108,7 @@
   (func $const-i32-a (type $out-i32) (i32.const 65))
   (func $const-i32-b (type $out-i32) (i32.const 66))
   (func (export "call-overwritten-element") (type $out-i32)
-    (call_indirect $out-i32 (i32.const 9))
+    (call_indirect (type $out-i32) (i32.const 9))
   )
 )
 
@@ -172,13 +172,13 @@
   (func $const-i32-a (type $out-i32) (i32.const 65))
   (func $const-i32-b (type $out-i32) (i32.const 66))
   (func (export "call-7") (type $out-i32)
-    (call_indirect $out-i32 (i32.const 7))
+    (call_indirect (type $out-i32) (i32.const 7))
   )
   (func (export "call-8") (type $out-i32)
-    (call_indirect $out-i32 (i32.const 8))
+    (call_indirect (type $out-i32) (i32.const 8))
   )
   (func (export "call-9") (type $out-i32)
-    (call_indirect $out-i32 (i32.const 9))
+    (call_indirect (type $out-i32) (i32.const 9))
   )
 )
 

+ 8 - 8
test/WasmSpec/testsuite/core/func.wast

@@ -333,24 +333,24 @@
   )
 
   (func (export "signature-explicit-reused")
-    (call_indirect $sig (i32.const 1))
-    (call_indirect $sig (i32.const 4))
+    (call_indirect (type $sig) (i32.const 1))
+    (call_indirect (type $sig) (i32.const 4))
   )
 
   (func (export "signature-implicit-reused")
     ;; The implicit index 3 in this test depends on the function and
     ;; type definitions, and may need adapting if they change.
-    (call_indirect 3
+    (call_indirect (type 3)
       (f64.const 0) (i64.const 0) (f64.const 0) (i64.const 0)
       (f64.const 0) (i64.const 0) (f32.const 0) (i32.const 0)
       (i32.const 0)
     )
-    (call_indirect 3
+    (call_indirect (type 3)
       (f64.const 0) (i64.const 0) (f64.const 0) (i64.const 0)
       (f64.const 0) (i64.const 0) (f32.const 0) (i32.const 0)
       (i32.const 2)
     )
-    (call_indirect 3
+    (call_indirect (type 3)
       (f64.const 0) (i64.const 0) (f64.const 0) (i64.const 0)
       (f64.const 0) (i64.const 0) (f32.const 0) (i32.const 0)
       (i32.const 3)
@@ -358,16 +358,16 @@
   )
 
   (func (export "signature-explicit-duplicate")
-    (call_indirect $empty-sig-duplicate (i32.const 1))
+    (call_indirect (type $empty-sig-duplicate) (i32.const 1))
   )
 
   (func (export "signature-implicit-duplicate")
-    (call_indirect $complex-sig-duplicate
+    (call_indirect (type $complex-sig-duplicate)
       (i64.const 0) (i64.const 0) (f64.const 0) (i64.const 0)
       (f64.const 0) (i64.const 0) (f32.const 0) (i32.const 0)
       (i32.const 5)
     )
-    (call_indirect $complex-sig-duplicate
+    (call_indirect (type $complex-sig-duplicate)
       (i64.const 0) (i64.const 0) (f64.const 0) (i64.const 0)
       (f64.const 0) (i64.const 0) (f32.const 0) (i32.const 0)
       (i32.const 6)

+ 3 - 3
test/WasmSpec/testsuite/core/func_ptrs.wast

@@ -60,11 +60,11 @@
   (func $u2 (type $U) (i32.const 5))
 
   (func (export "callt") (param $i i32) (result i32)
-    (call_indirect $T (get_local $i))
+    (call_indirect (type $T) (get_local $i))
   )
 
   (func (export "callu") (param $i i32) (result i32)
-    (call_indirect $U (get_local $i))
+    (call_indirect (type $U) (get_local $i))
   )
 )
 
@@ -98,7 +98,7 @@
   (func $t2 (type $T) (i32.const 2))
 
   (func (export "callt") (param $i i32) (result i32)
-    (call_indirect $T (get_local $i))
+    (call_indirect (type $T) (get_local $i))
   )
 )
 

+ 4 - 4
test/WasmSpec/testsuite/core/imports.wast

@@ -64,7 +64,7 @@
     (call $print_i32 (get_local $i))
     (call $print_i32-2 (get_local $i))
     (call $print_f32 (get_local $x))
-    (call_indirect $func_i32 (get_local $i) (i32.const 0))
+    (call_indirect (type $func_i32) (get_local $i) (i32.const 0))
   )
 
   (func (export "print64") (param $i i64)
@@ -80,7 +80,7 @@
     ;; (call $print_i64 (get_local $i))
     (call $print_f64 (get_local $x))
     (call $print_f64-2 (get_local $x))
-    (call_indirect $func_f64 (get_local $x) (i32.const 1))
+    (call_indirect (type $func_f64) (get_local $x) (i32.const 1))
   )
 )
 
@@ -265,7 +265,7 @@
   (import "spectest" "table" (table 10 20 anyfunc))
   (elem 0 (i32.const 1) $f $g)
 
-  (func (export "call") (param i32) (result i32) (call_indirect 0 (get_local 0)))
+  (func (export "call") (param i32) (result i32) (call_indirect (type 0) (get_local 0)))
   (func $f (result i32) (i32.const 11))
   (func $g (result i32) (i32.const 22))
 )
@@ -282,7 +282,7 @@
   (table (import "spectest" "table") 10 20 anyfunc)
   (elem 0 (i32.const 1) $f $g)
 
-  (func (export "call") (param i32) (result i32) (call_indirect 0 (get_local 0)))
+  (func (export "call") (param i32) (result i32) (call_indirect (type 0) (get_local 0)))
   (func $f (result i32) (i32.const 11))
   (func $g (result i32) (i32.const 22))
 )

+ 4 - 4
test/WasmSpec/testsuite/core/left-to-right.wast

@@ -88,7 +88,7 @@
   (func (export "i32_store8") (result i32) (call $reset) (i32.store8 (call $i32_left) (call $i32_right)) (call $get))
   (func (export "i32_store16") (result i32) (call $reset) (i32.store16 (call $i32_left) (call $i32_right)) (call $get))
   (func (export "i32_call") (result i32) (call $reset) (call $i32_dummy (call $i32_left) (call $i32_right)) (call $get))
-  (func (export "i32_call_indirect") (result i32) (call $reset) (drop (call_indirect $i32_T (call $i32_left) (call $i32_right) (call $i32_callee))) (call $get))
+  (func (export "i32_call_indirect") (result i32) (call $reset) (drop (call_indirect (type $i32_T) (call $i32_left) (call $i32_right) (call $i32_callee))) (call $get))
   (func (export "i32_select") (result i32) (call $reset) (drop (select (call $i32_left) (call $i32_right) (call $i32_bool))) (call $get))
 
   (func (export "i64_add") (result i32) (call $reset) (drop (i64.add (call $i64_left) (call $i64_right))) (call $get))
@@ -119,7 +119,7 @@
   (func (export "i64_store16") (result i32) (call $reset) (i64.store16 (call $i32_left) (call $i64_right)) (call $get))
   (func (export "i64_store32") (result i32) (call $reset) (i64.store32 (call $i32_left) (call $i64_right)) (call $get))
   (func (export "i64_call") (result i32) (call $reset) (call $i64_dummy (call $i64_left) (call $i64_right)) (call $get))
-  (func (export "i64_call_indirect") (result i32) (call $reset) (drop (call_indirect $i64_T (call $i64_left) (call $i64_right) (call $i64_callee))) (call $get))
+  (func (export "i64_call_indirect") (result i32) (call $reset) (drop (call_indirect (type $i64_T) (call $i64_left) (call $i64_right) (call $i64_callee))) (call $get))
   (func (export "i64_select") (result i32) (call $reset) (drop (select (call $i64_left) (call $i64_right) (call $i64_bool))) (call $get))
 
   (func (export "f32_add") (result i32) (call $reset) (drop (f32.add (call $f32_left) (call $f32_right))) (call $get))
@@ -137,7 +137,7 @@
   (func (export "f32_max") (result i32) (call $reset) (drop (f32.max (call $f32_left) (call $f32_right))) (call $get))
   (func (export "f32_store") (result i32) (call $reset) (f32.store (call $i32_left) (call $f32_right)) (call $get))
   (func (export "f32_call") (result i32) (call $reset) (call $f32_dummy (call $f32_left) (call $f32_right)) (call $get))
-  (func (export "f32_call_indirect") (result i32) (call $reset) (drop (call_indirect $f32_T (call $f32_left) (call $f32_right) (call $f32_callee))) (call $get))
+  (func (export "f32_call_indirect") (result i32) (call $reset) (drop (call_indirect (type $f32_T) (call $f32_left) (call $f32_right) (call $f32_callee))) (call $get))
   (func (export "f32_select") (result i32) (call $reset) (drop (select (call $f32_left) (call $f32_right) (call $f32_bool))) (call $get))
 
   (func (export "f64_add") (result i32) (call $reset) (drop (f64.add (call $f64_left) (call $f64_right))) (call $get))
@@ -155,7 +155,7 @@
   (func (export "f64_max") (result i32) (call $reset) (drop (f64.max (call $f64_left) (call $f64_right))) (call $get))
   (func (export "f64_store") (result i32) (call $reset) (f64.store (call $i32_left) (call $f64_right)) (call $get))
   (func (export "f64_call") (result i32) (call $reset) (call $f64_dummy (call $f64_left) (call $f64_right)) (call $get))
-  (func (export "f64_call_indirect") (result i32) (call $reset) (drop (call_indirect $f64_T (call $f64_left) (call $f64_right) (call $f64_callee))) (call $get))
+  (func (export "f64_call_indirect") (result i32) (call $reset) (drop (call_indirect (type $f64_T) (call $f64_left) (call $f64_right) (call $f64_callee))) (call $get))
   (func (export "f64_select") (result i32) (call $reset) (drop (select (call $f64_left) (call $f64_right) (call $f64_bool))) (call $get))
 
   (func (export "br_if") (result i32)

+ 3 - 3
test/WasmSpec/testsuite/core/linking.wast

@@ -71,7 +71,7 @@
   (func (export "h") (result i32) (i32.const -4))
 
   (func (export "call") (param i32) (result i32)
-    (call_indirect 0 (get_local 0))
+    (call_indirect (type 0) (get_local 0))
   )
 )
 (register "Mt" $Mt)
@@ -91,7 +91,7 @@
     (call $f (get_local 0))
   )
   (func (export "call") (param i32) (result i32)
-    (call_indirect 1 (get_local 0))
+    (call_indirect (type 1) (get_local 0))
   )
 )
 
@@ -127,7 +127,7 @@
   (func $i (result i32) (i32.const 6))
 
   (func (export "call") (param i32) (result i32)
-    (call_indirect 0 (get_local 0))
+    (call_indirect (type 0) (get_local 0))
   )
 )
 

+ 4 - 4
test/WasmSpec/testsuite/core/return.wast

@@ -124,16 +124,16 @@
   (type $sig (func (param i32 i32 i32) (result i32)))
   (table anyfunc (elem $f))
   (func (export "as-call_indirect-func") (result i32)
-    (call_indirect $sig (return (i32.const 20)) (i32.const 1) (i32.const 2) (i32.const 3))
+    (call_indirect (type $sig) (return (i32.const 20)) (i32.const 1) (i32.const 2) (i32.const 3))
   )
   (func (export "as-call_indirect-first") (result i32)
-    (call_indirect $sig (i32.const 0) (return (i32.const 21)) (i32.const 2) (i32.const 3))
+    (call_indirect (type $sig) (i32.const 0) (return (i32.const 21)) (i32.const 2) (i32.const 3))
   )
   (func (export "as-call_indirect-mid") (result i32)
-    (call_indirect $sig (i32.const 0) (i32.const 1) (return (i32.const 22)) (i32.const 3))
+    (call_indirect (type $sig) (i32.const 0) (i32.const 1) (return (i32.const 22)) (i32.const 3))
   )
   (func (export "as-call_indirect-last") (result i32)
-    (call_indirect $sig (i32.const 0) (i32.const 1) (i32.const 2) (return (i32.const 23)))
+    (call_indirect (type $sig) (i32.const 0) (i32.const 1) (i32.const 2) (return (i32.const 23)))
   )
 
   (func (export "as-set_local-value") (result i32) (local f32)

+ 2 - 2
test/WasmSpec/testsuite/core/typecheck.wast

@@ -234,7 +234,7 @@
     (func (type 0))
     (table 0 anyfunc)
     (func
-      (call_indirect 0 (i32.const 0) (f32.const 0))))
+      (call_indirect (type 0) (i32.const 0) (f32.const 0))))
   "type mismatch")
 
 ;; call_indirect index
@@ -243,7 +243,7 @@
     (type (func))
     (func (type 0))
     (table 0 anyfunc)
-    (func (call_indirect 0 (f32.const 0))))
+    (func (call_indirect (type 0) (f32.const 0))))
   "type mismatch")
 
 ;; return

+ 4 - 4
test/WasmSpec/testsuite/core/unreachable.wast

@@ -131,16 +131,16 @@
   (type $sig (func (param i32 i32 i32)))
   (table anyfunc (elem $dummy3))
   (func (export "as-call_indirect-func")
-    (call_indirect $sig (unreachable) (i32.const 1) (i32.const 2) (i32.const 3))
+    (call_indirect (type $sig) (unreachable) (i32.const 1) (i32.const 2) (i32.const 3))
   )
   (func (export "as-call_indirect-first")
-    (call_indirect $sig (i32.const 0) (unreachable) (i32.const 2) (i32.const 3))
+    (call_indirect (type $sig) (i32.const 0) (unreachable) (i32.const 2) (i32.const 3))
   )
   (func (export "as-call_indirect-mid")
-    (call_indirect $sig (i32.const 0) (i32.const 1) (unreachable) (i32.const 3))
+    (call_indirect (type $sig) (i32.const 0) (i32.const 1) (unreachable) (i32.const 3))
   )
   (func (export "as-call_indirect-last")
-    (call_indirect $sig (i32.const 0) (i32.const 1) (i32.const 2) (unreachable))
+    (call_indirect (type $sig) (i32.const 0) (i32.const 1) (i32.const 2) (unreachable))
   )
 
   (func (export "as-set_local-value") (local f32)

+ 1 - 1
test/wasm/basic.wast

@@ -15,7 +15,7 @@
         (if (i32.ge_s (i32.const 26) (i32.const 25))
             (set_local 0 (i32.add (get_local 0) (i32.const 4)))
         )
-        (set_local 0 (i32.add (get_local 0) (call_indirect $t1 (i32.const 0))))
+        (set_local 0 (i32.add (get_local 0) (call_indirect (type $t1) (i32.const 0))))
         (if_else (i32.ge_s (i32.const 22) (i32.const 25))
             (set_local 0 (i32.add (get_local 0) (i32.const 4)))
             (set_local 0 (i32.sub (get_local 0) (i32.const 5)))

+ 1 - 1
test/wasm/inlining.js

@@ -25,7 +25,7 @@ WebAssembly.instantiate(WebAssembly.wabt.convertWast2Wasm(`
         (if (i32.ge_s (i32.const 26) (i32.const 25))
             (set_local 0 (i32.add (get_local 0) (i32.const 4)))
         )
-        (set_local 0 (i32.add (get_local 0) (call_indirect $t1 (i32.const 0))))
+        (set_local 0 (i32.add (get_local 0) (call_indirect (type $t1) (i32.const 0))))
         (if (i32.ge_s (i32.const 22) (i32.const 25))
             (set_local 0 (i32.add (get_local 0) (i32.const 4)))
             (set_local 0 (i32.sub (get_local 0) (i32.const 5)))

+ 1 - 1
test/wasm/table.wast

@@ -25,6 +25,6 @@
   (func $g8 (result i32) (i32.const 85))
 
   (func (export "call") (param i32) (result i32)
-    (call_indirect 1 (get_local 0))
+    (call_indirect (type 1) (get_local 0))
   )
 )

+ 2 - 2
test/wasm/wasts/api.wast

@@ -20,9 +20,9 @@
   (export "g2" (global $g2))
   (export "table" (table $table))
   (export "fn2" (func $fn2))
-  (func (export "call_i32") (param i32) (result i32) (call_indirect $t1 (get_local 0)))
+  (func (export "call_i32") (param i32) (result i32) (call_indirect (type $t1) (get_local 0)))
   (export "mem" (memory $mem))
-  (func (export "call_f32") (param i32) (result f32) (call_indirect $t2 (get_local 0)))
+  (func (export "call_f32") (param i32) (result f32) (call_indirect (type $t2) (get_local 0)))
   (export "g3" (global $g1))
   (func (export "load") (param i32) (result i32) (i32.load (get_local 0)))
 )

+ 4 - 4
test/wasm/wasts/table_imports.wast

@@ -27,16 +27,16 @@
     )
 
     (func (export "binopI32") (param i32 i32 i32) (result i32)
-        (call_indirect $binopI32 (get_local 0) (get_local 1) (get_local 2))
+        (call_indirect (type $binopI32) (get_local 0) (get_local 1) (get_local 2))
     )
     (func (export "binopI64") (param i64 i64 i32) (result i64)
-        (call_indirect $binopI64 (get_local 0) (get_local 1) (get_local 2))
+        (call_indirect (type $binopI64) (get_local 0) (get_local 1) (get_local 2))
     )
     (func (export "binopF32") (param f32 f32 i32) (result f32)
-        (call_indirect $binopF32 (get_local 0) (get_local 1) (get_local 2))
+        (call_indirect (type $binopF32) (get_local 0) (get_local 1) (get_local 2))
     )
     (func (export "binopF64") (param f64 f64 i32) (result f64)
-        (call_indirect $binopF64 (get_local 0) (get_local 1) (get_local 2))
+        (call_indirect (type $binopF64) (get_local 0) (get_local 1) (get_local 2))
     )
 
     (table anyfunc (elem