[LLVM][Alignment] Introduce Alignment In Attributes
[llvm-core.git] / lib / DebugInfo / GSYM / Range.cpp
blobca61984dacbd11a74fc9e9b4ebd6ce1e31f7e1cb
1 //===- Range.cpp ------------------------------------------------*- 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 //===----------------------------------------------------------------------===//
10 #include "llvm/DebugInfo/GSYM/Range.h"
11 #include <algorithm>
12 #include <inttypes.h>
14 using namespace llvm;
15 using namespace gsym;
18 void AddressRanges::insert(AddressRange Range) {
19 if (Range.size() == 0)
20 return;
22 auto It = llvm::upper_bound(Ranges, Range);
23 auto It2 = It;
24 while (It2 != Ranges.end() && It2->Start < Range.End)
25 ++It2;
26 if (It != It2) {
27 Range.End = std::max(Range.End, It2[-1].End);
28 It = Ranges.erase(It, It2);
30 if (It != Ranges.begin() && Range.Start < It[-1].End)
31 It[-1].End = std::max(It[-1].End, Range.End);
32 else
33 Ranges.insert(It, Range);
36 bool AddressRanges::contains(uint64_t Addr) const {
37 auto It = std::partition_point(
38 Ranges.begin(), Ranges.end(),
39 [=](const AddressRange &R) { return R.Start <= Addr; });
40 return It != Ranges.begin() && Addr < It[-1].End;
43 raw_ostream &llvm::gsym::operator<<(raw_ostream &OS, const AddressRange &R) {
44 return OS << '[' << HEX64(R.Start) << " - " << HEX64(R.End) << ")";
47 raw_ostream &llvm::gsym::operator<<(raw_ostream &OS, const AddressRanges &AR) {
48 size_t Size = AR.size();
49 for (size_t I = 0; I < Size; ++I) {
50 if (I)
51 OS << ' ';
52 OS << AR[I];
54 return OS;