1 //===- DWARFAddressRange.h --------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H
10 #define LLVM_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H
12 #include "llvm/DebugInfo/DIContext.h"
22 struct DWARFAddressRange {
25 uint64_t SectionIndex;
27 DWARFAddressRange() = default;
29 /// Used for unit testing.
31 uint64_t LowPC, uint64_t HighPC,
32 uint64_t SectionIndex = object::SectionedAddress::UndefSection)
33 : LowPC(LowPC), HighPC(HighPC), SectionIndex(SectionIndex) {}
35 /// Returns true if LowPC is smaller or equal to HighPC. This accounts for
36 /// dead-stripped ranges.
37 bool valid() const { return LowPC <= HighPC; }
39 /// Returns true if [LowPC, HighPC) intersects with [RHS.LowPC, RHS.HighPC).
40 bool intersects(const DWARFAddressRange &RHS) const {
41 assert(valid() && RHS.valid());
42 // Empty ranges can't intersect.
43 if (LowPC == HighPC || RHS.LowPC == RHS.HighPC)
45 return LowPC < RHS.HighPC && RHS.LowPC < HighPC;
48 void dump(raw_ostream &OS, uint32_t AddressSize, DIDumpOptions DumpOpts = {},
49 const DWARFObject *Obj = nullptr) const;
52 inline bool operator<(const DWARFAddressRange &LHS,
53 const DWARFAddressRange &RHS) {
54 return std::tie(LHS.LowPC, LHS.HighPC) < std::tie(RHS.LowPC, RHS.HighPC);
57 inline bool operator==(const DWARFAddressRange &LHS,
58 const DWARFAddressRange &RHS) {
59 return std::tie(LHS.LowPC, LHS.HighPC) == std::tie(RHS.LowPC, RHS.HighPC);
62 raw_ostream &operator<<(raw_ostream &OS, const DWARFAddressRange &R);
64 /// DWARFAddressRangesVector - represents a set of absolute address ranges.
65 using DWARFAddressRangesVector = std::vector<DWARFAddressRange>;
67 } // end namespace llvm
69 #endif // LLVM_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H