| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 72 |
| 73 // Initialize the signature table. | 73 // Initialize the signature table. |
| 74 static void InitSigTable() { | 74 static void InitSigTable() { |
| 75 #define SET_SIG_TABLE(name, opcode, sig) \ | 75 #define SET_SIG_TABLE(name, opcode, sig) \ |
| 76 kSimpleExprSigTable[opcode] = static_cast<int>(kSigEnum_##sig) + 1; | 76 kSimpleExprSigTable[opcode] = static_cast<int>(kSigEnum_##sig) + 1; |
| 77 FOREACH_SIMPLE_OPCODE(SET_SIG_TABLE); | 77 FOREACH_SIMPLE_OPCODE(SET_SIG_TABLE); |
| 78 FOREACH_ASMJS_COMPAT_OPCODE(SET_SIG_TABLE); | 78 FOREACH_ASMJS_COMPAT_OPCODE(SET_SIG_TABLE); |
| 79 #undef SET_SIG_TABLE | 79 #undef SET_SIG_TABLE |
| 80 } | 80 } |
| 81 | 81 |
| 82 class SigTable { |
| 83 public: |
| 84 SigTable() { |
| 85 // TODO(ahaas): Move {InitSigTable} into the class. |
| 86 InitSigTable(); |
| 87 } |
| 88 FunctionSig* Signature(WasmOpcode opcode) const { |
| 89 return const_cast<FunctionSig*>( |
| 90 kSimpleExprSigs[kSimpleExprSigTable[static_cast<byte>(opcode)]]); |
| 91 } |
| 92 }; |
| 93 |
| 94 static base::LazyInstance<SigTable>::type sig_table = LAZY_INSTANCE_INITIALIZER; |
| 95 |
| 82 FunctionSig* WasmOpcodes::Signature(WasmOpcode opcode) { | 96 FunctionSig* WasmOpcodes::Signature(WasmOpcode opcode) { |
| 83 // TODO(titzer): use LazyInstance to make this thread safe. | 97 return sig_table.Get().Signature(opcode); |
| 84 if (kSimpleExprSigTable[kExprI32Add] == 0) InitSigTable(); | |
| 85 return const_cast<FunctionSig*>( | |
| 86 kSimpleExprSigs[kSimpleExprSigTable[static_cast<byte>(opcode)]]); | |
| 87 } | 98 } |
| 88 | 99 |
| 89 // TODO(titzer): pull WASM_64 up to a common header. | 100 // TODO(titzer): pull WASM_64 up to a common header. |
| 90 #if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64 | 101 #if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64 |
| 91 #define WASM_64 1 | 102 #define WASM_64 1 |
| 92 #else | 103 #else |
| 93 #define WASM_64 0 | 104 #define WASM_64 0 |
| 94 #endif | 105 #endif |
| 95 | 106 |
| 96 int WasmOpcodes::TrapReasonToMessageId(TrapReason reason) { | 107 int WasmOpcodes::TrapReasonToMessageId(TrapReason reason) { |
| 97 switch (reason) { | 108 switch (reason) { |
| 98 #define TRAPREASON_TO_MESSAGE(name) \ | 109 #define TRAPREASON_TO_MESSAGE(name) \ |
| 99 case k##name: \ | 110 case k##name: \ |
| 100 return MessageTemplate::kWasm##name; | 111 return MessageTemplate::kWasm##name; |
| 101 FOREACH_WASM_TRAPREASON(TRAPREASON_TO_MESSAGE) | 112 FOREACH_WASM_TRAPREASON(TRAPREASON_TO_MESSAGE) |
| 102 #undef TRAPREASON_TO_MESSAGE | 113 #undef TRAPREASON_TO_MESSAGE |
| 103 default: | 114 default: |
| 104 return MessageTemplate::kNone; | 115 return MessageTemplate::kNone; |
| 105 } | 116 } |
| 106 } | 117 } |
| 107 | 118 |
| 108 const char* WasmOpcodes::TrapReasonMessage(TrapReason reason) { | 119 const char* WasmOpcodes::TrapReasonMessage(TrapReason reason) { |
| 109 return MessageTemplate::TemplateString(TrapReasonToMessageId(reason)); | 120 return MessageTemplate::TemplateString(TrapReasonToMessageId(reason)); |
| 110 } | 121 } |
| 111 } // namespace wasm | 122 } // namespace wasm |
| 112 } // namespace internal | 123 } // namespace internal |
| 113 } // namespace v8 | 124 } // namespace v8 |
| OLD | NEW |