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