1//===-- VMRange.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//===----------------------------------------------------------------------===//
9
10#include "lldb/lldb-private.h"
11
12#include "lldb/Core/Stream.h"
13#include "lldb/Core/VMRange.h"
14#include <algorithm>
15
16using namespace lldb;
17using namespace lldb_private;
18
19bool
20VMRange::ContainsValue(const VMRange::collection& coll, lldb::addr_t value)
21{
22    ValueInRangeUnaryPredicate in_range_predicate(value);
23    VMRange::const_iterator pos;
24    VMRange::const_iterator end = coll.end();
25    pos = std::find_if( coll.begin(), end, in_range_predicate );
26    if (pos != end)
27        return true;
28    return false;
29}
30
31bool
32VMRange::ContainsRange(const VMRange::collection& coll, const VMRange& range)
33{
34    RangeInRangeUnaryPredicate in_range_predicate(range);
35    VMRange::const_iterator pos;
36    VMRange::const_iterator end = coll.end();
37    pos = std::find_if( coll.begin(), end, in_range_predicate );
38    if (pos != end)
39        return true;
40    return false;
41}
42
43size_t
44VMRange::FindRangeIndexThatContainsValue (const VMRange::collection& coll, lldb::addr_t value)
45{
46    ValueInRangeUnaryPredicate in_range_predicate(value);
47    VMRange::const_iterator begin = coll.begin();
48    VMRange::const_iterator end = coll.end();
49    VMRange::const_iterator pos = std::find_if (begin, end, in_range_predicate);
50    if (pos != end)
51        return std::distance (begin, pos);
52    return UINT32_MAX;
53}
54
55void
56VMRange::Dump(Stream *s, lldb::addr_t offset, uint32_t addr_width) const
57{
58    s->AddressRange(offset + GetBaseAddress(), offset + GetEndAddress(), addr_width);
59}
60
61bool
62lldb_private::operator== (const VMRange& lhs, const VMRange& rhs)
63{
64    return lhs.GetBaseAddress() == rhs.GetBaseAddress() && lhs.GetEndAddress() == rhs.GetEndAddress();
65}
66
67bool
68lldb_private::operator!= (const VMRange& lhs, const VMRange& rhs)
69{
70    return lhs.GetBaseAddress() != rhs.GetBaseAddress() || lhs.GetEndAddress() != rhs.GetEndAddress();
71}
72
73bool
74lldb_private::operator< (const VMRange& lhs, const VMRange& rhs)
75{
76    if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
77        return true;
78    else if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
79        return false;
80    return lhs.GetEndAddress() < rhs.GetEndAddress();
81}
82
83bool
84lldb_private::operator<= (const VMRange& lhs, const VMRange& rhs)
85{
86    if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
87        return true;
88    else if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
89        return false;
90    return lhs.GetEndAddress() <= rhs.GetEndAddress();
91}
92
93bool
94lldb_private::operator> (const VMRange& lhs, const VMRange& rhs)
95{
96    if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
97        return true;
98    else if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
99        return false;
100    return lhs.GetEndAddress() > rhs.GetEndAddress();
101}
102
103bool
104lldb_private::operator>= (const VMRange& lhs, const VMRange& rhs)
105{
106    if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
107        return true;
108    else if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
109        return false;
110    return lhs.GetEndAddress() >= rhs.GetEndAddress();
111}
112
113