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 operands used by bytecodes. | |
rmcilroy
2015/07/28 08:58:12
/s/operands/operand types/
oth
2015/07/28 13:24:14
Done.
| |
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 |
rmcilroy
2015/07/28 08:58:12
nit - extra newline
oth
2015/07/28 13:24:14
Done.
| |
30 // Enumeration of operand types used by bytecodes. | |
31 enum class OperandType : uint8_t { | |
32 #define DECLARE_OPERAND_TYPE(Name) k##Name, | |
33 OPERAND_TYPE_LIST(DECLARE_OPERAND_TYPE) | |
34 #undef DECLARE_OPERAND_TYPE | |
35 #define COUNT_OPERAND_TYPES(x) +1 | |
36 // The COUNT_OPERAND macro will turn this into kLast = -1 +1 +1... which will | |
37 // evaluate to the same value as the last operand. | |
38 kLast = -1 OPERAND_TYPE_LIST(COUNT_OPERAND_TYPES) | |
39 #undef COUNT_OPERAND_TYPES | |
40 }; | |
41 | |
rmcilroy
2015/07/28 08:58:12
nit - extra newline
oth
2015/07/28 13:24:14
Done.
| |
42 // Enumeration of interpreter bytecodes. | |
23 enum class Bytecode : uint8_t { | 43 enum class Bytecode : uint8_t { |
24 #define DECLARE_BYTECODE(Name, _) k##Name, | 44 #define DECLARE_BYTECODE(Name, ...) k##Name, |
25 BYTECODE_LIST(DECLARE_BYTECODE) | 45 BYTECODE_LIST(DECLARE_BYTECODE) |
26 #undef DECLARE_BYTECODE | 46 #undef DECLARE_BYTECODE |
27 #define COUNT_BYTECODE(x, _) +1 | 47 #define COUNT_BYTECODE(x, ...) +1 |
28 // The COUNT_BYTECODE macro will turn this into kLast = -1 +1 +1... which will | 48 // 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. | 49 // evaluate to the same value as the last real bytecode. |
30 kLast = -1 BYTECODE_LIST(COUNT_BYTECODE) | 50 kLast = -1 BYTECODE_LIST(COUNT_BYTECODE) |
31 #undef COUNT_BYTECODE | 51 #undef COUNT_BYTECODE |
32 }; | 52 }; |
33 | 53 |
54 | |
34 class Bytecodes { | 55 class Bytecodes { |
35 public: | 56 public: |
36 // Returns string representation of |bytecode|. | 57 // Returns string representation of |bytecode|. |
37 static const char* ToString(Bytecode bytecode); | 58 static const char* ToString(Bytecode bytecode); |
38 | 59 |
39 // Returns the number of arguments expected by |bytecode|. | 60 // Returns byte value of bytecode. |
40 static const int NumberOfArguments(Bytecode bytecode); | 61 static uint8_t ToByte(Bytecode bytecode); |
62 | |
63 // Returns bytecode for |value|, checking validity in the process. | |
rmcilroy
2015/07/28 08:58:12
nit - remove the ", checking validity in the proce
oth
2015/07/28 13:24:14
Done.
| |
64 static Bytecode FromByte(uint8_t value); | |
65 | |
66 // Returns the number of operands expected by |bytecode|. | |
67 static const int NumberOfOperands(Bytecode bytecode); | |
68 | |
69 // Return the i-th operand of |bytecode|. | |
70 static const OperandType GetOperandType(Bytecode bytecode, int i); | |
41 | 71 |
42 // Returns the size of the bytecode including its arguments. | 72 // Returns the size of the bytecode including its arguments. |
43 static const int Size(Bytecode bytecode); | 73 static const int Size(Bytecode bytecode); |
44 | 74 |
45 // The maximum number of arguments across all bytecodes. | 75 // The maximum number of operands across all bytecodes. |
46 static const int kMaximumNumberOfArguments = 1; | 76 static const int MaximumNumberOfOperands(); |
47 | 77 |
48 // Maximum size of a bytecode and its arguments. | 78 // Maximum size of a bytecode and its arguments. |
49 static const int kMaximumSize = 1 + kMaximumNumberOfArguments; | 79 static const int MaximumSize(); |
50 | 80 |
51 private: | 81 private: |
52 DISALLOW_IMPLICIT_CONSTRUCTORS(Bytecodes); | 82 DISALLOW_IMPLICIT_CONSTRUCTORS(Bytecodes); |
53 }; | 83 }; |
54 | 84 |
55 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode); | 85 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode); |
56 | 86 |
57 } // namespace interpreter | 87 } // namespace interpreter |
58 } // namespace internal | 88 } // namespace internal |
59 } // namespace v8 | 89 } // namespace v8 |
60 | 90 |
61 #endif // V8_INTERPRETER_BYTECODES_H_ | 91 #endif // V8_INTERPRETER_BYTECODES_H_ |
OLD | NEW |