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

Unified Diff: src/interpreter/bytecode-pipeline.cc

Issue 1947403002: [interpreter] Introduce bytecode generation pipeline. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Incorporate comments on patch set 6. Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: src/interpreter/bytecode-pipeline.cc
diff --git a/src/interpreter/bytecode-pipeline.cc b/src/interpreter/bytecode-pipeline.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c1d2e85d367c01445996cee8ba37d7317986b850
--- /dev/null
+++ b/src/interpreter/bytecode-pipeline.cc
@@ -0,0 +1,124 @@
+// 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.
+
+#include "src/interpreter/bytecode-pipeline.h"
+
+#include <iomanip>
+#include "src/interpreter/source-position-table.h"
+
+namespace v8 {
+namespace internal {
+namespace interpreter {
+
+void BytecodeSourceInfo::Update(const BytecodeSourceInfo& entry) {
+ DCHECK(entry.is_valid());
+ if (!is_valid() || (entry.is_statement() && !is_statement()) ||
+ (entry.is_statement() && is_statement() &&
+ entry.source_position() > source_position())) {
+ // Position is updated if there is no existing position. Or the
+ // incoming position is a statement and the current position is an
+ // expression. Or we already have a statement and incoming
+ // statement is later. This last piece is needed for the first
+ // statement in a function.
rmcilroy 2016/05/12 12:15:13 I'm not sure what "This last piece is needed for t
oth 2016/05/12 14:59:53 Comment updated. IIRC there may be multiple statem
+ source_position_ = entry.source_position_;
+ is_statement_ = entry.is_statement_;
+ }
+}
+
+BytecodeNode::BytecodeNode(Bytecode bytecode) {
+ DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0);
+ bytecode_ = bytecode;
+ operand_scale_ = OperandScale::kSingle;
+}
+
+BytecodeNode::BytecodeNode(Bytecode bytecode, uint32_t operand0,
+ OperandScale operand_scale) {
+ DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 1);
+ bytecode_ = bytecode;
+ operands_[0] = operand0;
+ operand_scale_ = operand_scale;
+}
+
+BytecodeNode::BytecodeNode(Bytecode bytecode, uint32_t operand0,
+ uint32_t operand1, OperandScale operand_scale) {
+ DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 2);
+ bytecode_ = bytecode;
+ operands_[0] = operand0;
+ operands_[1] = operand1;
+ operand_scale_ = operand_scale;
+}
+
+BytecodeNode::BytecodeNode(Bytecode bytecode, uint32_t operand0,
+ uint32_t operand1, uint32_t operand2,
+ OperandScale operand_scale) {
+ DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 3);
+ bytecode_ = bytecode;
+ operands_[0] = operand0;
+ operands_[1] = operand1;
+ operands_[2] = operand2;
+ operand_scale_ = operand_scale;
+}
+
+BytecodeNode::BytecodeNode(Bytecode bytecode, uint32_t operand0,
+ uint32_t operand1, uint32_t operand2,
+ uint32_t operand3, OperandScale operand_scale) {
+ DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 4);
+ bytecode_ = bytecode;
+ operands_[0] = operand0;
+ operands_[1] = operand1;
+ operands_[2] = operand2;
+ operands_[3] = operand3;
+ operand_scale_ = operand_scale;
+}
+
+void BytecodeNode::set_bytecode(Bytecode bytecode) {
+ DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0);
+ bytecode_ = bytecode;
+ operand_scale_ = OperandScale::kSingle;
+}
+
+void BytecodeNode::set_bytecode(Bytecode bytecode, uint32_t operand0,
+ OperandScale operand_scale) {
+ DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 1);
+ bytecode_ = bytecode;
+ operands_[0] = operand0;
+ operand_scale_ = operand_scale;
+}
+
+size_t BytecodeNode::Size() const {
+ size_t size = Bytecodes::Size(bytecode_, operand_scale_);
+ if (Bytecodes::OperandScaleRequiresPrefixBytecode(operand_scale_)) {
+ size += 1;
+ }
+ return size;
+}
+
+void BytecodeNode::Print(std::ostream& os) {
+#ifdef DEBUG
+ std::ios saved_state(nullptr);
+ saved_state.copyfmt(os);
+
+ os << Bytecodes::ToString(bytecode_);
+ if (Bytecodes::OperandScaleRequiresPrefixBytecode(operand_scale_)) {
+ Bytecode scale_prefix =
+ Bytecodes::OperandScaleToPrefixBytecode(operand_scale_);
+ os << '.' << Bytecodes::ToString(scale_prefix);
+ }
+
+ for (int i = 0; i < operand_count(); ++i) {
+ os << ' ' << std::setw(8) << std::setfill('0') << std::hex << operands_[i];
+ }
+ os.copyfmt(saved_state);
+
+ if (source_info_.is_valid()) {
+ char type = source_info_.is_statement() ? 'S' : 'E';
+ os << ' ' << type << '@' << source_info_.source_position();
+ }
+ os << '\n';
+#endif // DEBUG
+}
+
+} // namespace interpreter
+} // namespace internal
+} // namespace v8

Powered by Google App Engine
This is Rietveld 408576698