5 #ifndef V8_INTERPRETER_BYTECODE_REGISTER_H_ 6 #define V8_INTERPRETER_BYTECODE_REGISTER_H_ 8 #include "src/interpreter/bytecodes.h" 10 #include "src/base/macros.h" 11 #include "src/base/platform/platform.h" 12 #include "src/frame-constants.h" 13 #include "src/globals.h" 17 namespace interpreter {
23 explicit Register(
int index = kInvalidIndex) : index_(index) {}
25 int index()
const {
return index_; }
26 bool is_parameter()
const {
return index() < 0; }
27 bool is_valid()
const {
return index_ != kInvalidIndex; }
29 static Register FromParameterIndex(
int index,
int parameter_count);
30 int ToParameterIndex(
int parameter_count)
const;
37 bool is_function_closure()
const;
41 bool is_current_context()
const;
45 bool is_bytecode_array()
const;
49 bool is_bytecode_offset()
const;
54 static Register virtual_accumulator();
56 OperandSize SizeOfOperand()
const;
58 int32_t ToOperand()
const {
return kRegisterFileStartOffset - index_; }
59 static Register FromOperand(int32_t operand) {
60 return Register(kRegisterFileStartOffset - operand);
68 std::string ToString(
int parameter_count)
const;
70 bool operator==(
const Register& other)
const {
71 return index() == other.index();
73 bool operator!=(
const Register& other)
const {
74 return index() != other.index();
76 bool operator<(
const Register& other)
const {
77 return index() < other.index();
79 bool operator<=(
const Register& other)
const {
80 return index() <= other.index();
82 bool operator>(
const Register& other)
const {
83 return index() > other.index();
85 bool operator>=(
const Register& other)
const {
86 return index() >= other.index();
90 DISALLOW_NEW_AND_DELETE();
92 static const int kInvalidIndex = kMaxInt;
93 static const int kRegisterFileStartOffset =
94 InterpreterFrameConstants::kRegisterFileFromFp / kPointerSize;
102 : first_reg_index_(Register::invalid_value().index()),
103 register_count_(0) {}
109 DCHECK_GE(new_count, 0);
110 DCHECK_LT(new_count, register_count_);
114 const Register operator[](
size_t i)
const {
115 DCHECK_LT(static_cast<int>(
i), register_count_);
116 return Register(first_reg_index_ + static_cast<int>(
i));
119 const Register first_register()
const {
120 return (register_count() == 0) ?
Register(0) : (*this)[0];
123 const Register last_register()
const {
124 return (register_count() == 0) ?
Register(0) : (*this)[register_count_ - 1];
127 int register_count()
const {
return register_count_; }
132 friend class InterpreterTester;
133 friend class BytecodeUtils;
136 : first_reg_index_(first_reg_index), register_count_(register_count) {}
139 void IncrementRegisterCount() { register_count_++; }
141 int first_reg_index_;
149 #endif // V8_INTERPRETER_BYTECODE_REGISTER_H_