| 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-array-writer.h" |
| 9 #include "src/interpreter/bytecode-register-allocator.h" | 10 #include "src/interpreter/bytecode-register-allocator.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; |
| 20 | 21 |
| 21 namespace interpreter { | 22 namespace interpreter { |
| 22 | 23 |
| 23 class BytecodeLabel; | 24 class BytecodeLabel; |
| 25 class BytecodeNode; |
| 26 class BytecodePipelineStage; |
| 24 class Register; | 27 class Register; |
| 25 | 28 |
| 26 class BytecodeArrayBuilder final : public ZoneObject { | 29 class BytecodeArrayBuilder final : public ZoneObject { |
| 27 public: | 30 public: |
| 28 BytecodeArrayBuilder(Isolate* isolate, Zone* zone, int parameter_count, | 31 BytecodeArrayBuilder(Isolate* isolate, Zone* zone, int parameter_count, |
| 29 int context_count, int locals_count, | 32 int context_count, int locals_count, |
| 30 FunctionLiteral* literal = nullptr); | 33 FunctionLiteral* literal = nullptr); |
| 31 | 34 |
| 32 Handle<BytecodeArray> ToBytecodeArray(); | 35 Handle<BytecodeArray> ToBytecodeArray(); |
| 33 | 36 |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // entry, so that it can be referenced by above exception handling support. | 258 // entry, so that it can be referenced by above exception handling support. |
| 256 int NewHandlerEntry() { return handler_table_builder()->NewHandlerEntry(); } | 259 int NewHandlerEntry() { return handler_table_builder()->NewHandlerEntry(); } |
| 257 | 260 |
| 258 void InitializeReturnPosition(FunctionLiteral* literal); | 261 void InitializeReturnPosition(FunctionLiteral* literal); |
| 259 | 262 |
| 260 void SetStatementPosition(Statement* stmt); | 263 void SetStatementPosition(Statement* stmt); |
| 261 void SetExpressionPosition(Expression* expr); | 264 void SetExpressionPosition(Expression* expr); |
| 262 void SetExpressionAsStatementPosition(Expression* expr); | 265 void SetExpressionAsStatementPosition(Expression* expr); |
| 263 | 266 |
| 264 // Accessors | 267 // Accessors |
| 265 Zone* zone() const { return zone_; } | |
| 266 TemporaryRegisterAllocator* temporary_register_allocator() { | 268 TemporaryRegisterAllocator* temporary_register_allocator() { |
| 267 return &temporary_allocator_; | 269 return &temporary_allocator_; |
| 268 } | 270 } |
| 269 const TemporaryRegisterAllocator* temporary_register_allocator() const { | 271 const TemporaryRegisterAllocator* temporary_register_allocator() const { |
| 270 return &temporary_allocator_; | 272 return &temporary_allocator_; |
| 271 } | 273 } |
| 274 Zone* zone() const { return zone_; } |
| 272 | 275 |
| 273 void EnsureReturn(); | 276 void EnsureReturn(); |
| 274 | 277 |
| 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); | 278 static uint32_t RegisterOperand(Register reg); |
| 286 static Register RegisterFromOperand(uint32_t operand); | 279 static Register RegisterFromOperand(uint32_t operand); |
| 287 static uint32_t SignedOperand(int value, OperandSize size); | 280 static uint32_t SignedOperand(int value, OperandSize size); |
| 288 static uint32_t UnsignedOperand(int value); | 281 static uint32_t UnsignedOperand(int value); |
| 289 static uint32_t UnsignedOperand(size_t value); | 282 static uint32_t UnsignedOperand(size_t value); |
| 290 | 283 |
| 291 private: | 284 private: |
| 292 class PreviousBytecodeHelper; | |
| 293 friend class BytecodeRegisterAllocator; | 285 friend class BytecodeRegisterAllocator; |
| 294 | 286 |
| 295 static Bytecode BytecodeForBinaryOperation(Token::Value op); | 287 static Bytecode BytecodeForBinaryOperation(Token::Value op); |
| 296 static Bytecode BytecodeForCountOperation(Token::Value op); | 288 static Bytecode BytecodeForCountOperation(Token::Value op); |
| 297 static Bytecode BytecodeForCompareOperation(Token::Value op); | 289 static Bytecode BytecodeForCompareOperation(Token::Value op); |
| 298 static Bytecode BytecodeForStoreIC(LanguageMode language_mode); | 290 static Bytecode BytecodeForStoreIC(LanguageMode language_mode); |
| 299 static Bytecode BytecodeForKeyedStoreIC(LanguageMode language_mode); | 291 static Bytecode BytecodeForKeyedStoreIC(LanguageMode language_mode); |
| 300 static Bytecode BytecodeForLoadGlobal(TypeofMode typeof_mode); | 292 static Bytecode BytecodeForLoadGlobal(TypeofMode typeof_mode); |
| 301 static Bytecode BytecodeForStoreGlobal(LanguageMode language_mode); | 293 static Bytecode BytecodeForStoreGlobal(LanguageMode language_mode); |
| 302 static Bytecode BytecodeForStoreLookupSlot(LanguageMode language_mode); | 294 static Bytecode BytecodeForStoreLookupSlot(LanguageMode language_mode); |
| 303 static Bytecode BytecodeForCreateArguments(CreateArgumentsType type); | 295 static Bytecode BytecodeForCreateArguments(CreateArgumentsType type); |
| 304 static Bytecode BytecodeForDelete(LanguageMode language_mode); | 296 static Bytecode BytecodeForDelete(LanguageMode language_mode); |
| 305 static Bytecode BytecodeForCall(TailCallMode tail_call_mode); | 297 static Bytecode BytecodeForCall(TailCallMode tail_call_mode); |
| 306 | 298 |
| 307 static Bytecode GetJumpWithConstantOperand(Bytecode jump_smi8_operand); | 299 static Bytecode GetJumpWithConstantOperand(Bytecode jump_smi8_operand); |
| 308 static Bytecode GetJumpWithToBoolean(Bytecode jump_smi8_operand); | |
| 309 | 300 |
| 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); | 301 void Output(Bytecode bytecode); |
| 314 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, | 302 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, |
| 315 uint32_t operand0, uint32_t operand1, uint32_t operand2, | 303 uint32_t operand0, uint32_t operand1, uint32_t operand2, |
| 316 uint32_t operand3); | 304 uint32_t operand3); |
| 317 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, | 305 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, |
| 318 uint32_t operand0, uint32_t operand1, uint32_t operand2); | 306 uint32_t operand0, uint32_t operand1, uint32_t operand2); |
| 319 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, | 307 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, |
| 320 uint32_t operand0, uint32_t operand1); | 308 uint32_t operand0, uint32_t operand1); |
| 321 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, | 309 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, |
| 322 uint32_t operand0); | 310 uint32_t operand0); |
| 323 | 311 |
| 324 BytecodeArrayBuilder& OutputJump(Bytecode jump_bytecode, | 312 BytecodeArrayBuilder& OutputJump(Bytecode jump_bytecode, |
| 325 BytecodeLabel* label); | 313 BytecodeLabel* label); |
| 326 void PatchJump(const ZoneVector<uint8_t>::iterator& jump_target, | 314 void PatchJump(size_t jump_target, size_t jump_location); |
| 327 const ZoneVector<uint8_t>::iterator& jump_location); | 315 void PatchJumpWith8BitOperand(ZoneVector<uint8_t>* bytecodes, |
| 328 void PatchIndirectJumpWith8BitOperand( | 316 size_t jump_location, int delta); |
| 329 const ZoneVector<uint8_t>::iterator& jump_location, int delta); | 317 void PatchJumpWith16BitOperand(ZoneVector<uint8_t>* bytecodes, |
| 330 void PatchIndirectJumpWith16BitOperand( | 318 size_t jump_location, int delta); |
| 331 const ZoneVector<uint8_t>::iterator& jump_location, int delta); | 319 void PatchJumpWith32BitOperand(ZoneVector<uint8_t>* bytecodes, |
| 332 void PatchIndirectJumpWith32BitOperand( | 320 size_t jump_location, int delta); |
| 333 const ZoneVector<uint8_t>::iterator& jump_location, int delta); | |
| 334 | 321 |
| 335 void LeaveBasicBlock(); | 322 void LeaveBasicBlock(); |
| 336 | 323 |
| 337 bool OperandIsValid(Bytecode bytecode, OperandScale operand_scale, | 324 bool OperandIsValid(Bytecode bytecode, OperandScale operand_scale, |
| 338 int operand_index, uint32_t operand_value) const; | 325 int operand_index, uint32_t operand_value) const; |
| 339 bool RegisterIsValid(Register reg, OperandSize reg_size) const; | 326 bool RegisterIsValid(Register reg, OperandSize reg_size) const; |
| 340 | 327 |
| 341 bool LastBytecodeInSameBlock() const; | 328 // Attach latest source position to |node|. |
| 342 bool NeedToBooleanCast(); | 329 void AttachSourceInfo(BytecodeNode* node); |
| 343 bool IsRegisterInAccumulator(Register reg); | |
| 344 | 330 |
| 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_; } |
| 338 BytecodeArrayWriter* bytecode_array_writer() { |
| 339 return &bytecode_array_writer_; |
| 340 } |
| 341 BytecodePipelineStage* pipeline() { return pipeline_; } |
| 354 ConstantArrayBuilder* constant_array_builder() { | 342 ConstantArrayBuilder* constant_array_builder() { |
| 355 return &constant_array_builder_; | 343 return &constant_array_builder_; |
| 356 } | 344 } |
| 357 const ConstantArrayBuilder* constant_array_builder() const { | 345 const ConstantArrayBuilder* constant_array_builder() const { |
| 358 return &constant_array_builder_; | 346 return &constant_array_builder_; |
| 359 } | 347 } |
| 360 HandlerTableBuilder* handler_table_builder() { | 348 HandlerTableBuilder* handler_table_builder() { |
| 361 return &handler_table_builder_; | 349 return &handler_table_builder_; |
| 362 } | 350 } |
| 363 SourcePositionTableBuilder* source_position_table_builder() { | 351 SourcePositionTableBuilder* source_position_table_builder() { |
| 364 return &source_position_table_builder_; | 352 return &source_position_table_builder_; |
| 365 } | 353 } |
| 366 | 354 |
| 367 Isolate* isolate_; | 355 Isolate* isolate_; |
| 368 Zone* zone_; | 356 Zone* zone_; |
| 369 ZoneVector<uint8_t> bytecodes_; | |
| 370 bool bytecode_generated_; | 357 bool bytecode_generated_; |
| 371 ConstantArrayBuilder constant_array_builder_; | 358 ConstantArrayBuilder constant_array_builder_; |
| 372 HandlerTableBuilder handler_table_builder_; | 359 HandlerTableBuilder handler_table_builder_; |
| 373 SourcePositionTableBuilder source_position_table_builder_; | 360 SourcePositionTableBuilder source_position_table_builder_; |
| 374 size_t last_block_end_; | |
| 375 size_t last_bytecode_start_; | |
| 376 bool exit_seen_in_block_; | 361 bool exit_seen_in_block_; |
| 377 int unbound_jumps_; | 362 int unbound_jumps_; |
| 378 int parameter_count_; | 363 int parameter_count_; |
| 379 int local_register_count_; | 364 int local_register_count_; |
| 380 int context_register_count_; | 365 int context_register_count_; |
| 381 int return_position_; | 366 int return_position_; |
| 382 TemporaryRegisterAllocator temporary_allocator_; | 367 TemporaryRegisterAllocator temporary_allocator_; |
| 368 BytecodeArrayWriter bytecode_array_writer_; |
| 369 BytecodePipelineStage* pipeline_; |
| 370 BytecodeSourceInfo latest_source_info_; |
| 383 | 371 |
| 384 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); | 372 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); |
| 385 }; | 373 }; |
| 386 | 374 |
| 387 | 375 |
| 388 // A label representing a branch target in a bytecode array. When a | 376 // A label representing a branch target in a bytecode array. When a |
| 389 // label is bound, it represents a known position in the bytecode | 377 // label is bound, it represents a known position in the bytecode |
| 390 // array. For labels that are forward references there can be at most | 378 // array. For labels that are forward references there can be at most |
| 391 // one reference whilst it is unbound. | 379 // one reference whilst it is unbound. |
| 392 class BytecodeLabel final { | 380 class BytecodeLabel final { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 423 size_t offset_; | 411 size_t offset_; |
| 424 | 412 |
| 425 friend class BytecodeArrayBuilder; | 413 friend class BytecodeArrayBuilder; |
| 426 }; | 414 }; |
| 427 | 415 |
| 428 } // namespace interpreter | 416 } // namespace interpreter |
| 429 } // namespace internal | 417 } // namespace internal |
| 430 } // namespace v8 | 418 } // namespace v8 |
| 431 | 419 |
| 432 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 420 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
| OLD | NEW |