| 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 "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/interpreter/bytecode-register-allocator.h" | 9 #include "src/interpreter/bytecode-register-allocator.h" |
| 10 #include "src/interpreter/bytecode-writer.h" |
| 10 #include "src/interpreter/bytecodes.h" | 11 #include "src/interpreter/bytecodes.h" |
| 11 #include "src/interpreter/constant-array-builder.h" | 12 #include "src/interpreter/constant-array-builder.h" |
| 12 #include "src/interpreter/handler-table-builder.h" | 13 #include "src/interpreter/handler-table-builder.h" |
| 13 #include "src/interpreter/source-position-table.h" | 14 #include "src/interpreter/source-position-table.h" |
| 14 #include "src/zone-containers.h" | 15 #include "src/zone-containers.h" |
| 15 | 16 |
| 16 namespace v8 { | 17 namespace v8 { |
| 17 namespace internal { | 18 namespace internal { |
| 18 | 19 |
| 19 class Isolate; | 20 class Isolate; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 264 |
| 264 // Accessors | 265 // Accessors |
| 265 Zone* zone() const { return zone_; } | 266 Zone* zone() const { return zone_; } |
| 266 TemporaryRegisterAllocator* temporary_register_allocator() { | 267 TemporaryRegisterAllocator* temporary_register_allocator() { |
| 267 return &temporary_allocator_; | 268 return &temporary_allocator_; |
| 268 } | 269 } |
| 269 const TemporaryRegisterAllocator* temporary_register_allocator() const { | 270 const TemporaryRegisterAllocator* temporary_register_allocator() const { |
| 270 return &temporary_allocator_; | 271 return &temporary_allocator_; |
| 271 } | 272 } |
| 272 | 273 |
| 274 BytecodeWriter* writer() { return writer_; } |
| 275 void set_writer(BytecodeWriter* writer) { writer_ = writer; } |
| 276 |
| 273 void EnsureReturn(); | 277 void EnsureReturn(); |
| 274 | 278 |
| 275 static OperandScale OperandSizesToScale( | |
| 276 OperandSize size0, OperandSize size1 = OperandSize::kByte, | |
| 277 OperandSize size2 = OperandSize::kByte, | |
| 278 OperandSize size3 = OperandSize::kByte); | |
| 279 | |
| 280 static OperandSize SizeForRegisterOperand(Register reg); | |
| 281 static OperandSize SizeForSignedOperand(int value); | |
| 282 static OperandSize SizeForUnsignedOperand(int value); | |
| 283 static OperandSize SizeForUnsignedOperand(size_t value); | |
| 284 | |
| 285 static uint32_t RegisterOperand(Register reg); | 279 static uint32_t RegisterOperand(Register reg); |
| 286 static Register RegisterFromOperand(uint32_t operand); | 280 static Register RegisterFromOperand(uint32_t operand); |
| 287 static uint32_t SignedOperand(int value, OperandSize size); | 281 static uint32_t SignedOperand(int value, OperandSize size); |
| 288 static uint32_t UnsignedOperand(int value); | 282 static uint32_t UnsignedOperand(int value); |
| 289 static uint32_t UnsignedOperand(size_t value); | 283 static uint32_t UnsignedOperand(size_t value); |
| 290 | 284 |
| 291 private: | 285 private: |
| 292 class PreviousBytecodeHelper; | |
| 293 friend class BytecodeRegisterAllocator; | 286 friend class BytecodeRegisterAllocator; |
| 294 | 287 |
| 295 static Bytecode BytecodeForBinaryOperation(Token::Value op); | 288 static Bytecode BytecodeForBinaryOperation(Token::Value op); |
| 296 static Bytecode BytecodeForCountOperation(Token::Value op); | 289 static Bytecode BytecodeForCountOperation(Token::Value op); |
| 297 static Bytecode BytecodeForCompareOperation(Token::Value op); | 290 static Bytecode BytecodeForCompareOperation(Token::Value op); |
| 298 static Bytecode BytecodeForStoreIC(LanguageMode language_mode); | 291 static Bytecode BytecodeForStoreIC(LanguageMode language_mode); |
| 299 static Bytecode BytecodeForKeyedStoreIC(LanguageMode language_mode); | 292 static Bytecode BytecodeForKeyedStoreIC(LanguageMode language_mode); |
| 300 static Bytecode BytecodeForLoadGlobal(TypeofMode typeof_mode); | 293 static Bytecode BytecodeForLoadGlobal(TypeofMode typeof_mode); |
| 301 static Bytecode BytecodeForStoreGlobal(LanguageMode language_mode); | 294 static Bytecode BytecodeForStoreGlobal(LanguageMode language_mode); |
| 302 static Bytecode BytecodeForStoreLookupSlot(LanguageMode language_mode); | 295 static Bytecode BytecodeForStoreLookupSlot(LanguageMode language_mode); |
| 303 static Bytecode BytecodeForCreateArguments(CreateArgumentsType type); | 296 static Bytecode BytecodeForCreateArguments(CreateArgumentsType type); |
| 304 static Bytecode BytecodeForDelete(LanguageMode language_mode); | 297 static Bytecode BytecodeForDelete(LanguageMode language_mode); |
| 305 static Bytecode BytecodeForCall(TailCallMode tail_call_mode); | 298 static Bytecode BytecodeForCall(TailCallMode tail_call_mode); |
| 306 | 299 |
| 307 static Bytecode GetJumpWithConstantOperand(Bytecode jump_smi8_operand); | 300 static Bytecode GetJumpWithConstantOperand(Bytecode jump_smi8_operand); |
| 308 static Bytecode GetJumpWithToBoolean(Bytecode jump_smi8_operand); | 301 static Bytecode GetJumpWithToBoolean(Bytecode jump_smi8_operand); |
| 309 | 302 |
| 310 template <size_t N> | |
| 311 INLINE(void Output(Bytecode bytecode, uint32_t (&operands)[N], | |
| 312 OperandScale operand_scale = OperandScale::kSingle)); | |
| 313 void Output(Bytecode bytecode); | 303 void Output(Bytecode bytecode); |
| 314 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, | 304 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, |
| 315 uint32_t operand0, uint32_t operand1, uint32_t operand2, | 305 uint32_t operand0, uint32_t operand1, uint32_t operand2, |
| 316 uint32_t operand3); | 306 uint32_t operand3); |
| 317 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, | 307 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, |
| 318 uint32_t operand0, uint32_t operand1, uint32_t operand2); | 308 uint32_t operand0, uint32_t operand1, uint32_t operand2); |
| 319 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, | 309 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, |
| 320 uint32_t operand0, uint32_t operand1); | 310 uint32_t operand0, uint32_t operand1); |
| 321 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, | 311 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, |
| 322 uint32_t operand0); | 312 uint32_t operand0); |
| 323 | 313 |
| 324 BytecodeArrayBuilder& OutputJump(Bytecode jump_bytecode, | 314 BytecodeArrayBuilder& OutputJump(Bytecode jump_bytecode, |
| 325 BytecodeLabel* label); | 315 BytecodeLabel* label); |
| 326 void PatchJump(const ZoneVector<uint8_t>::iterator& jump_target, | 316 void PatchJump(ZoneVector<uint8_t>* bytecodes, size_t jump_target, |
| 327 const ZoneVector<uint8_t>::iterator& jump_location); | 317 size_t jump_location); |
| 328 void PatchIndirectJumpWith8BitOperand( | 318 void PatchJumpWith8BitOperand(ZoneVector<uint8_t>* bytecodes, |
| 329 const ZoneVector<uint8_t>::iterator& jump_location, int delta); | 319 size_t jump_location, int delta); |
| 330 void PatchIndirectJumpWith16BitOperand( | 320 void PatchJumpWith16BitOperand(ZoneVector<uint8_t>* bytecodes, |
| 331 const ZoneVector<uint8_t>::iterator& jump_location, int delta); | 321 size_t jump_location, int delta); |
| 332 void PatchIndirectJumpWith32BitOperand( | 322 void PatchJumpWith32BitOperand(ZoneVector<uint8_t>* bytecodes, |
| 333 const ZoneVector<uint8_t>::iterator& jump_location, int delta); | 323 size_t jump_location, int delta); |
| 334 | 324 |
| 335 void LeaveBasicBlock(); | 325 void LeaveBasicBlock(); |
| 336 | 326 |
| 337 bool OperandIsValid(Bytecode bytecode, OperandScale operand_scale, | 327 bool OperandIsValid(Bytecode bytecode, OperandScale operand_scale, |
| 338 int operand_index, uint32_t operand_value) const; | 328 int operand_index, uint32_t operand_value) const; |
| 339 bool RegisterIsValid(Register reg, OperandSize reg_size) const; | 329 bool RegisterIsValid(Register reg, OperandSize reg_size) const; |
| 340 | 330 |
| 341 bool LastBytecodeInSameBlock() const; | |
| 342 bool NeedToBooleanCast(); | |
| 343 bool IsRegisterInAccumulator(Register reg); | |
| 344 | |
| 345 // Set position for return. | 331 // Set position for return. |
| 346 void SetReturnPosition(); | 332 void SetReturnPosition(); |
| 347 | 333 |
| 348 // Gets a constant pool entry for the |object|. | 334 // Gets a constant pool entry for the |object|. |
| 349 size_t GetConstantPoolEntry(Handle<Object> object); | 335 size_t GetConstantPoolEntry(Handle<Object> object); |
| 350 | 336 |
| 351 ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; } | |
| 352 const ZoneVector<uint8_t>* bytecodes() const { return &bytecodes_; } | |
| 353 Isolate* isolate() const { return isolate_; } | 337 Isolate* isolate() const { return isolate_; } |
| 354 ConstantArrayBuilder* constant_array_builder() { | 338 ConstantArrayBuilder* constant_array_builder() { |
| 355 return &constant_array_builder_; | 339 return &constant_array_builder_; |
| 356 } | 340 } |
| 357 const ConstantArrayBuilder* constant_array_builder() const { | 341 const ConstantArrayBuilder* constant_array_builder() const { |
| 358 return &constant_array_builder_; | 342 return &constant_array_builder_; |
| 359 } | 343 } |
| 360 HandlerTableBuilder* handler_table_builder() { | 344 HandlerTableBuilder* handler_table_builder() { |
| 361 return &handler_table_builder_; | 345 return &handler_table_builder_; |
| 362 } | 346 } |
| 363 SourcePositionTableBuilder* source_position_table_builder() { | 347 SourcePositionTableBuilder* source_position_table_builder() { |
| 364 return &source_position_table_builder_; | 348 return &source_position_table_builder_; |
| 365 } | 349 } |
| 350 BytecodeNodeAllocator* bytecode_node_allocator() { |
| 351 return &bytecode_node_allocator_; |
| 352 } |
| 353 BytecodeNode* current_node() { return current_node_; } |
| 354 FinalStageBytecodeWriter* final_stage_writer() { |
| 355 return &final_stage_writer_; |
| 356 } |
| 366 | 357 |
| 367 Isolate* isolate_; | 358 Isolate* isolate_; |
| 368 Zone* zone_; | 359 Zone* zone_; |
| 369 ZoneVector<uint8_t> bytecodes_; | |
| 370 bool bytecode_generated_; | 360 bool bytecode_generated_; |
| 371 ConstantArrayBuilder constant_array_builder_; | 361 ConstantArrayBuilder constant_array_builder_; |
| 372 HandlerTableBuilder handler_table_builder_; | 362 HandlerTableBuilder handler_table_builder_; |
| 373 SourcePositionTableBuilder source_position_table_builder_; | 363 SourcePositionTableBuilder source_position_table_builder_; |
| 374 size_t last_block_end_; | |
| 375 size_t last_bytecode_start_; | |
| 376 bool exit_seen_in_block_; | 364 bool exit_seen_in_block_; |
| 377 int unbound_jumps_; | 365 int unbound_jumps_; |
| 378 int parameter_count_; | 366 int parameter_count_; |
| 379 int local_register_count_; | 367 int local_register_count_; |
| 380 int context_register_count_; | 368 int context_register_count_; |
| 381 int return_position_; | 369 int return_position_; |
| 382 TemporaryRegisterAllocator temporary_allocator_; | 370 TemporaryRegisterAllocator temporary_allocator_; |
| 371 BytecodeNodeAllocator bytecode_node_allocator_; |
| 372 FinalStageBytecodeWriter final_stage_writer_; |
| 373 BytecodeWriter* writer_; |
| 374 BytecodeNode* current_node_; |
| 383 | 375 |
| 384 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); | 376 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); |
| 385 }; | 377 }; |
| 386 | 378 |
| 387 | 379 |
| 388 // A label representing a branch target in a bytecode array. When a | 380 // A label representing a branch target in a bytecode array. When a |
| 389 // label is bound, it represents a known position in the bytecode | 381 // label is bound, it represents a known position in the bytecode |
| 390 // array. For labels that are forward references there can be at most | 382 // array. For labels that are forward references there can be at most |
| 391 // one reference whilst it is unbound. | 383 // one reference whilst it is unbound. |
| 392 class BytecodeLabel final { | 384 class BytecodeLabel final { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 423 size_t offset_; | 415 size_t offset_; |
| 424 | 416 |
| 425 friend class BytecodeArrayBuilder; | 417 friend class BytecodeArrayBuilder; |
| 426 }; | 418 }; |
| 427 | 419 |
| 428 } // namespace interpreter | 420 } // namespace interpreter |
| 429 } // namespace internal | 421 } // namespace internal |
| 430 } // namespace v8 | 422 } // namespace v8 |
| 431 | 423 |
| 432 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 424 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
| OLD | NEW |