LCOV - code coverage report
Current view: top level - src/wasm - wasm-opcodes.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 195 207 94.2 %
Date: 2017-10-20 Functions: 8 11 72.7 %

          Line data    Source code
       1             : // Copyright 2015 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #include "src/wasm/wasm-opcodes.h"
       6             : 
       7             : #include <array>
       8             : 
       9             : #include "src/base/template-utils.h"
      10             : #include "src/messages.h"
      11             : #include "src/runtime/runtime.h"
      12             : #include "src/signature.h"
      13             : 
      14             : namespace v8 {
      15             : namespace internal {
      16             : namespace wasm {
      17             : 
      18             : #define CASE_OP(name, str) \
      19             :   case kExpr##name:        \
      20             :     return str;
      21             : #define CASE_I32_OP(name, str) CASE_OP(I32##name, "i32." str)
      22             : #define CASE_I64_OP(name, str) CASE_OP(I64##name, "i64." str)
      23             : #define CASE_F32_OP(name, str) CASE_OP(F32##name, "f32." str)
      24             : #define CASE_F64_OP(name, str) CASE_OP(F64##name, "f64." str)
      25             : #define CASE_F32x4_OP(name, str) CASE_OP(F32x4##name, "f32x4." str)
      26             : #define CASE_I32x4_OP(name, str) CASE_OP(I32x4##name, "i32x4." str)
      27             : #define CASE_I16x8_OP(name, str) CASE_OP(I16x8##name, "i16x8." str)
      28             : #define CASE_I8x16_OP(name, str) CASE_OP(I8x16##name, "i8x16." str)
      29             : #define CASE_S128_OP(name, str) CASE_OP(S128##name, "s128." str)
      30             : #define CASE_S32x4_OP(name, str) CASE_OP(S32x4##name, "s32x4." str)
      31             : #define CASE_S16x8_OP(name, str) CASE_OP(S16x8##name, "s16x8." str)
      32             : #define CASE_S8x16_OP(name, str) CASE_OP(S8x16##name, "s8x16." str)
      33             : #define CASE_S1x4_OP(name, str) CASE_OP(S1x4##name, "s1x4." str)
      34             : #define CASE_S1x8_OP(name, str) CASE_OP(S1x8##name, "s1x8." str)
      35             : #define CASE_S1x16_OP(name, str) CASE_OP(S1x16##name, "s1x16." str)
      36             : #define CASE_INT_OP(name, str) CASE_I32_OP(name, str) CASE_I64_OP(name, str)
      37             : #define CASE_FLOAT_OP(name, str) CASE_F32_OP(name, str) CASE_F64_OP(name, str)
      38             : #define CASE_ALL_OP(name, str) CASE_FLOAT_OP(name, str) CASE_INT_OP(name, str)
      39             : #define CASE_SIMD_OP(name, str)                                              \
      40             :   CASE_F32x4_OP(name, str) CASE_I32x4_OP(name, str) CASE_I16x8_OP(name, str) \
      41             :       CASE_I8x16_OP(name, str)
      42             : #define CASE_SIMDI_OP(name, str) \
      43             :   CASE_I32x4_OP(name, str) CASE_I16x8_OP(name, str) CASE_I8x16_OP(name, str)
      44             : #define CASE_SIGN_OP(TYPE, name, str) \
      45             :   CASE_##TYPE##_OP(name##S, str "_s") CASE_##TYPE##_OP(name##U, str "_u")
      46             : #define CASE_UNSIGNED_OP(TYPE, name, str) CASE_##TYPE##_OP(name##U, str "_u")
      47             : #define CASE_ALL_SIGN_OP(name, str) \
      48             :   CASE_FLOAT_OP(name, str) CASE_SIGN_OP(INT, name, str)
      49             : #define CASE_CONVERT_OP(name, RES, SRC, src_suffix, str) \
      50             :   CASE_##RES##_OP(U##name##SRC, str "_u/" src_suffix)    \
      51             :       CASE_##RES##_OP(S##name##SRC, str "_s/" src_suffix)
      52             : #define CASE_L32_OP(name, str)          \
      53             :   CASE_SIGN_OP(I32, name##8, str "8")   \
      54             :   CASE_SIGN_OP(I32, name##16, str "16") \
      55             :   CASE_I32_OP(name, str "32")
      56             : #define CASE_U32_OP(name, str)            \
      57             :   CASE_I32_OP(name, str "32")             \
      58             :   CASE_UNSIGNED_OP(I32, name##8, str "8") \
      59             :   CASE_UNSIGNED_OP(I32, name##16, str "16")
      60             : 
      61       34102 : const char* WasmOpcodes::OpcodeName(WasmOpcode opcode) {
      62       34102 :   switch (opcode) {
      63             :     // clang-format off
      64             : 
      65             :     // Standard opcodes
      66          53 :     CASE_INT_OP(Eqz, "eqz")
      67         381 :     CASE_ALL_OP(Eq, "eq")
      68          81 :     CASE_ALL_OP(Ne, "ne")
      69         145 :     CASE_ALL_OP(Add, "add")
      70         141 :     CASE_ALL_OP(Sub, "sub")
      71         141 :     CASE_ALL_OP(Mul, "mul")
      72         141 :     CASE_ALL_SIGN_OP(Lt, "lt")
      73          81 :     CASE_ALL_SIGN_OP(Gt, "gt")
      74         141 :     CASE_ALL_SIGN_OP(Le, "le")
      75          81 :     CASE_ALL_SIGN_OP(Ge, "ge")
      76          33 :     CASE_INT_OP(Clz, "clz")
      77          93 :     CASE_INT_OP(Ctz, "ctz")
      78          33 :     CASE_INT_OP(Popcnt, "popcnt")
      79         141 :     CASE_ALL_SIGN_OP(Div, "div")
      80         144 :     CASE_SIGN_OP(INT, Rem, "rem")
      81         145 :     CASE_INT_OP(And, "and")
      82         144 :     CASE_INT_OP(Ior, "or")
      83         144 :     CASE_INT_OP(Xor, "xor")
      84         144 :     CASE_INT_OP(Shl, "shl")
      85         144 :     CASE_SIGN_OP(INT, Shr, "shr")
      86          81 :     CASE_INT_OP(Rol, "rol")
      87          81 :     CASE_INT_OP(Ror, "ror")
      88          33 :     CASE_FLOAT_OP(Abs, "abs")
      89          73 :     CASE_FLOAT_OP(Neg, "neg")
      90          33 :     CASE_FLOAT_OP(Ceil, "ceil")
      91          33 :     CASE_FLOAT_OP(Floor, "floor")
      92          33 :     CASE_FLOAT_OP(Trunc, "trunc")
      93          33 :     CASE_FLOAT_OP(NearestInt, "nearest")
      94          33 :     CASE_FLOAT_OP(Sqrt, "sqrt")
      95          81 :     CASE_FLOAT_OP(Min, "min")
      96          81 :     CASE_FLOAT_OP(Max, "max")
      97          81 :     CASE_FLOAT_OP(CopySign, "copysign")
      98          33 :     CASE_I32_OP(ConvertI64, "wrap/i64")
      99          45 :     CASE_CONVERT_OP(Convert, INT, F32, "f32", "trunc")
     100          45 :     CASE_CONVERT_OP(Convert, INT, F64, "f64", "trunc")
     101          33 :     CASE_CONVERT_OP(Convert, I64, I32, "i32", "extend")
     102          45 :     CASE_CONVERT_OP(Convert, F32, I32, "i32", "convert")
     103          33 :     CASE_CONVERT_OP(Convert, F32, I64, "i64", "convert")
     104          45 :     CASE_F32_OP(ConvertF64, "demote/f64")
     105          55 :     CASE_CONVERT_OP(Convert, F64, I32, "i32", "convert")
     106          33 :     CASE_CONVERT_OP(Convert, F64, I64, "i64", "convert")
     107          45 :     CASE_F64_OP(ConvertF32, "promote/f32")
     108          33 :     CASE_I32_OP(ReinterpretF32, "reinterpret/f32")
     109          33 :     CASE_I64_OP(ReinterpretF64, "reinterpret/f64")
     110          33 :     CASE_F32_OP(ReinterpretI32, "reinterpret/i32")
     111          33 :     CASE_F64_OP(ReinterpretI64, "reinterpret/i64")
     112           1 :     CASE_OP(Unreachable, "unreachable")
     113          35 :     CASE_OP(Nop, "nop")
     114          25 :     CASE_OP(Block, "block")
     115           6 :     CASE_OP(Loop, "loop")
     116         143 :     CASE_OP(If, "if")
     117           1 :     CASE_OP(Else, "else")
     118           1 :     CASE_OP(End, "end")
     119           6 :     CASE_OP(Br, "br")
     120         174 :     CASE_OP(BrIf, "br_if")
     121         102 :     CASE_OP(BrTable, "br_table")
     122         364 :     CASE_OP(Return, "return")
     123         191 :     CASE_OP(CallFunction, "call")
     124         221 :     CASE_OP(CallIndirect, "call_indirect")
     125          26 :     CASE_OP(Drop, "drop")
     126          77 :     CASE_OP(Select, "select")
     127       12774 :     CASE_OP(GetLocal, "get_local")
     128         270 :     CASE_OP(SetLocal, "set_local")
     129         263 :     CASE_OP(TeeLocal, "tee_local")
     130           1 :     CASE_OP(GetGlobal, "get_global")
     131          17 :     CASE_OP(SetGlobal, "set_global")
     132        2500 :     CASE_ALL_OP(Const, "const")
     133           1 :     CASE_OP(MemorySize, "current_memory")
     134          22 :     CASE_OP(GrowMemory, "grow_memory")
     135          21 :     CASE_ALL_OP(LoadMem, "load")
     136          21 :     CASE_SIGN_OP(INT, LoadMem8, "load8")
     137          21 :     CASE_SIGN_OP(INT, LoadMem16, "load16")
     138          21 :     CASE_SIGN_OP(I64, LoadMem32, "load32")
     139           1 :     CASE_S128_OP(LoadMem, "load128")
     140          44 :     CASE_ALL_OP(StoreMem, "store")
     141          47 :     CASE_INT_OP(StoreMem8, "store8")
     142          47 :     CASE_INT_OP(StoreMem16, "store16")
     143          41 :     CASE_I64_OP(StoreMem32, "store32")
     144           1 :     CASE_S128_OP(StoreMem, "store128")
     145             : 
     146             :     // Non-standard opcodes.
     147           1 :     CASE_OP(Try, "try")
     148           1 :     CASE_OP(Throw, "throw")
     149           1 :     CASE_OP(Rethrow, "rethrow")
     150           2 :     CASE_OP(Catch, "catch")
     151           1 :     CASE_OP(CatchAll, "catch_all")
     152             : 
     153             :     // asm.js-only opcodes.
     154          13 :     CASE_F64_OP(Acos, "acos")
     155          13 :     CASE_F64_OP(Asin, "asin")
     156          13 :     CASE_F64_OP(Atan, "atan")
     157          13 :     CASE_F64_OP(Cos, "cos")
     158          13 :     CASE_F64_OP(Sin, "sin")
     159          13 :     CASE_F64_OP(Tan, "tan")
     160          13 :     CASE_F64_OP(Exp, "exp")
     161          13 :     CASE_F64_OP(Log, "log")
     162          61 :     CASE_F64_OP(Atan2, "atan2")
     163          61 :     CASE_F64_OP(Pow, "pow")
     164          61 :     CASE_F64_OP(Mod, "mod")
     165          13 :     CASE_F32_OP(AsmjsLoadMem, "asmjs_load")
     166          13 :     CASE_F64_OP(AsmjsLoadMem, "asmjs_load")
     167          13 :     CASE_L32_OP(AsmjsLoadMem, "asmjs_load")
     168          61 :     CASE_I32_OP(AsmjsStoreMem, "asmjs_store")
     169          61 :     CASE_F32_OP(AsmjsStoreMem, "asmjs_store")
     170          61 :     CASE_F64_OP(AsmjsStoreMem, "asmjs_store")
     171          61 :     CASE_I32_OP(AsmjsStoreMem8, "asmjs_store8")
     172          61 :     CASE_I32_OP(AsmjsStoreMem16, "asmjs_store16")
     173          61 :     CASE_SIGN_OP(I32, AsmjsDiv, "asmjs_div")
     174          61 :     CASE_SIGN_OP(I32, AsmjsRem, "asmjs_rem")
     175          13 :     CASE_I32_OP(AsmjsSConvertF32, "asmjs_convert_s/f32")
     176          13 :     CASE_I32_OP(AsmjsUConvertF32, "asmjs_convert_u/f32")
     177          13 :     CASE_I32_OP(AsmjsSConvertF64, "asmjs_convert_s/f64")
     178          13 :     CASE_I32_OP(AsmjsUConvertF64, "asmjs_convert_u/f64")
     179             : 
     180             :     // SIMD opcodes.
     181           1 :     CASE_SIMD_OP(Splat, "splat")
     182           1 :     CASE_SIMD_OP(Neg, "neg")
     183           1 :     CASE_SIMD_OP(Eq, "eq")
     184           1 :     CASE_SIMD_OP(Ne, "ne")
     185           1 :     CASE_SIMD_OP(Add, "add")
     186           1 :     CASE_SIMD_OP(Sub, "sub")
     187           1 :     CASE_SIMD_OP(Mul, "mul")
     188           1 :     CASE_F32x4_OP(Abs, "abs")
     189           1 :     CASE_F32x4_OP(AddHoriz, "add_horizontal")
     190           1 :     CASE_F32x4_OP(RecipApprox, "recip_approx")
     191           1 :     CASE_F32x4_OP(RecipSqrtApprox, "recip_sqrt_approx")
     192           1 :     CASE_F32x4_OP(Min, "min")
     193           1 :     CASE_F32x4_OP(Max, "max")
     194           1 :     CASE_F32x4_OP(Lt, "lt")
     195           1 :     CASE_F32x4_OP(Le, "le")
     196           1 :     CASE_F32x4_OP(Gt, "gt")
     197           1 :     CASE_F32x4_OP(Ge, "ge")
     198           1 :     CASE_CONVERT_OP(Convert, F32x4, I32x4, "i32", "convert")
     199           1 :     CASE_CONVERT_OP(Convert, I32x4, F32x4, "f32", "convert")
     200           1 :     CASE_CONVERT_OP(Convert, I32x4, I16x8Low, "i32", "convert")
     201           1 :     CASE_CONVERT_OP(Convert, I32x4, I16x8High, "i32", "convert")
     202           1 :     CASE_CONVERT_OP(Convert, I16x8, I32x4, "i32", "convert")
     203           1 :     CASE_CONVERT_OP(Convert, I16x8, I8x16Low, "i32", "convert")
     204           1 :     CASE_CONVERT_OP(Convert, I16x8, I8x16High, "i32", "convert")
     205           1 :     CASE_CONVERT_OP(Convert, I8x16, I16x8, "i32", "convert")
     206           1 :     CASE_F32x4_OP(ExtractLane, "extract_lane")
     207           1 :     CASE_F32x4_OP(ReplaceLane, "replace_lane")
     208           1 :     CASE_SIMDI_OP(ExtractLane, "extract_lane")
     209           1 :     CASE_SIMDI_OP(ReplaceLane, "replace_lane")
     210           1 :     CASE_SIGN_OP(SIMDI, Min, "min")
     211           1 :     CASE_SIGN_OP(SIMDI, Max, "max")
     212           1 :     CASE_SIGN_OP(SIMDI, Lt, "lt")
     213           1 :     CASE_SIGN_OP(SIMDI, Le, "le")
     214           1 :     CASE_SIGN_OP(SIMDI, Gt, "gt")
     215           1 :     CASE_SIGN_OP(SIMDI, Ge, "ge")
     216           1 :     CASE_SIGN_OP(SIMDI, Shr, "shr")
     217           1 :     CASE_SIMDI_OP(Shl, "shl")
     218           1 :     CASE_I32x4_OP(AddHoriz, "add_horizontal")
     219           1 :     CASE_I16x8_OP(AddHoriz, "add_horizontal")
     220           1 :     CASE_SIGN_OP(I16x8, AddSaturate, "add_saturate")
     221           1 :     CASE_SIGN_OP(I8x16, AddSaturate, "add_saturate")
     222           1 :     CASE_SIGN_OP(I16x8, SubSaturate, "sub_saturate")
     223           1 :     CASE_SIGN_OP(I8x16, SubSaturate, "sub_saturate")
     224           1 :     CASE_S128_OP(And, "and")
     225           1 :     CASE_S128_OP(Or, "or")
     226           1 :     CASE_S128_OP(Xor, "xor")
     227           1 :     CASE_S128_OP(Not, "not")
     228           1 :     CASE_S128_OP(Select, "select")
     229           1 :     CASE_S8x16_OP(Shuffle, "shuffle")
     230           1 :     CASE_S1x4_OP(AnyTrue, "any_true")
     231           1 :     CASE_S1x4_OP(AllTrue, "all_true")
     232           1 :     CASE_S1x8_OP(AnyTrue, "any_true")
     233           1 :     CASE_S1x8_OP(AllTrue, "all_true")
     234           1 :     CASE_S1x16_OP(AnyTrue, "any_true")
     235           1 :     CASE_S1x16_OP(AllTrue, "all_true")
     236             : 
     237             :     // Atomic operations.
     238           7 :     CASE_U32_OP(AtomicLoad, "atomic_load")
     239           7 :     CASE_U32_OP(AtomicStore, "atomic_store")
     240           1 :     CASE_U32_OP(AtomicAdd, "atomic_add")
     241           1 :     CASE_U32_OP(AtomicSub, "atomic_sub")
     242           1 :     CASE_U32_OP(AtomicAnd, "atomic_and")
     243           1 :     CASE_U32_OP(AtomicOr, "atomic_or")
     244           1 :     CASE_U32_OP(AtomicXor, "atomic_xor")
     245           1 :     CASE_U32_OP(AtomicExchange, "atomic_xchng")
     246           1 :     CASE_U32_OP(AtomicCompareExchange, "atomic_cmpxchng")
     247             : 
     248          12 :     default : return "unknown";
     249             :     // clang-format on
     250             :   }
     251             : }
     252             : 
     253             : #undef CASE_OP
     254             : #undef CASE_I32_OP
     255             : #undef CASE_I64_OP
     256             : #undef CASE_F32_OP
     257             : #undef CASE_F64_OP
     258             : #undef CASE_F32x4_OP
     259             : #undef CASE_I32x4_OP
     260             : #undef CASE_I16x8_OP
     261             : #undef CASE_I8x16_OP
     262             : #undef CASE_S128_OP
     263             : #undef CASE_S32x4_OP
     264             : #undef CASE_S16x8_OP
     265             : #undef CASE_S8x16_OP
     266             : #undef CASE_S1x4_OP
     267             : #undef CASE_S1x8_OP
     268             : #undef CASE_S1x16_OP
     269             : #undef CASE_INT_OP
     270             : #undef CASE_FLOAT_OP
     271             : #undef CASE_ALL_OP
     272             : #undef CASE_SIMD_OP
     273             : #undef CASE_SIMDI_OP
     274             : #undef CASE_SIGN_OP
     275             : #undef CASE_UNSIGNED_OP
     276             : #undef CASE_ALL_SIGN_OP
     277             : #undef CASE_CONVERT_OP
     278             : #undef CASE_L32_OP
     279             : #undef CASE_U32_OP
     280             : 
     281      174707 : bool WasmOpcodes::IsPrefixOpcode(WasmOpcode opcode) {
     282      174707 :   switch (opcode) {
     283             : #define CHECK_PREFIX(name, opcode) case k##name##Prefix:
     284             :     FOREACH_PREFIX(CHECK_PREFIX)
     285             : #undef CHECK_PREFIX
     286             :     return true;
     287             :     default:
     288      174707 :       return false;
     289             :   }
     290             : }
     291             : 
     292           0 : bool WasmOpcodes::IsControlOpcode(WasmOpcode opcode) {
     293           0 :   switch (opcode) {
     294             : #define CHECK_OPCODE(name, opcode, _) case kExpr##name:
     295             :     FOREACH_CONTROL_OPCODE(CHECK_OPCODE)
     296             : #undef CHECK_OPCODE
     297             :     return true;
     298             :     default:
     299           0 :       return false;
     300             :   }
     301             : }
     302             : 
     303      213311 : bool WasmOpcodes::IsUnconditionalJump(WasmOpcode opcode) {
     304      213311 :   switch (opcode) {
     305             :     case kExprUnreachable:
     306             :     case kExprBr:
     307             :     case kExprBrTable:
     308             :     case kExprReturn:
     309             :       return true;
     310             :     default:
     311      181160 :       return false;
     312             :   }
     313             : }
     314             : 
     315           0 : std::ostream& operator<<(std::ostream& os, const FunctionSig& sig) {
     316           0 :   if (sig.return_count() == 0) os << "v";
     317           0 :   for (auto ret : sig.returns()) {
     318             :     os << WasmOpcodes::ShortNameOf(ret);
     319             :   }
     320           0 :   os << "_";
     321           0 :   if (sig.parameter_count() == 0) os << "v";
     322           0 :   for (auto param : sig.parameters()) {
     323             :     os << WasmOpcodes::ShortNameOf(param);
     324             :   }
     325           0 :   return os;
     326             : }
     327             : 
     328      173668 : bool IsJSCompatibleSignature(const FunctionSig* sig) {
     329      334065 :   for (auto type : sig->all()) {
     330      161307 :     if (type == wasm::kWasmI64 || type == wasm::kWasmS128) return false;
     331             :   }
     332             :   return true;
     333             : }
     334             : 
     335             : namespace {
     336             : 
     337             : #define DECLARE_SIG_ENUM(name, ...) kSigEnum_##name,
     338             : enum WasmOpcodeSig : byte {
     339             :   kSigEnum_None,
     340             :   FOREACH_SIGNATURE(DECLARE_SIG_ENUM)
     341             : };
     342             : #undef DECLARE_SIG_ENUM
     343             : 
     344             : #define DECLARE_SIG(name, ...)                         \
     345             :   constexpr ValueType kTypes_##name[] = {__VA_ARGS__}; \
     346             :   constexpr FunctionSig kSig_##name(                   \
     347             :       1, static_cast<int>(arraysize(kTypes_##name)) - 1, kTypes_##name);
     348             : FOREACH_SIGNATURE(DECLARE_SIG)
     349             : #undef DECLARE_SIG
     350             : 
     351             : #define DECLARE_SIG_ENTRY(name, ...) &kSig_##name,
     352             : constexpr const FunctionSig* kSimpleExprSigs[] = {
     353             :     nullptr, FOREACH_SIGNATURE(DECLARE_SIG_ENTRY)};
     354             : #undef DECLARE_SIG_ENTRY
     355             : 
     356             : // gcc 4.7 - 4.9 has a bug which causes the constexpr attribute to get lost when
     357             : // passing functions (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52892). Hence
     358             : // encapsulate these constexpr functions in functors.
     359             : // TODO(clemensh): Remove this once we require gcc >= 5.0.
     360             : 
     361             : struct GetOpcodeSigIndex {
     362             :   constexpr WasmOpcodeSig operator()(byte opcode) const {
     363             : #define CASE(name, opc, sig) opcode == opc ? kSigEnum_##sig:
     364             :     return FOREACH_SIMPLE_OPCODE(CASE) kSigEnum_None;
     365             : #undef CASE
     366             :   }
     367             : };
     368             : 
     369             : struct GetAsmJsOpcodeSigIndex {
     370             :   constexpr WasmOpcodeSig operator()(byte opcode) const {
     371             : #define CASE(name, opc, sig) opcode == opc ? kSigEnum_##sig:
     372             :     return FOREACH_ASMJS_COMPAT_OPCODE(CASE) kSigEnum_None;
     373             : #undef CASE
     374             :   }
     375             : };
     376             : 
     377             : struct GetSimdOpcodeSigIndex {
     378             :   constexpr WasmOpcodeSig operator()(byte opcode) const {
     379             : #define CASE(name, opc, sig) opcode == (opc & 0xff) ? kSigEnum_##sig:
     380             :     return FOREACH_SIMD_0_OPERAND_OPCODE(CASE) kSigEnum_None;
     381             : #undef CASE
     382             :   }
     383             : };
     384             : 
     385             : struct GetAtomicOpcodeSigIndex {
     386             :   constexpr WasmOpcodeSig operator()(byte opcode) const {
     387             : #define CASE(name, opc, sig) opcode == (opc & 0xff) ? kSigEnum_##sig:
     388             :     return FOREACH_ATOMIC_OPCODE(CASE) kSigEnum_None;
     389             : #undef CASE
     390             : }
     391             : };
     392             : 
     393             : constexpr std::array<WasmOpcodeSig, 256> kSimpleExprSigTable =
     394             :     base::make_array<256>(GetOpcodeSigIndex{});
     395             : constexpr std::array<WasmOpcodeSig, 256> kSimpleAsmjsExprSigTable =
     396             :     base::make_array<256>(GetAsmJsOpcodeSigIndex{});
     397             : constexpr std::array<WasmOpcodeSig, 256> kSimdExprSigTable =
     398             :     base::make_array<256>(GetSimdOpcodeSigIndex{});
     399             : constexpr std::array<WasmOpcodeSig, 256> kAtomicExprSigTable =
     400             :     base::make_array<256>(GetAtomicOpcodeSigIndex{});
     401             : 
     402             : }  // namespace
     403             : 
     404     8146656 : FunctionSig* WasmOpcodes::Signature(WasmOpcode opcode) {
     405     8146656 :   if (opcode >> 8 == kSimdPrefix) {
     406             :     return const_cast<FunctionSig*>(
     407        2694 :         kSimpleExprSigs[kSimdExprSigTable[opcode & 0xff]]);
     408             :   } else {
     409             :     DCHECK_GT(kSimpleExprSigTable.size(), opcode);
     410             :     return const_cast<FunctionSig*>(
     411     8143962 :         kSimpleExprSigs[kSimpleExprSigTable[opcode]]);
     412             :   }
     413             : }
     414             : 
     415      308151 : FunctionSig* WasmOpcodes::AsmjsSignature(WasmOpcode opcode) {
     416             :   DCHECK_GT(kSimpleAsmjsExprSigTable.size(), opcode);
     417             :   return const_cast<FunctionSig*>(
     418      308151 :       kSimpleExprSigs[kSimpleAsmjsExprSigTable[opcode]]);
     419             : }
     420             : 
     421         512 : FunctionSig* WasmOpcodes::AtomicSignature(WasmOpcode opcode) {
     422             :   return const_cast<FunctionSig*>(
     423         512 :       kSimpleExprSigs[kAtomicExprSigTable[opcode & 0xff]]);
     424             : }
     425             : 
     426         348 : int WasmOpcodes::TrapReasonToMessageId(TrapReason reason) {
     427         348 :   switch (reason) {
     428             : #define TRAPREASON_TO_MESSAGE(name) \
     429             :   case k##name:                     \
     430             :     return MessageTemplate::kWasm##name;
     431             :     FOREACH_WASM_TRAPREASON(TRAPREASON_TO_MESSAGE)
     432             : #undef TRAPREASON_TO_MESSAGE
     433             :     default:
     434             :       return MessageTemplate::kNone;
     435             :   }
     436             : }
     437             : 
     438           0 : const char* WasmOpcodes::TrapReasonMessage(TrapReason reason) {
     439           0 :   return MessageTemplate::TemplateString(TrapReasonToMessageId(reason));
     440             : }
     441             : }  // namespace wasm
     442             : }  // namespace internal
     443             : }  // namespace v8

Generated by: LCOV version 1.10