DWARFAddressRange.h revision 360784
1246145Shselasky//===- DWARFAddressRange.h --------------------------------------*- C++ -*-===// 2246145Shselasky// 3246145Shselasky// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4246145Shselasky// See https://llvm.org/LICENSE.txt for license information. 5246145Shselasky// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6246145Shselasky// 7246145Shselasky//===----------------------------------------------------------------------===// 8246145Shselasky 9246145Shselasky#ifndef LLVM_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H 10246145Shselasky#define LLVM_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H 11246145Shselasky 12246145Shselasky#include "llvm/DebugInfo/DIContext.h" 13246145Shselasky#include <cstdint> 14246145Shselasky#include <tuple> 15246145Shselasky#include <vector> 16246145Shselasky 17246145Shselaskynamespace llvm { 18246145Shselasky 19246145Shselaskyclass raw_ostream; 20246145Shselaskyclass DWARFObject; 21246145Shselasky 22246145Shselaskystruct DWARFAddressRange { 23246145Shselasky uint64_t LowPC; 24246145Shselasky uint64_t HighPC; 25246145Shselasky uint64_t SectionIndex; 26246145Shselasky 27246145Shselasky DWARFAddressRange() = default; 28246145Shselasky 29246145Shselasky /// Used for unit testing. 30246145Shselasky DWARFAddressRange( 31246145Shselasky uint64_t LowPC, uint64_t HighPC, 32246145Shselasky uint64_t SectionIndex = object::SectionedAddress::UndefSection) 33246145Shselasky : LowPC(LowPC), HighPC(HighPC), SectionIndex(SectionIndex) {} 34246145Shselasky 35246145Shselasky /// Returns true if LowPC is smaller or equal to HighPC. This accounts for 36246145Shselasky /// dead-stripped ranges. 37246145Shselasky bool valid() const { return LowPC <= HighPC; } 38246145Shselasky 39246145Shselasky /// Returns true if [LowPC, HighPC) intersects with [RHS.LowPC, RHS.HighPC). 40246145Shselasky bool intersects(const DWARFAddressRange &RHS) const { 41246145Shselasky assert(valid() && RHS.valid()); 42246616Shselasky // Empty ranges can't intersect. 43246145Shselasky if (LowPC == HighPC || RHS.LowPC == RHS.HighPC) 44246145Shselasky return false; 45246145Shselasky return LowPC < RHS.HighPC && RHS.LowPC < HighPC; 46246145Shselasky } 47246145Shselasky 48246145Shselasky void dump(raw_ostream &OS, uint32_t AddressSize, DIDumpOptions DumpOpts = {}, 49246145Shselasky const DWARFObject *Obj = nullptr) const; 50246145Shselasky}; 51246145Shselasky 52246145Shselaskyinline bool operator<(const DWARFAddressRange &LHS, 53246145Shselasky const DWARFAddressRange &RHS) { 54246145Shselasky return std::tie(LHS.LowPC, LHS.HighPC) < std::tie(RHS.LowPC, RHS.HighPC); 55246145Shselasky} 56246145Shselasky 57246145Shselaskyinline bool operator==(const DWARFAddressRange &LHS, 58246145Shselasky const DWARFAddressRange &RHS) { 59246145Shselasky return std::tie(LHS.LowPC, LHS.HighPC) == std::tie(RHS.LowPC, RHS.HighPC); 60246145Shselasky} 61246145Shselasky 62246145Shselaskyraw_ostream &operator<<(raw_ostream &OS, const DWARFAddressRange &R); 63246363Shselasky 64246363Shselasky/// DWARFAddressRangesVector - represents a set of absolute address ranges. 65246145Shselaskyusing DWARFAddressRangesVector = std::vector<DWARFAddressRange>; 66 67} // end namespace llvm 68 69#endif // LLVM_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H 70