OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_INTERPRETER_BYTECODE_LABEL_H_ | 5 #ifndef V8_INTERPRETER_BYTECODE_LABEL_H_ |
6 #define V8_INTERPRETER_BYTECODE_LABEL_H_ | 6 #define V8_INTERPRETER_BYTECODE_LABEL_H_ |
7 | 7 |
8 #include "src/zone/zone-containers.h" | 8 #include "src/zone/zone-containers.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace internal { | 11 namespace internal { |
12 namespace interpreter { | 12 namespace interpreter { |
13 | 13 |
14 class BytecodeArrayBuilder; | 14 class BytecodeArrayBuilder; |
15 | 15 |
16 // A label representing a branch target in a bytecode array. When a | 16 // A label representing a branch target in a bytecode array. When a |
17 // label is bound, it represents a known position in the bytecode | 17 // label is bound, it represents a known position in the bytecode |
18 // array. For labels that are forward references there can be at most | 18 // array. For labels that are forward references there can be at most |
19 // one reference whilst it is unbound. | 19 // one reference whilst it is unbound. |
20 class BytecodeLabel final { | 20 class V8_EXPORT_PRIVATE BytecodeLabel final { |
21 public: | 21 public: |
22 BytecodeLabel() : bound_(false), offset_(kInvalidOffset) {} | 22 BytecodeLabel() : bound_(false), offset_(kInvalidOffset) {} |
23 | 23 |
24 bool is_bound() const { return bound_; } | 24 bool is_bound() const { return bound_; } |
25 size_t offset() const { return offset_; } | 25 size_t offset() const { return offset_; } |
26 | 26 |
27 private: | 27 private: |
28 static const size_t kInvalidOffset = static_cast<size_t>(-1); | 28 static const size_t kInvalidOffset = static_cast<size_t>(-1); |
29 | 29 |
30 void bind_to(size_t offset) { | 30 void bind_to(size_t offset) { |
(...skipping 16 matching lines...) Expand all Loading... |
47 // UNSET false kInvalidOffset | 47 // UNSET false kInvalidOffset |
48 // FORWARD_TARGET false Offset of referring jump | 48 // FORWARD_TARGET false Offset of referring jump |
49 // BACKWARD_TARGET true Offset of label in bytecode array when bound | 49 // BACKWARD_TARGET true Offset of label in bytecode array when bound |
50 bool bound_; | 50 bool bound_; |
51 size_t offset_; | 51 size_t offset_; |
52 | 52 |
53 friend class BytecodeArrayWriter; | 53 friend class BytecodeArrayWriter; |
54 }; | 54 }; |
55 | 55 |
56 // Class representing a branch target of multiple jumps. | 56 // Class representing a branch target of multiple jumps. |
57 class BytecodeLabels { | 57 class V8_EXPORT_PRIVATE BytecodeLabels { |
58 public: | 58 public: |
59 explicit BytecodeLabels(Zone* zone) : labels_(zone) {} | 59 explicit BytecodeLabels(Zone* zone) : labels_(zone) {} |
60 | 60 |
61 BytecodeLabel* New(); | 61 BytecodeLabel* New(); |
62 | 62 |
63 void Bind(BytecodeArrayBuilder* builder); | 63 void Bind(BytecodeArrayBuilder* builder); |
64 | 64 |
65 void BindToLabel(BytecodeArrayBuilder* builder, const BytecodeLabel& target); | 65 void BindToLabel(BytecodeArrayBuilder* builder, const BytecodeLabel& target); |
66 | 66 |
67 bool is_bound() const { | 67 bool is_bound() const { |
(...skipping 10 matching lines...) Expand all Loading... |
78 ZoneVector<BytecodeLabel> labels_; | 78 ZoneVector<BytecodeLabel> labels_; |
79 | 79 |
80 DISALLOW_COPY_AND_ASSIGN(BytecodeLabels); | 80 DISALLOW_COPY_AND_ASSIGN(BytecodeLabels); |
81 }; | 81 }; |
82 | 82 |
83 } // namespace interpreter | 83 } // namespace interpreter |
84 } // namespace internal | 84 } // namespace internal |
85 } // namespace v8 | 85 } // namespace v8 |
86 | 86 |
87 #endif // V8_INTERPRETER_BYTECODE_LABEL_H_ | 87 #endif // V8_INTERPRETER_BYTECODE_LABEL_H_ |
OLD | NEW |