| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/wasm/wasm-opcodes.h" | 5 #include "src/wasm/wasm-opcodes.h" |
| 6 #include "src/messages.h" | 6 #include "src/messages.h" |
| 7 #include "src/signature.h" | 7 #include "src/signature.h" |
| 8 | 8 |
| 9 namespace v8 { | 9 namespace v8 { |
| 10 namespace internal { | 10 namespace internal { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 static const FunctionSig* kSimpleExprSigs[] = { | 80 static const FunctionSig* kSimpleExprSigs[] = { |
| 81 nullptr, FOREACH_SIGNATURE(DECLARE_SIG_ENTRY)}; | 81 nullptr, FOREACH_SIGNATURE(DECLARE_SIG_ENTRY)}; |
| 82 | 82 |
| 83 #define DECLARE_SIMD_SIG_ENTRY(name, ...) &kSig_##name, | 83 #define DECLARE_SIMD_SIG_ENTRY(name, ...) &kSig_##name, |
| 84 | 84 |
| 85 static const FunctionSig* kSimdExprSigs[] = { | 85 static const FunctionSig* kSimdExprSigs[] = { |
| 86 nullptr, FOREACH_SIMD_SIGNATURE(DECLARE_SIMD_SIG_ENTRY)}; | 86 nullptr, FOREACH_SIMD_SIGNATURE(DECLARE_SIMD_SIG_ENTRY)}; |
| 87 | 87 |
| 88 static byte kSimpleExprSigTable[256]; | 88 static byte kSimpleExprSigTable[256]; |
| 89 static byte kSimpleAsmjsExprSigTable[256]; |
| 89 static byte kSimdExprSigTable[256]; | 90 static byte kSimdExprSigTable[256]; |
| 90 | 91 |
| 91 // Initialize the signature table. | 92 // Initialize the signature table. |
| 92 static void InitSigTables() { | 93 static void InitSigTables() { |
| 93 #define SET_SIG_TABLE(name, opcode, sig) \ | 94 #define SET_SIG_TABLE(name, opcode, sig) \ |
| 94 kSimpleExprSigTable[opcode] = static_cast<int>(kSigEnum_##sig) + 1; | 95 kSimpleExprSigTable[opcode] = static_cast<int>(kSigEnum_##sig) + 1; |
| 95 FOREACH_SIMPLE_OPCODE(SET_SIG_TABLE); | 96 FOREACH_SIMPLE_OPCODE(SET_SIG_TABLE); |
| 96 FOREACH_SIMPLE_MEM_OPCODE(SET_SIG_TABLE); | |
| 97 FOREACH_ASMJS_COMPAT_OPCODE(SET_SIG_TABLE); | |
| 98 #undef SET_SIG_TABLE | 97 #undef SET_SIG_TABLE |
| 98 #define SET_ASMJS_SIG_TABLE(name, opcode, sig) \ |
| 99 kSimpleAsmjsExprSigTable[opcode] = static_cast<int>(kSigEnum_##sig) + 1; |
| 100 FOREACH_ASMJS_COMPAT_OPCODE(SET_ASMJS_SIG_TABLE); |
| 101 #undef SET_ASMJS_SIG_TABLE |
| 99 byte simd_index; | 102 byte simd_index; |
| 100 #define SET_SIG_TABLE(name, opcode, sig) \ | 103 #define SET_SIG_TABLE(name, opcode, sig) \ |
| 101 simd_index = opcode & 0xff; \ | 104 simd_index = opcode & 0xff; \ |
| 102 kSimdExprSigTable[simd_index] = static_cast<int>(kSigEnum_##sig) + 1; | 105 kSimdExprSigTable[simd_index] = static_cast<int>(kSigEnum_##sig) + 1; |
| 103 FOREACH_SIMD_0_OPERAND_OPCODE(SET_SIG_TABLE) | 106 FOREACH_SIMD_0_OPERAND_OPCODE(SET_SIG_TABLE) |
| 104 #undef SET_SIG_TABLE | 107 #undef SET_SIG_TABLE |
| 105 } | 108 } |
| 106 | 109 |
| 107 class SigTable { | 110 class SigTable { |
| 108 public: | 111 public: |
| 109 SigTable() { | 112 SigTable() { |
| 110 // TODO(ahaas): Move {InitSigTable} into the class. | 113 // TODO(ahaas): Move {InitSigTable} into the class. |
| 111 InitSigTables(); | 114 InitSigTables(); |
| 112 } | 115 } |
| 113 FunctionSig* Signature(WasmOpcode opcode) const { | 116 FunctionSig* Signature(WasmOpcode opcode) const { |
| 114 return const_cast<FunctionSig*>( | 117 return const_cast<FunctionSig*>( |
| 115 kSimpleExprSigs[kSimpleExprSigTable[static_cast<byte>(opcode)]]); | 118 kSimpleExprSigs[kSimpleExprSigTable[static_cast<byte>(opcode)]]); |
| 116 } | 119 } |
| 120 FunctionSig* AsmjsSignature(WasmOpcode opcode) const { |
| 121 return const_cast<FunctionSig*>( |
| 122 kSimpleExprSigs[kSimpleAsmjsExprSigTable[static_cast<byte>(opcode)]]); |
| 123 } |
| 117 FunctionSig* SimdSignature(WasmOpcode opcode) const { | 124 FunctionSig* SimdSignature(WasmOpcode opcode) const { |
| 118 return const_cast<FunctionSig*>( | 125 return const_cast<FunctionSig*>( |
| 119 kSimdExprSigs[kSimdExprSigTable[static_cast<byte>(opcode & 0xff)]]); | 126 kSimdExprSigs[kSimdExprSigTable[static_cast<byte>(opcode & 0xff)]]); |
| 120 } | 127 } |
| 121 }; | 128 }; |
| 122 | 129 |
| 123 static base::LazyInstance<SigTable>::type sig_table = LAZY_INSTANCE_INITIALIZER; | 130 static base::LazyInstance<SigTable>::type sig_table = LAZY_INSTANCE_INITIALIZER; |
| 124 | 131 |
| 125 FunctionSig* WasmOpcodes::Signature(WasmOpcode opcode) { | 132 FunctionSig* WasmOpcodes::Signature(WasmOpcode opcode) { |
| 126 if (opcode >> 8 == kSimdPrefix) { | 133 if (opcode >> 8 == kSimdPrefix) { |
| 127 return sig_table.Get().SimdSignature(opcode); | 134 return sig_table.Get().SimdSignature(opcode); |
| 128 } else { | 135 } else { |
| 129 return sig_table.Get().Signature(opcode); | 136 return sig_table.Get().Signature(opcode); |
| 130 } | 137 } |
| 131 } | 138 } |
| 132 | 139 |
| 140 FunctionSig* WasmOpcodes::AsmjsSignature(WasmOpcode opcode) { |
| 141 return sig_table.Get().AsmjsSignature(opcode); |
| 142 } |
| 143 |
| 133 // TODO(titzer): pull WASM_64 up to a common header. | 144 // TODO(titzer): pull WASM_64 up to a common header. |
| 134 #if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64 | 145 #if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64 |
| 135 #define WASM_64 1 | 146 #define WASM_64 1 |
| 136 #else | 147 #else |
| 137 #define WASM_64 0 | 148 #define WASM_64 0 |
| 138 #endif | 149 #endif |
| 139 | 150 |
| 140 int WasmOpcodes::TrapReasonToMessageId(TrapReason reason) { | 151 int WasmOpcodes::TrapReasonToMessageId(TrapReason reason) { |
| 141 switch (reason) { | 152 switch (reason) { |
| 142 #define TRAPREASON_TO_MESSAGE(name) \ | 153 #define TRAPREASON_TO_MESSAGE(name) \ |
| 143 case k##name: \ | 154 case k##name: \ |
| 144 return MessageTemplate::kWasm##name; | 155 return MessageTemplate::kWasm##name; |
| 145 FOREACH_WASM_TRAPREASON(TRAPREASON_TO_MESSAGE) | 156 FOREACH_WASM_TRAPREASON(TRAPREASON_TO_MESSAGE) |
| 146 #undef TRAPREASON_TO_MESSAGE | 157 #undef TRAPREASON_TO_MESSAGE |
| 147 default: | 158 default: |
| 148 return MessageTemplate::kNone; | 159 return MessageTemplate::kNone; |
| 149 } | 160 } |
| 150 } | 161 } |
| 151 | 162 |
| 152 const char* WasmOpcodes::TrapReasonMessage(TrapReason reason) { | 163 const char* WasmOpcodes::TrapReasonMessage(TrapReason reason) { |
| 153 return MessageTemplate::TemplateString(TrapReasonToMessageId(reason)); | 164 return MessageTemplate::TemplateString(TrapReasonToMessageId(reason)); |
| 154 } | 165 } |
| 155 } // namespace wasm | 166 } // namespace wasm |
| 156 } // namespace internal | 167 } // namespace internal |
| 157 } // namespace v8 | 168 } // namespace v8 |
| OLD | NEW |