v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
block-coverage-builder.h
Go to the documentation of this file.
1// Copyright 2017 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_BLOCK_COVERAGE_BUILDER_H_
6#define V8_INTERPRETER_BLOCK_COVERAGE_BUILDER_H_
7
10
12
13namespace v8 {
14namespace internal {
15namespace interpreter {
16
17// Used to generate IncBlockCounter bytecodes and the {source range, slot}
18// mapping for block coverage.
19class BlockCoverageBuilder final : public ZoneObject {
20 public:
22 SourceRangeMap* source_range_map)
23 : slots_(0, zone),
24 builder_(builder),
25 source_range_map_(source_range_map) {
26 DCHECK_NOT_NULL(builder);
27 DCHECK_NOT_NULL(source_range_map);
28 }
29
30 static constexpr int kNoCoverageArraySlot = -1;
31
34 if (ranges == nullptr) return kNoCoverageArraySlot;
35
36 SourceRange range = ranges->GetRange(kind);
37 if (range.IsEmpty()) return kNoCoverageArraySlot;
38
39 const int slot = static_cast<int>(slots_.size());
40 slots_.emplace_back(range);
41 return slot;
42 }
43
47 if (ranges == nullptr) return kNoCoverageArraySlot;
48
49 SourceRange range = ranges->GetRangeAtIndex(index);
50 if (range.IsEmpty()) return kNoCoverageArraySlot;
51
52 const int slot = static_cast<int>(slots_.size());
53 slots_.emplace_back(range);
54 return slot;
55 }
56
59 size_t index) {
61 static_cast<ConditionalChainSourceRanges*>(
62 source_range_map_->Find(node));
63 if (ranges == nullptr) return kNoCoverageArraySlot;
64
65 SourceRange range = ranges->GetRangeAtIndex(kind, index);
66 if (range.IsEmpty()) return kNoCoverageArraySlot;
67
68 const int slot = static_cast<int>(slots_.size());
69 slots_.emplace_back(range);
70 return slot;
71 }
72
73 void IncrementBlockCounter(int coverage_array_slot) {
74 if (coverage_array_slot == kNoCoverageArraySlot) return;
75 builder_->IncBlockCounter(coverage_array_slot);
76 }
77
82
83 const ZoneVector<SourceRange>& slots() const { return slots_; }
84
85 private:
86 // Contains source range information for allocated block coverage counter
87 // slots. Slot i covers range slots_[i].
91};
92
93} // namespace interpreter
94} // namespace internal
95} // namespace v8
96
97#endif // V8_INTERPRETER_BLOCK_COVERAGE_BUILDER_H_
Builtins::Kind kind
Definition builtins.cc:40
AstNodeSourceRanges * Find(ZoneObject *node)
const ZoneVector< SourceRange > & slots() const
int AllocateNaryBlockCoverageSlot(NaryOperation *node, size_t index)
int AllocateConditionalChainBlockCoverageSlot(ConditionalChain *node, SourceRangeKind kind, size_t index)
void IncrementBlockCounter(ZoneObject *node, SourceRangeKind kind)
int AllocateBlockCoverageSlot(ZoneObject *node, SourceRangeKind kind)
BlockCoverageBuilder(Zone *zone, BytecodeArrayBuilder *builder, SourceRangeMap *source_range_map)
#define DCHECK_NOT_NULL(val)
Definition logging.h:492