2019-06-26 22:09:09 +08:00
|
|
|
//===- Range.cpp ------------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/DebugInfo/GSYM/Range.h"
|
|
|
|
#include <algorithm>
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace gsym;
|
|
|
|
|
|
|
|
|
2019-06-28 18:06:11 +08:00
|
|
|
void AddressRanges::insert(AddressRange Range) {
|
2019-06-26 22:09:09 +08:00
|
|
|
if (Range.size() == 0)
|
|
|
|
return;
|
|
|
|
|
2019-06-28 18:06:11 +08:00
|
|
|
auto It = llvm::upper_bound(Ranges, Range);
|
|
|
|
auto It2 = It;
|
|
|
|
while (It2 != Ranges.end() && It2->Start < Range.End)
|
|
|
|
++It2;
|
|
|
|
if (It != It2) {
|
|
|
|
Range.End = std::max(Range.End, It2[-1].End);
|
|
|
|
It = Ranges.erase(It, It2);
|
2019-06-26 22:09:09 +08:00
|
|
|
}
|
2019-06-28 18:06:11 +08:00
|
|
|
if (It != Ranges.begin() && Range.Start < It[-1].End)
|
|
|
|
It[-1].End = std::max(It[-1].End, Range.End);
|
|
|
|
else
|
|
|
|
Ranges.insert(It, Range);
|
2019-06-26 22:09:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AddressRanges::contains(uint64_t Addr) const {
|
2019-06-28 16:58:05 +08:00
|
|
|
auto It = std::partition_point(
|
|
|
|
Ranges.begin(), Ranges.end(),
|
2019-06-28 18:06:11 +08:00
|
|
|
[=](const AddressRange &R) { return R.Start <= Addr; });
|
|
|
|
return It != Ranges.begin() && Addr < It[-1].End;
|
2019-06-26 22:09:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
raw_ostream &llvm::gsym::operator<<(raw_ostream &OS, const AddressRange &R) {
|
2019-06-28 18:06:11 +08:00
|
|
|
return OS << '[' << HEX64(R.Start) << " - " << HEX64(R.End) << ")";
|
2019-06-26 22:09:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
raw_ostream &llvm::gsym::operator<<(raw_ostream &OS, const AddressRanges &AR) {
|
|
|
|
size_t Size = AR.size();
|
2019-06-28 18:06:11 +08:00
|
|
|
for (size_t I = 0; I < Size; ++I) {
|
2019-06-26 22:09:09 +08:00
|
|
|
if (I)
|
|
|
|
OS << ' ';
|
|
|
|
OS << AR[I];
|
|
|
|
}
|
|
|
|
return OS;
|
|
|
|
}
|