| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef V8_INTERPRETER_BYTECODE_REGISTER_H_ | |
| 6 #define V8_INTERPRETER_BYTECODE_REGISTER_H_ | |
| 7 | |
| 8 #include "src/interpreter/bytecodes.h" | |
| 9 | |
| 10 namespace v8 { | |
| 11 namespace internal { | |
| 12 namespace interpreter { | |
| 13 | |
| 14 // An interpreter Register which is located in the function's Register file | |
| 15 // in its stack-frame. Register hold parameters, this, and expression values. | |
| 16 class Register final { | |
| 17 public: | |
| 18 explicit Register(int index = kInvalidIndex) : index_(index) {} | |
| 19 | |
| 20 int index() const { return index_; } | |
| 21 bool is_parameter() const { return index() < 0; } | |
| 22 bool is_valid() const { return index_ != kInvalidIndex; } | |
| 23 | |
| 24 static Register FromParameterIndex(int index, int parameter_count); | |
| 25 int ToParameterIndex(int parameter_count) const; | |
| 26 | |
| 27 // Returns an invalid register. | |
| 28 static Register invalid_value() { return Register(); } | |
| 29 | |
| 30 // Returns the register for the function's closure object. | |
| 31 static Register function_closure(); | |
| 32 bool is_function_closure() const; | |
| 33 | |
| 34 // Returns the register which holds the current context object. | |
| 35 static Register current_context(); | |
| 36 bool is_current_context() const; | |
| 37 | |
| 38 // Returns the register for the incoming new target value. | |
| 39 static Register new_target(); | |
| 40 bool is_new_target() const; | |
| 41 | |
| 42 // Returns the register for the bytecode array. | |
| 43 static Register bytecode_array(); | |
| 44 bool is_bytecode_array() const; | |
| 45 | |
| 46 // Returns the register for the saved bytecode offset. | |
| 47 static Register bytecode_offset(); | |
| 48 bool is_bytecode_offset() const; | |
| 49 | |
| 50 // Returns a register that can be used to represent the accumulator | |
| 51 // within code in the interpreter, but should never be emitted in | |
| 52 // bytecode. | |
| 53 static Register virtual_accumulator(); | |
| 54 | |
| 55 OperandSize SizeOfOperand() const; | |
| 56 | |
| 57 int32_t ToOperand() const { return kRegisterFileStartOffset - index_; } | |
| 58 static Register FromOperand(int32_t operand) { | |
| 59 return Register(kRegisterFileStartOffset - operand); | |
| 60 } | |
| 61 | |
| 62 static bool AreContiguous(Register reg1, Register reg2, | |
| 63 Register reg3 = Register(), | |
| 64 Register reg4 = Register(), | |
| 65 Register reg5 = Register()); | |
| 66 | |
| 67 std::string ToString(int parameter_count); | |
| 68 | |
| 69 bool operator==(const Register& other) const { | |
| 70 return index() == other.index(); | |
| 71 } | |
| 72 bool operator!=(const Register& other) const { | |
| 73 return index() != other.index(); | |
| 74 } | |
| 75 bool operator<(const Register& other) const { | |
| 76 return index() < other.index(); | |
| 77 } | |
| 78 bool operator<=(const Register& other) const { | |
| 79 return index() <= other.index(); | |
| 80 } | |
| 81 bool operator>(const Register& other) const { | |
| 82 return index() > other.index(); | |
| 83 } | |
| 84 bool operator>=(const Register& other) const { | |
| 85 return index() >= other.index(); | |
| 86 } | |
| 87 | |
| 88 private: | |
| 89 static const int kInvalidIndex; | |
| 90 static const int kRegisterFileStartOffset; | |
| 91 | |
| 92 void* operator new(size_t size) = delete; | |
| 93 void operator delete(void* p) = delete; | |
| 94 | |
| 95 int index_; | |
| 96 }; | |
| 97 | |
| 98 } // namespace interpreter | |
| 99 } // namespace internal | |
| 100 } // namespace v8 | |
| 101 | |
| 102 #endif // V8_INTERPRETER_BYTECODE_REGISTER_H_ | |
| OLD | NEW |