5 #include <featureTests.h>
6 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
7 #include "sage3basic.h"
9 #include <boost/foreach.hpp>
24 retval.
insert(toExtent(interval));
30 for (ExtentMap::const_iterator iter=x.
begin(); iter!=x.
end(); ++iter)
31 retval.
insert(toAddressInterval(iter->first));
85 iterator found = best_fit(size, begin());
87 throw std::bad_alloc();
88 Extent retval(found->first.first(), size);
97 iterator found = first_fit(size, begin());
99 throw std::bad_alloc();
100 Extent retval(found->first.first(), size);
109 ROSE_ASSERT(subtract_from(request).size()==0);
118 ExtentMap::precipitate(rose_addr_t reagent)
122 for (iterator i=begin(); i!=end(); ) {
123 ExtentPair left = *i++;
124 for (; i!=end() && left.first+left.second+reagent >= i->first; i++)
125 left.second = (i->first + i->second) - left.first;
135 ExtentMap::find_address(rose_addr_t addr)
const
137 const_iterator i = upper_bound(addr);
138 RangeMapType::const_iterator i2 = ranges.find(addr);
140 assert(i2==ranges.end());
141 throw std::bad_alloc();
144 if (i->first+i->second <= addr) {
145 assert(i2==ranges.end());
146 throw std::bad_alloc();
149 assert(i->first==i2->first.begin);
150 assert(i->second==i2->first.size);
159 ExtentMap::exists_all(ExtentPair what)
const
161 while (what.second>0) {
163 ExtentPair found = find_address(what.first);
164 assert(found.second > 0);
165 assert(found.first <= what.first);
166 assert(what.first <= found.first + found.second);
167 rose_addr_t nfound = std::min(what.second, found.second-(what.first-found.first));
168 what.first = found.first + found.second;
169 what.second -= nfound;
170 }
catch (
const std::bad_alloc&) {
171 assert(!ranges.contains(RangeType(what.first, what.second)));
175 assert(ranges.contains(RangeType(what.first, what.second)));
181 ExtentMap::dump_extents(std::ostream &o,
const std::string &prefix,
const std::string &label)
const
183 using namespace StringUtility;
185 for (const_iterator i=begin(); i!=end(); ++i, ++idx) {
186 o <<prefix <<(label.empty()?std::string(
"Extent"):label) <<
"[" <<idx <<
"]"
188 <<
" for " <<
unsignedToHex(i->first.size()) <<(1==i->first.size()?
" byte":
" bytes")
189 <<
" ending at " <<
unsignedToHex(i->first.first() + i->first.size()) <<
"\n";
196 ExtentMap::dump_extents(FILE *f,
const char *prefix,
const char *label,
bool pad)
const
200 for (const_iterator i=begin(); i!=end(); ++i, ++idx) {
201 if (!label) label =
"Extent";
202 sprintf(p,
"%s%s[%zd]", prefix, label, idx);
203 int w = pad ? std::max(1, DUMP_FIELD_WIDTH-(
int)strlen(p)) : 1;
204 fprintf(f,
"%s%-*s = offset 0x%08" PRIx64
" (%" PRIu64
"),"
205 " for 0x%08" PRIx64
" (%" PRIu64
") byte%s,"
206 " ending at 0x%08" PRIx64
" (%" PRIu64
")\n",
207 p, w,
"", i->first.first(), i->first.first(),
208 i->first.size(), i->first.size(), 1==i->first.size()?
"":
"s",
209 i->first.first()+i->first.size(), i->first.first()+i->first.size());
bool isEmpty() const
True if interval is empty.
Extent allocate_first_fit(const rose_addr_t size)
Allocate an extent of the specified size (first fit) from the extent map, removing the returned exten...
A contiguous range of values.
bool isSingleton() const
True if interval is a singleton.
Main namespace for the ROSE library.
Value relaxed_first() const
Accessor for the first value of a range.
void allocate_at(const Extent &request)
Allocate the specified extent, which must be in the free list.
A container holding a set of values.
void insert(const Interval2 &interval)
Insert specified values.
static char category(const Extent &a, const Extent &b)
Class method comparing two extents.
iterator insert(Range new_range, Value new_value=Value(), bool make_hole=true)
Insert a range/value pair into the map.
T least() const
Returns lower limit.
ROSE_UTIL_API std::string addrToString(uint64_t value, size_t nbits=0)
Convert a virtual address to a string.
iterator begin()
First-item iterator.
Value size() const
Returns the number of values represented by the range.
bool empty() const
Returns true if this range is empty.
iterator end()
End-item iterator.
std::string unsignedToHex(T value)
Convert a number to a hexadecimal and decimal string.
boost::iterator_range< ConstIntervalIterator > intervals() const
Iterator range for all intervals actually stored by this set.
Range of values delimited by endpoints.
Extent allocate_best_fit(const rose_addr_t size)
Allocate an extent of the specified size (best fit first) from the extent map, removing the returned ...
T greatest() const
Returns upper limit.