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

Unified Diff: src/interpreter/bytecode-array-iterator.cc

Issue 1291693004: [Interpreter] Bytecode graph builder (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Incorporate comments on patch set 8. Created 5 years, 3 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-array-iterator.cc
diff --git a/src/interpreter/bytecode-array-iterator.cc b/src/interpreter/bytecode-array-iterator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8c077b9ad83f9d60d1818fb0e9bc39fc849b2da6
--- /dev/null
+++ b/src/interpreter/bytecode-array-iterator.cc
@@ -0,0 +1,104 @@
+// 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-array-iterator.h"
+
+#include "src/objects-inl.h"
+
+namespace v8 {
+namespace internal {
+namespace interpreter {
+
+BytecodeArrayIterator::BytecodeArrayIterator(
+ Handle<BytecodeArray> bytecode_array)
+ : bytecode_array_(bytecode_array), bytecode_offset_(0) {
rmcilroy 2015/09/04 11:35:37 need to init operands_used_ if DEBUG
oth 2015/09/04 16:15:46 Yes, but that's what MarkOperandsUnused() does.
+ MarkOperandsUnused();
+}
+
+
+BytecodeArrayIterator::~BytecodeArrayIterator() { CheckOperandsUsed(); }
+
+
+void BytecodeArrayIterator::Next() {
+ DCHECK(More());
+ CheckOperandsUsed();
+ MarkOperandsUnused();
+ bytecode_offset_ += Bytecodes::Size(current_bytecode());
+}
+
+
+bool BytecodeArrayIterator::More() const {
rmcilroy 2015/09/04 11:35:37 More seems a little confusing here, since it impli
oth 2015/09/04 16:15:46 Done. These were adopted from elsewhere in the tre
+ return bytecode_offset_ < bytecode_array()->length();
+}
+
+
+Bytecode BytecodeArrayIterator::current_bytecode() const {
+ uint8_t current_byte = bytecode_array()->get(bytecode_offset_);
+ return interpreter::Bytecodes::FromByte(current_byte);
+}
+
+
+uint8_t BytecodeArrayIterator::GetOperand(int operand_index,
+ OperandType operand_type) const {
+ DCHECK_GE(operand_index, 0);
+ DCHECK_LT(operand_index, Bytecodes::NumberOfOperands(current_bytecode()));
+ DCHECK_EQ(operand_type,
+ Bytecodes::GetOperandType(current_bytecode(), operand_index));
+ MarkOperandUsed(operand_index);
+ int operands_start = bytecode_offset_ + 1;
+ return bytecode_array()->get(operands_start + operand_index);
+}
+
+
+int8_t BytecodeArrayIterator::GetSmi8Operand(int operand_index) const {
+ uint8_t operand = GetOperand(operand_index, OperandType::kImm8);
+ return static_cast<int8_t>(operand);
+}
+
+
+int BytecodeArrayIterator::GetIndexOperand(int operand_index) const {
+ uint8_t operand = GetOperand(operand_index, OperandType::kIdx);
+ return static_cast<int>(operand);
+}
+
+
+Register BytecodeArrayIterator::GetRegisterOperand(int operand_index) const {
+ uint8_t operand = GetOperand(operand_index, OperandType::kReg);
+ return Register::FromOperand(operand);
+}
+
+
+Handle<Object> BytecodeArrayIterator::GetConstantForIndexOperand(
+ int operand_index) const {
+ Handle<FixedArray> constants = handle(bytecode_array()->constant_pool());
+ return FixedArray::get(constants, GetIndexOperand(operand_index));
+}
+
+
+void BytecodeArrayIterator::MarkOperandsUnused() {
+#ifdef DEBUG
+ operands_used_ = 0;
+#endif // DEBUG
+}
+
+
+void BytecodeArrayIterator::CheckOperandsUsed() const {
rmcilroy 2015/09/04 11:35:37 I'm wondering how useful this will be (and whether
oth 2015/09/04 16:15:46 Gone :-)
+#ifdef DEBUG
+ if (More()) {
+ Bytecode bytecode = current_bytecode();
+ int mask = (1 << Bytecodes::NumberOfOperands(bytecode)) - 1;
+ DCHECK_EQ(operands_used_, mask);
+ }
+#endif // DEBUG
+}
+
+void BytecodeArrayIterator::MarkOperandUsed(int operand_index) const {
+#ifdef DEBUG
+ operands_used_ |= 1 << operand_index;
+#endif // DEBUG
+}
+
+} // namespace interpreter
+} // namespace internal
+} // namespace v8

Powered by Google App Engine
This is Rietveld 408576698