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" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 | 80 |
| 81 // Tests. | 81 // Tests. |
| 82 BytecodeArrayBuilder& CompareOperation(Token::Value op, Register reg, | 82 BytecodeArrayBuilder& CompareOperation(Token::Value op, Register reg, |
| 83 LanguageMode language_mode); | 83 LanguageMode language_mode); |
| 84 | 84 |
| 85 // Casts | 85 // Casts |
| 86 BytecodeArrayBuilder& CastAccumulatorToBoolean(); | 86 BytecodeArrayBuilder& CastAccumulatorToBoolean(); |
| 87 | 87 |
| 88 // Flow Control. | 88 // Flow Control. |
| 89 BytecodeArrayBuilder& Bind(BytecodeLabel* label); | 89 BytecodeArrayBuilder& Bind(BytecodeLabel* label); |
| 90 BytecodeArrayBuilder& Bind(BytecodeLabel* unbound, | |
| 91 const BytecodeLabel* const bound); | |
|
rmcilroy
2015/10/01 12:12:07
const ref instead? Also, the names still confuse m
oth
2015/10/01 13:13:56
As discussed, changed to:
BytecodeArrayBuilder::B
| |
| 90 BytecodeArrayBuilder& Jump(BytecodeLabel* label); | 92 BytecodeArrayBuilder& Jump(BytecodeLabel* label); |
| 91 BytecodeArrayBuilder& JumpIfTrue(BytecodeLabel* label); | 93 BytecodeArrayBuilder& JumpIfTrue(BytecodeLabel* label); |
| 92 BytecodeArrayBuilder& JumpIfFalse(BytecodeLabel* label); | 94 BytecodeArrayBuilder& JumpIfFalse(BytecodeLabel* label); |
| 93 BytecodeArrayBuilder& Return(); | 95 BytecodeArrayBuilder& Return(); |
| 94 | 96 |
| 95 BytecodeArrayBuilder& EnterBlock(); | 97 BytecodeArrayBuilder& EnterBlock(); |
| 96 BytecodeArrayBuilder& LeaveBlock(); | 98 BytecodeArrayBuilder& LeaveBlock(); |
| 97 | 99 |
| 100 // Accessors | |
| 101 Zone* zone() const { return zone_; } | |
| 102 | |
| 98 private: | 103 private: |
| 99 ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; } | 104 ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; } |
| 100 const ZoneVector<uint8_t>* bytecodes() const { return &bytecodes_; } | 105 const ZoneVector<uint8_t>* bytecodes() const { return &bytecodes_; } |
| 101 Isolate* isolate() const { return isolate_; } | 106 Isolate* isolate() const { return isolate_; } |
| 102 | 107 |
| 103 static Bytecode BytecodeForBinaryOperation(Token::Value op); | 108 static Bytecode BytecodeForBinaryOperation(Token::Value op); |
| 104 static Bytecode BytecodeForCompareOperation(Token::Value op); | 109 static Bytecode BytecodeForCompareOperation(Token::Value op); |
| 105 static bool FitsInIdxOperand(int value); | 110 static bool FitsInIdxOperand(int value); |
| 106 static bool FitsInIdxOperand(size_t value); | 111 static bool FitsInIdxOperand(size_t value); |
| 107 static bool FitsInImm8Operand(int value); | 112 static bool FitsInImm8Operand(int value); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 126 uint8_t operand_value) const; | 131 uint8_t operand_value) const; |
| 127 bool LastBytecodeInSameBlock() const; | 132 bool LastBytecodeInSameBlock() const; |
| 128 | 133 |
| 129 size_t GetConstantPoolEntry(Handle<Object> object); | 134 size_t GetConstantPoolEntry(Handle<Object> object); |
| 130 | 135 |
| 131 // Scope helpers used by TemporaryRegisterScope | 136 // Scope helpers used by TemporaryRegisterScope |
| 132 int BorrowTemporaryRegister(); | 137 int BorrowTemporaryRegister(); |
| 133 void ReturnTemporaryRegister(int reg_index); | 138 void ReturnTemporaryRegister(int reg_index); |
| 134 | 139 |
| 135 Isolate* isolate_; | 140 Isolate* isolate_; |
| 141 Zone* zone_; | |
| 136 ZoneVector<uint8_t> bytecodes_; | 142 ZoneVector<uint8_t> bytecodes_; |
| 137 bool bytecode_generated_; | 143 bool bytecode_generated_; |
| 138 size_t last_block_end_; | 144 size_t last_block_end_; |
| 139 size_t last_bytecode_start_; | 145 size_t last_bytecode_start_; |
| 140 bool return_seen_in_block_; | 146 bool return_seen_in_block_; |
| 141 | 147 |
| 142 IdentityMap<size_t> constants_map_; | 148 IdentityMap<size_t> constants_map_; |
| 143 ZoneVector<Handle<Object>> constants_; | 149 ZoneVector<Handle<Object>> constants_; |
| 144 | 150 |
| 145 int parameter_count_; | 151 int parameter_count_; |
| 146 int local_register_count_; | 152 int local_register_count_; |
| 147 int temporary_register_count_; | 153 int temporary_register_count_; |
| 148 int temporary_register_next_; | 154 int temporary_register_next_; |
| 149 | 155 |
| 150 friend class TemporaryRegisterScope; | 156 friend class TemporaryRegisterScope; |
| 151 DISALLOW_IMPLICIT_CONSTRUCTORS(BytecodeArrayBuilder); | 157 DISALLOW_IMPLICIT_CONSTRUCTORS(BytecodeArrayBuilder); |
| 152 }; | 158 }; |
| 153 | 159 |
| 154 | 160 |
| 155 // A label representing a branch target in a bytecode array. When a | 161 // A label representing a branch target in a bytecode array. When a |
| 156 // label is bound, it represents a known position in the bytecode | 162 // label is bound, it represents a known position in the bytecode |
| 157 // array. For labels that are forward references there can be at most | 163 // array. For labels that are forward references there can be at most |
| 158 // one reference whilst it is unbound. | 164 // one reference whilst it is unbound. |
| 159 class BytecodeLabel final { | 165 class BytecodeLabel final { |
| 160 public: | 166 public: |
| 161 BytecodeLabel() : bound_(false), offset_(kInvalidOffset) {} | 167 BytecodeLabel() : bound_(false), offset_(kInvalidOffset) {} |
| 162 ~BytecodeLabel() { DCHECK(bound_ && offset_ != kInvalidOffset); } | |
| 163 | 168 |
| 164 private: | 169 private: |
| 165 static const size_t kInvalidOffset = static_cast<size_t>(-1); | 170 static const size_t kInvalidOffset = static_cast<size_t>(-1); |
| 166 | 171 |
| 167 INLINE(void bind_to(size_t offset)) { | 172 INLINE(void bind_to(size_t offset)) { |
| 168 DCHECK(!bound_ && offset != kInvalidOffset); | 173 DCHECK(!bound_ && offset != kInvalidOffset); |
| 169 offset_ = offset; | 174 offset_ = offset; |
| 170 bound_ = true; | 175 bound_ = true; |
| 171 } | 176 } |
| 172 INLINE(void set_referrer(size_t offset)) { | 177 INLINE(void set_referrer(size_t offset)) { |
| 173 DCHECK(!bound_ && offset != kInvalidOffset); | 178 DCHECK(!bound_ && offset != kInvalidOffset); |
| 174 offset_ = offset; | 179 offset_ = offset; |
| 175 } | 180 } |
| 176 INLINE(size_t offset() const) { return offset_; } | 181 INLINE(size_t offset() const) { return offset_; } |
| 177 INLINE(bool is_bound() const) { return bound_; } | 182 INLINE(bool is_bound() const) { return bound_; } |
| 178 INLINE(bool is_forward_target() const) { | 183 INLINE(bool is_forward_target() const) { |
| 179 return offset() != kInvalidOffset && !is_bound(); | 184 return offset() != kInvalidOffset && !is_bound(); |
| 180 } | 185 } |
| 181 | 186 |
| 182 // There are three states for a label: | 187 // There are three states for a label: |
| 183 // bound_ offset_ | 188 // bound_ offset_ |
| 184 // UNSET false kInvalidOffset | 189 // UNSET false kInvalidOffset |
| 185 // FORWARD_TARGET false Offset of referring jump | 190 // FORWARD_TARGET false Offset of referring jump |
| 186 // BACKWARD_TARGET true Offset of label in bytecode array when bound | 191 // BACKWARD_TARGET true Offset of label in bytecode array when bound |
| 187 bool bound_; | 192 bool bound_; |
| 188 size_t offset_; | 193 size_t offset_; |
| 189 | 194 |
| 190 friend class BytecodeArrayBuilder; | 195 friend class BytecodeArrayBuilder; |
| 191 DISALLOW_COPY_AND_ASSIGN(BytecodeLabel); | |
| 192 }; | 196 }; |
| 193 | 197 |
| 194 | 198 |
| 195 // A stack-allocated class than allows the instantiator to allocate | 199 // A stack-allocated class than allows the instantiator to allocate |
| 196 // temporary registers that are cleaned up when scope is closed. | 200 // temporary registers that are cleaned up when scope is closed. |
| 197 class TemporaryRegisterScope { | 201 class TemporaryRegisterScope { |
| 198 public: | 202 public: |
| 199 explicit TemporaryRegisterScope(BytecodeArrayBuilder* builder); | 203 explicit TemporaryRegisterScope(BytecodeArrayBuilder* builder); |
| 200 ~TemporaryRegisterScope(); | 204 ~TemporaryRegisterScope(); |
| 201 Register NewRegister(); | 205 Register NewRegister(); |
| 202 | 206 |
| 203 private: | 207 private: |
| 204 void* operator new(size_t size); | 208 void* operator new(size_t size); |
| 205 void operator delete(void* p); | 209 void operator delete(void* p); |
| 206 | 210 |
| 207 BytecodeArrayBuilder* builder_; | 211 BytecodeArrayBuilder* builder_; |
| 208 int count_; | 212 int count_; |
| 209 int last_register_index_; | 213 int last_register_index_; |
| 210 | 214 |
| 211 DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterScope); | 215 DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterScope); |
| 212 }; | 216 }; |
| 213 | 217 |
| 214 | 218 |
| 215 } // namespace interpreter | 219 } // namespace interpreter |
| 216 } // namespace internal | 220 } // namespace internal |
| 217 } // namespace v8 | 221 } // namespace v8 |
| 218 | 222 |
| 219 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 223 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
| OLD | NEW |