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(Count, OperandSize::kByte) \ | |
| 26 V(Imm8, OperandSize::kByte) \ | |
| 27 V(Idx, OperandSize::kByte) \ | |
| 28 V(Reg, OperandSize::kByte) \ | |
| 29 \ | |
| 30 /* Wide operands. */ \ | |
| 31 V(WideIdx, OperandSize::kWide) | |
|
oth
2015/09/28 09:21:25
Wide is a loose term. It's currently a 16-bit oper
rmcilroy
2015/10/01 14:09:14
Renamed OperandSize::kWide to 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::kIdx) \ |
| 33 V(LdaUndefined, OperandType::kNone) \ | 40 V(LdaUndefined, OperandType::kNone) \ |
| 34 V(LdaNull, OperandType::kNone) \ | 41 V(LdaNull, OperandType::kNone) \ |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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::kIdx) \ |
| 82 V(JumpIfTrue, OperandType::kImm8) \ | 89 V(JumpIfTrue, OperandType::kImm8) \ |
| 83 V(JumpIfTrueConstant, OperandType::kIdx) \ | 90 V(JumpIfTrueConstant, OperandType::kIdx) \ |
| 84 V(JumpIfFalse, OperandType::kImm8) \ | 91 V(JumpIfFalse, OperandType::kImm8) \ |
| 85 V(JumpIfFalseConstant, OperandType::kIdx) \ | 92 V(JumpIfFalseConstant, OperandType::kIdx) \ |
| 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 kWide = 2, | |
|
oth
2015/09/28 09:21:25
More descriptive names to avoid wide? kOneByte kTw
rmcilroy
2015/10/01 14:09:14
Made it kByte, kShort and will be kLong for 32.
| |
| 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, |
| (...skipping 57 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 // Returns the offset of the i-th operand of |bytecode| relative to the start | |
| 188 // of the bytecode. | |
| 189 static int GetOperandOffset(Bytecode bytecode, int i); | |
| 190 | |
| 172 // Returns the size of the bytecode including its operands. | 191 // Returns the size of the bytecode including its operands. |
| 173 static int Size(Bytecode bytecode); | 192 static int Size(Bytecode bytecode); |
| 174 | 193 |
| 175 // The maximum number of operands across all bytecodes. | 194 // Returns the size of operand. |
| 176 static int MaximumNumberOfOperands(); | 195 static OperandSize SizeOfOperand(OperandType operand); |
| 177 | 196 |
| 178 // Maximum size of a bytecode and its operands. | 197 // Converts bytes[0] and bytes[1] to a 16 bit wide operand value. |
| 179 static int MaximumSize(); | 198 static uint16_t WideOperandFromBytes(const uint8_t* bytes); |
| 199 | |
| 200 // Converts 16 bit wide |operand| into bytes_out[0] and bytes_out[1]. | |
| 201 static void WideOperandToBytes(uint16_t operand, uint8_t* bytes_out); | |
| 180 | 202 |
| 181 // Decode a single bytecode and operands to |os|. | 203 // Decode a single bytecode and operands to |os|. |
| 182 static std::ostream& Decode(std::ostream& os, const uint8_t* bytecode_start, | 204 static std::ostream& Decode(std::ostream& os, const uint8_t* bytecode_start, |
| 183 int number_of_parameters); | 205 int number_of_parameters); |
| 184 | 206 |
| 185 private: | 207 private: |
| 186 DISALLOW_IMPLICIT_CONSTRUCTORS(Bytecodes); | 208 DISALLOW_IMPLICIT_CONSTRUCTORS(Bytecodes); |
| 187 }; | 209 }; |
| 188 | 210 |
| 189 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode); | 211 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode); |
| 190 std::ostream& operator<<(std::ostream& os, const OperandType& operand_type); | 212 std::ostream& operator<<(std::ostream& os, const OperandType& operand_type); |
| 191 | 213 |
| 192 } // namespace interpreter | 214 } // namespace interpreter |
| 193 } // namespace internal | 215 } // namespace internal |
| 194 } // namespace v8 | 216 } // namespace v8 |
| 195 | 217 |
| 196 #endif // V8_INTERPRETER_BYTECODES_H_ | 218 #endif // V8_INTERPRETER_BYTECODES_H_ |
| OLD | NEW |