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/signature.h" | 6 #include "src/signature.h" |
7 | 7 |
8 namespace v8 { | 8 namespace v8 { |
9 namespace internal { | 9 namespace internal { |
10 namespace wasm { | 10 namespace wasm { |
11 | 11 |
12 typedef Signature<LocalType> FunctionSig; | 12 typedef Signature<LocalType> FunctionSig; |
13 | 13 |
14 const char* WasmOpcodes::OpcodeName(WasmOpcode opcode) { | 14 const char* WasmOpcodes::OpcodeName(WasmOpcode opcode) { |
15 switch (opcode) { | 15 switch (opcode) { |
16 #define DECLARE_NAME_CASE(name, opcode, sig) \ | 16 #define DECLARE_NAME_CASE(name, opcode, sig) \ |
17 case kExpr##name: \ | 17 case kExpr##name: \ |
18 return "Expr" #name; | 18 return "Expr" #name; |
19 FOREACH_OPCODE(DECLARE_NAME_CASE) | 19 FOREACH_OPCODE(DECLARE_NAME_CASE) |
20 #undef DECLARE_NAME_CASE | 20 #undef DECLARE_NAME_CASE |
21 default: | 21 default: |
22 break; | 22 break; |
23 } | 23 } |
24 return "Unknown"; | 24 return "Unknown"; |
25 } | 25 } |
26 | 26 |
27 | 27 |
| 28 std::ostream& operator<<(std::ostream& os, const FunctionSig& sig) { |
| 29 if (sig.return_count() == 0) os << "v"; |
| 30 for (size_t i = 0; i < sig.return_count(); i++) { |
| 31 os << WasmOpcodes::ShortNameOf(sig.GetReturn(i)); |
| 32 } |
| 33 os << "_"; |
| 34 if (sig.parameter_count() == 0) os << "v"; |
| 35 for (size_t i = 0; i < sig.parameter_count(); i++) { |
| 36 os << WasmOpcodes::ShortNameOf(sig.GetParam(i)); |
| 37 } |
| 38 return os; |
| 39 } |
| 40 |
| 41 |
28 #define DECLARE_SIG_ENUM(name, ...) kSigEnum_##name, | 42 #define DECLARE_SIG_ENUM(name, ...) kSigEnum_##name, |
29 | 43 |
30 | 44 |
31 enum WasmOpcodeSig { FOREACH_SIGNATURE(DECLARE_SIG_ENUM) }; | 45 enum WasmOpcodeSig { FOREACH_SIGNATURE(DECLARE_SIG_ENUM) }; |
32 | 46 |
33 | 47 |
34 // TODO(titzer): not static-initializer safe. Wrap in LazyInstance. | 48 // TODO(titzer): not static-initializer safe. Wrap in LazyInstance. |
35 #define DECLARE_SIG(name, ...) \ | 49 #define DECLARE_SIG(name, ...) \ |
36 static LocalType kTypes_##name[] = {__VA_ARGS__}; \ | 50 static LocalType kTypes_##name[] = {__VA_ARGS__}; \ |
37 static const FunctionSig kSig_##name( \ | 51 static const FunctionSig kSig_##name( \ |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 default: | 138 default: |
125 return true; | 139 return true; |
126 } | 140 } |
127 #else | 141 #else |
128 return true; | 142 return true; |
129 #endif | 143 #endif |
130 } | 144 } |
131 } // namespace wasm | 145 } // namespace wasm |
132 } // namespace internal | 146 } // namespace internal |
133 } // namespace v8 | 147 } // namespace v8 |
OLD | NEW |