Moved TargetAddressSpaceDescriptor member functions to separate source file
This commit is contained in:
@@ -2,6 +2,7 @@ target_sources(
|
|||||||
Bloom
|
Bloom
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/TargetDescription/TargetDescriptionFile.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/TargetDescription/TargetDescriptionFile.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/TargetAddressSpaceDescriptor.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/TargetRegisterDescriptor.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/TargetRegisterDescriptor.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/TargetMemoryCache.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/TargetMemoryCache.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/TargetPhysicalInterface.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/TargetPhysicalInterface.cpp
|
||||||
|
|||||||
49
src/Targets/TargetAddressSpaceDescriptor.cpp
Normal file
49
src/Targets/TargetAddressSpaceDescriptor.cpp
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#include "TargetAddressSpaceDescriptor.hpp"
|
||||||
|
|
||||||
|
#include "src/Exceptions/InternalFatalErrorException.hpp"
|
||||||
|
|
||||||
|
namespace Targets
|
||||||
|
{
|
||||||
|
TargetAddressSpaceDescriptor::TargetAddressSpaceDescriptor(
|
||||||
|
const std::string& key,
|
||||||
|
const TargetMemoryAddressRange& addressRange,
|
||||||
|
TargetMemoryEndianness endianness,
|
||||||
|
const std::map<std::string, TargetMemorySegmentDescriptor>& segmentDescriptorsByKey
|
||||||
|
)
|
||||||
|
: id(++(TargetAddressSpaceDescriptor::lastAddressSpaceDescriptorId))
|
||||||
|
, key(key)
|
||||||
|
, addressRange(addressRange)
|
||||||
|
, endianness(endianness)
|
||||||
|
, segmentDescriptorsByKey(segmentDescriptorsByKey)
|
||||||
|
{}
|
||||||
|
|
||||||
|
TargetMemorySize TargetAddressSpaceDescriptor::size() const {
|
||||||
|
return this->addressRange.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<
|
||||||
|
std::reference_wrapper<const TargetMemorySegmentDescriptor>
|
||||||
|
> TargetAddressSpaceDescriptor::tryGetMemorySegmentDescriptor(const std::string& key) const {
|
||||||
|
const auto segmentIt = this->segmentDescriptorsByKey.find(key);
|
||||||
|
|
||||||
|
if (segmentIt == this->segmentDescriptorsByKey.end()) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::cref(segmentIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
const TargetMemorySegmentDescriptor& TargetAddressSpaceDescriptor::getMemorySegmentDescriptor(
|
||||||
|
const std::string& key
|
||||||
|
) const {
|
||||||
|
const auto segment = this->tryGetMemorySegmentDescriptor(key);
|
||||||
|
if (!segment.has_value()) {
|
||||||
|
throw Exceptions::InternalFatalErrorException(
|
||||||
|
"Failed to get memory segment descriptor \"" + key + "\" from address space \"" + this->key
|
||||||
|
+ "\" - segment not found"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return segment->get();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
#include "TargetMemory.hpp"
|
#include "TargetMemory.hpp"
|
||||||
#include "TargetMemorySegmentDescriptor.hpp"
|
#include "TargetMemorySegmentDescriptor.hpp"
|
||||||
#include "src/Exceptions/InternalFatalErrorException.hpp"
|
|
||||||
|
|
||||||
namespace Targets
|
namespace Targets
|
||||||
{
|
{
|
||||||
@@ -28,41 +27,34 @@ namespace Targets
|
|||||||
const TargetMemoryAddressRange& addressRange,
|
const TargetMemoryAddressRange& addressRange,
|
||||||
TargetMemoryEndianness endianness,
|
TargetMemoryEndianness endianness,
|
||||||
const std::map<std::string, TargetMemorySegmentDescriptor>& segmentDescriptorsByKey
|
const std::map<std::string, TargetMemorySegmentDescriptor>& segmentDescriptorsByKey
|
||||||
)
|
);
|
||||||
: id(++(TargetAddressSpaceDescriptor::lastAddressSpaceDescriptorId))
|
|
||||||
, key(key)
|
|
||||||
, addressRange(addressRange)
|
|
||||||
, endianness(endianness)
|
|
||||||
, segmentDescriptorsByKey(segmentDescriptorsByKey)
|
|
||||||
{};
|
|
||||||
|
|
||||||
TargetMemorySize size() const {
|
TargetMemorySize size() const;
|
||||||
return this->addressRange.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to fetch a memory segment descriptor with the given key.
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
* The key of the memory segment descriptor to lookup.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* A reference wrapper of the memory segment descriptor, if found. Otherwise, std::nullopt.
|
||||||
|
*/
|
||||||
std::optional<std::reference_wrapper<const TargetMemorySegmentDescriptor>> tryGetMemorySegmentDescriptor(
|
std::optional<std::reference_wrapper<const TargetMemorySegmentDescriptor>> tryGetMemorySegmentDescriptor(
|
||||||
const std::string& key
|
const std::string& key
|
||||||
) const {
|
) const;
|
||||||
const auto segmentIt = this->segmentDescriptorsByKey.find(key);
|
|
||||||
|
|
||||||
if (segmentIt == this->segmentDescriptorsByKey.end()) {
|
/**
|
||||||
return std::nullopt;
|
* Fetches a memory segment descriptor with the given key. If the descriptor doesn't exist, an
|
||||||
}
|
* InternalFatalErrorException is thrown.
|
||||||
|
*
|
||||||
return std::cref(segmentIt->second);
|
* @param key
|
||||||
}
|
* The key of the memory segment descriptor to lookup.
|
||||||
|
*
|
||||||
const TargetMemorySegmentDescriptor& getMemorySegmentDescriptor(const std::string& key) const {
|
* @return
|
||||||
const auto segment = this->tryGetMemorySegmentDescriptor(key);
|
* A reference to the memory segment descriptor.
|
||||||
if (!segment.has_value()) {
|
*/
|
||||||
throw Exceptions::InternalFatalErrorException(
|
const TargetMemorySegmentDescriptor& getMemorySegmentDescriptor(const std::string& key) const;
|
||||||
"Failed to get memory segment descriptor \"" + key + "\" from address space \"" + this->key
|
|
||||||
+ "\" - segment not found"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return segment->get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static inline std::atomic<TargetAddressSpaceDescriptorId> lastAddressSpaceDescriptorId = 0;
|
static inline std::atomic<TargetAddressSpaceDescriptorId> lastAddressSpaceDescriptorId = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user