blob: b372894fd8a3284aff1cdd93dc239e642b3ea318 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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/handles.h"
9#include "src/interpreter/bytecodes.h"
10#include "src/objects.h"
11
12namespace v8 {
13namespace internal {
14namespace interpreter {
15
16class BytecodeArrayIterator {
17 public:
18 explicit BytecodeArrayIterator(Handle<BytecodeArray> bytecode_array);
19
20 void Advance();
21 bool done() const;
22 Bytecode current_bytecode() const;
23 int current_bytecode_size() const;
24 int current_offset() const { return bytecode_offset_; }
Ben Murdochda12d292016-06-02 14:46:10 +010025 OperandScale current_operand_scale() const { return operand_scale_; }
26 int current_prefix_offset() const { return prefix_offset_; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000027 const Handle<BytecodeArray>& bytecode_array() const {
28 return bytecode_array_;
29 }
30
Ben Murdochda12d292016-06-02 14:46:10 +010031 uint32_t GetFlagOperand(int operand_index) const;
32 int32_t GetImmediateOperand(int operand_index) const;
33 uint32_t GetIndexOperand(int operand_index) const;
34 uint32_t GetRegisterCountOperand(int operand_index) const;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000035 Register GetRegisterOperand(int operand_index) const;
Ben Murdoch097c5b22016-05-18 11:27:45 +010036 int GetRegisterOperandRange(int operand_index) const;
Ben Murdochda12d292016-06-02 14:46:10 +010037 uint32_t GetRuntimeIdOperand(int operand_index) const;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000038 Handle<Object> GetConstantForIndexOperand(int operand_index) const;
39
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000040 // Returns the absolute offset of the branch target at the current
41 // bytecode. It is an error to call this method if the bytecode is
42 // not for a jump or conditional jump.
43 int GetJumpTargetOffset() const;
44
45 private:
Ben Murdochda12d292016-06-02 14:46:10 +010046 uint32_t GetUnsignedOperand(int operand_index,
47 OperandType operand_type) const;
48 int32_t GetSignedOperand(int operand_index, OperandType operand_type) const;
49
50 void UpdateOperandScale();
51
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000052 Handle<BytecodeArray> bytecode_array_;
53 int bytecode_offset_;
Ben Murdochda12d292016-06-02 14:46:10 +010054 OperandScale operand_scale_;
55 int prefix_offset_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000056
57 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayIterator);
58};
59
60} // namespace interpreter
61} // namespace internal
62} // namespace v8
63
64#endif // V8_INTERPRETER_BYTECODE_GRAPH_ITERATOR_H_