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_PIPELINE_H_ | 5 #ifndef V8_INTERPRETER_BYTECODE_PIPELINE_H_ |
6 #define V8_INTERPRETER_BYTECODE_PIPELINE_H_ | 6 #define V8_INTERPRETER_BYTECODE_PIPELINE_H_ |
7 | 7 |
8 #include "src/interpreter/bytecode-register-allocator.h" | 8 #include "src/interpreter/bytecode-register-allocator.h" |
9 #include "src/interpreter/bytecodes.h" | 9 #include "src/interpreter/bytecodes.h" |
10 #include "src/zone-containers.h" | 10 #include "src/zone-containers.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 virtual Handle<BytecodeArray> ToBytecodeArray( | 47 virtual Handle<BytecodeArray> ToBytecodeArray( |
48 int fixed_register_count, int parameter_count, | 48 int fixed_register_count, int parameter_count, |
49 Handle<FixedArray> handler_table) = 0; | 49 Handle<FixedArray> handler_table) = 0; |
50 }; | 50 }; |
51 | 51 |
52 // Source code position information. | 52 // Source code position information. |
53 class BytecodeSourceInfo final { | 53 class BytecodeSourceInfo final { |
54 public: | 54 public: |
55 static const int kUninitializedPosition = -1; | 55 static const int kUninitializedPosition = -1; |
56 | 56 |
57 BytecodeSourceInfo(int position = kUninitializedPosition, | 57 BytecodeSourceInfo() |
58 bool is_statement = false) | 58 : position_type_(PositionType::kNone), |
59 : source_position_(position), is_statement_(is_statement) {} | 59 source_position_(kUninitializedPosition) {} |
60 | 60 |
61 // Combine later source info with current. | 61 BytecodeSourceInfo(int source_position, bool is_statement) |
62 void Update(const BytecodeSourceInfo& entry); | 62 : position_type_(is_statement ? PositionType::kStatement |
| 63 : PositionType::kExpression), |
| 64 source_position_(source_position) { |
| 65 DCHECK_GE(source_position, 0); |
| 66 } |
| 67 |
| 68 // Makes instance into a statement position. |
| 69 void MakeStatementPosition(int source_position) { |
| 70 // Statement positions can be replaced by other statement |
| 71 // positions. For example , "for (x = 0; x < 3; ++x) 7;" has a |
| 72 // statement position associated with 7 but no bytecode associated |
| 73 // with it. Then Next is emitted after the body and has |
| 74 // statement position and overrides the existing one. |
| 75 position_type_ = PositionType::kStatement; |
| 76 source_position_ = source_position; |
| 77 } |
| 78 |
| 79 // Makes instance into an expression position. Instance should not |
| 80 // be a statement position otherwise it could be lost and impair the |
| 81 // debugging experience. |
| 82 void MakeExpressionPosition(int source_position) { |
| 83 DCHECK(!is_statement()); |
| 84 position_type_ = PositionType::kExpression; |
| 85 source_position_ = source_position; |
| 86 } |
| 87 |
| 88 // Forces an instance into an expression position. |
| 89 void ForceExpressionPosition(int source_position) { |
| 90 position_type_ = PositionType::kExpression; |
| 91 source_position_ = source_position; |
| 92 } |
| 93 |
| 94 // Clones a source position. The current instance is expected to be |
| 95 // invalid. |
| 96 void Clone(const BytecodeSourceInfo& other) { |
| 97 DCHECK(!is_valid()); |
| 98 position_type_ = other.position_type_; |
| 99 source_position_ = other.source_position_; |
| 100 } |
63 | 101 |
64 int source_position() const { | 102 int source_position() const { |
65 DCHECK(is_valid()); | 103 DCHECK(is_valid()); |
66 return source_position_; | 104 return source_position_; |
67 } | 105 } |
68 | 106 |
69 bool is_statement() const { return is_valid() && is_statement_; } | 107 bool is_statement() const { |
70 bool is_expression() const { return is_valid() && !is_statement_; } | 108 return position_type_ == PositionType::kStatement; |
| 109 } |
| 110 bool is_expression() const { |
| 111 return position_type_ == PositionType::kExpression; |
| 112 } |
71 | 113 |
72 bool is_valid() const { return source_position_ != kUninitializedPosition; } | 114 bool is_valid() const { return position_type_ != PositionType::kNone; } |
73 void set_invalid() { source_position_ = kUninitializedPosition; } | 115 void set_invalid() { |
| 116 position_type_ = PositionType::kNone; |
| 117 source_position_ = kUninitializedPosition; |
| 118 } |
74 | 119 |
75 bool operator==(const BytecodeSourceInfo& other) const { | 120 bool operator==(const BytecodeSourceInfo& other) const { |
76 return source_position_ == other.source_position_ && | 121 return position_type_ == other.position_type_ && |
77 is_statement_ == other.is_statement_; | 122 source_position_ == other.source_position_; |
78 } | 123 } |
| 124 |
79 bool operator!=(const BytecodeSourceInfo& other) const { | 125 bool operator!=(const BytecodeSourceInfo& other) const { |
80 return source_position_ != other.source_position_ || | 126 return position_type_ != other.position_type_ || |
81 is_statement_ != other.is_statement_; | 127 source_position_ != other.source_position_; |
82 } | 128 } |
83 | 129 |
84 private: | 130 private: |
| 131 enum class PositionType : uint8_t { kNone, kExpression, kStatement }; |
| 132 |
| 133 PositionType position_type_; |
85 int source_position_; | 134 int source_position_; |
86 bool is_statement_; | 135 |
| 136 DISALLOW_COPY_AND_ASSIGN(BytecodeSourceInfo); |
87 }; | 137 }; |
88 | 138 |
89 // A container for a generated bytecode, it's operands, and source information. | 139 // A container for a generated bytecode, it's operands, and source information. |
90 // These must be allocated by a BytecodeNodeAllocator instance. | 140 // These must be allocated by a BytecodeNodeAllocator instance. |
91 class BytecodeNode final : ZoneObject { | 141 class BytecodeNode final : ZoneObject { |
92 public: | 142 public: |
93 explicit BytecodeNode(Bytecode bytecode = Bytecode::kIllegal); | 143 explicit BytecodeNode(Bytecode bytecode = Bytecode::kIllegal); |
94 BytecodeNode(Bytecode bytecode, uint32_t operand0); | 144 BytecodeNode(Bytecode bytecode, uint32_t operand0); |
95 BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1); | 145 BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1); |
96 BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | 146 BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 }; | 191 }; |
142 | 192 |
143 std::ostream& operator<<(std::ostream& os, const BytecodeSourceInfo& info); | 193 std::ostream& operator<<(std::ostream& os, const BytecodeSourceInfo& info); |
144 std::ostream& operator<<(std::ostream& os, const BytecodeNode& node); | 194 std::ostream& operator<<(std::ostream& os, const BytecodeNode& node); |
145 | 195 |
146 } // namespace interpreter | 196 } // namespace interpreter |
147 } // namespace internal | 197 } // namespace internal |
148 } // namespace v8 | 198 } // namespace v8 |
149 | 199 |
150 #endif // V8_INTERPRETER_BYTECODE_PIPELINE_H_ | 200 #endif // V8_INTERPRETER_BYTECODE_PIPELINE_H_ |
OLD | NEW |