Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame^] | 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 | |
| 15 | using namespace lldb; |
| 16 | using namespace lldb_private; |
| 17 | |
| 18 | bool |
| 19 | VMRange::ContainsValue(const VMRange::collection& coll, lldb::addr_t value) |
| 20 | { |
| 21 | ValueInRangeUnaryPredicate in_range_predicate(value); |
| 22 | VMRange::const_iterator pos; |
| 23 | VMRange::const_iterator end = coll.end(); |
| 24 | pos = std::find_if( coll.begin(), end, in_range_predicate ); |
| 25 | if (pos != end) |
| 26 | return true; |
| 27 | return false; |
| 28 | } |
| 29 | |
| 30 | bool |
| 31 | VMRange::ContainsRange(const VMRange::collection& coll, const VMRange& range) |
| 32 | { |
| 33 | RangeInRangeUnaryPredicate in_range_predicate(range); |
| 34 | VMRange::const_iterator pos; |
| 35 | VMRange::const_iterator end = coll.end(); |
| 36 | pos = std::find_if( coll.begin(), end, in_range_predicate ); |
| 37 | if (pos != end) |
| 38 | return true; |
| 39 | return false; |
| 40 | } |
| 41 | |
| 42 | |
| 43 | void |
| 44 | VMRange::Dump(Stream *s, lldb::addr_t offset) const |
| 45 | { |
| 46 | s->AddressRange(offset + GetBaseAddress(), offset + GetEndAddress(), sizeof (addr_t)); |
| 47 | } |
| 48 | |
| 49 | bool |
| 50 | lldb_private::operator== (const VMRange& lhs, const VMRange& rhs) |
| 51 | { |
| 52 | return lhs.GetBaseAddress() == rhs.GetBaseAddress() && lhs.GetEndAddress() == rhs.GetEndAddress(); |
| 53 | } |
| 54 | |
| 55 | bool |
| 56 | lldb_private::operator!= (const VMRange& lhs, const VMRange& rhs) |
| 57 | { |
| 58 | return lhs.GetBaseAddress() != rhs.GetBaseAddress() || lhs.GetEndAddress() != rhs.GetEndAddress(); |
| 59 | } |
| 60 | |
| 61 | bool |
| 62 | lldb_private::operator< (const VMRange& lhs, const VMRange& rhs) |
| 63 | { |
| 64 | if (lhs.GetBaseAddress() < rhs.GetBaseAddress()) |
| 65 | return true; |
| 66 | else if (lhs.GetBaseAddress() > rhs.GetBaseAddress()) |
| 67 | return false; |
| 68 | return lhs.GetEndAddress() < rhs.GetEndAddress(); |
| 69 | } |
| 70 | |
| 71 | bool |
| 72 | lldb_private::operator<= (const VMRange& lhs, const VMRange& rhs) |
| 73 | { |
| 74 | if (lhs.GetBaseAddress() < rhs.GetBaseAddress()) |
| 75 | return true; |
| 76 | else if (lhs.GetBaseAddress() > rhs.GetBaseAddress()) |
| 77 | return false; |
| 78 | return lhs.GetEndAddress() <= rhs.GetEndAddress(); |
| 79 | } |
| 80 | |
| 81 | bool |
| 82 | lldb_private::operator> (const VMRange& lhs, const VMRange& rhs) |
| 83 | { |
| 84 | if (lhs.GetBaseAddress() > rhs.GetBaseAddress()) |
| 85 | return true; |
| 86 | else if (lhs.GetBaseAddress() < rhs.GetBaseAddress()) |
| 87 | return false; |
| 88 | return lhs.GetEndAddress() > rhs.GetEndAddress(); |
| 89 | } |
| 90 | |
| 91 | bool |
| 92 | lldb_private::operator>= (const VMRange& lhs, const VMRange& rhs) |
| 93 | { |
| 94 | if (lhs.GetBaseAddress() > rhs.GetBaseAddress()) |
| 95 | return true; |
| 96 | else if (lhs.GetBaseAddress() < rhs.GetBaseAddress()) |
| 97 | return false; |
| 98 | return lhs.GetEndAddress() >= rhs.GetEndAddress(); |
| 99 | } |
| 100 | |