Chromium Code Reviews| Index: src/interpreter/bytecode-pipeline.h |
| diff --git a/src/interpreter/bytecode-pipeline.h b/src/interpreter/bytecode-pipeline.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1d6a15c3a15d9ee073ff2a09534a812757b2fce1 |
| --- /dev/null |
| +++ b/src/interpreter/bytecode-pipeline.h |
| @@ -0,0 +1,128 @@ |
| +// Copyright 2015 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef V8_INTERPRETER_BYTECODE_PIPELINE_H_ |
| +#define V8_INTERPRETER_BYTECODE_PIPELINE_H_ |
| + |
| +#include "src/interpreter/bytecode-register-allocator.h" |
| +#include "src/interpreter/bytecodes.h" |
| +#include "src/zone-containers.h" |
| + |
| +namespace v8 { |
| +namespace internal { |
| +namespace interpreter { |
| + |
| +class BytecodeNodeAllocator; |
|
rmcilroy
2016/05/12 12:15:13
Remove
oth
2016/05/12 14:59:53
Done.
|
| + |
| +// Source code position information. |
| +class BytecodeSourceInfo final { |
| + public: |
| + static const int kUninitializedPosition = -1; |
| + |
| + BytecodeSourceInfo(int position = kUninitializedPosition, |
| + bool is_statement = false) |
| + : source_position_(position), is_statement_(is_statement) {} |
| + |
| + // Combine later source info with current. |
| + void Update(const BytecodeSourceInfo& entry); |
| + |
| + int source_position() const { |
| + DCHECK(is_valid()); |
| + return source_position_; |
| + } |
| + |
| + bool is_statement() const { return is_valid() && is_statement_; } |
| + |
| + bool is_valid() const { return source_position_ != kUninitializedPosition; } |
| + void set_invalid() { source_position_ = kUninitializedPosition; } |
| + |
| + bool operator==(const BytecodeSourceInfo& other) const { |
| + return source_position_ == other.source_position_ && |
| + is_statement_ == other.is_statement_; |
| + } |
| + bool operator!=(const BytecodeSourceInfo& other) const { |
| + return source_position_ != other.source_position_ || |
| + is_statement_ != other.is_statement_; |
| + } |
| + |
| + private: |
| + int source_position_; |
| + bool is_statement_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BytecodeSourceInfo); |
| +}; |
| + |
| +// A container for a generated bytecode, it's operands, and source information. |
| +// These must be allocated by a BytecodeNodeAllocator instance. |
| +class BytecodeNode final : ZoneObject { |
| + public: |
| + explicit BytecodeNode(Bytecode bytecode = Bytecode::kIllegal); |
| + BytecodeNode(Bytecode bytecode, uint32_t operand0, |
| + OperandScale operand_scale); |
| + BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
| + OperandScale operand_scale); |
| + BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
| + uint32_t operand2, OperandScale operand_scale); |
| + BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
| + uint32_t operand2, uint32_t operand3, |
| + OperandScale operand_scale); |
| + |
| + void set_bytecode(Bytecode bytecode); |
| + void set_bytecode(Bytecode bytecode, uint32_t operand0, |
| + OperandScale operand_scale); |
| + |
| + // Print to stream. |
| + void Print(std::ostream& os); |
| + |
| + // Return the size when this node is serialized to a bytecode array. |
| + size_t Size() const; |
| + |
| + Bytecode bytecode() const { return bytecode_; } |
| + |
| + uint32_t operand(int i) const { |
| + DCHECK_LT(i, operand_count()); |
| + return operands_[i]; |
| + } |
| + uint32_t* operands() { return operands_; } |
| + const uint32_t* operands() const { return operands_; } |
| + |
| + int operand_count() const { return Bytecodes::NumberOfOperands(bytecode_); } |
| + |
| + OperandScale operand_scale() const { return operand_scale_; } |
| + |
| + const BytecodeSourceInfo& source_info() const { return source_info_; } |
| + BytecodeSourceInfo& source_info() { return source_info_; } |
| + |
| + private: |
| + static const int kInvalidPosition = kMinInt; |
| + static const size_t kMaxOperands = 4; |
| + |
| + Bytecode bytecode_; |
| + uint32_t operands_[kMaxOperands]; |
| + OperandScale operand_scale_; |
| + BytecodeSourceInfo source_info_; |
| +}; |
| + |
| +// Interface for bytecode pipeline stages. |
| +class BytecodePipelineStage { |
|
rmcilroy
2016/05/12 12:15:14
nit - Forward declare BytecodeNode and BytecodeSou
oth
2016/05/12 14:59:53
Done.
|
| + public: |
| + virtual ~BytecodePipelineStage() {} |
| + |
| + // Flush state for bytecode array offset calculation. Returns the |
| + // current size of bytecode array. |
| + virtual size_t FlushForOffset() = 0; |
| + |
| + // Flush state to terminate basic block. |
| + virtual void FlushBasicBlock() = 0; |
| + |
| + // Write bytecode into pipeline. The callee owns node from here and |
| + // the caller should not hold any references to it. |
| + virtual void Write(BytecodeNode* node) = 0; |
| +}; |
| + |
| +} // namespace interpreter |
| +} // namespace internal |
| +} // namespace v8 |
| + |
| +#endif // V8_INTERPRETER_BYTECODE_PIPELINE_H_ |