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_BYTECODE_ARRAY_BUILDER_H_ | 5 #ifndef V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
| 6 #define V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 6 #define V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "src/ast.h" | 10 #include "src/ast.h" |
| 11 #include "src/frames.h" | |
| 12 #include "src/identity-map.h" | 11 #include "src/identity-map.h" |
| 13 #include "src/interpreter/bytecodes.h" | 12 #include "src/interpreter/bytecodes.h" |
| 14 #include "src/zone.h" | 13 #include "src/zone.h" |
| 15 #include "src/zone-containers.h" | 14 #include "src/zone-containers.h" |
| 16 | 15 |
| 17 namespace v8 { | 16 namespace v8 { |
| 18 namespace internal { | 17 namespace internal { |
| 19 | 18 |
| 20 class Isolate; | 19 class Isolate; |
| 21 | 20 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 51 BytecodeArrayBuilder& LoadAccumulatorWithRegister(Register reg); | 50 BytecodeArrayBuilder& LoadAccumulatorWithRegister(Register reg); |
| 52 BytecodeArrayBuilder& StoreAccumulatorInRegister(Register reg); | 51 BytecodeArrayBuilder& StoreAccumulatorInRegister(Register reg); |
| 53 | 52 |
| 54 // Operators. | 53 // Operators. |
| 55 BytecodeArrayBuilder& BinaryOperation(Token::Value binop, Register reg); | 54 BytecodeArrayBuilder& BinaryOperation(Token::Value binop, Register reg); |
| 56 | 55 |
| 57 // Flow Control. | 56 // Flow Control. |
| 58 BytecodeArrayBuilder& Return(); | 57 BytecodeArrayBuilder& Return(); |
| 59 | 58 |
| 60 private: | 59 private: |
| 61 static const int kLastParamRegisterIndex = | |
| 62 -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize; | |
| 63 | |
| 64 static Bytecode BytecodeForBinaryOperation(Token::Value op); | 60 static Bytecode BytecodeForBinaryOperation(Token::Value op); |
| 65 | 61 |
| 66 void Output(Bytecode bytecode, uint8_t r0, uint8_t r1, uint8_t r2); | 62 void Output(Bytecode bytecode, uint8_t r0, uint8_t r1, uint8_t r2); |
| 67 void Output(Bytecode bytecode, uint8_t r0, uint8_t r1); | 63 void Output(Bytecode bytecode, uint8_t r0, uint8_t r1); |
| 68 void Output(Bytecode bytecode, uint8_t r0); | 64 void Output(Bytecode bytecode, uint8_t r0); |
| 69 void Output(Bytecode bytecode); | 65 void Output(Bytecode bytecode); |
| 70 | 66 |
| 71 bool OperandIsValid(Bytecode bytecode, int operand_index, | 67 bool OperandIsValid(Bytecode bytecode, int operand_index, |
| 72 uint8_t operand_value) const; | 68 uint8_t operand_value) const; |
| 73 | 69 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 87 int local_register_count_; | 83 int local_register_count_; |
| 88 int temporary_register_count_; | 84 int temporary_register_count_; |
| 89 int temporary_register_next_; | 85 int temporary_register_next_; |
| 90 | 86 |
| 91 friend class TemporaryRegisterScope; | 87 friend class TemporaryRegisterScope; |
| 92 DISALLOW_IMPLICIT_CONSTRUCTORS(BytecodeArrayBuilder); | 88 DISALLOW_IMPLICIT_CONSTRUCTORS(BytecodeArrayBuilder); |
| 93 }; | 89 }; |
| 94 | 90 |
| 95 // An interpreter register which is located in the function's register file | 91 // An interpreter register which is located in the function's register file |
| 96 // in its stack-frame. | 92 // in its stack-frame. |
| 97 class Register { | 93 class Register { |
|
rmcilroy
2015/09/02 11:42:41
Would it be simpler just to move the Register clas
oth
2015/09/02 14:02:19
Done.
| |
| 98 public: | 94 public: |
| 99 static const int kMaxRegisterIndex = 128; | 95 static const int kMaxRegisterIndex = 128; |
| 100 static const int kMinRegisterIndex = -127; | 96 static const int kMinRegisterIndex = -127; |
| 101 | 97 |
| 102 explicit Register(int index) : index_(index) { | 98 explicit Register(int index) : index_(index) { |
| 103 DCHECK_LE(index_, kMaxRegisterIndex); | 99 DCHECK_LE(index_, kMaxRegisterIndex); |
| 104 DCHECK_GE(index_, kMinRegisterIndex); | 100 DCHECK_GE(index_, kMinRegisterIndex); |
| 105 } | 101 } |
| 106 | 102 |
| 107 int index() { return index_; } | 103 int index() { return index_; } |
| 108 | 104 |
| 109 uint8_t ToOperand() { return static_cast<uint8_t>(-index_); } | 105 uint8_t ToOperand() { return Bytecodes::RegisterIndexToOperand(index_); } |
| 110 static Register FromOperand(uint8_t operand) { | 106 static Register FromOperand(uint8_t operand) { |
| 111 return Register(-static_cast<int8_t>(operand)); | 107 return Register(Bytecodes::RegisterIndexFromOperand(operand)); |
| 112 } | 108 } |
| 113 | 109 |
| 114 private: | 110 private: |
| 115 void* operator new(size_t size); | 111 void* operator new(size_t size); |
| 116 void operator delete(void* p); | 112 void operator delete(void* p); |
| 117 | 113 |
| 118 int index_; | 114 int index_; |
| 119 }; | 115 }; |
| 120 | 116 |
| 121 // A stack-allocated class than allows the instantiator to allocate | 117 // A stack-allocated class than allows the instantiator to allocate |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 136 | 132 |
| 137 DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterScope); | 133 DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterScope); |
| 138 }; | 134 }; |
| 139 | 135 |
| 140 | 136 |
| 141 } // namespace interpreter | 137 } // namespace interpreter |
| 142 } // namespace internal | 138 } // namespace internal |
| 143 } // namespace v8 | 139 } // namespace v8 |
| 144 | 140 |
| 145 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 141 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
| OLD | NEW |