| 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 V(None) \ |
| 21 V(Imm8) \ | 21 V(Imm8) \ |
| 22 V(Idx) \ | 22 V(Idx) \ |
| 23 V(Reg) | 23 V(Reg) |
| 24 | 24 |
| 25 // The list of bytecodes which are interpreted by the interpreter. | 25 // The list of bytecodes which are interpreted by the interpreter. |
| 26 #define BYTECODE_LIST(V) \ | 26 #define BYTECODE_LIST(V) \ |
| 27 \ | 27 \ |
| 28 /* Loading the accumulator */ \ | 28 /* Loading the accumulator */ \ |
| 29 V(LdaZero, OperandType::kNone) \ | 29 V(LdaZero, OperandType::kNone) \ |
| 30 V(LdaSmi8, OperandType::kImm8) \ | 30 V(LdaSmi8, OperandType::kImm8) \ |
| 31 V(LdaConstant, OperandType::kIdx) \ | 31 V(LdaConstant, OperandType::kIdx) \ |
| 32 V(LdaUndefined, OperandType::kNone) \ | 32 V(LdaUndefined, OperandType::kNone) \ |
| 33 V(LdaNull, OperandType::kNone) \ | 33 V(LdaNull, OperandType::kNone) \ |
| 34 V(LdaTheHole, OperandType::kNone) \ | 34 V(LdaTheHole, OperandType::kNone) \ |
| 35 V(LdaTrue, OperandType::kNone) \ | 35 V(LdaTrue, OperandType::kNone) \ |
| 36 V(LdaFalse, OperandType::kNone) \ | 36 V(LdaFalse, OperandType::kNone) \ |
| 37 \ | 37 \ |
| 38 /* Register-accumulator transfers */ \ | 38 /* Register-accumulator transfers */ \ |
| 39 V(Ldar, OperandType::kReg) \ | 39 V(Ldar, OperandType::kReg) \ |
| 40 V(Star, OperandType::kReg) \ | 40 V(Star, OperandType::kReg) \ |
| 41 \ | 41 \ |
| 42 /* LoadIC operations */ \ | 42 /* LoadIC operations */ \ |
| 43 V(LoadIC, OperandType::kReg, OperandType::kIdx) \ | 43 V(LoadIC, OperandType::kReg, OperandType::kIdx) \ |
| 44 V(KeyedLoadIC, OperandType::kReg, OperandType::kIdx) \ | 44 V(KeyedLoadIC, OperandType::kReg, OperandType::kIdx) \ |
| 45 \ | 45 \ |
| 46 /* Binary Operators */ \ | 46 /* StoreIC operations */ \ |
| 47 V(Add, OperandType::kReg) \ | 47 V(StoreIC, OperandType::kReg, OperandType::kReg, OperandType::kIdx) \ |
| 48 V(Sub, OperandType::kReg) \ | 48 V(KeyedStoreIC, OperandType::kReg, OperandType::kReg, OperandType::kIdx) \ |
| 49 V(Mul, OperandType::kReg) \ | 49 \ |
| 50 V(Div, OperandType::kReg) \ | 50 /* Binary Operators */ \ |
| 51 V(Mod, OperandType::kReg) \ | 51 V(Add, OperandType::kReg) \ |
| 52 \ | 52 V(Sub, OperandType::kReg) \ |
| 53 /* Control Flow */ \ | 53 V(Mul, OperandType::kReg) \ |
| 54 V(Div, OperandType::kReg) \ |
| 55 V(Mod, OperandType::kReg) \ |
| 56 \ |
| 57 /* Control Flow */ \ |
| 54 V(Return, OperandType::kNone) | 58 V(Return, OperandType::kNone) |
| 55 | 59 |
| 56 | 60 |
| 57 // Enumeration of operand types used by bytecodes. | 61 // Enumeration of operand types used by bytecodes. |
| 58 enum class OperandType : uint8_t { | 62 enum class OperandType : uint8_t { |
| 59 #define DECLARE_OPERAND_TYPE(Name) k##Name, | 63 #define DECLARE_OPERAND_TYPE(Name) k##Name, |
| 60 OPERAND_TYPE_LIST(DECLARE_OPERAND_TYPE) | 64 OPERAND_TYPE_LIST(DECLARE_OPERAND_TYPE) |
| 61 #undef DECLARE_OPERAND_TYPE | 65 #undef DECLARE_OPERAND_TYPE |
| 62 #define COUNT_OPERAND_TYPES(x) +1 | 66 #define COUNT_OPERAND_TYPES(x) +1 |
| 63 // The COUNT_OPERAND macro will turn this into kLast = -1 +1 +1... which will | 67 // The COUNT_OPERAND macro will turn this into kLast = -1 +1 +1... which will |
| (...skipping 16 matching lines...) Expand all Loading... |
| 80 }; | 84 }; |
| 81 | 85 |
| 82 | 86 |
| 83 // An interpreter register which is located in the function's register file | 87 // An interpreter register which is located in the function's register file |
| 84 // in its stack-frame. Register hold parameters, this, and expression values. | 88 // in its stack-frame. Register hold parameters, this, and expression values. |
| 85 class Register { | 89 class Register { |
| 86 public: | 90 public: |
| 87 static const int kMaxRegisterIndex = 127; | 91 static const int kMaxRegisterIndex = 127; |
| 88 static const int kMinRegisterIndex = -128; | 92 static const int kMinRegisterIndex = -128; |
| 89 | 93 |
| 94 Register() : index_(kIllegalIndex) {} |
| 95 |
| 90 explicit Register(int index) : index_(index) { | 96 explicit Register(int index) : index_(index) { |
| 91 DCHECK_LE(index_, kMaxRegisterIndex); | 97 DCHECK_LE(index_, kMaxRegisterIndex); |
| 92 DCHECK_GE(index_, kMinRegisterIndex); | 98 DCHECK_GE(index_, kMinRegisterIndex); |
| 93 } | 99 } |
| 94 | 100 |
| 95 int index() const { return index_; } | 101 int index() const { |
| 96 bool is_parameter() const { return index_ < 0; } | 102 DCHECK(index_ != kIllegalIndex); |
| 103 return index_; |
| 104 } |
| 105 bool is_parameter() const { return index() < 0; } |
| 97 | 106 |
| 98 static Register FromParameterIndex(int index, int parameter_count); | 107 static Register FromParameterIndex(int index, int parameter_count); |
| 99 int ToParameterIndex(int parameter_count) const; | 108 int ToParameterIndex(int parameter_count) const; |
| 100 static int MaxParameterIndex(); | 109 static int MaxParameterIndex(); |
| 101 | 110 |
| 102 static Register FromOperand(uint8_t operand); | 111 static Register FromOperand(uint8_t operand); |
| 103 uint8_t ToOperand() const; | 112 uint8_t ToOperand() const; |
| 104 | 113 |
| 105 private: | 114 private: |
| 115 static const int kIllegalIndex = kMaxInt; |
| 116 |
| 106 void* operator new(size_t size); | 117 void* operator new(size_t size); |
| 107 void operator delete(void* p); | 118 void operator delete(void* p); |
| 108 | 119 |
| 109 int index_; | 120 int index_; |
| 110 }; | 121 }; |
| 111 | 122 |
| 112 | 123 |
| 113 class Bytecodes { | 124 class Bytecodes { |
| 114 public: | 125 public: |
| 115 // Returns string representation of |bytecode|. | 126 // Returns string representation of |bytecode|. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 }; | 159 }; |
| 149 | 160 |
| 150 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode); | 161 std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode); |
| 151 std::ostream& operator<<(std::ostream& os, const OperandType& operand_type); | 162 std::ostream& operator<<(std::ostream& os, const OperandType& operand_type); |
| 152 | 163 |
| 153 } // namespace interpreter | 164 } // namespace interpreter |
| 154 } // namespace internal | 165 } // namespace internal |
| 155 } // namespace v8 | 166 } // namespace v8 |
| 156 | 167 |
| 157 #endif // V8_INTERPRETER_BYTECODES_H_ | 168 #endif // V8_INTERPRETER_BYTECODES_H_ |
| OLD | NEW |