Chromium Code Reviews| 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. | 18 // The list of operand types used by bytecodes. |
| 19 #define OPERAND_TYPE_LIST(V) \ | 19 #define OPERAND_TYPE_LIST(V) \ |
| 20 V(None) \ | 20 \ |
| 21 V(Count) \ | 21 /* None operand. */ \ |
| 22 V(Imm8) \ | 22 V(None, OperandSize::kNone) \ |
| 23 V(Idx) \ | 23 \ |
| 24 V(Reg) | 24 /* Byte operands. */ \ |
| 25 V(Count8, OperandSize::kByte) \ | |
| 26 V(Imm8, OperandSize::kByte) \ | |
| 27 V(Idx8, OperandSize::kByte) \ | |
| 28 V(Reg8, OperandSize::kByte) \ | |
| 29 \ | |
| 30 /* Short operands. */ \ | |
| 31 V(Idx16, OperandSize::kShort) | |
| 25 | 32 |
| 26 // The list of bytecodes which are interpreted by the interpreter. | 33 // The list of bytecodes which are interpreted by the interpreter. |
| 27 #define BYTECODE_LIST(V) \ | 34 #define BYTECODE_LIST(V) \ |
| 28 \ | 35 \ |
| 29 /* Loading the accumulator */ \ | 36 /* Loading the accumulator */ \ |
| 30 V(LdaZero, OperandType::kNone) \ | 37 V(LdaZero, OperandType::kNone) \ |
| 31 V(LdaSmi8, OperandType::kImm8) \ | 38 V(LdaSmi8, OperandType::kImm8) \ |
| 32 V(LdaConstant, OperandType::kIdx) \ | 39 V(LdaConstant, OperandType::kIdx8) \ |
| 33 V(LdaUndefined, OperandType::kNone) \ | 40 V(LdaUndefined, OperandType::kNone) \ |
| 34 V(LdaNull, OperandType::kNone) \ | 41 V(LdaNull, OperandType::kNone) \ |
| 35 V(LdaTheHole, OperandType::kNone) \ | 42 V(LdaTheHole, OperandType::kNone) \ |
| 36 V(LdaTrue, OperandType::kNone) \ | 43 V(LdaTrue, OperandType::kNone) \ |
| 37 V(LdaFalse, OperandType::kNone) \ | 44 V(LdaFalse, OperandType::kNone) \ |
| 38 \ | 45 \ |
| 39 /* Load globals */ \ | 46 /* Load globals */ \ |
| 40 V(LdaGlobal, OperandType::kIdx) \ | 47 V(LdaGlobal, OperandType::kIdx8) \ |
| 41 \ | 48 \ |
| 42 /* Register-accumulator transfers */ \ | 49 /* Reg8ister-accumulator transfers */ \ |
| 43 V(Ldar, OperandType::kReg) \ | 50 V(Ldar, OperandType::kReg8) \ |
| 44 V(Star, OperandType::kReg) \ | 51 V(Star, OperandType::kReg8) \ |
| 45 \ | 52 \ |
| 46 /* LoadIC operations */ \ | 53 /* LoadIC operations */ \ |
| 47 V(LoadIC, OperandType::kReg, OperandType::kIdx) \ | 54 V(LoadIC, OperandType::kReg8, OperandType::kIdx8) \ |
| 48 V(KeyedLoadIC, OperandType::kReg, OperandType::kIdx) \ | 55 V(KeyedLoadIC, OperandType::kReg8, OperandType::kIdx8) \ |
| 49 \ | 56 \ |
| 50 /* StoreIC operations */ \ | 57 /* StoreIC operations */ \ |
| 51 V(StoreIC, OperandType::kReg, OperandType::kReg, OperandType::kIdx) \ | 58 V(StoreIC, OperandType::kReg8, OperandType::kReg8, OperandType::kIdx8) \ |
| 52 V(KeyedStoreIC, OperandType::kReg, OperandType::kReg, OperandType::kIdx) \ | 59 V(KeyedStoreIC, OperandType::kReg8, OperandType::kReg8, OperandType::kIdx8) \ |
| 53 \ | 60 \ |
| 54 /* Binary Operators */ \ | 61 /* Binary Operators */ \ |
| 55 V(Add, OperandType::kReg) \ | 62 V(Add, OperandType::kReg8) \ |
| 56 V(Sub, OperandType::kReg) \ | 63 V(Sub, OperandType::kReg8) \ |
| 57 V(Mul, OperandType::kReg) \ | 64 V(Mul, OperandType::kReg8) \ |
| 58 V(Div, OperandType::kReg) \ | 65 V(Div, OperandType::kReg8) \ |
| 59 V(Mod, OperandType::kReg) \ | 66 V(Mod, OperandType::kReg8) \ |
| 60 \ | 67 \ |
| 61 /* Call operations. */ \ | 68 /* Call operations. */ \ |
| 62 V(Call, OperandType::kReg, OperandType::kReg, OperandType::kCount) \ | 69 V(Call, OperandType::kReg8, OperandType::kReg8, OperandType::kCount8) \ |
| 63 \ | 70 \ |
| 64 /* Test Operators */ \ | 71 /* Test Operators */ \ |
| 65 V(TestEqual, OperandType::kReg) \ | 72 V(TestEqual, OperandType::kReg8) \ |
| 66 V(TestNotEqual, OperandType::kReg) \ | 73 V(TestNotEqual, OperandType::kReg8) \ |
| 67 V(TestEqualStrict, OperandType::kReg) \ | 74 V(TestEqualStrict, OperandType::kReg8) \ |
| 68 V(TestNotEqualStrict, OperandType::kReg) \ | 75 V(TestNotEqualStrict, OperandType::kReg8) \ |
| 69 V(TestLessThan, OperandType::kReg) \ | 76 V(TestLessThan, OperandType::kReg8) \ |
| 70 V(TestGreaterThan, OperandType::kReg) \ | 77 V(TestGreaterThan, OperandType::kReg8) \ |
| 71 V(TestLessThanEqual, OperandType::kReg) \ | 78 V(TestLessThanEqual, OperandType::kReg8) \ |
| 72 V(TestGreaterThanEqual, OperandType::kReg) \ | 79 V(TestGreaterThanEqual, OperandType::kReg8) \ |
| 73 V(TestInstanceOf, OperandType::kReg) \ | 80 V(TestInstanceOf, OperandType::kReg8) \ |
| 74 V(TestIn, OperandType::kReg) \ | 81 V(TestIn, OperandType::kReg8) \ |
| 75 \ | 82 \ |
| 76 /* Cast operators */ \ | 83 /* Cast operators */ \ |
| 77 V(ToBoolean, OperandType::kNone) \ | 84 V(ToBoolean, OperandType::kNone) \ |
| 78 \ | 85 \ |
| 79 /* Control Flow */ \ | 86 /* Control Flow */ \ |
| 80 V(Jump, OperandType::kImm8) \ | 87 V(Jump, OperandType::kImm8) \ |
| 81 V(JumpConstant, OperandType::kIdx) \ | 88 V(JumpConstant, OperandType::kIdx8) \ |
| 82 V(JumpIfTrue, OperandType::kImm8) \ | 89 V(JumpIfTrue, OperandType::kImm8) \ |
| 83 V(JumpIfTrueConstant, OperandType::kIdx) \ | 90 V(JumpIfTrueConstant, OperandType::kIdx8) \ |
| 84 V(JumpIfFalse, OperandType::kImm8) \ | 91 V(JumpIfFalse, OperandType::kImm8) \ |
| 85 V(JumpIfFalseConstant, OperandType::kIdx) \ | 92 V(JumpIfFalseConstant, OperandType::kIdx8) \ |
| 86 V(Return, OperandType::kNone) | 93 V(Return, OperandType::kNone) |
| 87 | 94 |
| 88 | 95 |
| 96 // Enumeration of the size classes of operand types used by bytecodes. | |
| 97 enum class OperandSize : uint8_t { | |
| 98 kNone = 0, | |
| 99 kByte = 1, | |
| 100 kShort = 2, | |
| 101 }; | |
| 102 | |
| 103 | |
| 89 // Enumeration of operand types used by bytecodes. | 104 // Enumeration of operand types used by bytecodes. |
| 90 enum class OperandType : uint8_t { | 105 enum class OperandType : uint8_t { |
| 91 #define DECLARE_OPERAND_TYPE(Name) k##Name, | 106 #define DECLARE_OPERAND_TYPE(Name, _) k##Name, |
| 92 OPERAND_TYPE_LIST(DECLARE_OPERAND_TYPE) | 107 OPERAND_TYPE_LIST(DECLARE_OPERAND_TYPE) |
| 93 #undef DECLARE_OPERAND_TYPE | 108 #undef DECLARE_OPERAND_TYPE |
| 94 #define COUNT_OPERAND_TYPES(x) +1 | 109 #define COUNT_OPERAND_TYPES(x, _) +1 |
| 95 // The COUNT_OPERAND macro will turn this into kLast = -1 +1 +1... which will | 110 // The COUNT_OPERAND macro will turn this into kLast = -1 +1 +1... which will |
| 96 // evaluate to the same value as the last operand. | 111 // evaluate to the same value as the last operand. |
| 97 kLast = -1 OPERAND_TYPE_LIST(COUNT_OPERAND_TYPES) | 112 kLast = -1 OPERAND_TYPE_LIST(COUNT_OPERAND_TYPES) |
| 98 #undef COUNT_OPERAND_TYPES | 113 #undef COUNT_OPERAND_TYPES |
| 99 }; | 114 }; |
| 100 | 115 |
| 101 | 116 |
| 102 // Enumeration of interpreter bytecodes. | 117 // Enumeration of interpreter bytecodes. |
| 103 enum class Bytecode : uint8_t { | 118 enum class Bytecode : uint8_t { |
| 104 #define DECLARE_BYTECODE(Name, ...) k##Name, | 119 #define DECLARE_BYTECODE(Name, ...) k##Name, |
| 105 BYTECODE_LIST(DECLARE_BYTECODE) | 120 BYTECODE_LIST(DECLARE_BYTECODE) |
| 106 #undef DECLARE_BYTECODE | 121 #undef DECLARE_BYTECODE |
| 107 #define COUNT_BYTECODE(x, ...) +1 | 122 #define COUNT_BYTECODE(x, ...) +1 |
| 108 // The COUNT_BYTECODE macro will turn this into kLast = -1 +1 +1... which will | 123 // The Count_BYTECODE macro will turn this into kLast = -1 +1 +1... which will |
|
oth
2015/10/01 15:12:15
Intentional?
rmcilroy
2015/10/01 16:25:07
Nope, thanks! Done.
| |
| 109 // evaluate to the same value as the last real bytecode. | 124 // evaluate to the same value as the last real bytecode. |
| 110 kLast = -1 BYTECODE_LIST(COUNT_BYTECODE) | 125 kLast = -1 BYTECODE_LIST(COUNT_BYTECODE) |
| 111 #undef COUNT_BYTECODE | 126 #undef COUNT_BYTECODE |
| 112 }; | 127 }; |
| 113 | 128 |
| 114 | 129 |
| 115 // An interpreter register which is located in the function's register file | 130 // An interpreter Reg8ister which is located in the function's Reg8ister file |
| 116 // in its stack-frame. Register hold parameters, this, and expression values. | 131 // in its stack-frame. Reg8ister hold parameters, this, and expression values. |
| 117 class Register { | 132 class Register { |
| 118 public: | 133 public: |
| 119 static const int kMaxRegisterIndex = 127; | 134 static const int kMaxRegisterIndex = 127; |
| 120 static const int kMinRegisterIndex = -128; | 135 static const int kMinRegisterIndex = -128; |
| 121 | 136 |
| 122 Register() : index_(kIllegalIndex) {} | 137 Register() : index_(kIllegalIndex) {} |
| 123 | 138 |
| 124 explicit Register(int index) : index_(index) { | 139 explicit Register(int index) : index_(index) { |
| 125 DCHECK_LE(index_, kMaxRegisterIndex); | 140 DCHECK_LE(index_, kMaxRegisterIndex); |
| 126 DCHECK_GE(index_, kMinRegisterIndex); | 141 DCHECK_GE(index_, kMinRegisterIndex); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 | 177 |
| 163 // Returns bytecode for |value|. | 178 // Returns bytecode for |value|. |
| 164 static Bytecode FromByte(uint8_t value); | 179 static Bytecode FromByte(uint8_t value); |
| 165 | 180 |
| 166 // Returns the number of operands expected by |bytecode|. | 181 // Returns the number of operands expected by |bytecode|. |
| 167 static int NumberOfOperands(Bytecode bytecode); | 182 static int NumberOfOperands(Bytecode bytecode); |
| 168 | 183 |
| 169 // Return the i-th operand of |bytecode|. | 184 // Return the i-th operand of |bytecode|. |
| 170 static OperandType GetOperandType(Bytecode bytecode, int i); | 185 static OperandType GetOperandType(Bytecode bytecode, int i); |
| 171 | 186 |
| 187 // Return the size of the i-th operand of |bytecode|. | |
| 188 static OperandSize GetOperandSize(Bytecode bytecode, int i); | |
| 189 | |
| 190 // Returns the offset of the i-th operand of |bytecode| relative to the start | |
| 191 // of the bytecode. | |
| 192 static int GetOperandOffset(Bytecode bytecode, int i); | |
| 193 | |
| 172 // Returns the size of the bytecode including its operands. | 194 // Returns the size of the bytecode including its operands. |
| 173 static int Size(Bytecode bytecode); | 195 static int Size(Bytecode bytecode); |
| 174 | 196 |
| 175 // The maximum number of operands across all bytecodes. | 197 // Returns the size of operand. |
|
oth
2015/10/01 15:12:15
|operand|
rmcilroy
2015/10/01 16:25:07
Done.
| |
| 176 static int MaximumNumberOfOperands(); | 198 static OperandSize SizeOfOperand(OperandType operand); |
| 177 | 199 |
| 178 // Maximum size of a bytecode and its operands. | 200 // Converts bytes[0] and bytes[1] to a 16 bit 'short' operand value. |
| 179 static int MaximumSize(); | 201 static uint16_t ShortOperandFromBytes(const uint8_t* bytes); |
| 202 | |
| 203 // Converts 16 bit 'short' |operand| into bytes_out[0] and bytes_out[1]. | |
| 204 static void ShortOperandToBytes(uint16_t operand, uint8_t* bytes_out); | |
| 180 | 205 |
| 181 // Decode a single bytecode and operands to |os|. | 206 // Decode a single bytecode and operands to |os|. |
| 182 static std::ostream& Decode(std::ostream& os, const uint8_t* bytecode_start, | 207 static std::ostream& Decode(std::ostream& os, const uint8_t* bytecode_start, |
| 183 int number_of_parameters); | 208 int number_of_parameters); |
| 184 | 209 |
| 185 private: | 210 private: |
| 186 DISALLOW_IMPLICIT_CONSTRUCTORS(Bytecodes); | 211 DISALLOW_IMPLICIT_CONSTRUCTORS(Bytecodes); |
| 187 }; | 212 }; |
| 188 | 213 |
| 189 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode); | 214 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode); |
| 190 std::ostream& operator<<(std::ostream& os, const OperandType& operand_type); | 215 std::ostream& operator<<(std::ostream& os, const OperandType& operand_type); |
| 191 | 216 |
| 192 } // namespace interpreter | 217 } // namespace interpreter |
| 193 } // namespace internal | 218 } // namespace internal |
| 194 } // namespace v8 | 219 } // namespace v8 |
| 195 | 220 |
| 196 #endif // V8_INTERPRETER_BYTECODES_H_ | 221 #endif // V8_INTERPRETER_BYTECODES_H_ |
| OLD | NEW |