1 //===- Range.cpp ------------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/DebugInfo/GSYM/Range.h"
11 #include "llvm/DebugInfo/GSYM/FileWriter.h"
12 #include "llvm/Support/DataExtractor.h"
20 void AddressRanges::insert(AddressRange Range
) {
21 if (Range
.size() == 0)
24 auto It
= llvm::upper_bound(Ranges
, Range
);
26 while (It2
!= Ranges
.end() && It2
->Start
< Range
.End
)
29 Range
.End
= std::max(Range
.End
, It2
[-1].End
);
30 It
= Ranges
.erase(It
, It2
);
32 if (It
!= Ranges
.begin() && Range
.Start
< It
[-1].End
)
33 It
[-1].End
= std::max(It
[-1].End
, Range
.End
);
35 Ranges
.insert(It
, Range
);
38 bool AddressRanges::contains(uint64_t Addr
) const {
39 auto It
= std::partition_point(
40 Ranges
.begin(), Ranges
.end(),
41 [=](const AddressRange
&R
) { return R
.Start
<= Addr
; });
42 return It
!= Ranges
.begin() && Addr
< It
[-1].End
;
45 bool AddressRanges::contains(AddressRange Range
) const {
46 if (Range
.size() == 0)
48 auto It
= std::partition_point(
49 Ranges
.begin(), Ranges
.end(),
50 [=](const AddressRange
&R
) { return R
.Start
<= Range
.Start
; });
51 if (It
== Ranges
.begin())
53 return Range
.End
<= It
[-1].End
;
56 raw_ostream
&llvm::gsym::operator<<(raw_ostream
&OS
, const AddressRange
&R
) {
57 return OS
<< '[' << HEX64(R
.Start
) << " - " << HEX64(R
.End
) << ")";
60 raw_ostream
&llvm::gsym::operator<<(raw_ostream
&OS
, const AddressRanges
&AR
) {
61 size_t Size
= AR
.size();
62 for (size_t I
= 0; I
< Size
; ++I
) {
70 void AddressRange::encode(FileWriter
&O
, uint64_t BaseAddr
) const {
71 assert(Start
>= BaseAddr
);
72 O
.writeULEB(Start
- BaseAddr
);
76 void AddressRange::decode(DataExtractor
&Data
, uint64_t BaseAddr
,
78 const uint64_t AddrOffset
= Data
.getULEB128(&Offset
);
79 const uint64_t Size
= Data
.getULEB128(&Offset
);
80 const uint64_t StartAddr
= BaseAddr
+ AddrOffset
;
82 End
= StartAddr
+ Size
;
85 void AddressRanges::encode(FileWriter
&O
, uint64_t BaseAddr
) const {
86 O
.writeULEB(Ranges
.size());
89 for (auto Range
: Ranges
)
90 Range
.encode(O
, BaseAddr
);
93 void AddressRanges::decode(DataExtractor
&Data
, uint64_t BaseAddr
,
96 uint64_t NumRanges
= Data
.getULEB128(&Offset
);
99 Ranges
.resize(NumRanges
);
100 for (auto &Range
: Ranges
)
101 Range
.decode(Data
, BaseAddr
, Offset
);