Home | History | Annotate | Download | only in interpreter
      1 // Copyright 2016 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_ACCESSOR_H_
      6 #define V8_INTERPRETER_BYTECODE_ARRAY_ACCESSOR_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 BytecodeArrayAccessor {
     20  public:
     21   BytecodeArrayAccessor(Handle<BytecodeArray> bytecode_array,
     22                         int initial_offset);
     23 
     24   void SetOffset(int offset);
     25 
     26   Bytecode current_bytecode() const;
     27   int current_bytecode_size() const;
     28   int current_offset() const { return bytecode_offset_; }
     29   OperandScale current_operand_scale() const { return operand_scale_; }
     30   int current_prefix_offset() const { return prefix_offset_; }
     31   const Handle<BytecodeArray>& bytecode_array() const {
     32     return bytecode_array_;
     33   }
     34 
     35   uint32_t GetFlagOperand(int operand_index) const;
     36   uint32_t GetUnsignedImmediateOperand(int operand_index) const;
     37   int32_t GetImmediateOperand(int operand_index) const;
     38   uint32_t GetIndexOperand(int operand_index) const;
     39   uint32_t GetRegisterCountOperand(int operand_index) const;
     40   Register GetRegisterOperand(int operand_index) const;
     41   int GetRegisterOperandRange(int operand_index) const;
     42   Runtime::FunctionId GetRuntimeIdOperand(int operand_index) const;
     43   Runtime::FunctionId GetIntrinsicIdOperand(int operand_index) const;
     44   Handle<Object> GetConstantForIndexOperand(int operand_index) const;
     45 
     46   // Returns the absolute offset of the branch target at the current
     47   // bytecode. It is an error to call this method if the bytecode is
     48   // not for a jump or conditional jump.
     49   int GetJumpTargetOffset() const;
     50 
     51   bool OffsetWithinBytecode(int offset) const;
     52 
     53   std::ostream& PrintTo(std::ostream& os) const;
     54 
     55  private:
     56   bool OffsetInBounds() const;
     57 
     58   uint32_t GetUnsignedOperand(int operand_index,
     59                               OperandType operand_type) const;
     60   int32_t GetSignedOperand(int operand_index, OperandType operand_type) const;
     61 
     62   void UpdateOperandScale();
     63 
     64   Handle<BytecodeArray> bytecode_array_;
     65   int bytecode_offset_;
     66   OperandScale operand_scale_;
     67   int prefix_offset_;
     68 
     69   DISALLOW_COPY_AND_ASSIGN(BytecodeArrayAccessor);
     70 };
     71 
     72 }  // namespace interpreter
     73 }  // namespace internal
     74 }  // namespace v8
     75 
     76 #endif  // V8_INTERPRETER_BYTECODE_GRAPH_ACCESSOR_H_
     77