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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 static const FunctionSig kSig_##name( \ | 61 static const FunctionSig kSig_##name( \ |
62 1, static_cast<int>(arraysize(kTypes_##name)) - 1, kTypes_##name); | 62 1, static_cast<int>(arraysize(kTypes_##name)) - 1, kTypes_##name); |
63 | 63 |
64 FOREACH_SIGNATURE(DECLARE_SIG) | 64 FOREACH_SIGNATURE(DECLARE_SIG) |
65 | 65 |
66 #define DECLARE_SIG_ENTRY(name, ...) &kSig_##name, | 66 #define DECLARE_SIG_ENTRY(name, ...) &kSig_##name, |
67 | 67 |
68 static const FunctionSig* kSimpleExprSigs[] = { | 68 static const FunctionSig* kSimpleExprSigs[] = { |
69 nullptr, FOREACH_SIGNATURE(DECLARE_SIG_ENTRY)}; | 69 nullptr, FOREACH_SIGNATURE(DECLARE_SIG_ENTRY)}; |
70 | 70 |
71 #define DECLARE_SIMD_SIG_ENTRY(name, ...) &kSig_##name, | |
72 | |
73 static const FunctionSig* kSimdExprSigs[] = { | |
74 nullptr, FOREACH_SIMD_SIGNATURE(DECLARE_SIMD_SIG_ENTRY)}; | |
75 | |
76 static byte kSimpleExprSigTable[256]; | 71 static byte kSimpleExprSigTable[256]; |
77 static byte kSimdExprSigTable[256]; | |
78 | 72 |
79 // Initialize the signature table. | 73 // Initialize the signature table. |
80 static void InitSigTables() { | 74 static void InitSigTable() { |
81 #define SET_SIG_TABLE(name, opcode, sig) \ | 75 #define SET_SIG_TABLE(name, opcode, sig) \ |
82 kSimpleExprSigTable[opcode] = static_cast<int>(kSigEnum_##sig) + 1; | 76 kSimpleExprSigTable[opcode] = static_cast<int>(kSigEnum_##sig) + 1; |
83 FOREACH_SIMPLE_OPCODE(SET_SIG_TABLE); | 77 FOREACH_SIMPLE_OPCODE(SET_SIG_TABLE); |
84 FOREACH_SIMPLE_MEM_OPCODE(SET_SIG_TABLE); | 78 FOREACH_SIMPLE_MEM_OPCODE(SET_SIG_TABLE); |
85 FOREACH_ASMJS_COMPAT_OPCODE(SET_SIG_TABLE); | 79 FOREACH_ASMJS_COMPAT_OPCODE(SET_SIG_TABLE); |
86 #undef SET_SIG_TABLE | 80 #undef SET_SIG_TABLE |
87 byte simd_index; | |
88 #define SET_SIG_TABLE(name, opcode, sig) \ | |
89 simd_index = opcode & 0xff; \ | |
90 kSimdExprSigTable[simd_index] = static_cast<int>(kSigEnum_##sig) + 1; | |
91 FOREACH_SIMD_OPCODE(SET_SIG_TABLE) | |
92 #undef SET_SIG_TABLE | |
93 } | 81 } |
94 | 82 |
95 class SigTable { | 83 class SigTable { |
96 public: | 84 public: |
97 SigTable() { | 85 SigTable() { |
98 // TODO(ahaas): Move {InitSigTable} into the class. | 86 // TODO(ahaas): Move {InitSigTable} into the class. |
99 InitSigTables(); | 87 InitSigTable(); |
100 } | 88 } |
101 FunctionSig* Signature(WasmOpcode opcode) const { | 89 FunctionSig* Signature(WasmOpcode opcode) const { |
102 return const_cast<FunctionSig*>( | 90 return const_cast<FunctionSig*>( |
103 kSimpleExprSigs[kSimpleExprSigTable[static_cast<byte>(opcode)]]); | 91 kSimpleExprSigs[kSimpleExprSigTable[static_cast<byte>(opcode)]]); |
104 } | 92 } |
105 FunctionSig* SimdSignature(WasmOpcode opcode) const { | |
106 return const_cast<FunctionSig*>( | |
107 kSimdExprSigs[kSimdExprSigTable[static_cast<byte>(opcode & 0xff)]]); | |
108 } | |
109 }; | 93 }; |
110 | 94 |
111 static base::LazyInstance<SigTable>::type sig_table = LAZY_INSTANCE_INITIALIZER; | 95 static base::LazyInstance<SigTable>::type sig_table = LAZY_INSTANCE_INITIALIZER; |
112 | 96 |
113 FunctionSig* WasmOpcodes::Signature(WasmOpcode opcode) { | 97 FunctionSig* WasmOpcodes::Signature(WasmOpcode opcode) { |
114 if (opcode >> 8 == kSimdPrefix) { | 98 return sig_table.Get().Signature(opcode); |
115 return sig_table.Get().SimdSignature(opcode); | |
116 } else { | |
117 return sig_table.Get().Signature(opcode); | |
118 } | |
119 } | 99 } |
120 | 100 |
121 // TODO(titzer): pull WASM_64 up to a common header. | 101 // TODO(titzer): pull WASM_64 up to a common header. |
122 #if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64 | 102 #if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64 |
123 #define WASM_64 1 | 103 #define WASM_64 1 |
124 #else | 104 #else |
125 #define WASM_64 0 | 105 #define WASM_64 0 |
126 #endif | 106 #endif |
127 | 107 |
128 int WasmOpcodes::TrapReasonToMessageId(TrapReason reason) { | 108 int WasmOpcodes::TrapReasonToMessageId(TrapReason reason) { |
129 switch (reason) { | 109 switch (reason) { |
130 #define TRAPREASON_TO_MESSAGE(name) \ | 110 #define TRAPREASON_TO_MESSAGE(name) \ |
131 case k##name: \ | 111 case k##name: \ |
132 return MessageTemplate::kWasm##name; | 112 return MessageTemplate::kWasm##name; |
133 FOREACH_WASM_TRAPREASON(TRAPREASON_TO_MESSAGE) | 113 FOREACH_WASM_TRAPREASON(TRAPREASON_TO_MESSAGE) |
134 #undef TRAPREASON_TO_MESSAGE | 114 #undef TRAPREASON_TO_MESSAGE |
135 default: | 115 default: |
136 return MessageTemplate::kNone; | 116 return MessageTemplate::kNone; |
137 } | 117 } |
138 } | 118 } |
139 | 119 |
140 const char* WasmOpcodes::TrapReasonMessage(TrapReason reason) { | 120 const char* WasmOpcodes::TrapReasonMessage(TrapReason reason) { |
141 return MessageTemplate::TemplateString(TrapReasonToMessageId(reason)); | 121 return MessageTemplate::TemplateString(TrapReasonToMessageId(reason)); |
142 } | 122 } |
143 } // namespace wasm | 123 } // namespace wasm |
144 } // namespace internal | 124 } // namespace internal |
145 } // namespace v8 | 125 } // namespace v8 |
OLD | NEW |