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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 os << WasmOpcodes::ShortNameOf(sig.GetReturn(i)); | 44 os << WasmOpcodes::ShortNameOf(sig.GetReturn(i)); |
45 } | 45 } |
46 os << "_"; | 46 os << "_"; |
47 if (sig.parameter_count() == 0) os << "v"; | 47 if (sig.parameter_count() == 0) os << "v"; |
48 for (size_t i = 0; i < sig.parameter_count(); i++) { | 48 for (size_t i = 0; i < sig.parameter_count(); i++) { |
49 os << WasmOpcodes::ShortNameOf(sig.GetParam(i)); | 49 os << WasmOpcodes::ShortNameOf(sig.GetParam(i)); |
50 } | 50 } |
51 return os; | 51 return os; |
52 } | 52 } |
53 | 53 |
54 | |
55 #define DECLARE_SIG_ENUM(name, ...) kSigEnum_##name, | 54 #define DECLARE_SIG_ENUM(name, ...) kSigEnum_##name, |
56 | 55 |
57 | |
58 enum WasmOpcodeSig { FOREACH_SIGNATURE(DECLARE_SIG_ENUM) }; | 56 enum WasmOpcodeSig { FOREACH_SIGNATURE(DECLARE_SIG_ENUM) }; |
59 | 57 |
60 | |
61 // TODO(titzer): not static-initializer safe. Wrap in LazyInstance. | 58 // TODO(titzer): not static-initializer safe. Wrap in LazyInstance. |
62 #define DECLARE_SIG(name, ...) \ | 59 #define DECLARE_SIG(name, ...) \ |
63 static LocalType kTypes_##name[] = {__VA_ARGS__}; \ | 60 static LocalType kTypes_##name[] = {__VA_ARGS__}; \ |
64 static const FunctionSig kSig_##name( \ | 61 static const FunctionSig kSig_##name( \ |
65 1, static_cast<int>(arraysize(kTypes_##name)) - 1, kTypes_##name); | 62 1, static_cast<int>(arraysize(kTypes_##name)) - 1, kTypes_##name); |
66 | 63 |
67 FOREACH_SIGNATURE(DECLARE_SIG) | 64 FOREACH_SIGNATURE(DECLARE_SIG) |
68 | 65 |
69 #define DECLARE_SIG_ENTRY(name, ...) &kSig_##name, | 66 #define DECLARE_SIG_ENTRY(name, ...) &kSig_##name, |
70 | 67 |
71 static const FunctionSig* kSimpleExprSigs[] = { | 68 static const FunctionSig* kSimpleExprSigs[] = { |
72 nullptr, FOREACH_SIGNATURE(DECLARE_SIG_ENTRY)}; | 69 nullptr, FOREACH_SIGNATURE(DECLARE_SIG_ENTRY)}; |
73 | 70 |
74 static byte kSimpleExprSigTable[256]; | 71 static byte kSimpleExprSigTable[256]; |
75 | 72 |
76 | |
77 // Initialize the signature table. | 73 // Initialize the signature table. |
78 static void InitSigTable() { | 74 static void InitSigTable() { |
79 #define SET_SIG_TABLE(name, opcode, sig) \ | 75 #define SET_SIG_TABLE(name, opcode, sig) \ |
80 kSimpleExprSigTable[opcode] = static_cast<int>(kSigEnum_##sig) + 1; | 76 kSimpleExprSigTable[opcode] = static_cast<int>(kSigEnum_##sig) + 1; |
81 FOREACH_SIMPLE_OPCODE(SET_SIG_TABLE); | 77 FOREACH_SIMPLE_OPCODE(SET_SIG_TABLE); |
82 FOREACH_ASMJS_COMPAT_OPCODE(SET_SIG_TABLE); | 78 FOREACH_ASMJS_COMPAT_OPCODE(SET_SIG_TABLE); |
83 #undef SET_SIG_TABLE | 79 #undef SET_SIG_TABLE |
84 } | 80 } |
85 | 81 |
86 | |
87 FunctionSig* WasmOpcodes::Signature(WasmOpcode opcode) { | 82 FunctionSig* WasmOpcodes::Signature(WasmOpcode opcode) { |
88 // TODO(titzer): use LazyInstance to make this thread safe. | 83 // TODO(titzer): use LazyInstance to make this thread safe. |
89 if (kSimpleExprSigTable[kExprI32Add] == 0) InitSigTable(); | 84 if (kSimpleExprSigTable[kExprI32Add] == 0) InitSigTable(); |
90 return const_cast<FunctionSig*>( | 85 return const_cast<FunctionSig*>( |
91 kSimpleExprSigs[kSimpleExprSigTable[static_cast<byte>(opcode)]]); | 86 kSimpleExprSigs[kSimpleExprSigTable[static_cast<byte>(opcode)]]); |
92 } | 87 } |
93 | 88 |
94 | |
95 // TODO(titzer): pull WASM_64 up to a common header. | 89 // TODO(titzer): pull WASM_64 up to a common header. |
96 #if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64 | 90 #if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64 |
97 #define WASM_64 1 | 91 #define WASM_64 1 |
98 #else | 92 #else |
99 #define WASM_64 0 | 93 #define WASM_64 0 |
100 #endif | 94 #endif |
101 | 95 |
102 int WasmOpcodes::TrapReasonToMessageId(TrapReason reason) { | 96 int WasmOpcodes::TrapReasonToMessageId(TrapReason reason) { |
103 switch (reason) { | 97 switch (reason) { |
104 #define TRAPREASON_TO_MESSAGE(name) \ | 98 #define TRAPREASON_TO_MESSAGE(name) \ |
105 case k##name: \ | 99 case k##name: \ |
106 return MessageTemplate::kWasm##name; | 100 return MessageTemplate::kWasm##name; |
107 FOREACH_WASM_TRAPREASON(TRAPREASON_TO_MESSAGE) | 101 FOREACH_WASM_TRAPREASON(TRAPREASON_TO_MESSAGE) |
108 #undef TRAPREASON_TO_MESSAGE | 102 #undef TRAPREASON_TO_MESSAGE |
109 default: | 103 default: |
110 return MessageTemplate::kNone; | 104 return MessageTemplate::kNone; |
111 } | 105 } |
112 } | 106 } |
113 | 107 |
114 const char* WasmOpcodes::TrapReasonMessage(TrapReason reason) { | 108 const char* WasmOpcodes::TrapReasonMessage(TrapReason reason) { |
115 return MessageTemplate::TemplateString(TrapReasonToMessageId(reason)); | 109 return MessageTemplate::TemplateString(TrapReasonToMessageId(reason)); |
116 } | 110 } |
117 } // namespace wasm | 111 } // namespace wasm |
118 } // namespace internal | 112 } // namespace internal |
119 } // namespace v8 | 113 } // namespace v8 |
OLD | NEW |