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 #ifndef V8_INTERPRETER_BYTECODES_H_ | 5 #ifndef V8_INTERPRETER_BYTECODES_H_ |
6 #define V8_INTERPRETER_BYTECODES_H_ | 6 #define V8_INTERPRETER_BYTECODES_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 | 9 |
10 // Clients of this interface shouldn't depend on lots of interpreter internals. | 10 // Clients of this interface shouldn't depend on lots of interpreter internals. |
11 // Do not include anything from src/interpreter here! | 11 // Do not include anything from src/interpreter here! |
12 #include "src/utils.h" | 12 #include "src/utils.h" |
13 | 13 |
14 namespace v8 { | 14 namespace v8 { |
15 namespace internal { | 15 namespace internal { |
16 namespace interpreter { | 16 namespace interpreter { |
17 | 17 |
| 18 // The list of operand types used by bytecodes. |
| 19 #define OPERAND_TYPE_LIST(V) \ |
| 20 V(None) \ |
| 21 V(Imm8) \ |
| 22 V(Reg) |
| 23 |
18 // The list of bytecodes which are interpreted by the interpreter. | 24 // The list of bytecodes which are interpreted by the interpreter. |
19 #define BYTECODE_LIST(V) \ | 25 #define BYTECODE_LIST(V) \ |
20 V(LoadLiteral0, 1) \ | 26 V(LoadLiteral0, OperandType::kReg) \ |
21 V(Return, 0) | 27 V(LoadSmi8, OperandType::kReg, OperandType::kImm8) \ |
| 28 V(Return, OperandType::kNone) |
22 | 29 |
| 30 |
| 31 // Enumeration of operand types used by bytecodes. |
| 32 enum class OperandType : uint8_t { |
| 33 #define DECLARE_OPERAND_TYPE(Name) k##Name, |
| 34 OPERAND_TYPE_LIST(DECLARE_OPERAND_TYPE) |
| 35 #undef DECLARE_OPERAND_TYPE |
| 36 #define COUNT_OPERAND_TYPES(x) +1 |
| 37 // The COUNT_OPERAND macro will turn this into kLast = -1 +1 +1... which will |
| 38 // evaluate to the same value as the last operand. |
| 39 kLast = -1 OPERAND_TYPE_LIST(COUNT_OPERAND_TYPES) |
| 40 #undef COUNT_OPERAND_TYPES |
| 41 }; |
| 42 |
| 43 |
| 44 // Enumeration of interpreter bytecodes. |
23 enum class Bytecode : uint8_t { | 45 enum class Bytecode : uint8_t { |
24 #define DECLARE_BYTECODE(Name, _) k##Name, | 46 #define DECLARE_BYTECODE(Name, ...) k##Name, |
25 BYTECODE_LIST(DECLARE_BYTECODE) | 47 BYTECODE_LIST(DECLARE_BYTECODE) |
26 #undef DECLARE_BYTECODE | 48 #undef DECLARE_BYTECODE |
27 #define COUNT_BYTECODE(x, _) +1 | 49 #define COUNT_BYTECODE(x, ...) +1 |
28 // The COUNT_BYTECODE macro will turn this into kLast = -1 +1 +1... which will | 50 // The COUNT_BYTECODE macro will turn this into kLast = -1 +1 +1... which will |
29 // evaluate to the same value as the last real bytecode. | 51 // evaluate to the same value as the last real bytecode. |
30 kLast = -1 BYTECODE_LIST(COUNT_BYTECODE) | 52 kLast = -1 BYTECODE_LIST(COUNT_BYTECODE) |
31 #undef COUNT_BYTECODE | 53 #undef COUNT_BYTECODE |
32 }; | 54 }; |
33 | 55 |
| 56 |
34 class Bytecodes { | 57 class Bytecodes { |
35 public: | 58 public: |
36 // Returns string representation of |bytecode|. | 59 // Returns string representation of |bytecode|. |
37 static const char* ToString(Bytecode bytecode); | 60 static const char* ToString(Bytecode bytecode); |
38 | 61 |
39 // Returns the number of arguments expected by |bytecode|. | 62 // Returns byte value of bytecode. |
40 static const int NumberOfArguments(Bytecode bytecode); | 63 static uint8_t ToByte(Bytecode bytecode); |
| 64 |
| 65 // Returns bytecode for |value|. |
| 66 static Bytecode FromByte(uint8_t value); |
| 67 |
| 68 // Returns the number of operands expected by |bytecode|. |
| 69 static const int NumberOfOperands(Bytecode bytecode); |
| 70 |
| 71 // Return the i-th operand of |bytecode|. |
| 72 static const OperandType GetOperandType(Bytecode bytecode, int i); |
41 | 73 |
42 // Returns the size of the bytecode including its arguments. | 74 // Returns the size of the bytecode including its arguments. |
43 static const int Size(Bytecode bytecode); | 75 static const int Size(Bytecode bytecode); |
44 | 76 |
45 // The maximum number of arguments across all bytecodes. | 77 // The maximum number of operands across all bytecodes. |
46 static const int kMaximumNumberOfArguments = 1; | 78 static const int MaximumNumberOfOperands(); |
47 | 79 |
48 // Maximum size of a bytecode and its arguments. | 80 // Maximum size of a bytecode and its arguments. |
49 static const int kMaximumSize = 1 + kMaximumNumberOfArguments; | 81 static const int MaximumSize(); |
50 | 82 |
51 private: | 83 private: |
52 DISALLOW_IMPLICIT_CONSTRUCTORS(Bytecodes); | 84 DISALLOW_IMPLICIT_CONSTRUCTORS(Bytecodes); |
53 }; | 85 }; |
54 | 86 |
55 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode); | 87 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode); |
56 | 88 |
57 } // namespace interpreter | 89 } // namespace interpreter |
58 } // namespace internal | 90 } // namespace internal |
59 } // namespace v8 | 91 } // namespace v8 |
60 | 92 |
61 #endif // V8_INTERPRETER_BYTECODES_H_ | 93 #endif // V8_INTERPRETER_BYTECODES_H_ |
OLD | NEW |