V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
bytecode-array-accessor.h
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/objects/smi.h"
14 #include "src/runtime/runtime.h"
15 
16 namespace v8 {
17 namespace internal {
18 
19 class BytecodeArray;
20 
21 namespace interpreter {
22 
23 class BytecodeArrayAccessor;
24 
25 struct V8_EXPORT_PRIVATE JumpTableTargetOffset {
26  int case_value;
27  int target_offset;
28 };
29 
30 class V8_EXPORT_PRIVATE JumpTableTargetOffsets final {
31  public:
32  // Minimal iterator implementation for use in ranged-for.
33  class V8_EXPORT_PRIVATE iterator final {
34  public:
35  iterator(int case_value, int table_offset, int table_end,
36  const BytecodeArrayAccessor* accessor);
37 
38  JumpTableTargetOffset operator*();
39  iterator& operator++();
40  bool operator!=(const iterator& other);
41 
42  private:
43  void UpdateAndAdvanceToValid();
44 
45  const BytecodeArrayAccessor* accessor_;
46  Smi current_;
47  int index_;
48  int table_offset_;
49  int table_end_;
50  };
51 
52  JumpTableTargetOffsets(const BytecodeArrayAccessor* accessor, int table_start,
53  int table_size, int case_value_base);
54 
55  iterator begin() const;
56  iterator end() const;
57 
58  int size() const;
59 
60  private:
61  const BytecodeArrayAccessor* accessor_;
62  int table_start_;
63  int table_size_;
64  int case_value_base_;
65 };
66 
67 class V8_EXPORT_PRIVATE BytecodeArrayAccessor {
68  public:
70  int initial_offset);
71 
72  void SetOffset(int offset);
73 
74  void ApplyDebugBreak();
75 
76  Bytecode current_bytecode() const;
77  int current_bytecode_size() const;
78  int current_offset() const { return bytecode_offset_; }
79  OperandScale current_operand_scale() const { return operand_scale_; }
80  int current_prefix_offset() const { return prefix_offset_; }
81  const Handle<BytecodeArray>& bytecode_array() const {
82  return bytecode_array_;
83  }
84 
85  uint32_t GetFlagOperand(int operand_index) const;
86  uint32_t GetUnsignedImmediateOperand(int operand_index) const;
87  int32_t GetImmediateOperand(int operand_index) const;
88  uint32_t GetIndexOperand(int operand_index) const;
89  FeedbackSlot GetSlotOperand(int operand_index) const;
90  uint32_t GetRegisterCountOperand(int operand_index) const;
91  Register GetRegisterOperand(int operand_index) const;
92  int GetRegisterOperandRange(int operand_index) const;
93  Runtime::FunctionId GetRuntimeIdOperand(int operand_index) const;
94  Runtime::FunctionId GetIntrinsicIdOperand(int operand_index) const;
95  uint32_t GetNativeContextIndexOperand(int operand_index) const;
96  Object* GetConstantAtIndex(int offset) const;
97  Object* GetConstantForIndexOperand(int operand_index) const;
98 
99  // Returns the absolute offset of the branch target at the current bytecode.
100  // It is an error to call this method if the bytecode is not for a jump or
101  // conditional jump.
102  int GetJumpTargetOffset() const;
103  // Returns an iterator over the absolute offsets of the targets of the current
104  // switch bytecode's jump table. It is an error to call this method if the
105  // bytecode is not a switch.
106  JumpTableTargetOffsets GetJumpTableTargetOffsets() const;
107 
108  // Returns the absolute offset of the bytecode at the given relative offset
109  // from the current bytecode.
110  int GetAbsoluteOffset(int relative_offset) const;
111 
112  bool OffsetWithinBytecode(int offset) const;
113 
114  std::ostream& PrintTo(std::ostream& os) const;
115 
116  private:
117  bool OffsetInBounds() const;
118 
119  uint32_t GetUnsignedOperand(int operand_index,
120  OperandType operand_type) const;
121  int32_t GetSignedOperand(int operand_index, OperandType operand_type) const;
122 
123  void UpdateOperandScale();
124 
125  Handle<BytecodeArray> bytecode_array_;
126  int bytecode_offset_;
127  OperandScale operand_scale_;
128  int prefix_offset_;
129 
130  DISALLOW_COPY_AND_ASSIGN(BytecodeArrayAccessor);
131 };
132 
133 } // namespace interpreter
134 } // namespace internal
135 } // namespace v8
136 
137 #endif // V8_INTERPRETER_BYTECODE_ARRAY_ACCESSOR_H_
Definition: libplatform.h:13