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; | |
rmcilroy
2016/05/12 12:15:13
Remove
oth
2016/05/12 14:59:53
Done.
| |
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 // A container for a generated bytecode, it's operands, and source information. | |
57 // These must be allocated by a BytecodeNodeAllocator instance. | |
58 class BytecodeNode final : ZoneObject { | |
59 public: | |
60 explicit BytecodeNode(Bytecode bytecode = Bytecode::kIllegal); | |
61 BytecodeNode(Bytecode bytecode, uint32_t operand0, | |
62 OperandScale operand_scale); | |
63 BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | |
64 OperandScale operand_scale); | |
65 BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | |
66 uint32_t operand2, OperandScale operand_scale); | |
67 BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | |
68 uint32_t operand2, uint32_t operand3, | |
69 OperandScale operand_scale); | |
70 | |
71 void set_bytecode(Bytecode bytecode); | |
72 void set_bytecode(Bytecode bytecode, uint32_t operand0, | |
73 OperandScale operand_scale); | |
74 | |
75 // Print to stream. | |
76 void Print(std::ostream& os); | |
77 | |
78 // Return the size when this node is serialized to a bytecode array. | |
79 size_t Size() const; | |
80 | |
81 Bytecode bytecode() const { return bytecode_; } | |
82 | |
83 uint32_t operand(int i) const { | |
84 DCHECK_LT(i, operand_count()); | |
85 return operands_[i]; | |
86 } | |
87 uint32_t* operands() { return operands_; } | |
88 const uint32_t* operands() const { return operands_; } | |
89 | |
90 int operand_count() const { return Bytecodes::NumberOfOperands(bytecode_); } | |
91 | |
92 OperandScale operand_scale() const { return operand_scale_; } | |
93 | |
94 const BytecodeSourceInfo& source_info() const { return source_info_; } | |
95 BytecodeSourceInfo& source_info() { return source_info_; } | |
96 | |
97 private: | |
98 static const int kInvalidPosition = kMinInt; | |
99 static const size_t kMaxOperands = 4; | |
100 | |
101 Bytecode bytecode_; | |
102 uint32_t operands_[kMaxOperands]; | |
103 OperandScale operand_scale_; | |
104 BytecodeSourceInfo source_info_; | |
105 }; | |
106 | |
107 // Interface for bytecode pipeline stages. | |
108 class BytecodePipelineStage { | |
rmcilroy
2016/05/12 12:15:14
nit - Forward declare BytecodeNode and BytecodeSou
oth
2016/05/12 14:59:53
Done.
| |
109 public: | |
110 virtual ~BytecodePipelineStage() {} | |
111 | |
112 // Flush state for bytecode array offset calculation. Returns the | |
113 // current size of bytecode array. | |
114 virtual size_t FlushForOffset() = 0; | |
115 | |
116 // Flush state to terminate basic block. | |
117 virtual void FlushBasicBlock() = 0; | |
118 | |
119 // Write bytecode into pipeline. The callee owns node from here and | |
120 // the caller should not hold any references to it. | |
121 virtual void Write(BytecodeNode* node) = 0; | |
122 }; | |
123 | |
124 } // namespace interpreter | |
125 } // namespace internal | |
126 } // namespace v8 | |
127 | |
128 #endif // V8_INTERPRETER_BYTECODE_PIPELINE_H_ | |
OLD | NEW |