LCOV - code coverage report
Current view: top level - src/wasm - wasm-opcodes.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 221 235 94.0 %
Date: 2019-01-20 Functions: 11 14 78.6 %

          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_REF_OP(name, str) CASE_OP(Ref##name, "ref." str)
      26             : #define CASE_F32x4_OP(name, str) CASE_OP(F32x4##name, "f32x4." str)
      27             : #define CASE_I32x4_OP(name, str) CASE_OP(I32x4##name, "i32x4." str)
      28             : #define CASE_I16x8_OP(name, str) CASE_OP(I16x8##name, "i16x8." str)
      29             : #define CASE_I8x16_OP(name, str) CASE_OP(I8x16##name, "i8x16." str)
      30             : #define CASE_S128_OP(name, str) CASE_OP(S128##name, "s128." str)
      31             : #define CASE_S32x4_OP(name, str) CASE_OP(S32x4##name, "s32x4." str)
      32             : #define CASE_S16x8_OP(name, str) CASE_OP(S16x8##name, "s16x8." str)
      33             : #define CASE_S8x16_OP(name, str) CASE_OP(S8x16##name, "s8x16." str)
      34             : #define CASE_S1x4_OP(name, str) CASE_OP(S1x4##name, "s1x4." str)
      35             : #define CASE_S1x8_OP(name, str) CASE_OP(S1x8##name, "s1x8." str)
      36             : #define CASE_S1x16_OP(name, str) CASE_OP(S1x16##name, "s1x16." str)
      37             : #define CASE_INT_OP(name, str) CASE_I32_OP(name, str) CASE_I64_OP(name, str)
      38             : #define CASE_FLOAT_OP(name, str) CASE_F32_OP(name, str) CASE_F64_OP(name, str)
      39             : #define CASE_ALL_OP(name, str) CASE_FLOAT_OP(name, str) CASE_INT_OP(name, str)
      40             : #define CASE_SIMD_OP(name, str)                                              \
      41             :   CASE_F32x4_OP(name, str) CASE_I32x4_OP(name, str) CASE_I16x8_OP(name, str) \
      42             :       CASE_I8x16_OP(name, str)
      43             : #define CASE_SIMDI_OP(name, str) \
      44             :   CASE_I32x4_OP(name, str) CASE_I16x8_OP(name, str) CASE_I8x16_OP(name, str)
      45             : #define CASE_SIGN_OP(TYPE, name, str) \
      46             :   CASE_##TYPE##_OP(name##S, str "_s") CASE_##TYPE##_OP(name##U, str "_u")
      47             : #define CASE_UNSIGNED_OP(TYPE, name, str) CASE_##TYPE##_OP(name##U, str "_u")
      48             : #define CASE_ALL_SIGN_OP(name, str) \
      49             :   CASE_FLOAT_OP(name, str) CASE_SIGN_OP(INT, name, str)
      50             : #define CASE_CONVERT_OP(name, RES, SRC, src_suffix, str) \
      51             :   CASE_##RES##_OP(U##name##SRC, str "_u/" src_suffix)    \
      52             :       CASE_##RES##_OP(S##name##SRC, str "_s/" src_suffix)
      53             : #define CASE_CONVERT_SAT_OP(name, RES, SRC, src_suffix, str)   \
      54             :   CASE_##RES##_OP(U##name##Sat##SRC, str "_u:sat/" src_suffix) \
      55             :       CASE_##RES##_OP(S##name##Sat##SRC, str "_s:sat/" src_suffix)
      56             : #define CASE_L32_OP(name, str)          \
      57             :   CASE_SIGN_OP(I32, name##8, str "8")   \
      58             :   CASE_SIGN_OP(I32, name##16, str "16") \
      59             :   CASE_I32_OP(name, str "32")
      60             : #define CASE_U32_OP(name, str)            \
      61             :   CASE_I32_OP(name, str "32")             \
      62             :   CASE_UNSIGNED_OP(I32, name##8, str "8") \
      63             :   CASE_UNSIGNED_OP(I32, name##16, str "16")
      64             : #define CASE_UNSIGNED_ALL_OP(name, str)     \
      65             :   CASE_U32_OP(name, str)                    \
      66             :   CASE_I64_OP(name, str "64")               \
      67             :   CASE_UNSIGNED_OP(I64, name##8, str "8")   \
      68             :   CASE_UNSIGNED_OP(I64, name##16, str "16") \
      69             :   CASE_UNSIGNED_OP(I64, name##32, str "32")
      70             : 
      71       59913 : const char* WasmOpcodes::OpcodeName(WasmOpcode opcode) {
      72       59913 :   switch (opcode) {
      73             :     // clang-format off
      74             : 
      75             :     // Standard opcodes
      76          75 :     CASE_INT_OP(Eqz, "eqz")
      77         592 :     CASE_ALL_OP(Eq, "eq")
      78         148 :     CASE_ALL_OP(Ne, "ne")
      79         272 :     CASE_ALL_OP(Add, "add")
      80         268 :     CASE_ALL_OP(Sub, "sub")
      81         268 :     CASE_ALL_OP(Mul, "mul")
      82         268 :     CASE_ALL_SIGN_OP(Lt, "lt")
      83         148 :     CASE_ALL_SIGN_OP(Gt, "gt")
      84         268 :     CASE_ALL_SIGN_OP(Le, "le")
      85         148 :     CASE_ALL_SIGN_OP(Ge, "ge")
      86          48 :     CASE_INT_OP(Clz, "clz")
      87         237 :     CASE_INT_OP(Ctz, "ctz")
      88          48 :     CASE_INT_OP(Popcnt, "popcnt")
      89         268 :     CASE_ALL_SIGN_OP(Div, "div")
      90         271 :     CASE_SIGN_OP(INT, Rem, "rem")
      91         272 :     CASE_INT_OP(And, "and")
      92         271 :     CASE_INT_OP(Ior, "or")
      93         271 :     CASE_INT_OP(Xor, "xor")
      94         271 :     CASE_INT_OP(Shl, "shl")
      95         271 :     CASE_SIGN_OP(INT, Shr, "shr")
      96         148 :     CASE_INT_OP(Rol, "rol")
      97         148 :     CASE_INT_OP(Ror, "ror")
      98          48 :     CASE_FLOAT_OP(Abs, "abs")
      99         104 :     CASE_FLOAT_OP(Neg, "neg")
     100          48 :     CASE_FLOAT_OP(Ceil, "ceil")
     101         183 :     CASE_FLOAT_OP(Floor, "floor")
     102          48 :     CASE_FLOAT_OP(Trunc, "trunc")
     103          48 :     CASE_FLOAT_OP(NearestInt, "nearest")
     104          48 :     CASE_FLOAT_OP(Sqrt, "sqrt")
     105         148 :     CASE_FLOAT_OP(Min, "min")
     106         148 :     CASE_FLOAT_OP(Max, "max")
     107         148 :     CASE_FLOAT_OP(CopySign, "copysign")
     108           1 :     CASE_REF_OP(Null, "null")
     109           1 :     CASE_REF_OP(IsNull, "is_null")
     110          48 :     CASE_I32_OP(ConvertI64, "wrap/i64")
     111          68 :     CASE_CONVERT_OP(Convert, INT, F32, "f32", "trunc")
     112          68 :     CASE_CONVERT_OP(Convert, INT, F64, "f64", "trunc")
     113          75 :     CASE_CONVERT_OP(Convert, I64, I32, "i32", "extend")
     114          68 :     CASE_CONVERT_OP(Convert, F32, I32, "i32", "convert")
     115          48 :     CASE_CONVERT_OP(Convert, F32, I64, "i64", "convert")
     116          68 :     CASE_F32_OP(ConvertF64, "demote/f64")
     117          78 :     CASE_CONVERT_OP(Convert, F64, I32, "i32", "convert")
     118          48 :     CASE_CONVERT_OP(Convert, F64, I64, "i64", "convert")
     119          68 :     CASE_F64_OP(ConvertF32, "promote/f32")
     120          48 :     CASE_I32_OP(ReinterpretF32, "reinterpret/f32")
     121          48 :     CASE_I64_OP(ReinterpretF64, "reinterpret/f64")
     122          48 :     CASE_F32_OP(ReinterpretI32, "reinterpret/i32")
     123          48 :     CASE_F64_OP(ReinterpretI64, "reinterpret/i64")
     124           1 :     CASE_INT_OP(SExtendI8, "sign_extend8")
     125           1 :     CASE_INT_OP(SExtendI16, "sign_extend16")
     126           1 :     CASE_I64_OP(SExtendI32, "sign_extend32")
     127           1 :     CASE_OP(Unreachable, "unreachable")
     128          40 :     CASE_OP(Nop, "nop")
     129          28 :     CASE_OP(Block, "block")
     130          14 :     CASE_OP(Loop, "loop")
     131         191 :     CASE_OP(If, "if")
     132           1 :     CASE_OP(Else, "else")
     133           1 :     CASE_OP(End, "end")
     134          11 :     CASE_OP(Br, "br")
     135         264 :     CASE_OP(BrIf, "br_if")
     136         137 :     CASE_OP(BrTable, "br_table")
     137           1 :     CASE_OP(Return, "return")
     138         263 :     CASE_OP(CallFunction, "call")
     139         299 :     CASE_OP(CallIndirect, "call_indirect")
     140          33 :     CASE_OP(Drop, "drop")
     141         182 :     CASE_OP(Select, "select")
     142       25933 :     CASE_OP(GetLocal, "get_local")
     143         369 :     CASE_OP(SetLocal, "set_local")
     144         354 :     CASE_OP(TeeLocal, "tee_local")
     145           1 :     CASE_OP(GetGlobal, "get_global")
     146          25 :     CASE_OP(SetGlobal, "set_global")
     147        3325 :     CASE_ALL_OP(Const, "const")
     148           1 :     CASE_OP(MemorySize, "memory.size")
     149          29 :     CASE_OP(MemoryGrow, "memory.grow")
     150          28 :     CASE_ALL_OP(LoadMem, "load")
     151          28 :     CASE_SIGN_OP(INT, LoadMem8, "load8")
     152          28 :     CASE_SIGN_OP(INT, LoadMem16, "load16")
     153          28 :     CASE_SIGN_OP(I64, LoadMem32, "load32")
     154           1 :     CASE_S128_OP(LoadMem, "load128")
     155          59 :     CASE_ALL_OP(StoreMem, "store")
     156          63 :     CASE_INT_OP(StoreMem8, "store8")
     157          63 :     CASE_INT_OP(StoreMem16, "store16")
     158          55 :     CASE_I64_OP(StoreMem32, "store32")
     159           1 :     CASE_S128_OP(StoreMem, "store128")
     160             : 
     161             :     // Exception handling opcodes.
     162           1 :     CASE_OP(Try, "try")
     163           1 :     CASE_OP(Catch, "catch")
     164           3 :     CASE_OP(Throw, "throw")
     165           4 :     CASE_OP(Rethrow, "rethrow")
     166           2 :     CASE_OP(BrOnExn, "br_on_exn")
     167             : 
     168             :     // asm.js-only opcodes.
     169          21 :     CASE_F64_OP(Acos, "acos")
     170          21 :     CASE_F64_OP(Asin, "asin")
     171          21 :     CASE_F64_OP(Atan, "atan")
     172          21 :     CASE_F64_OP(Cos, "cos")
     173          21 :     CASE_F64_OP(Sin, "sin")
     174          21 :     CASE_F64_OP(Tan, "tan")
     175          21 :     CASE_F64_OP(Exp, "exp")
     176          21 :     CASE_F64_OP(Log, "log")
     177         121 :     CASE_F64_OP(Atan2, "atan2")
     178         121 :     CASE_F64_OP(Pow, "pow")
     179         121 :     CASE_F64_OP(Mod, "mod")
     180          26 :     CASE_F32_OP(AsmjsLoadMem, "asmjs_load")
     181          26 :     CASE_F64_OP(AsmjsLoadMem, "asmjs_load")
     182          21 :     CASE_L32_OP(AsmjsLoadMem, "asmjs_load")
     183         126 :     CASE_I32_OP(AsmjsStoreMem, "asmjs_store")
     184         121 :     CASE_F32_OP(AsmjsStoreMem, "asmjs_store")
     185         121 :     CASE_F64_OP(AsmjsStoreMem, "asmjs_store")
     186         121 :     CASE_I32_OP(AsmjsStoreMem8, "asmjs_store8")
     187         121 :     CASE_I32_OP(AsmjsStoreMem16, "asmjs_store16")
     188         176 :     CASE_SIGN_OP(I32, AsmjsDiv, "asmjs_div")
     189         176 :     CASE_SIGN_OP(I32, AsmjsRem, "asmjs_rem")
     190          26 :     CASE_I32_OP(AsmjsSConvertF32, "asmjs_convert_s/f32")
     191          26 :     CASE_I32_OP(AsmjsUConvertF32, "asmjs_convert_u/f32")
     192          26 :     CASE_I32_OP(AsmjsSConvertF64, "asmjs_convert_s/f64")
     193          26 :     CASE_I32_OP(AsmjsUConvertF64, "asmjs_convert_u/f64")
     194             : 
     195             :     // Numeric Opcodes.
     196           6 :     CASE_CONVERT_SAT_OP(Convert, I32, F32, "f32", "trunc")
     197           6 :     CASE_CONVERT_SAT_OP(Convert, I32, F64, "f64", "trunc")
     198           6 :     CASE_CONVERT_SAT_OP(Convert, I64, F32, "f32", "trunc")
     199           6 :     CASE_CONVERT_SAT_OP(Convert, I64, F64, "f64", "trunc")
     200           1 :     CASE_OP(MemoryInit, "memory.init")
     201           1 :     CASE_OP(MemoryDrop, "memory.drop")
     202           1 :     CASE_OP(MemoryCopy, "memory.copy")
     203           1 :     CASE_OP(MemoryFill, "memory.fill")
     204           1 :     CASE_OP(TableInit, "table.init")
     205           1 :     CASE_OP(TableDrop, "table.drop")
     206           1 :     CASE_OP(TableCopy, "table.copy")
     207             : 
     208             :     // SIMD opcodes.
     209           1 :     CASE_SIMD_OP(Splat, "splat")
     210           1 :     CASE_SIMD_OP(Neg, "neg")
     211           1 :     CASE_SIMD_OP(Eq, "eq")
     212           1 :     CASE_SIMD_OP(Ne, "ne")
     213           1 :     CASE_SIMD_OP(Add, "add")
     214           1 :     CASE_SIMD_OP(Sub, "sub")
     215           1 :     CASE_SIMD_OP(Mul, "mul")
     216           1 :     CASE_F32x4_OP(Abs, "abs")
     217           1 :     CASE_F32x4_OP(AddHoriz, "add_horizontal")
     218           1 :     CASE_F32x4_OP(RecipApprox, "recip_approx")
     219           1 :     CASE_F32x4_OP(RecipSqrtApprox, "recip_sqrt_approx")
     220           1 :     CASE_F32x4_OP(Min, "min")
     221           1 :     CASE_F32x4_OP(Max, "max")
     222           1 :     CASE_F32x4_OP(Lt, "lt")
     223           1 :     CASE_F32x4_OP(Le, "le")
     224           1 :     CASE_F32x4_OP(Gt, "gt")
     225           1 :     CASE_F32x4_OP(Ge, "ge")
     226           1 :     CASE_CONVERT_OP(Convert, F32x4, I32x4, "i32", "convert")
     227           1 :     CASE_CONVERT_OP(Convert, I32x4, F32x4, "f32", "convert")
     228           1 :     CASE_CONVERT_OP(Convert, I32x4, I16x8Low, "i32", "convert")
     229           1 :     CASE_CONVERT_OP(Convert, I32x4, I16x8High, "i32", "convert")
     230           1 :     CASE_CONVERT_OP(Convert, I16x8, I32x4, "i32", "convert")
     231           1 :     CASE_CONVERT_OP(Convert, I16x8, I8x16Low, "i32", "convert")
     232           1 :     CASE_CONVERT_OP(Convert, I16x8, I8x16High, "i32", "convert")
     233           1 :     CASE_CONVERT_OP(Convert, I8x16, I16x8, "i32", "convert")
     234           1 :     CASE_F32x4_OP(ExtractLane, "extract_lane")
     235           1 :     CASE_F32x4_OP(ReplaceLane, "replace_lane")
     236           1 :     CASE_SIMDI_OP(ExtractLane, "extract_lane")
     237           1 :     CASE_SIMDI_OP(ReplaceLane, "replace_lane")
     238           1 :     CASE_SIGN_OP(SIMDI, Min, "min")
     239           1 :     CASE_SIGN_OP(SIMDI, Max, "max")
     240           1 :     CASE_SIGN_OP(SIMDI, Lt, "lt")
     241           1 :     CASE_SIGN_OP(SIMDI, Le, "le")
     242           1 :     CASE_SIGN_OP(SIMDI, Gt, "gt")
     243           1 :     CASE_SIGN_OP(SIMDI, Ge, "ge")
     244           1 :     CASE_SIGN_OP(SIMDI, Shr, "shr")
     245           1 :     CASE_SIMDI_OP(Shl, "shl")
     246           1 :     CASE_I32x4_OP(AddHoriz, "add_horizontal")
     247           1 :     CASE_I16x8_OP(AddHoriz, "add_horizontal")
     248           1 :     CASE_SIGN_OP(I16x8, AddSaturate, "add_saturate")
     249           1 :     CASE_SIGN_OP(I8x16, AddSaturate, "add_saturate")
     250           1 :     CASE_SIGN_OP(I16x8, SubSaturate, "sub_saturate")
     251           1 :     CASE_SIGN_OP(I8x16, SubSaturate, "sub_saturate")
     252           1 :     CASE_S128_OP(And, "and")
     253           1 :     CASE_S128_OP(Or, "or")
     254           1 :     CASE_S128_OP(Xor, "xor")
     255           1 :     CASE_S128_OP(Not, "not")
     256           1 :     CASE_S128_OP(Select, "select")
     257           1 :     CASE_S8x16_OP(Shuffle, "shuffle")
     258           1 :     CASE_S1x4_OP(AnyTrue, "any_true")
     259           1 :     CASE_S1x4_OP(AllTrue, "all_true")
     260           1 :     CASE_S1x8_OP(AnyTrue, "any_true")
     261           1 :     CASE_S1x8_OP(AllTrue, "all_true")
     262           1 :     CASE_S1x16_OP(AnyTrue, "any_true")
     263           1 :     CASE_S1x16_OP(AllTrue, "all_true")
     264             : 
     265             :     // Atomic operations.
     266           1 :     CASE_OP(AtomicWake, "atomic_wake")
     267           1 :     CASE_INT_OP(AtomicWait, "atomic_wait")
     268           6 :     CASE_UNSIGNED_ALL_OP(AtomicLoad, "atomic_load")
     269           6 :     CASE_UNSIGNED_ALL_OP(AtomicStore, "atomic_store")
     270           1 :     CASE_UNSIGNED_ALL_OP(AtomicAdd, "atomic_add")
     271           1 :     CASE_UNSIGNED_ALL_OP(AtomicSub, "atomic_sub")
     272           1 :     CASE_UNSIGNED_ALL_OP(AtomicAnd, "atomic_and")
     273           1 :     CASE_UNSIGNED_ALL_OP(AtomicOr, "atomic_or")
     274           1 :     CASE_UNSIGNED_ALL_OP(AtomicXor, "atomic_xor")
     275           1 :     CASE_UNSIGNED_ALL_OP(AtomicExchange, "atomic_xchng")
     276           1 :     CASE_UNSIGNED_ALL_OP(AtomicCompareExchange, "atomic_cmpxchng")
     277             : 
     278           0 :     default : return "unknown";
     279             :     // clang-format on
     280             :   }
     281             : }
     282             : 
     283             : #undef CASE_OP
     284             : #undef CASE_I32_OP
     285             : #undef CASE_I64_OP
     286             : #undef CASE_F32_OP
     287             : #undef CASE_F64_OP
     288             : #undef CASE_REF_OP
     289             : #undef CASE_F32x4_OP
     290             : #undef CASE_I32x4_OP
     291             : #undef CASE_I16x8_OP
     292             : #undef CASE_I8x16_OP
     293             : #undef CASE_S128_OP
     294             : #undef CASE_S32x4_OP
     295             : #undef CASE_S16x8_OP
     296             : #undef CASE_S8x16_OP
     297             : #undef CASE_S1x4_OP
     298             : #undef CASE_S1x8_OP
     299             : #undef CASE_S1x16_OP
     300             : #undef CASE_INT_OP
     301             : #undef CASE_FLOAT_OP
     302             : #undef CASE_ALL_OP
     303             : #undef CASE_SIMD_OP
     304             : #undef CASE_SIMDI_OP
     305             : #undef CASE_SIGN_OP
     306             : #undef CASE_UNSIGNED_OP
     307             : #undef CASE_UNSIGNED_ALL_OP
     308             : #undef CASE_ALL_SIGN_OP
     309             : #undef CASE_CONVERT_OP
     310             : #undef CASE_CONVERT_SAT_OP
     311             : #undef CASE_L32_OP
     312             : #undef CASE_U32_OP
     313             : 
     314    78394793 : bool WasmOpcodes::IsPrefixOpcode(WasmOpcode opcode) {
     315    78394793 :   switch (opcode) {
     316             : #define CHECK_PREFIX(name, opcode) case k##name##Prefix:
     317             :     FOREACH_PREFIX(CHECK_PREFIX)
     318             : #undef CHECK_PREFIX
     319             :     return true;
     320             :     default:
     321    71228783 :       return false;
     322             :   }
     323             : }
     324             : 
     325           0 : bool WasmOpcodes::IsControlOpcode(WasmOpcode opcode) {
     326           0 :   switch (opcode) {
     327             : #define CHECK_OPCODE(name, opcode, _) case kExpr##name:
     328             :     FOREACH_CONTROL_OPCODE(CHECK_OPCODE)
     329             : #undef CHECK_OPCODE
     330             :     return true;
     331             :     default:
     332           0 :       return false;
     333             :   }
     334             : }
     335             : 
     336     2918265 : bool WasmOpcodes::IsUnconditionalJump(WasmOpcode opcode) {
     337     2918265 :   switch (opcode) {
     338             :     case kExprUnreachable:
     339             :     case kExprBr:
     340             :     case kExprBrTable:
     341             :     case kExprReturn:
     342             :       return true;
     343             :     default:
     344     2880079 :       return false;
     345             :   }
     346             : }
     347             : 
     348         129 : bool WasmOpcodes::IsSignExtensionOpcode(WasmOpcode opcode) {
     349         129 :   switch (opcode) {
     350             :     case kExprI32SExtendI8:
     351             :     case kExprI32SExtendI16:
     352             :     case kExprI64SExtendI8:
     353             :     case kExprI64SExtendI16:
     354             :     case kExprI64SExtendI32:
     355             :       return true;
     356             :     default:
     357          36 :       return false;
     358             :   }
     359             : }
     360             : 
     361         744 : bool WasmOpcodes::IsAnyRefOpcode(WasmOpcode opcode) {
     362         744 :   switch (opcode) {
     363             :     case kExprRefNull:
     364             :     case kExprRefIsNull:
     365             :       return true;
     366             :     default:
     367         708 :       return false;
     368             :   }
     369             : }
     370             : 
     371           0 : std::ostream& operator<<(std::ostream& os, const FunctionSig& sig) {
     372           0 :   if (sig.return_count() == 0) os << "v";
     373           0 :   for (auto ret : sig.returns()) {
     374             :     os << ValueTypes::ShortNameOf(ret);
     375             :   }
     376           0 :   os << "_";
     377           0 :   if (sig.parameter_count() == 0) os << "v";
     378           0 :   for (auto param : sig.parameters()) {
     379             :     os << ValueTypes::ShortNameOf(param);
     380             :   }
     381           0 :   return os;
     382             : }
     383             : 
     384      177308 : bool IsJSCompatibleSignature(const FunctionSig* sig, bool has_bigint_feature) {
     385      177308 :   if (sig->return_count() > 1) {
     386             :     return false;
     387             :   }
     388      367344 :   for (auto type : sig->all()) {
     389      190954 :     if (!has_bigint_feature && type == kWasmI64) {
     390             :       return false;
     391             :     }
     392             : 
     393      190036 :     if (type == kWasmS128) return false;
     394             :   }
     395             :   return true;
     396             : }
     397             : 
     398             : namespace {
     399             : 
     400             : #define DECLARE_SIG_ENUM(name, ...) kSigEnum_##name,
     401             : enum WasmOpcodeSig : byte {
     402             :   kSigEnum_None,
     403             :   FOREACH_SIGNATURE(DECLARE_SIG_ENUM)
     404             : };
     405             : #undef DECLARE_SIG_ENUM
     406             : #define DECLARE_SIG(name, ...)                                                \
     407             :   constexpr ValueType kTypes_##name[] = {__VA_ARGS__};                        \
     408             :   constexpr int kReturnsCount_##name = kTypes_##name[0] == kWasmStmt ? 0 : 1; \
     409             :   constexpr FunctionSig kSig_##name(                                          \
     410             :       kReturnsCount_##name, static_cast<int>(arraysize(kTypes_##name)) - 1,   \
     411             :       kTypes_##name + (1 - kReturnsCount_##name));
     412             : FOREACH_SIGNATURE(DECLARE_SIG)
     413             : #undef DECLARE_SIG
     414             : 
     415             : #define DECLARE_SIG_ENTRY(name, ...) &kSig_##name,
     416             : constexpr const FunctionSig* kCachedSigs[] = {
     417             :     nullptr, FOREACH_SIGNATURE(DECLARE_SIG_ENTRY)};
     418             : #undef DECLARE_SIG_ENTRY
     419             : 
     420             : // gcc 4.7 - 4.9 has a bug which causes the constexpr attribute to get lost when
     421             : // passing functions (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52892). Hence
     422             : // encapsulate these constexpr functions in functors.
     423             : // TODO(clemensh): Remove this once we require gcc >= 5.0.
     424             : 
     425             : struct GetShortOpcodeSigIndex {
     426             :   constexpr WasmOpcodeSig operator()(byte opcode) const {
     427             : #define CASE(name, opc, sig) opcode == opc ? kSigEnum_##sig:
     428             :     return FOREACH_SIMPLE_OPCODE(CASE) FOREACH_SIMPLE_PROTOTYPE_OPCODE(CASE)
     429             :         kSigEnum_None;
     430             : #undef CASE
     431             :   }
     432             : };
     433             : 
     434             : struct GetAsmJsOpcodeSigIndex {
     435             :   constexpr WasmOpcodeSig operator()(byte opcode) const {
     436             : #define CASE(name, opc, sig) opcode == opc ? kSigEnum_##sig:
     437             :     return FOREACH_ASMJS_COMPAT_OPCODE(CASE) kSigEnum_None;
     438             : #undef CASE
     439             :   }
     440             : };
     441             : 
     442             : struct GetSimdOpcodeSigIndex {
     443             :   constexpr WasmOpcodeSig operator()(byte opcode) const {
     444             : #define CASE(name, opc, sig) opcode == (opc & 0xFF) ? kSigEnum_##sig:
     445             :     return FOREACH_SIMD_0_OPERAND_OPCODE(CASE) FOREACH_SIMD_MEM_OPCODE(CASE)
     446             :         kSigEnum_None;
     447             : #undef CASE
     448             :   }
     449             : };
     450             : 
     451             : struct GetAtomicOpcodeSigIndex {
     452             :   constexpr WasmOpcodeSig operator()(byte opcode) const {
     453             : #define CASE(name, opc, sig) opcode == (opc & 0xFF) ? kSigEnum_##sig:
     454             :     return FOREACH_ATOMIC_OPCODE(CASE) kSigEnum_None;
     455             : #undef CASE
     456             : }
     457             : };
     458             : 
     459             : struct GetNumericOpcodeSigIndex {
     460             :   constexpr WasmOpcodeSig operator()(byte opcode) const {
     461             : #define CASE(name, opc, sig) opcode == (opc & 0xFF) ? kSigEnum_##sig:
     462             :     return FOREACH_NUMERIC_OPCODE(CASE) kSigEnum_None;
     463             : #undef CASE
     464             :   }
     465             : };
     466             : 
     467             : constexpr std::array<WasmOpcodeSig, 256> kShortSigTable =
     468             :     base::make_array<256>(GetShortOpcodeSigIndex{});
     469             : constexpr std::array<WasmOpcodeSig, 256> kSimpleAsmjsExprSigTable =
     470             :     base::make_array<256>(GetAsmJsOpcodeSigIndex{});
     471             : constexpr std::array<WasmOpcodeSig, 256> kSimdExprSigTable =
     472             :     base::make_array<256>(GetSimdOpcodeSigIndex{});
     473             : constexpr std::array<WasmOpcodeSig, 256> kAtomicExprSigTable =
     474             :     base::make_array<256>(GetAtomicOpcodeSigIndex{});
     475             : constexpr std::array<WasmOpcodeSig, 256> kNumericExprSigTable =
     476             :     base::make_array<256>(GetNumericOpcodeSigIndex{});
     477             : 
     478             : }  // namespace
     479             : 
     480     2939961 : FunctionSig* WasmOpcodes::Signature(WasmOpcode opcode) {
     481     2939961 :   switch (opcode >> 8) {
     482             :     case 0:
     483     2880166 :       return const_cast<FunctionSig*>(kCachedSigs[kShortSigTable[opcode]]);
     484             :     case kSimdPrefix:
     485             :       return const_cast<FunctionSig*>(
     486       10165 :           kCachedSigs[kSimdExprSigTable[opcode & 0xFF]]);
     487             :     case kAtomicPrefix:
     488             :       return const_cast<FunctionSig*>(
     489       49000 :           kCachedSigs[kAtomicExprSigTable[opcode & 0xFF]]);
     490             :     case kNumericPrefix:
     491             :       return const_cast<FunctionSig*>(
     492         630 :           kCachedSigs[kNumericExprSigTable[opcode & 0xFF]]);
     493             :     default:
     494           0 :       UNREACHABLE();  // invalid prefix.
     495             :       return nullptr;
     496             :   }
     497             : }
     498             : 
     499     2546421 : FunctionSig* WasmOpcodes::AsmjsSignature(WasmOpcode opcode) {
     500             :   DCHECK_GT(kSimpleAsmjsExprSigTable.size(), opcode);
     501             :   return const_cast<FunctionSig*>(
     502     2546421 :       kCachedSigs[kSimpleAsmjsExprSigTable[opcode]]);
     503             : }
     504             : 
     505             : // Define constexpr arrays.
     506             : constexpr uint8_t LoadType::kLoadSizeLog2[];
     507             : constexpr ValueType LoadType::kValueType[];
     508             : constexpr MachineType LoadType::kMemType[];
     509             : constexpr uint8_t StoreType::kStoreSizeLog2[];
     510             : constexpr ValueType StoreType::kValueType[];
     511             : constexpr MachineRepresentation StoreType::kMemRep[];
     512             : 
     513         753 : MessageTemplate WasmOpcodes::TrapReasonToMessageId(TrapReason reason) {
     514         753 :   switch (reason) {
     515             : #define TRAPREASON_TO_MESSAGE(name) \
     516             :   case k##name:                     \
     517             :     return MessageTemplate::kWasm##name;
     518             :     FOREACH_WASM_TRAPREASON(TRAPREASON_TO_MESSAGE)
     519             : #undef TRAPREASON_TO_MESSAGE
     520             :     default:
     521             :       return MessageTemplate::kNone;
     522             :   }
     523             : }
     524             : 
     525           0 : const char* WasmOpcodes::TrapReasonMessage(TrapReason reason) {
     526           0 :   return MessageFormatter::TemplateString(TrapReasonToMessageId(reason));
     527             : }
     528             : }  // namespace wasm
     529             : }  // namespace internal
     530      183867 : }  // namespace v8

Generated by: LCOV version 1.10