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 10 matching lines...) Expand all Loading... | |
| 21 namespace interpreter { | 21 namespace interpreter { |
| 22 | 22 |
| 23 class BytecodeLabel; | 23 class BytecodeLabel; |
| 24 class Register; | 24 class Register; |
| 25 | 25 |
| 26 class BytecodeArrayBuilder { | 26 class BytecodeArrayBuilder { |
| 27 public: | 27 public: |
| 28 BytecodeArrayBuilder(Isolate* isolate, Zone* zone); | 28 BytecodeArrayBuilder(Isolate* isolate, Zone* zone); |
| 29 Handle<BytecodeArray> ToBytecodeArray(); | 29 Handle<BytecodeArray> ToBytecodeArray(); |
| 30 | 30 |
| 31 // Set number of parameters expected by function. | 31 // Set the number of parameters expected by function. |
| 32 void set_parameter_count(int number_of_params); | 32 void set_parameter_count(int number_of_params); |
| 33 int parameter_count() const { | 33 int parameter_count() const { |
| 34 DCHECK_GE(parameter_count_, 0); | 34 DCHECK_GE(parameter_count_, 0); |
| 35 return parameter_count_; | 35 return parameter_count_; |
| 36 } | 36 } |
| 37 | 37 |
| 38 // Set number of locals required for bytecode array. | 38 // Set the number of locals required for bytecode array. |
| 39 void set_locals_count(int number_of_locals); | 39 void set_locals_count(int number_of_locals); |
| 40 int locals_count() const { | 40 int locals_count() const { |
| 41 DCHECK_GE(local_register_count_, 0); | 41 DCHECK_GE(local_register_count_, 0); |
| 42 return local_register_count_; | 42 return local_register_count_; |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Set number of contexts required for bytecode array. | 45 // Set number of contexts required for bytecode array. |
| 46 void set_context_count(int number_of_contexts); | 46 void set_context_count(int number_of_contexts); |
| 47 int context_count() const { | 47 int context_count() const { |
| 48 DCHECK_GE(context_register_count_, 0); | 48 DCHECK_GE(context_register_count_, 0); |
| 49 return context_register_count_; | 49 return context_register_count_; |
| 50 } | 50 } |
| 51 | 51 |
| 52 Register first_context_register() const; | 52 Register first_context_register() const; |
| 53 Register last_context_register() const; | 53 Register last_context_register() const; |
| 54 | 54 |
| 55 // Returns the number of fixed (non-temporary) registers. | 55 // Returns the number of fixed (non-temporary) registers. |
| 56 int fixed_register_count() const { return context_count() + locals_count(); } | 56 int fixed_register_count() const { return context_count() + locals_count(); } |
| 57 | 57 |
| 58 Register Parameter(int parameter_index) const; | 58 Register Parameter(int parameter_index) const; |
| 59 | 59 |
| 60 // Constant loads to the accumulator. | 60 // Return true if the register |reg| represents a parameter or a |
| 61 // local. | |
| 62 bool RegisterIsParameterOrLocal(Register reg) const; | |
| 63 | |
| 64 // Constant loads to accumulator. | |
| 61 BytecodeArrayBuilder& LoadLiteral(v8::internal::Smi* value); | 65 BytecodeArrayBuilder& LoadLiteral(v8::internal::Smi* value); |
| 62 BytecodeArrayBuilder& LoadLiteral(Handle<Object> object); | 66 BytecodeArrayBuilder& LoadLiteral(Handle<Object> object); |
| 63 BytecodeArrayBuilder& LoadUndefined(); | 67 BytecodeArrayBuilder& LoadUndefined(); |
| 64 BytecodeArrayBuilder& LoadNull(); | 68 BytecodeArrayBuilder& LoadNull(); |
| 65 BytecodeArrayBuilder& LoadTheHole(); | 69 BytecodeArrayBuilder& LoadTheHole(); |
| 66 BytecodeArrayBuilder& LoadTrue(); | 70 BytecodeArrayBuilder& LoadTrue(); |
| 67 BytecodeArrayBuilder& LoadFalse(); | 71 BytecodeArrayBuilder& LoadFalse(); |
| 68 | 72 |
| 69 // Global loads to accumulator and stores from the accumulator. | 73 // Global loads to the accumulator and stores from the accumulator. |
| 70 BytecodeArrayBuilder& LoadGlobal(int slot_index); | 74 BytecodeArrayBuilder& LoadGlobal(int slot_index); |
| 71 BytecodeArrayBuilder& StoreGlobal(int slot_index, LanguageMode language_mode); | 75 BytecodeArrayBuilder& StoreGlobal(int slot_index, LanguageMode language_mode); |
| 72 | 76 |
| 73 // Load the object at |slot_index| in |context| into the accumulator. | 77 // Load the object at |slot_index| in |context| into the accumulator. |
| 74 BytecodeArrayBuilder& LoadContextSlot(Register context, int slot_index); | 78 BytecodeArrayBuilder& LoadContextSlot(Register context, int slot_index); |
| 75 | 79 |
| 76 // Stores the object in the accumulator into |slot_index| of |context|. | 80 // Stores the object in the accumulator into |slot_index| of |context|. |
| 77 BytecodeArrayBuilder& StoreContextSlot(Register context, int slot_index); | 81 BytecodeArrayBuilder& StoreContextSlot(Register context, int slot_index); |
| 78 | 82 |
| 79 // Register-accumulator transfers. | 83 // Register-accumulator transfers. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 Strength strength); | 137 Strength strength); |
| 134 | 138 |
| 135 // Unary Operators. | 139 // Unary Operators. |
| 136 BytecodeArrayBuilder& LogicalNot(); | 140 BytecodeArrayBuilder& LogicalNot(); |
| 137 BytecodeArrayBuilder& TypeOf(); | 141 BytecodeArrayBuilder& TypeOf(); |
| 138 | 142 |
| 139 // Tests. | 143 // Tests. |
| 140 BytecodeArrayBuilder& CompareOperation(Token::Value op, Register reg, | 144 BytecodeArrayBuilder& CompareOperation(Token::Value op, Register reg, |
| 141 Strength strength); | 145 Strength strength); |
| 142 | 146 |
| 143 // Casts | 147 // Casts. |
| 144 BytecodeArrayBuilder& CastAccumulatorToBoolean(); | 148 BytecodeArrayBuilder& CastAccumulatorToBoolean(); |
| 145 BytecodeArrayBuilder& CastAccumulatorToName(); | 149 BytecodeArrayBuilder& CastAccumulatorToName(); |
| 146 | 150 |
| 147 // Flow Control. | 151 // Flow Control. |
| 148 BytecodeArrayBuilder& Bind(BytecodeLabel* label); | 152 BytecodeArrayBuilder& Bind(BytecodeLabel* label); |
| 149 BytecodeArrayBuilder& Bind(const BytecodeLabel& target, BytecodeLabel* label); | 153 BytecodeArrayBuilder& Bind(const BytecodeLabel& target, BytecodeLabel* label); |
| 150 | 154 |
| 151 BytecodeArrayBuilder& Jump(BytecodeLabel* label); | 155 BytecodeArrayBuilder& Jump(BytecodeLabel* label); |
| 152 BytecodeArrayBuilder& JumpIfTrue(BytecodeLabel* label); | 156 BytecodeArrayBuilder& JumpIfTrue(BytecodeLabel* label); |
| 153 BytecodeArrayBuilder& JumpIfFalse(BytecodeLabel* label); | 157 BytecodeArrayBuilder& JumpIfFalse(BytecodeLabel* label); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 | 203 |
| 200 void EnsureReturn(); | 204 void EnsureReturn(); |
| 201 | 205 |
| 202 bool OperandIsValid(Bytecode bytecode, int operand_index, | 206 bool OperandIsValid(Bytecode bytecode, int operand_index, |
| 203 uint32_t operand_value) const; | 207 uint32_t operand_value) const; |
| 204 bool LastBytecodeInSameBlock() const; | 208 bool LastBytecodeInSameBlock() const; |
| 205 | 209 |
| 206 size_t GetConstantPoolEntry(Handle<Object> object); | 210 size_t GetConstantPoolEntry(Handle<Object> object); |
| 207 | 211 |
| 208 // Scope helpers used by TemporaryRegisterScope | 212 // Scope helpers used by TemporaryRegisterScope |
| 213 Register first_temporary_register() const; | |
| 214 Register last_temporary_register() const; | |
|
rmcilroy
2015/10/19 12:56:22
nit - move getters below TemporaryRegisterIsLive()
oth
2015/10/20 15:28:52
Done.
| |
| 209 int BorrowTemporaryRegister(); | 215 int BorrowTemporaryRegister(); |
| 210 void ReturnTemporaryRegister(int reg_index); | 216 void ReturnTemporaryRegister(int reg_index); |
| 217 void PrepareForConsecutiveTemporaryRegisters(size_t count); | |
| 218 bool TemporaryRegisterIsLive(Register reg) const; | |
| 211 | 219 |
| 212 Isolate* isolate_; | 220 Isolate* isolate_; |
| 213 Zone* zone_; | 221 Zone* zone_; |
| 214 ZoneVector<uint8_t> bytecodes_; | 222 ZoneVector<uint8_t> bytecodes_; |
| 215 bool bytecode_generated_; | 223 bool bytecode_generated_; |
| 216 size_t last_block_end_; | 224 size_t last_block_end_; |
| 217 size_t last_bytecode_start_; | 225 size_t last_bytecode_start_; |
| 218 bool return_seen_in_block_; | 226 bool return_seen_in_block_; |
| 219 | 227 |
| 220 IdentityMap<size_t> constants_map_; | 228 IdentityMap<size_t> constants_map_; |
| 221 ZoneVector<Handle<Object>> constants_; | 229 ZoneVector<Handle<Object>> constants_; |
| 222 | 230 |
| 223 int parameter_count_; | 231 int parameter_count_; |
| 224 int local_register_count_; | 232 int local_register_count_; |
| 225 int context_register_count_; | 233 int context_register_count_; |
| 234 ZoneVector<int> free_temporaries_; | |
| 226 int temporary_register_count_; | 235 int temporary_register_count_; |
| 227 int temporary_register_next_; | |
| 228 | 236 |
| 229 friend class TemporaryRegisterScope; | 237 friend class TemporaryRegisterScope; |
| 230 DISALLOW_IMPLICIT_CONSTRUCTORS(BytecodeArrayBuilder); | 238 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); |
| 231 }; | 239 }; |
| 232 | 240 |
| 233 | 241 |
| 234 // A label representing a branch target in a bytecode array. When a | 242 // A label representing a branch target in a bytecode array. When a |
| 235 // label is bound, it represents a known position in the bytecode | 243 // label is bound, it represents a known position in the bytecode |
| 236 // array. For labels that are forward references there can be at most | 244 // array. For labels that are forward references there can be at most |
| 237 // one reference whilst it is unbound. | 245 // one reference whilst it is unbound. |
| 238 class BytecodeLabel final { | 246 class BytecodeLabel final { |
| 239 public: | 247 public: |
| 240 BytecodeLabel() : bound_(false), offset_(kInvalidOffset) {} | 248 BytecodeLabel() : bound_(false), offset_(kInvalidOffset) {} |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 269 }; | 277 }; |
| 270 | 278 |
| 271 | 279 |
| 272 // A stack-allocated class than allows the instantiator to allocate | 280 // A stack-allocated class than allows the instantiator to allocate |
| 273 // temporary registers that are cleaned up when scope is closed. | 281 // temporary registers that are cleaned up when scope is closed. |
| 274 class TemporaryRegisterScope { | 282 class TemporaryRegisterScope { |
| 275 public: | 283 public: |
| 276 explicit TemporaryRegisterScope(BytecodeArrayBuilder* builder); | 284 explicit TemporaryRegisterScope(BytecodeArrayBuilder* builder); |
| 277 ~TemporaryRegisterScope(); | 285 ~TemporaryRegisterScope(); |
| 278 Register NewRegister(); | 286 Register NewRegister(); |
| 287 void PrepareForConsecutiveAllocations(size_t count); | |
| 279 | 288 |
| 280 private: | 289 private: |
| 281 void* operator new(size_t size); | 290 void* operator new(size_t size); |
| 282 void operator delete(void* p); | 291 void operator delete(void* p); |
| 283 | 292 |
| 284 BytecodeArrayBuilder* builder_; | 293 BytecodeArrayBuilder* builder_; |
| 285 int count_; | 294 const TemporaryRegisterScope* outer_; |
| 286 int last_register_index_; | 295 ZoneVector<int> allocated_; |
| 287 | 296 |
| 288 DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterScope); | 297 DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterScope); |
| 289 }; | 298 }; |
| 290 | 299 |
| 291 | 300 |
| 292 } // namespace interpreter | 301 } // namespace interpreter |
| 293 } // namespace internal | 302 } // namespace internal |
| 294 } // namespace v8 | 303 } // namespace v8 |
| 295 | 304 |
| 296 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 305 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
| OLD | NEW |