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

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

Issue 2519923002: [ignition] Refactor array iterator to separate out access (Closed)
Patch Set: Final class and private function Created 4 years, 1 month 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
« no previous file with comments | « src/interpreter/bytecode-array-accessor.h ('k') | src/interpreter/bytecode-array-iterator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/interpreter/bytecode-array-accessor.cc
diff --git a/src/interpreter/bytecode-array-iterator.cc b/src/interpreter/bytecode-array-accessor.cc
similarity index 81%
copy from src/interpreter/bytecode-array-iterator.cc
copy to src/interpreter/bytecode-array-accessor.cc
index e596b11a0568a9fe6edaa5dcd9cc3d68dacb222f..d351e223954bed3c924a898b82e7485c36014dc6 100644
--- a/src/interpreter/bytecode-array-iterator.cc
+++ b/src/interpreter/bytecode-array-accessor.cc
@@ -2,7 +2,7 @@
// 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/interpreter/bytecode-array-accessor.h"
#include "src/interpreter/bytecode-decoder.h"
#include "src/interpreter/interpreter-intrinsics.h"
@@ -12,22 +12,22 @@ namespace v8 {
namespace internal {
namespace interpreter {
-BytecodeArrayIterator::BytecodeArrayIterator(
- Handle<BytecodeArray> bytecode_array)
+BytecodeArrayAccessor::BytecodeArrayAccessor(
+ Handle<BytecodeArray> bytecode_array, int initial_offset)
: bytecode_array_(bytecode_array),
- bytecode_offset_(0),
+ bytecode_offset_(initial_offset),
operand_scale_(OperandScale::kSingle),
prefix_offset_(0) {
UpdateOperandScale();
}
-void BytecodeArrayIterator::Advance() {
- bytecode_offset_ += current_bytecode_size();
+void BytecodeArrayAccessor::SetOffset(int offset) {
+ bytecode_offset_ = offset;
UpdateOperandScale();
}
-void BytecodeArrayIterator::UpdateOperandScale() {
- if (!done()) {
+void BytecodeArrayAccessor::UpdateOperandScale() {
+ if (OffsetInBounds()) {
uint8_t current_byte = bytecode_array()->get(bytecode_offset_);
Bytecode current_bytecode = Bytecodes::FromByte(current_byte);
if (Bytecodes::IsPrefixScalingBytecode(current_bytecode)) {
@@ -41,12 +41,12 @@ void BytecodeArrayIterator::UpdateOperandScale() {
}
}
-bool BytecodeArrayIterator::done() const {
- return bytecode_offset_ >= bytecode_array()->length();
+bool BytecodeArrayAccessor::OffsetInBounds() const {
+ return bytecode_offset_ >= 0 && bytecode_offset_ < bytecode_array()->length();
}
-Bytecode BytecodeArrayIterator::current_bytecode() const {
- DCHECK(!done());
+Bytecode BytecodeArrayAccessor::current_bytecode() const {
+ DCHECK(OffsetInBounds());
uint8_t current_byte =
bytecode_array()->get(bytecode_offset_ + current_prefix_offset());
Bytecode current_bytecode = Bytecodes::FromByte(current_byte);
@@ -54,12 +54,12 @@ Bytecode BytecodeArrayIterator::current_bytecode() const {
return current_bytecode;
}
-int BytecodeArrayIterator::current_bytecode_size() const {
+int BytecodeArrayAccessor::current_bytecode_size() const {
return current_prefix_offset() +
Bytecodes::Size(current_bytecode(), current_operand_scale());
}
-uint32_t BytecodeArrayIterator::GetUnsignedOperand(
+uint32_t BytecodeArrayAccessor::GetUnsignedOperand(
int operand_index, OperandType operand_type) const {
DCHECK_GE(operand_index, 0);
DCHECK_LT(operand_index, Bytecodes::NumberOfOperands(current_bytecode()));
@@ -75,7 +75,7 @@ uint32_t BytecodeArrayIterator::GetUnsignedOperand(
current_operand_scale());
}
-int32_t BytecodeArrayIterator::GetSignedOperand(
+int32_t BytecodeArrayAccessor::GetSignedOperand(
int operand_index, OperandType operand_type) const {
DCHECK_GE(operand_index, 0);
DCHECK_LT(operand_index, Bytecodes::NumberOfOperands(current_bytecode()));
@@ -91,40 +91,40 @@ int32_t BytecodeArrayIterator::GetSignedOperand(
current_operand_scale());
}
-uint32_t BytecodeArrayIterator::GetFlagOperand(int operand_index) const {
+uint32_t BytecodeArrayAccessor::GetFlagOperand(int operand_index) const {
DCHECK_EQ(Bytecodes::GetOperandType(current_bytecode(), operand_index),
OperandType::kFlag8);
return GetUnsignedOperand(operand_index, OperandType::kFlag8);
}
-uint32_t BytecodeArrayIterator::GetUnsignedImmediateOperand(
+uint32_t BytecodeArrayAccessor::GetUnsignedImmediateOperand(
int operand_index) const {
DCHECK_EQ(Bytecodes::GetOperandType(current_bytecode(), operand_index),
OperandType::kUImm);
return GetUnsignedOperand(operand_index, OperandType::kUImm);
}
-int32_t BytecodeArrayIterator::GetImmediateOperand(int operand_index) const {
+int32_t BytecodeArrayAccessor::GetImmediateOperand(int operand_index) const {
DCHECK_EQ(Bytecodes::GetOperandType(current_bytecode(), operand_index),
OperandType::kImm);
return GetSignedOperand(operand_index, OperandType::kImm);
}
-uint32_t BytecodeArrayIterator::GetRegisterCountOperand(
+uint32_t BytecodeArrayAccessor::GetRegisterCountOperand(
int operand_index) const {
DCHECK_EQ(Bytecodes::GetOperandType(current_bytecode(), operand_index),
OperandType::kRegCount);
return GetUnsignedOperand(operand_index, OperandType::kRegCount);
}
-uint32_t BytecodeArrayIterator::GetIndexOperand(int operand_index) const {
+uint32_t BytecodeArrayAccessor::GetIndexOperand(int operand_index) const {
OperandType operand_type =
Bytecodes::GetOperandType(current_bytecode(), operand_index);
DCHECK_EQ(operand_type, OperandType::kIdx);
return GetUnsignedOperand(operand_index, operand_type);
}
-Register BytecodeArrayIterator::GetRegisterOperand(int operand_index) const {
+Register BytecodeArrayAccessor::GetRegisterOperand(int operand_index) const {
OperandType operand_type =
Bytecodes::GetOperandType(current_bytecode(), operand_index);
const uint8_t* operand_start =
@@ -136,7 +136,7 @@ Register BytecodeArrayIterator::GetRegisterOperand(int operand_index) const {
current_operand_scale());
}
-int BytecodeArrayIterator::GetRegisterOperandRange(int operand_index) const {
+int BytecodeArrayAccessor::GetRegisterOperandRange(int operand_index) const {
DCHECK_LE(operand_index, Bytecodes::NumberOfOperands(current_bytecode()));
const OperandType* operand_types =
Bytecodes::GetOperandTypes(current_bytecode());
@@ -149,7 +149,7 @@ int BytecodeArrayIterator::GetRegisterOperandRange(int operand_index) const {
}
}
-Runtime::FunctionId BytecodeArrayIterator::GetRuntimeIdOperand(
+Runtime::FunctionId BytecodeArrayAccessor::GetRuntimeIdOperand(
int operand_index) const {
OperandType operand_type =
Bytecodes::GetOperandType(current_bytecode(), operand_index);
@@ -158,7 +158,7 @@ Runtime::FunctionId BytecodeArrayIterator::GetRuntimeIdOperand(
return static_cast<Runtime::FunctionId>(raw_id);
}
-Runtime::FunctionId BytecodeArrayIterator::GetIntrinsicIdOperand(
+Runtime::FunctionId BytecodeArrayAccessor::GetIntrinsicIdOperand(
int operand_index) const {
OperandType operand_type =
Bytecodes::GetOperandType(current_bytecode(), operand_index);
@@ -168,15 +168,14 @@ Runtime::FunctionId BytecodeArrayIterator::GetIntrinsicIdOperand(
static_cast<IntrinsicsHelper::IntrinsicId>(raw_id));
}
-Handle<Object> BytecodeArrayIterator::GetConstantForIndexOperand(
+Handle<Object> BytecodeArrayAccessor::GetConstantForIndexOperand(
int operand_index) const {
return FixedArray::get(bytecode_array()->constant_pool(),
GetIndexOperand(operand_index),
bytecode_array()->GetIsolate());
}
-
-int BytecodeArrayIterator::GetJumpTargetOffset() const {
+int BytecodeArrayAccessor::GetJumpTargetOffset() const {
Bytecode bytecode = current_bytecode();
if (interpreter::Bytecodes::IsJumpImmediate(bytecode)) {
int relative_offset = GetImmediateOperand(0);
« no previous file with comments | « src/interpreter/bytecode-array-accessor.h ('k') | src/interpreter/bytecode-array-iterator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698