diff --git a/src/core/util/CMakeLists.txt b/src/core/util/CMakeLists.txt index d3f4d81b..1051b3f1 100644 --- a/src/core/util/CMakeLists.txt +++ b/src/core/util/CMakeLists.txt @@ -37,8 +37,8 @@ find_package(Protobuf REQUIRED) include_directories(${PROTOBUF_INCLUDE_DIRS}) include_directories(${CMAKE_CURRENT_BINARY_DIR}) -# required by Synchronized*.cc: -find_package(Boost 1.42 COMPONENTS thread regex system REQUIRED) +# required by Synchronized*.cc, MemoryMap.* (needs icl, which came with 1.46): +find_package(Boost 1.46 COMPONENTS thread regex system REQUIRED) include_directories(${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) diff --git a/src/core/util/MemoryMap.cc b/src/core/util/MemoryMap.cc index 1855bd3d..4429cf1b 100644 --- a/src/core/util/MemoryMap.cc +++ b/src/core/util/MemoryMap.cc @@ -37,9 +37,12 @@ bool MemoryMap::writeToFile(char const * const filename) return false; } - for (iterator it = begin(); it != end(); ++it) { - file << *it << "\t1\n"; +#ifndef __puma + for (address_set::iterator it = as.begin(); + it != as.end(); ++it) { + file << it->lower() << " " << (it->upper() - it->lower() + 1) << "\n"; } +#endif return true; } diff --git a/src/core/util/MemoryMap.hpp b/src/core/util/MemoryMap.hpp index dca92c94..923e8446 100644 --- a/src/core/util/MemoryMap.hpp +++ b/src/core/util/MemoryMap.hpp @@ -1,12 +1,13 @@ #ifndef __MEMORYMAP_HPP__ #define __MEMORYMAP_HPP__ -#ifdef BOOST_1_46_OR_NEWER +#ifndef __puma +#include +#include #include -using namespace boost::icl; #endif -#include +#include #include "sal/SALConfig.hpp" @@ -17,62 +18,78 @@ namespace fail { * An efficient container for memory maps with holes. */ class MemoryMap { +#ifndef __puma private: -#ifdef BOOST_1_46_OR_NEWER - typedef interval::type address_interval; - typedef interval_set::type address_set; + typedef boost::icl::discrete_interval::type address_interval; + typedef boost::icl::interval_set::type address_set; address_set as; + public: - MemoryMap() { } - void clear() { as.clear(); } - void add(address_t addr, int size) { as.add(address_interval(addr, addr+size-1)); } - void isMatching(address_t addr, int size) { return intersects(as, address_interval(addr, addr+size-1)); } + /** + * The (STL-style) iterator of this class used to iterate over all + * addresses in this map. + */ + typedef address_set::element_iterator iterator; +#else +public: + typedef int const* iterator; #endif - std::set as; + public: - MemoryMap() { } /** * Clears the map. */ - void clear() { as.clear(); } + void clear() + { +#ifndef __puma + as.clear(); +#endif + } + /** * Adds one or a sequence of addresses to the map. */ void add(address_t addr, int size = 1) { - for (int i = 0; i < size; ++i) { - as.insert(addr + i); - } +#ifndef __puma + as.add(boost::icl::construct(addr, addr + size - 1, boost::icl::interval_bounds::closed())); +#endif } + /** * Determines whether a given memory access at address \a addr with width * \a size hits the map. */ bool isMatching(address_t addr, int size = 1) { - for (int i = 0; i < size; ++i) { - if (as.find(addr + i) != as.end()) { - return true; - } - } - return false; +#ifndef __puma + return boost::icl::intersects(as, boost::icl::construct(addr, addr + size - 1, boost::icl::interval_bounds::closed())); +#endif } - /** - * The (STL-style) iterator of this class used to iterate over all - * addresses in this map. - */ - typedef std::set::iterator iterator; + /** * Returns an (STL-style) iterator to the beginning of the internal data * structure. */ - iterator begin() { return as.begin(); } + iterator begin() + { +#ifndef __puma + return boost::icl::elements_begin(as); +#endif + } + /** * Returns an (STL-style) iterator to the end of the interal data * structure. */ - iterator end() { return as.end(); } + iterator end() + { +#ifndef __puma + return boost::icl::elements_end(as); +#endif + } + /** * Loads a memory map from a file and merges it with the current state. * @@ -91,6 +108,14 @@ public: * to a long list of single-byte addresses. */ bool writeToFile(char const * const filename); + + // debugging + void dump(std::ostream& os) + { +#ifndef __puma + os << as << std::endl; +#endif + } }; } // end-of-namespace: fail