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_ARRAY_ITERATOR_H_ 6 #define V8_INTERPRETER_BYTECODE_ARRAY_ITERATOR_H_ 7 8 #include "src/globals.h" 9 #include "src/handles.h" 10 #include "src/interpreter/bytecode-register.h" 11 #include "src/interpreter/bytecodes.h" 12 #include "src/objects.h" 13 #include "src/runtime/runtime.h" 14 15 namespace v8 { 16 namespace internal { 17 namespace interpreter { 18 19 class V8_EXPORT_PRIVATE BytecodeArrayIterator { 20 public: 21 explicit BytecodeArrayIterator(Handle<BytecodeArray> bytecode_array); 22 23 void Advance(); 24 bool done() const; 25 Bytecode current_bytecode() const; 26 int current_bytecode_size() const; current_offset()27 int current_offset() const { return bytecode_offset_; } current_operand_scale()28 OperandScale current_operand_scale() const { return operand_scale_; } current_prefix_offset()29 int current_prefix_offset() const { return prefix_offset_; } bytecode_array()30 const Handle<BytecodeArray>& bytecode_array() const { 31 return bytecode_array_; 32 } 33 34 uint32_t GetFlagOperand(int operand_index) const; 35 uint32_t GetUnsignedImmediateOperand(int operand_index) const; 36 int32_t GetImmediateOperand(int operand_index) const; 37 uint32_t GetIndexOperand(int operand_index) const; 38 uint32_t GetRegisterCountOperand(int operand_index) const; 39 Register GetRegisterOperand(int operand_index) const; 40 int GetRegisterOperandRange(int operand_index) const; 41 Runtime::FunctionId GetRuntimeIdOperand(int operand_index) const; 42 Runtime::FunctionId GetIntrinsicIdOperand(int operand_index) const; 43 Handle<Object> GetConstantForIndexOperand(int operand_index) const; 44 45 // Returns the absolute offset of the branch target at the current 46 // bytecode. It is an error to call this method if the bytecode is 47 // not for a jump or conditional jump. 48 int GetJumpTargetOffset() const; 49 50 private: 51 uint32_t GetUnsignedOperand(int operand_index, 52 OperandType operand_type) const; 53 int32_t GetSignedOperand(int operand_index, OperandType operand_type) const; 54 55 void UpdateOperandScale(); 56 57 Handle<BytecodeArray> bytecode_array_; 58 int bytecode_offset_; 59 OperandScale operand_scale_; 60 int prefix_offset_; 61 62 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayIterator); 63 }; 64 65 } // namespace interpreter 66 } // namespace internal 67 } // namespace v8 68 69 #endif // V8_INTERPRETER_BYTECODE_GRAPH_ITERATOR_H_ 70