OLD | NEW |
(Empty) | |
| 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_PIPELINE_H_ |
| 6 #define V8_INTERPRETER_BYTECODE_PIPELINE_H_ |
| 7 |
| 8 #include "src/interpreter/bytecode-register-allocator.h" |
| 9 #include "src/interpreter/bytecodes.h" |
| 10 #include "src/zone-containers.h" |
| 11 |
| 12 namespace v8 { |
| 13 namespace internal { |
| 14 namespace interpreter { |
| 15 |
| 16 class BytecodeNodeAllocator; |
| 17 |
| 18 // Source code position information. |
| 19 class BytecodeSourceInfo final { |
| 20 public: |
| 21 static const int kUninitializedPosition = -1; |
| 22 |
| 23 BytecodeSourceInfo(int position = kUninitializedPosition, |
| 24 bool is_statement = false) |
| 25 : source_position_(position), is_statement_(is_statement) {} |
| 26 |
| 27 // Combine later source info with current. |
| 28 void Update(const BytecodeSourceInfo& entry); |
| 29 |
| 30 int source_position() const { |
| 31 DCHECK(is_valid()); |
| 32 return source_position_; |
| 33 } |
| 34 |
| 35 bool is_statement() const { return is_valid() && is_statement_; } |
| 36 |
| 37 bool is_valid() const { return source_position_ != kUninitializedPosition; } |
| 38 void set_invalid() { source_position_ = kUninitializedPosition; } |
| 39 |
| 40 bool operator==(const BytecodeSourceInfo& other) const { |
| 41 return source_position_ == other.source_position_ && |
| 42 is_statement_ == other.is_statement_; |
| 43 } |
| 44 bool operator!=(const BytecodeSourceInfo& other) const { |
| 45 return source_position_ != other.source_position_ || |
| 46 is_statement_ != other.is_statement_; |
| 47 } |
| 48 |
| 49 private: |
| 50 int source_position_; |
| 51 bool is_statement_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(BytecodeSourceInfo); |
| 54 }; |
| 55 |
| 56 std::ostream& operator<<(std::ostream& os, const BytecodeSourceInfo& info); |
| 57 |
| 58 // A container for a generated bytecode, it's operands, and source information. |
| 59 // These must be allocated by a BytecodeNodeAllocator instance. |
| 60 class BytecodeNode final : ZoneObject { |
| 61 public: |
| 62 explicit BytecodeNode(Bytecode bytecode = Bytecode::kIllegal); |
| 63 BytecodeNode(Bytecode bytecode, uint32_t operand0, |
| 64 OperandScale operand_scale); |
| 65 BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
| 66 OperandScale operand_scale); |
| 67 BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
| 68 uint32_t operand2, OperandScale operand_scale); |
| 69 BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
| 70 uint32_t operand2, uint32_t operand3, |
| 71 OperandScale operand_scale); |
| 72 |
| 73 void set_bytecode(Bytecode bytecode); |
| 74 void set_bytecode(Bytecode bytecode, uint32_t operand0, |
| 75 OperandScale operand_scale); |
| 76 |
| 77 // Clone |other|. |
| 78 void Clone(const BytecodeNode* const other); |
| 79 |
| 80 // Print to stream |os|. |
| 81 void Print(std::ostream& os) const; |
| 82 |
| 83 // Return the size when this node is serialized to a bytecode array. |
| 84 size_t Size() const; |
| 85 |
| 86 Bytecode bytecode() const { return bytecode_; } |
| 87 |
| 88 uint32_t operand(int i) const { |
| 89 DCHECK_LT(i, operand_count()); |
| 90 return operands_[i]; |
| 91 } |
| 92 uint32_t* operands() { return operands_; } |
| 93 const uint32_t* operands() const { return operands_; } |
| 94 |
| 95 int operand_count() const { return Bytecodes::NumberOfOperands(bytecode_); } |
| 96 OperandScale operand_scale() const { return operand_scale_; } |
| 97 |
| 98 const BytecodeSourceInfo& source_info() const { return source_info_; } |
| 99 BytecodeSourceInfo& source_info() { return source_info_; } |
| 100 |
| 101 bool operator==(const BytecodeNode& other) const; |
| 102 bool operator!=(const BytecodeNode& other) const { return !(*this == other); } |
| 103 |
| 104 private: |
| 105 static const int kInvalidPosition = kMinInt; |
| 106 static const size_t kMaxOperands = 4; |
| 107 |
| 108 Bytecode bytecode_; |
| 109 uint32_t operands_[kMaxOperands]; |
| 110 OperandScale operand_scale_; |
| 111 BytecodeSourceInfo source_info_; |
| 112 }; |
| 113 |
| 114 std::ostream& operator<<(std::ostream& os, const BytecodeNode& node); |
| 115 |
| 116 // Interface for bytecode pipeline stages. |
| 117 class BytecodePipelineStage { |
| 118 public: |
| 119 virtual ~BytecodePipelineStage() {} |
| 120 |
| 121 // Flush state for bytecode array offset calculation. Returns the |
| 122 // current size of bytecode array. |
| 123 virtual size_t FlushForOffset() = 0; |
| 124 |
| 125 // Flush state to terminate basic block. |
| 126 virtual void FlushBasicBlock() = 0; |
| 127 |
| 128 // Write bytecode node |node| into pipeline. The node is only valid |
| 129 // for the duration of the call. Callee's should clone it if |
| 130 // deferring Write() to the next stage. |
| 131 virtual void Write(BytecodeNode* node) = 0; |
| 132 }; |
| 133 |
| 134 } // namespace interpreter |
| 135 } // namespace internal |
| 136 } // namespace v8 |
| 137 |
| 138 #endif // V8_INTERPRETER_BYTECODE_PIPELINE_H_ |
OLD | NEW |