Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 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/handles.h" |
| 9 | #include "src/interpreter/bytecodes.h" |
| 10 | #include "src/objects.h" |
| 11 | |
| 12 | namespace v8 { |
| 13 | namespace internal { |
| 14 | namespace interpreter { |
| 15 | |
| 16 | class 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_; } |
| 25 | const Handle<BytecodeArray>& bytecode_array() const { |
| 26 | return bytecode_array_; |
| 27 | } |
| 28 | |
| 29 | int8_t GetImmediateOperand(int operand_index) const; |
| 30 | int GetIndexOperand(int operand_index) const; |
| 31 | int GetCountOperand(int operand_index) const; |
| 32 | Register GetRegisterOperand(int operand_index) const; |
| 33 | Handle<Object> GetConstantForIndexOperand(int operand_index) const; |
| 34 | |
| 35 | // Get the raw byte for the given operand. Note: you should prefer using the |
| 36 | // typed versions above which cast the return to an appropriate type. |
| 37 | uint32_t GetRawOperand(int operand_index, OperandType operand_type) const; |
| 38 | |
| 39 | // Returns the absolute offset of the branch target at the current |
| 40 | // bytecode. It is an error to call this method if the bytecode is |
| 41 | // not for a jump or conditional jump. |
| 42 | int GetJumpTargetOffset() const; |
| 43 | |
| 44 | private: |
| 45 | Handle<BytecodeArray> bytecode_array_; |
| 46 | int bytecode_offset_; |
| 47 | |
| 48 | DISALLOW_COPY_AND_ASSIGN(BytecodeArrayIterator); |
| 49 | }; |
| 50 | |
| 51 | } // namespace interpreter |
| 52 | } // namespace internal |
| 53 | } // namespace v8 |
| 54 | |
| 55 | #endif // V8_INTERPRETER_BYTECODE_GRAPH_ITERATOR_H_ |