Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(948)

Side by Side Diff: src/interpreter/bytecode-pipeline.h

Issue 2048203002: [interpreter] Minor clean-up of BytecodeSourceInfo. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@oth-0066-suppress
Patch Set: Add BytecodeSourceInfo::ForceExpressionPosition(). Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // Makes an invalid instance into a new source position.
95 void MakeInvalidEqualTo(const BytecodeSourceInfo& other) {
rmcilroy 2016/06/20 11:21:39 I'm not keen on this name. One possible suggestio
oth 2016/06/21 10:05:46 Okay, the method is renamed Clone(). I totally agr
96 DCHECK(!is_valid());
97 position_type_ = other.position_type_;
98 source_position_ = other.source_position_;
99 }
63 100
64 int source_position() const { 101 int source_position() const {
65 DCHECK(is_valid()); 102 DCHECK(is_valid());
66 return source_position_; 103 return source_position_;
67 } 104 }
68 105
69 bool is_statement() const { return is_valid() && is_statement_; } 106 bool is_statement() const {
70 bool is_expression() const { return is_valid() && !is_statement_; } 107 return position_type_ == PositionType::kStatement;
108 }
109 bool is_expression() const {
110 return position_type_ == PositionType::kExpression;
111 }
71 112
72 bool is_valid() const { return source_position_ != kUninitializedPosition; } 113 bool is_valid() const { return position_type_ != PositionType::kNone; }
73 void set_invalid() { source_position_ = kUninitializedPosition; } 114 void set_invalid() {
115 position_type_ = PositionType::kNone;
116 source_position_ = kUninitializedPosition;
117 }
74 118
75 bool operator==(const BytecodeSourceInfo& other) const { 119 bool operator==(const BytecodeSourceInfo& other) const {
76 return source_position_ == other.source_position_ && 120 return position_type_ == other.position_type_ &&
77 is_statement_ == other.is_statement_; 121 source_position_ == other.source_position_;
78 } 122 }
123
79 bool operator!=(const BytecodeSourceInfo& other) const { 124 bool operator!=(const BytecodeSourceInfo& other) const {
80 return source_position_ != other.source_position_ || 125 return position_type_ != other.position_type_ ||
81 is_statement_ != other.is_statement_; 126 source_position_ != other.source_position_;
82 } 127 }
83 128
84 private: 129 private:
130 enum class PositionType : uint8_t { kNone, kExpression, kStatement };
131
132 PositionType position_type_;
85 int source_position_; 133 int source_position_;
86 bool is_statement_; 134
135 DISALLOW_COPY_AND_ASSIGN(BytecodeSourceInfo);
87 }; 136 };
88 137
89 // A container for a generated bytecode, it's operands, and source information. 138 // A container for a generated bytecode, it's operands, and source information.
90 // These must be allocated by a BytecodeNodeAllocator instance. 139 // These must be allocated by a BytecodeNodeAllocator instance.
91 class BytecodeNode final : ZoneObject { 140 class BytecodeNode final : ZoneObject {
92 public: 141 public:
93 explicit BytecodeNode(Bytecode bytecode = Bytecode::kIllegal); 142 explicit BytecodeNode(Bytecode bytecode = Bytecode::kIllegal);
94 BytecodeNode(Bytecode bytecode, uint32_t operand0); 143 BytecodeNode(Bytecode bytecode, uint32_t operand0);
95 BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1); 144 BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1);
96 BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, 145 BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 }; 190 };
142 191
143 std::ostream& operator<<(std::ostream& os, const BytecodeSourceInfo& info); 192 std::ostream& operator<<(std::ostream& os, const BytecodeSourceInfo& info);
144 std::ostream& operator<<(std::ostream& os, const BytecodeNode& node); 193 std::ostream& operator<<(std::ostream& os, const BytecodeNode& node);
145 194
146 } // namespace interpreter 195 } // namespace interpreter
147 } // namespace internal 196 } // namespace internal
148 } // namespace v8 197 } // namespace v8
149 198
150 #endif // V8_INTERPRETER_BYTECODE_PIPELINE_H_ 199 #endif // V8_INTERPRETER_BYTECODE_PIPELINE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698