blob: 5379bbf0288d3140db0e8114b2f7080c924289f1 [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;
Ben Murdoch097c5b22016-05-18 11:27:45 +010024 void set_current_offset(int offset) { bytecode_offset_ = offset; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000025 int current_offset() const { return bytecode_offset_; }
26 const Handle<BytecodeArray>& bytecode_array() const {
27 return bytecode_array_;
28 }
29
30 int8_t GetImmediateOperand(int operand_index) const;
31 int GetIndexOperand(int operand_index) const;
Ben Murdoch097c5b22016-05-18 11:27:45 +010032 int GetRegisterCountOperand(int operand_index) const;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000033 Register GetRegisterOperand(int operand_index) const;
Ben Murdoch097c5b22016-05-18 11:27:45 +010034 int GetRegisterOperandRange(int operand_index) const;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000035 Handle<Object> GetConstantForIndexOperand(int operand_index) const;
36
37 // Get the raw byte for the given operand. Note: you should prefer using the
38 // typed versions above which cast the return to an appropriate type.
39 uint32_t GetRawOperand(int operand_index, OperandType operand_type) const;
40
41 // Returns the absolute offset of the branch target at the current
42 // bytecode. It is an error to call this method if the bytecode is
43 // not for a jump or conditional jump.
44 int GetJumpTargetOffset() const;
45
46 private:
47 Handle<BytecodeArray> bytecode_array_;
48 int bytecode_offset_;
49
50 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayIterator);
51};
52
53} // namespace interpreter
54} // namespace internal
55} // namespace v8
56
57#endif // V8_INTERPRETER_BYTECODE_GRAPH_ITERATOR_H_