Separated TargetMemoryAddressRange from TargetMemory.hpp
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
target_sources(
|
||||
Bloom
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TargetMemoryAddressRange.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TargetDescriptor.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TargetAddressSpaceDescriptor.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TargetMemorySegmentDescriptor.cpp
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "DynamicRegisterValue.hpp"
|
||||
|
||||
#include <bitset>
|
||||
#include <cassert>
|
||||
|
||||
namespace Targets
|
||||
{
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "TargetState.hpp"
|
||||
#include "TargetRegisterDescriptor.hpp"
|
||||
#include "TargetMemory.hpp"
|
||||
#include "TargetMemoryAddressRange.hpp"
|
||||
#include "TargetBreakpoint.hpp"
|
||||
#include "TargetPadDescriptor.hpp"
|
||||
#include "TargetGpioPadState.hpp"
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <optional>
|
||||
|
||||
#include "TargetMemory.hpp"
|
||||
#include "TargetMemoryAddressRange.hpp"
|
||||
#include "TargetMemorySegmentDescriptor.hpp"
|
||||
|
||||
namespace Targets
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <span>
|
||||
#include <set>
|
||||
#include <optional>
|
||||
#include <cassert>
|
||||
|
||||
namespace Targets
|
||||
{
|
||||
@@ -25,98 +21,6 @@ namespace Targets
|
||||
LITTLE,
|
||||
};
|
||||
|
||||
struct TargetMemoryAddressRange
|
||||
{
|
||||
TargetMemoryAddress startAddress = 0;
|
||||
TargetMemoryAddress endAddress = 0;
|
||||
|
||||
TargetMemoryAddressRange() = default;
|
||||
TargetMemoryAddressRange(TargetMemoryAddress startAddress, TargetMemoryAddress endAddress)
|
||||
: startAddress(startAddress)
|
||||
, endAddress(endAddress)
|
||||
{
|
||||
assert(this->startAddress <= this->endAddress);
|
||||
}
|
||||
|
||||
bool operator == (const TargetMemoryAddressRange& rhs) const {
|
||||
return this->startAddress == rhs.startAddress && this->endAddress == rhs.endAddress;
|
||||
}
|
||||
|
||||
bool operator < (const TargetMemoryAddressRange& rhs) const {
|
||||
return this->startAddress < rhs.startAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of addresses in the range.
|
||||
*
|
||||
* Keep in mind that the number of addresses may not be equal to the number of bytes in the range. It depends
|
||||
* on whether the address space is byte-addressable. See TargetAddressSpaceDescriptor::unitSize for more.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
[[nodiscard]] TargetMemorySize size() const {
|
||||
return this->endAddress - this->startAddress + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this range intersects with the given range.
|
||||
*
|
||||
* @param other
|
||||
* @return
|
||||
*/
|
||||
[[nodiscard]] bool intersectsWith(const TargetMemoryAddressRange& other) const noexcept {
|
||||
return this->startAddress <= other.endAddress && other.startAddress <= this->endAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of addresses in this range that intersect with the given range.
|
||||
*
|
||||
* @param other
|
||||
* @return
|
||||
*/
|
||||
[[nodiscard]] TargetMemorySize intersectingSize(const TargetMemoryAddressRange& other) const noexcept {
|
||||
return this->intersectsWith(other)
|
||||
? std::min(this->endAddress, other.endAddress) - std::max(this->startAddress, other.startAddress) + 1
|
||||
: 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given address is contained within this range.
|
||||
*
|
||||
* @param address
|
||||
* @return
|
||||
*/
|
||||
[[nodiscard]] bool contains(TargetMemoryAddress address) const noexcept {
|
||||
return address >= this->startAddress && address <= this->endAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given range is completely contained within this range.
|
||||
*
|
||||
* @param addressRange
|
||||
* @return
|
||||
*/
|
||||
[[nodiscard]] bool contains(const TargetMemoryAddressRange& addressRange) const noexcept {
|
||||
return this->startAddress <= addressRange.startAddress && this->endAddress >= addressRange.endAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of all addresses within this range.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
[[nodiscard]] std::set<Targets::TargetMemoryAddress> addresses() const noexcept {
|
||||
auto addresses = std::set<Targets::TargetMemoryAddress>{};
|
||||
auto addressesIt = addresses.end();
|
||||
|
||||
for (auto i = this->startAddress; i <= this->endAddress; ++i) {
|
||||
addressesIt = addresses.insert(addressesIt, i);
|
||||
}
|
||||
|
||||
return addresses;
|
||||
}
|
||||
};
|
||||
|
||||
struct TargetMemoryAccess
|
||||
{
|
||||
bool readable = false;
|
||||
|
||||
79
src/Targets/TargetMemoryAddressRange.cpp
Normal file
79
src/Targets/TargetMemoryAddressRange.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
#include "TargetMemoryAddressRange.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
#include "src/Services/IntegerService.hpp"
|
||||
|
||||
namespace Targets
|
||||
{
|
||||
TargetMemoryAddressRange::TargetMemoryAddressRange(
|
||||
TargetMemoryAddress startAddress,
|
||||
TargetMemoryAddress endAddress
|
||||
)
|
||||
: startAddress(startAddress)
|
||||
, endAddress(endAddress)
|
||||
{
|
||||
assert(this->startAddress <= this->endAddress);
|
||||
}
|
||||
|
||||
bool TargetMemoryAddressRange::operator == (const TargetMemoryAddressRange& rhs) const {
|
||||
return this->startAddress == rhs.startAddress && this->endAddress == rhs.endAddress;
|
||||
}
|
||||
|
||||
bool TargetMemoryAddressRange::operator < (const TargetMemoryAddressRange& rhs) const {
|
||||
return this->startAddress < rhs.startAddress;
|
||||
}
|
||||
|
||||
TargetMemorySize TargetMemoryAddressRange::size() const {
|
||||
return this->endAddress - this->startAddress + 1;
|
||||
}
|
||||
|
||||
bool TargetMemoryAddressRange::intersectsWith(const TargetMemoryAddressRange& other) const noexcept {
|
||||
return this->startAddress <= other.endAddress && other.startAddress <= this->endAddress;
|
||||
}
|
||||
|
||||
TargetMemorySize TargetMemoryAddressRange::intersectingSize(const TargetMemoryAddressRange& other) const noexcept {
|
||||
return this->intersectsWith(other)
|
||||
? std::min(this->endAddress, other.endAddress) - std::max(this->startAddress, other.startAddress) + 1
|
||||
: 0;
|
||||
}
|
||||
|
||||
bool TargetMemoryAddressRange::contains(TargetMemoryAddress address) const noexcept {
|
||||
return address >= this->startAddress && address <= this->endAddress;
|
||||
}
|
||||
|
||||
bool TargetMemoryAddressRange::contains(const TargetMemoryAddressRange& addressRange) const noexcept {
|
||||
return this->startAddress <= addressRange.startAddress && this->endAddress >= addressRange.endAddress;
|
||||
}
|
||||
|
||||
std::set<Targets::TargetMemoryAddress> TargetMemoryAddressRange::addresses() const noexcept {
|
||||
auto addresses = std::set<Targets::TargetMemoryAddress>{};
|
||||
auto addressesIt = addresses.end();
|
||||
|
||||
for (auto i = this->startAddress; i <= this->endAddress; ++i) {
|
||||
addressesIt = addresses.insert(addressesIt, i);
|
||||
}
|
||||
|
||||
return addresses;
|
||||
}
|
||||
|
||||
std::vector<TargetMemoryAddressRange> TargetMemoryAddressRange::blocks(TargetMemorySize blockSize) const noexcept {
|
||||
const auto startBlock = this->startAddress / blockSize;
|
||||
const auto endBlock = this->endAddress / blockSize;
|
||||
|
||||
auto output = std::vector<TargetMemoryAddressRange>{};
|
||||
output.reserve(endBlock - startBlock + 1);
|
||||
|
||||
for (auto block = startBlock; block <= endBlock; ++block) {
|
||||
const auto blockStartAddress = blockSize * block;
|
||||
const auto blockEndAddress = blockStartAddress + blockSize - 1;
|
||||
output.emplace_back(
|
||||
std::max(blockStartAddress, this->startAddress),
|
||||
std::min(blockEndAddress, this->endAddress)
|
||||
);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
78
src/Targets/TargetMemoryAddressRange.hpp
Normal file
78
src/Targets/TargetMemoryAddressRange.hpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#pragma once
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#include "TargetMemory.hpp"
|
||||
|
||||
namespace Targets
|
||||
{
|
||||
struct TargetMemoryAddressRange
|
||||
{
|
||||
TargetMemoryAddress startAddress = 0;
|
||||
TargetMemoryAddress endAddress = 0;
|
||||
|
||||
TargetMemoryAddressRange() = default;
|
||||
TargetMemoryAddressRange(TargetMemoryAddress startAddress, TargetMemoryAddress endAddress);
|
||||
|
||||
bool operator == (const TargetMemoryAddressRange& rhs) const;
|
||||
bool operator < (const TargetMemoryAddressRange& rhs) const;
|
||||
|
||||
/**
|
||||
* Returns the number of addresses in the range.
|
||||
*
|
||||
* Keep in mind that the number of addresses may not be equal to the number of bytes in the range. It depends
|
||||
* on whether the address space is byte-addressable. See TargetAddressSpaceDescriptor::unitSize for more.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
[[nodiscard]] TargetMemorySize size() const;
|
||||
|
||||
/**
|
||||
* Checks if this range intersects with the given range.
|
||||
*
|
||||
* @param other
|
||||
* @return
|
||||
*/
|
||||
[[nodiscard]] bool intersectsWith(const TargetMemoryAddressRange& other) const noexcept;
|
||||
|
||||
/**
|
||||
* Returns the number of addresses in this range that intersect with the given range.
|
||||
*
|
||||
* @param other
|
||||
* @return
|
||||
*/
|
||||
[[nodiscard]] TargetMemorySize intersectingSize(const TargetMemoryAddressRange& other) const noexcept;
|
||||
|
||||
/**
|
||||
* Checks if the given address is contained within this range.
|
||||
*
|
||||
* @param address
|
||||
* @return
|
||||
*/
|
||||
[[nodiscard]] bool contains(TargetMemoryAddress address) const noexcept;
|
||||
|
||||
/**
|
||||
* Checks if the given range is completely contained within this range.
|
||||
*
|
||||
* @param addressRange
|
||||
* @return
|
||||
*/
|
||||
[[nodiscard]] bool contains(const TargetMemoryAddressRange& addressRange) const noexcept;
|
||||
|
||||
/**
|
||||
* Returns a set of all addresses within this range.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
[[nodiscard]] std::set<TargetMemoryAddress> addresses() const noexcept;
|
||||
|
||||
/**
|
||||
* Splits the address range into a vector of blocks, with the given block size.
|
||||
*
|
||||
* @param blockSize
|
||||
* @return
|
||||
*/
|
||||
[[nodiscard]] std::vector<TargetMemoryAddressRange> blocks(TargetMemorySize blockSize) const noexcept;
|
||||
};
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include "TargetMemory.hpp"
|
||||
#include "TargetMemoryAddressRange.hpp"
|
||||
#include "TargetMemorySegmentType.hpp"
|
||||
|
||||
namespace Targets
|
||||
|
||||
Reference in New Issue
Block a user