blob: 5a7df5c353e8838d0d18699758cb6894a2ce495d [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- DWARFAddressRange.h --------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H
11#define LLVM_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H
12
13#include "llvm/DebugInfo/DIContext.h"
14#include <cstdint>
15#include <tuple>
16#include <vector>
17
18namespace llvm {
19
20class raw_ostream;
21
22struct DWARFAddressRange {
23 uint64_t LowPC;
24 uint64_t HighPC;
25 uint64_t SectionIndex;
26
27 DWARFAddressRange() = default;
28
29 /// Used for unit testing.
30 DWARFAddressRange(uint64_t LowPC, uint64_t HighPC, uint64_t SectionIndex = 0)
31 : LowPC(LowPC), HighPC(HighPC), SectionIndex(SectionIndex) {}
32
33 /// Returns true if LowPC is smaller or equal to HighPC. This accounts for
34 /// dead-stripped ranges.
35 bool valid() const { return LowPC <= HighPC; }
36
37 /// Returns true if [LowPC, HighPC) intersects with [RHS.LowPC, RHS.HighPC).
38 bool intersects(const DWARFAddressRange &RHS) const {
39 assert(valid() && RHS.valid());
40 // Empty ranges can't intersect.
41 if (LowPC == HighPC || RHS.LowPC == RHS.HighPC)
42 return false;
43 return LowPC < RHS.HighPC && RHS.LowPC < HighPC;
44 }
45
46 /// Returns true if [LowPC, HighPC) fully contains [RHS.LowPC, RHS.HighPC).
47 bool contains(const DWARFAddressRange &RHS) const {
48 assert(valid() && RHS.valid());
49 return LowPC <= RHS.LowPC && RHS.HighPC <= HighPC;
50 }
51
52 void dump(raw_ostream &OS, uint32_t AddressSize,
53 DIDumpOptions DumpOpts = {}) const;
54};
55
56static inline bool operator<(const DWARFAddressRange &LHS,
57 const DWARFAddressRange &RHS) {
58 return std::tie(LHS.LowPC, LHS.HighPC) < std::tie(RHS.LowPC, RHS.HighPC);
59}
60
61raw_ostream &operator<<(raw_ostream &OS, const DWARFAddressRange &R);
62
63/// DWARFAddressRangesVector - represents a set of absolute address ranges.
64using DWARFAddressRangesVector = std::vector<DWARFAddressRange>;
65
66} // end namespace llvm
67
68#endif // LLVM_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H