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 \ | 20 \ |
21 /* None operand. */ \ | 21 /* None operand. */ \ |
22 V(None, OperandSize::kNone) \ | 22 V(None, OperandSize::kNone) \ |
23 \ | 23 \ |
24 /* Byte operands. */ \ | 24 /* Byte operands. */ \ |
25 V(Count8, OperandSize::kByte) \ | 25 V(Count8, OperandSize::kByte) \ |
26 V(Imm8, OperandSize::kByte) \ | 26 V(Imm8, OperandSize::kByte) \ |
27 V(Idx8, OperandSize::kByte) \ | 27 V(Idx8, OperandSize::kByte) \ |
| 28 V(MaybeReg8, OperandSize::kByte) \ |
28 V(Reg8, OperandSize::kByte) \ | 29 V(Reg8, OperandSize::kByte) \ |
29 V(MaybeReg8, OperandSize::kByte) \ | |
30 \ | 30 \ |
31 /* Short operands. */ \ | 31 /* Short operands. */ \ |
32 V(Count16, OperandSize::kShort) \ | 32 V(Count16, OperandSize::kShort) \ |
33 V(Idx16, OperandSize::kShort) | 33 V(Idx16, OperandSize::kShort) \ |
| 34 V(Reg16, OperandSize::kShort) |
34 | 35 |
35 // The list of bytecodes which are interpreted by the interpreter. | 36 // The list of bytecodes which are interpreted by the interpreter. |
36 #define BYTECODE_LIST(V) \ | 37 #define BYTECODE_LIST(V) \ |
37 \ | 38 \ |
38 /* Loading the accumulator */ \ | 39 /* Loading the accumulator */ \ |
39 V(LdaZero, OperandType::kNone) \ | 40 V(LdaZero, OperandType::kNone) \ |
40 V(LdaSmi8, OperandType::kImm8) \ | 41 V(LdaSmi8, OperandType::kImm8) \ |
41 V(LdaUndefined, OperandType::kNone) \ | 42 V(LdaUndefined, OperandType::kNone) \ |
42 V(LdaNull, OperandType::kNone) \ | 43 V(LdaNull, OperandType::kNone) \ |
43 V(LdaTheHole, OperandType::kNone) \ | 44 V(LdaTheHole, OperandType::kNone) \ |
(...skipping 27 matching lines...) Expand all Loading... |
71 V(LdaLookupSlotInsideTypeof, OperandType::kIdx8) \ | 72 V(LdaLookupSlotInsideTypeof, OperandType::kIdx8) \ |
72 V(StaLookupSlotSloppy, OperandType::kIdx8) \ | 73 V(StaLookupSlotSloppy, OperandType::kIdx8) \ |
73 V(StaLookupSlotStrict, OperandType::kIdx8) \ | 74 V(StaLookupSlotStrict, OperandType::kIdx8) \ |
74 \ | 75 \ |
75 /* Register-accumulator transfers */ \ | 76 /* Register-accumulator transfers */ \ |
76 V(Ldar, OperandType::kReg8) \ | 77 V(Ldar, OperandType::kReg8) \ |
77 V(Star, OperandType::kReg8) \ | 78 V(Star, OperandType::kReg8) \ |
78 \ | 79 \ |
79 /* Register-register transfers */ \ | 80 /* Register-register transfers */ \ |
80 V(Mov, OperandType::kReg8, OperandType::kReg8) \ | 81 V(Mov, OperandType::kReg8, OperandType::kReg8) \ |
| 82 V(Exchange, OperandType::kReg8, OperandType::kReg16) \ |
| 83 V(ExchangeWide, OperandType::kReg16, OperandType::kReg16) \ |
81 \ | 84 \ |
82 /* LoadIC operations */ \ | 85 /* LoadIC operations */ \ |
83 V(LoadICSloppy, OperandType::kReg8, OperandType::kIdx8, OperandType::kIdx8) \ | 86 V(LoadICSloppy, OperandType::kReg8, OperandType::kIdx8, OperandType::kIdx8) \ |
84 V(LoadICStrict, OperandType::kReg8, OperandType::kIdx8, OperandType::kIdx8) \ | 87 V(LoadICStrict, OperandType::kReg8, OperandType::kIdx8, OperandType::kIdx8) \ |
85 V(KeyedLoadICSloppy, OperandType::kReg8, OperandType::kIdx8) \ | 88 V(KeyedLoadICSloppy, OperandType::kReg8, OperandType::kIdx8) \ |
86 V(KeyedLoadICStrict, OperandType::kReg8, OperandType::kIdx8) \ | 89 V(KeyedLoadICStrict, OperandType::kReg8, OperandType::kIdx8) \ |
87 /* TODO(rmcilroy): Wide register operands too? */ \ | 90 /* TODO(rmcilroy): Wide register operands too? */ \ |
88 V(LoadICSloppyWide, OperandType::kReg8, OperandType::kIdx16, \ | 91 V(LoadICSloppyWide, OperandType::kReg8, OperandType::kIdx16, \ |
89 OperandType::kIdx16) \ | 92 OperandType::kIdx16) \ |
90 V(LoadICStrictWide, OperandType::kReg8, OperandType::kIdx16, \ | 93 V(LoadICStrictWide, OperandType::kReg8, OperandType::kIdx16, \ |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 // evaluate to the same value as the last real bytecode. | 245 // evaluate to the same value as the last real bytecode. |
243 kLast = -1 BYTECODE_LIST(COUNT_BYTECODE) | 246 kLast = -1 BYTECODE_LIST(COUNT_BYTECODE) |
244 #undef COUNT_BYTECODE | 247 #undef COUNT_BYTECODE |
245 }; | 248 }; |
246 | 249 |
247 | 250 |
248 // An interpreter Register which is located in the function's Register file | 251 // An interpreter Register which is located in the function's Register file |
249 // in its stack-frame. Register hold parameters, this, and expression values. | 252 // in its stack-frame. Register hold parameters, this, and expression values. |
250 class Register { | 253 class Register { |
251 public: | 254 public: |
252 static const int kMaxRegisterIndex = 127; | |
253 static const int kMinRegisterIndex = -128; | |
254 | |
255 Register() : index_(kIllegalIndex) {} | 255 Register() : index_(kIllegalIndex) {} |
256 | 256 |
257 explicit Register(int index) : index_(index) { | 257 explicit Register(int index) : index_(index) {} |
258 DCHECK_LE(index_, kMaxRegisterIndex); | |
259 DCHECK_GE(index_, kMinRegisterIndex); | |
260 } | |
261 | 258 |
262 int index() const { | 259 int index() const { |
263 DCHECK(index_ != kIllegalIndex); | 260 DCHECK(index_ != kIllegalIndex); |
264 return index_; | 261 return index_; |
265 } | 262 } |
266 bool is_parameter() const { return index() < 0; } | 263 bool is_parameter() const { return index() < 0; } |
267 bool is_valid() const { return index_ != kIllegalIndex; } | 264 bool is_valid() const { return index_ != kIllegalIndex; } |
268 | 265 |
269 static Register FromParameterIndex(int index, int parameter_count); | 266 static Register FromParameterIndex(int index, int parameter_count); |
270 int ToParameterIndex(int parameter_count) const; | 267 int ToParameterIndex(int parameter_count) const; |
271 static int MaxParameterIndex(); | 268 static int MaxParameterIndex(); |
272 | 269 |
273 // Returns the register for the function's closure object. | 270 // Returns the register for the function's closure object. |
274 static Register function_closure(); | 271 static Register function_closure(); |
275 bool is_function_closure() const; | 272 bool is_function_closure() const; |
276 | 273 |
277 // Returns the register for the function's outer context. | 274 // Returns the register for the function's outer context. |
278 static Register function_context(); | 275 static Register function_context(); |
279 bool is_function_context() const; | 276 bool is_function_context() const; |
280 | 277 |
281 // Returns the register for the incoming new target value. | 278 // Returns the register for the incoming new target value. |
282 static Register new_target(); | 279 static Register new_target(); |
283 bool is_new_target() const; | 280 bool is_new_target() const; |
284 | 281 |
285 static Register FromOperand(uint8_t operand); | 282 static Register FromOperand(uint8_t operand); |
286 uint8_t ToOperand() const; | 283 uint8_t ToOperand() const; |
287 | 284 |
| 285 static Register FromWideOperand(uint16_t operand); |
| 286 uint16_t ToWideOperand() const; |
| 287 |
288 static bool AreContiguous(Register reg1, Register reg2, | 288 static bool AreContiguous(Register reg1, Register reg2, |
289 Register reg3 = Register(), | 289 Register reg3 = Register(), |
290 Register reg4 = Register(), | 290 Register reg4 = Register(), |
291 Register reg5 = Register()); | 291 Register reg5 = Register()); |
292 | 292 |
293 bool operator==(const Register& other) const { | 293 bool operator==(const Register& other) const { |
294 return index() == other.index(); | 294 return index() == other.index(); |
295 } | 295 } |
296 bool operator!=(const Register& other) const { | 296 bool operator!=(const Register& other) const { |
297 return index() != other.index(); | 297 return index() != other.index(); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 | 386 |
387 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode); | 387 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode); |
388 std::ostream& operator<<(std::ostream& os, const OperandType& operand_type); | 388 std::ostream& operator<<(std::ostream& os, const OperandType& operand_type); |
389 std::ostream& operator<<(std::ostream& os, const OperandSize& operand_type); | 389 std::ostream& operator<<(std::ostream& os, const OperandSize& operand_type); |
390 | 390 |
391 } // namespace interpreter | 391 } // namespace interpreter |
392 } // namespace internal | 392 } // namespace internal |
393 } // namespace v8 | 393 } // namespace v8 |
394 | 394 |
395 #endif // V8_INTERPRETER_BYTECODES_H_ | 395 #endif // V8_INTERPRETER_BYTECODES_H_ |
OLD | NEW |