LCOV - code coverage report
Current view: top level - src/interpreter - bytecode-array-writer.h (source / functions) Hit Total Coverage
Test: app.info Lines: 2 2 100.0 %
Date: 2019-04-17 Functions: 0 0 -

          Line data    Source code
       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
       3             : // found in the LICENSE file.
       4             : 
       5             : #ifndef V8_INTERPRETER_BYTECODE_ARRAY_WRITER_H_
       6             : #define V8_INTERPRETER_BYTECODE_ARRAY_WRITER_H_
       7             : 
       8             : #include "src/base/compiler-specific.h"
       9             : #include "src/globals.h"
      10             : #include "src/interpreter/bytecodes.h"
      11             : #include "src/source-position-table.h"
      12             : 
      13             : namespace v8 {
      14             : namespace internal {
      15             : 
      16             : class BytecodeArray;
      17             : class SourcePositionTableBuilder;
      18             : 
      19             : namespace interpreter {
      20             : 
      21             : class BytecodeLabel;
      22             : class BytecodeLoopHeader;
      23             : class BytecodeNode;
      24             : class BytecodeJumpTable;
      25             : class ConstantArrayBuilder;
      26             : class HandlerTableBuilder;
      27             : 
      28             : namespace bytecode_array_writer_unittest {
      29             : class BytecodeArrayWriterUnittest;
      30             : }  // namespace bytecode_array_writer_unittest
      31             : 
      32             : // Class for emitting bytecode as the final stage of the bytecode
      33             : // generation pipeline.
      34     2136516 : class V8_EXPORT_PRIVATE BytecodeArrayWriter final {
      35             :  public:
      36             :   BytecodeArrayWriter(
      37             :       Zone* zone, ConstantArrayBuilder* constant_array_builder,
      38             :       SourcePositionTableBuilder::RecordingMode source_position_mode);
      39             : 
      40             :   void Write(BytecodeNode* node);
      41             :   void WriteJump(BytecodeNode* node, BytecodeLabel* label);
      42             :   void WriteJumpLoop(BytecodeNode* node, BytecodeLoopHeader* loop_header);
      43             :   void WriteSwitch(BytecodeNode* node, BytecodeJumpTable* jump_table);
      44             :   void BindLabel(BytecodeLabel* label);
      45             :   void BindLoopHeader(BytecodeLoopHeader* loop_header);
      46             :   void BindJumpTableEntry(BytecodeJumpTable* jump_table, int case_value);
      47             :   void BindHandlerTarget(HandlerTableBuilder* handler_table_builder,
      48             :                          int handler_id);
      49             :   void BindTryRegionStart(HandlerTableBuilder* handler_table_builder,
      50             :                           int handler_id);
      51             :   void BindTryRegionEnd(HandlerTableBuilder* handler_table_builder,
      52             :                         int handler_id);
      53             : 
      54             :   Handle<BytecodeArray> ToBytecodeArray(Isolate* isolate, int register_count,
      55             :                                         int parameter_count,
      56             :                                         Handle<ByteArray> handler_table);
      57             : 
      58             :   bool RemainderOfBlockIsDead() const { return exit_seen_in_block_; }
      59             : 
      60             :  private:
      61             :   // Maximum sized packed bytecode is comprised of a prefix bytecode,
      62             :   // plus the actual bytecode, plus the maximum number of operands times
      63             :   // the maximum operand size.
      64             :   static const size_t kMaxSizeOfPackedBytecode =
      65             :       2 * sizeof(Bytecode) +
      66             :       Bytecodes::kMaxOperands * static_cast<size_t>(OperandSize::kLast);
      67             : 
      68             :   // Constants that act as placeholders for jump operands to be
      69             :   // patched. These have operand sizes that match the sizes of
      70             :   // reserved constant pool entries.
      71             :   const uint32_t k8BitJumpPlaceholder = 0x7f;
      72             :   const uint32_t k16BitJumpPlaceholder =
      73             :       k8BitJumpPlaceholder | (k8BitJumpPlaceholder << 8);
      74             :   const uint32_t k32BitJumpPlaceholder =
      75             :       k16BitJumpPlaceholder | (k16BitJumpPlaceholder << 16);
      76             : 
      77             :   void PatchJump(size_t jump_target, size_t jump_location);
      78             :   void PatchJumpWith8BitOperand(size_t jump_location, int delta);
      79             :   void PatchJumpWith16BitOperand(size_t jump_location, int delta);
      80             :   void PatchJumpWith32BitOperand(size_t jump_location, int delta);
      81             : 
      82             :   void EmitBytecode(const BytecodeNode* const node);
      83             :   void EmitJump(BytecodeNode* node, BytecodeLabel* label);
      84             :   void EmitJumpLoop(BytecodeNode* node, BytecodeLoopHeader* loop_header);
      85             :   void EmitSwitch(BytecodeNode* node, BytecodeJumpTable* jump_table);
      86             :   void UpdateSourcePositionTable(const BytecodeNode* const node);
      87             : 
      88             :   void UpdateExitSeenInBlock(Bytecode bytecode);
      89             : 
      90             :   void MaybeElideLastBytecode(Bytecode next_bytecode, bool has_source_info);
      91             :   void InvalidateLastBytecode();
      92             : 
      93             :   void StartBasicBlock();
      94             : 
      95             :   ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; }
      96             :   SourcePositionTableBuilder* source_position_table_builder() {
      97    34214286 :     return &source_position_table_builder_;
      98             :   }
      99             :   ConstantArrayBuilder* constant_array_builder() {
     100             :     return constant_array_builder_;
     101             :   }
     102             : 
     103             :   ZoneVector<uint8_t> bytecodes_;
     104             :   int unbound_jumps_;
     105             :   SourcePositionTableBuilder source_position_table_builder_;
     106             :   ConstantArrayBuilder* constant_array_builder_;
     107             : 
     108             :   Bytecode last_bytecode_;
     109             :   size_t last_bytecode_offset_;
     110             :   bool last_bytecode_had_source_info_;
     111             :   bool elide_noneffectful_bytecodes_;
     112             : 
     113             :   bool exit_seen_in_block_;
     114             : 
     115             :   friend class bytecode_array_writer_unittest::BytecodeArrayWriterUnittest;
     116             :   DISALLOW_COPY_AND_ASSIGN(BytecodeArrayWriter);
     117             : };
     118             : 
     119             : }  // namespace interpreter
     120             : }  // namespace internal
     121             : }  // namespace v8
     122             : 
     123             : #endif  // V8_INTERPRETER_BYTECODE_ARRAY_WRITER_H_

Generated by: LCOV version 1.10