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-array-writer.h" |
10 #include "src/interpreter/bytecode-register-allocator.h" | 10 #include "src/interpreter/bytecode-register-allocator.h" |
11 #include "src/interpreter/bytecodes.h" | 11 #include "src/interpreter/bytecodes.h" |
12 #include "src/interpreter/constant-array-builder.h" | 12 #include "src/interpreter/constant-array-builder.h" |
13 #include "src/interpreter/handler-table-builder.h" | 13 #include "src/interpreter/handler-table-builder.h" |
14 #include "src/interpreter/source-position-table.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 |
22 namespace interpreter { | 21 namespace interpreter { |
23 | 22 |
24 class BytecodeLabel; | 23 class BytecodeLabel; |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 static Bytecode BytecodeForCompareOperation(Token::Value op); | 289 static Bytecode BytecodeForCompareOperation(Token::Value op); |
291 static Bytecode BytecodeForStoreNamedProperty(LanguageMode language_mode); | 290 static Bytecode BytecodeForStoreNamedProperty(LanguageMode language_mode); |
292 static Bytecode BytecodeForStoreKeyedProperty(LanguageMode language_mode); | 291 static Bytecode BytecodeForStoreKeyedProperty(LanguageMode language_mode); |
293 static Bytecode BytecodeForLoadGlobal(TypeofMode typeof_mode); | 292 static Bytecode BytecodeForLoadGlobal(TypeofMode typeof_mode); |
294 static Bytecode BytecodeForStoreGlobal(LanguageMode language_mode); | 293 static Bytecode BytecodeForStoreGlobal(LanguageMode language_mode); |
295 static Bytecode BytecodeForStoreLookupSlot(LanguageMode language_mode); | 294 static Bytecode BytecodeForStoreLookupSlot(LanguageMode language_mode); |
296 static Bytecode BytecodeForCreateArguments(CreateArgumentsType type); | 295 static Bytecode BytecodeForCreateArguments(CreateArgumentsType type); |
297 static Bytecode BytecodeForDelete(LanguageMode language_mode); | 296 static Bytecode BytecodeForDelete(LanguageMode language_mode); |
298 static Bytecode BytecodeForCall(TailCallMode tail_call_mode); | 297 static Bytecode BytecodeForCall(TailCallMode tail_call_mode); |
299 | 298 |
300 static Bytecode GetJumpWithConstantOperand(Bytecode jump_smi8_operand); | |
301 | |
302 void Output(Bytecode bytecode); | 299 void Output(Bytecode bytecode); |
303 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, | 300 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, |
304 uint32_t operand0, uint32_t operand1, uint32_t operand2, | 301 uint32_t operand0, uint32_t operand1, uint32_t operand2, |
305 uint32_t operand3); | 302 uint32_t operand3); |
306 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, | 303 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, |
307 uint32_t operand0, uint32_t operand1, uint32_t operand2); | 304 uint32_t operand0, uint32_t operand1, uint32_t operand2); |
308 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, | 305 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, |
309 uint32_t operand0, uint32_t operand1); | 306 uint32_t operand0, uint32_t operand1); |
310 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, | 307 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, |
311 uint32_t operand0); | 308 uint32_t operand0); |
312 | 309 |
313 BytecodeArrayBuilder& OutputJump(Bytecode jump_bytecode, | 310 BytecodeArrayBuilder& OutputJump(Bytecode jump_bytecode, |
314 BytecodeLabel* label); | 311 BytecodeLabel* label); |
315 void PatchJump(size_t jump_target, size_t jump_location); | |
316 void PatchJumpWith8BitOperand(ZoneVector<uint8_t>* bytecodes, | |
317 size_t jump_location, int delta); | |
318 void PatchJumpWith16BitOperand(ZoneVector<uint8_t>* bytecodes, | |
319 size_t jump_location, int delta); | |
320 void PatchJumpWith32BitOperand(ZoneVector<uint8_t>* bytecodes, | |
321 size_t jump_location, int delta); | |
322 | 312 |
323 void LeaveBasicBlock(); | |
324 | 313 |
325 bool OperandIsValid(Bytecode bytecode, OperandScale operand_scale, | 314 bool OperandIsValid(Bytecode bytecode, OperandScale operand_scale, |
326 int operand_index, uint32_t operand_value) const; | 315 int operand_index, uint32_t operand_value) const; |
327 bool RegisterIsValid(Register reg, OperandSize reg_size) const; | 316 bool RegisterIsValid(Register reg, OperandSize reg_size) const; |
328 | 317 |
329 // Attach latest source position to |node|. | 318 // Attach latest source position to |node|. |
330 void AttachSourceInfo(BytecodeNode* node); | 319 void AttachSourceInfo(BytecodeNode* node); |
331 | 320 |
332 // Gets a constant pool entry for the |object|. | 321 // Gets a constant pool entry for the |object|. |
333 size_t GetConstantPoolEntry(Handle<Object> object); | 322 size_t GetConstantPoolEntry(Handle<Object> object); |
334 | 323 |
335 // Not implemented as the illegal bytecode is used inside internally | 324 // Not implemented as the illegal bytecode is used inside internally |
336 // to indicate a bytecode field is not valid or an error has occured | 325 // to indicate a bytecode field is not valid or an error has occured |
337 // during bytecode generation. | 326 // during bytecode generation. |
338 BytecodeArrayBuilder& Illegal(); | 327 BytecodeArrayBuilder& Illegal(); |
339 | 328 |
| 329 void LeaveBasicBlock() { return_seen_in_block_ = false; } |
| 330 |
340 Isolate* isolate() const { return isolate_; } | 331 Isolate* isolate() const { return isolate_; } |
341 BytecodeArrayWriter* bytecode_array_writer() { | 332 BytecodeArrayWriter* bytecode_array_writer() { |
342 return &bytecode_array_writer_; | 333 return &bytecode_array_writer_; |
343 } | 334 } |
344 BytecodePipelineStage* pipeline() { return pipeline_; } | 335 BytecodePipelineStage* pipeline() { return pipeline_; } |
345 ConstantArrayBuilder* constant_array_builder() { | 336 ConstantArrayBuilder* constant_array_builder() { |
346 return &constant_array_builder_; | 337 return &constant_array_builder_; |
347 } | 338 } |
348 const ConstantArrayBuilder* constant_array_builder() const { | 339 const ConstantArrayBuilder* constant_array_builder() const { |
349 return &constant_array_builder_; | 340 return &constant_array_builder_; |
350 } | 341 } |
351 HandlerTableBuilder* handler_table_builder() { | 342 HandlerTableBuilder* handler_table_builder() { |
352 return &handler_table_builder_; | 343 return &handler_table_builder_; |
353 } | 344 } |
354 SourcePositionTableBuilder* source_position_table_builder() { | |
355 return &source_position_table_builder_; | |
356 } | |
357 | 345 |
358 Isolate* isolate_; | 346 Isolate* isolate_; |
359 Zone* zone_; | 347 Zone* zone_; |
360 bool bytecode_generated_; | 348 bool bytecode_generated_; |
361 ConstantArrayBuilder constant_array_builder_; | 349 ConstantArrayBuilder constant_array_builder_; |
362 HandlerTableBuilder handler_table_builder_; | 350 HandlerTableBuilder handler_table_builder_; |
363 SourcePositionTableBuilder source_position_table_builder_; | |
364 bool return_seen_in_block_; | 351 bool return_seen_in_block_; |
365 int unbound_jumps_; | |
366 int parameter_count_; | 352 int parameter_count_; |
367 int local_register_count_; | 353 int local_register_count_; |
368 int context_register_count_; | 354 int context_register_count_; |
369 int return_position_; | 355 int return_position_; |
370 TemporaryRegisterAllocator temporary_allocator_; | 356 TemporaryRegisterAllocator temporary_allocator_; |
371 BytecodeArrayWriter bytecode_array_writer_; | 357 BytecodeArrayWriter bytecode_array_writer_; |
372 BytecodePipelineStage* pipeline_; | 358 BytecodePipelineStage* pipeline_; |
373 BytecodeSourceInfo latest_source_info_; | 359 BytecodeSourceInfo latest_source_info_; |
374 | 360 |
375 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); | 361 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); |
376 }; | 362 }; |
377 | 363 |
378 | |
379 // A label representing a branch target in a bytecode array. When a | |
380 // label is bound, it represents a known position in the bytecode | |
381 // array. For labels that are forward references there can be at most | |
382 // one reference whilst it is unbound. | |
383 class BytecodeLabel final { | |
384 public: | |
385 BytecodeLabel() : bound_(false), offset_(kInvalidOffset) {} | |
386 | |
387 bool is_bound() const { return bound_; } | |
388 size_t offset() const { return offset_; } | |
389 | |
390 private: | |
391 static const size_t kInvalidOffset = static_cast<size_t>(-1); | |
392 | |
393 void bind_to(size_t offset) { | |
394 DCHECK(!bound_ && offset != kInvalidOffset); | |
395 offset_ = offset; | |
396 bound_ = true; | |
397 } | |
398 | |
399 void set_referrer(size_t offset) { | |
400 DCHECK(!bound_ && offset != kInvalidOffset && offset_ == kInvalidOffset); | |
401 offset_ = offset; | |
402 } | |
403 | |
404 bool is_forward_target() const { | |
405 return offset() != kInvalidOffset && !is_bound(); | |
406 } | |
407 | |
408 // There are three states for a label: | |
409 // bound_ offset_ | |
410 // UNSET false kInvalidOffset | |
411 // FORWARD_TARGET false Offset of referring jump | |
412 // BACKWARD_TARGET true Offset of label in bytecode array when bound | |
413 bool bound_; | |
414 size_t offset_; | |
415 | |
416 friend class BytecodeArrayBuilder; | |
417 }; | |
418 | |
419 } // namespace interpreter | 364 } // namespace interpreter |
420 } // namespace internal | 365 } // namespace internal |
421 } // namespace v8 | 366 } // namespace v8 |
422 | 367 |
423 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 368 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
OLD | NEW |