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