Moved TargetRegisterDescriptor struct to separate file

This commit is contained in:
Nav
2024-03-09 17:16:29 +00:00
parent 534b269b56
commit 75d5124265
28 changed files with 149 additions and 130 deletions

View File

@@ -2,7 +2,7 @@ target_sources(
Bloom
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/TargetDescription/TargetDescriptionFile.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TargetRegister.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TargetRegisterDescriptor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TargetMemoryCache.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TargetPhysicalInterface.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Microchip/AVR/AVR8/Avr8.cpp

View File

@@ -12,7 +12,6 @@
#include "src/Exceptions/InvalidConfig.hpp"
#include "Exceptions/DebugWirePhysicalInterfaceError.hpp"
#include "src/Targets/TargetRegister.hpp"
namespace Targets::Microchip::Avr::Avr8Bit
{

View File

@@ -19,7 +19,7 @@
#include "src/Targets/Microchip/AVR/Fuse.hpp"
#include "src/Targets/TargetPhysicalInterface.hpp"
#include "src/Targets/TargetRegister.hpp"
#include "src/Targets/TargetRegisterDescriptor.hpp"
#include "src/Targets/TargetBreakpoint.hpp"
#include "TargetDescription/TargetDescriptionFile.hpp"

View File

@@ -6,7 +6,7 @@
#include "src/Targets/TargetDescription/TargetDescriptionFile.hpp"
#include "src/Targets/TargetVariant.hpp"
#include "src/Targets/TargetRegister.hpp"
#include "src/Targets/TargetRegisterDescriptor.hpp"
#include "src/Targets/Microchip/AVR/TargetSignature.hpp"
#include "src/Targets/Microchip/AVR/IspParameters.hpp"

View File

@@ -2,7 +2,7 @@
#include <cstdint>
#include "src/Targets/TargetRegister.hpp"
#include "src/Targets/TargetRegisterDescriptor.hpp"
#include "RiscVGeneric.hpp"

View File

@@ -11,6 +11,7 @@
#include "TargetDescriptor.hpp"
#include "TargetState.hpp"
#include "TargetRegisterDescriptor.hpp"
#include "TargetRegister.hpp"
#include "TargetMemory.hpp"
#include "TargetBreakpoint.hpp"

View File

@@ -9,7 +9,7 @@
#include "TargetFamily.hpp"
#include "TargetMemory.hpp"
#include "TargetRegister.hpp"
#include "TargetRegisterDescriptor.hpp"
#include "TargetVariant.hpp"
#include "TargetBreakpoint.hpp"

View File

@@ -1,105 +1,14 @@
#pragma once
#include <cstdint>
#include <atomic>
#include <string>
#include <optional>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include "TargetRegisterDescriptor.hpp"
#include "TargetMemory.hpp"
namespace Targets
{
using TargetRegisterDescriptorId = std::uint32_t;
using TargetRegisterDescriptorIds = std::set<Targets::TargetRegisterDescriptorId>;
enum class TargetRegisterType: std::uint8_t
{
GENERAL_PURPOSE_REGISTER,
PROGRAM_COUNTER,
STACK_POINTER,
STATUS_REGISTER,
PORT_REGISTER,
OTHER,
};
struct TargetRegisterAccess
{
bool readable = false;
bool writable = false;
TargetRegisterAccess(
bool readable,
bool writable
)
: readable(readable)
, writable(writable)
{}
};
struct TargetRegisterDescriptor
{
public:
TargetRegisterDescriptorId id;
TargetRegisterType type;
std::optional<TargetMemoryAddress> startAddress;
TargetMemorySize size;
TargetMemoryType memoryType;
std::optional<std::string> name;
std::optional<std::string> groupName;
std::optional<std::string> description;
TargetRegisterAccess access;
TargetRegisterDescriptor(
TargetRegisterType type,
std::optional<TargetMemoryAddress> startAddress,
TargetMemorySize size,
TargetMemoryType memoryType,
std::optional<std::string> name,
std::optional<std::string> groupName,
std::optional<std::string> description,
TargetRegisterAccess access
)
: id(++(TargetRegisterDescriptor::lastRegisterDescriptorId))
, type(type)
, startAddress(startAddress)
, size(size)
, memoryType(memoryType)
, name(name)
, groupName(groupName)
, description(description)
, access(access)
{};
bool operator == (const TargetRegisterDescriptor& other) const {
return this->getHash() == other.getHash();
}
bool operator < (const TargetRegisterDescriptor& other) const {
if (this->type == other.type) {
return this->startAddress.value_or(0) < other.startAddress.value_or(0);
}
/*
* If the registers are of different type, there is no meaningful way to sort them, so we just use
* the unique hash.
*/
return this->getHash() < other.getHash();
}
private:
mutable std::optional<std::size_t> cachedHash;
static inline std::atomic<TargetRegisterDescriptorId> lastRegisterDescriptorId = 0;
std::size_t getHash() const;
friend std::hash<Targets::TargetRegisterDescriptor>;
};
struct TargetRegister
{
TargetRegisterDescriptorId descriptorId;
@@ -120,24 +29,4 @@ namespace Targets
};
using TargetRegisters = std::vector<TargetRegister>;
using TargetRegisterDescriptors = std::set<TargetRegisterDescriptor>;
using TargetRegisterDescriptorMapping = std::map<TargetRegisterDescriptorId, TargetRegisterDescriptor>;
}
namespace std
{
/**
* Hashing function for TargetRegisterDescriptor type.
*
* This is required in order to use TargetRegisterDescriptor as a key in an std::unordered_map (see the BiMap
* class)
*/
template<>
class hash<Targets::TargetRegisterDescriptor>
{
public:
std::size_t operator()(const Targets::TargetRegisterDescriptor& descriptor) const {
return descriptor.getHash();
}
};
}

View File

@@ -1,4 +1,4 @@
#include "TargetRegister.hpp"
#include "TargetRegisterDescriptor.hpp"
namespace Targets
{

View File

@@ -0,0 +1,125 @@
#pragma once
#include <cstdint>
#include <atomic>
#include <string>
#include <optional>
#include <utility>
#include <map>
#include <set>
#include "TargetMemory.hpp"
namespace Targets
{
using TargetRegisterDescriptorId = std::uint32_t;
using TargetRegisterDescriptorIds = std::set<Targets::TargetRegisterDescriptorId>;
enum class TargetRegisterType: std::uint8_t
{
GENERAL_PURPOSE_REGISTER,
PROGRAM_COUNTER,
STACK_POINTER,
STATUS_REGISTER,
PORT_REGISTER,
OTHER,
};
struct TargetRegisterAccess
{
bool readable = false;
bool writable = false;
TargetRegisterAccess(
bool readable,
bool writable
)
: readable(readable)
, writable(writable)
{}
};
struct TargetRegisterDescriptor
{
public:
TargetRegisterDescriptorId id;
TargetRegisterType type;
std::optional<TargetMemoryAddress> startAddress;
TargetMemorySize size;
TargetMemoryType memoryType;
std::optional<std::string> name;
std::optional<std::string> groupName;
std::optional<std::string> description;
TargetRegisterAccess access;
TargetRegisterDescriptor(
TargetRegisterType type,
std::optional<TargetMemoryAddress> startAddress,
TargetMemorySize size,
TargetMemoryType memoryType,
std::optional<std::string> name,
std::optional<std::string> groupName,
std::optional<std::string> description,
TargetRegisterAccess access
)
: id(++(TargetRegisterDescriptor::lastRegisterDescriptorId))
, type(type)
, startAddress(startAddress)
, size(size)
, memoryType(memoryType)
, name(name)
, groupName(groupName)
, description(description)
, access(access)
{};
bool operator == (const TargetRegisterDescriptor& other) const {
return this->getHash() == other.getHash();
}
bool operator < (const TargetRegisterDescriptor& other) const {
if (this->type == other.type) {
return this->startAddress.has_value() && other.startAddress.has_value()
? this->startAddress < other.startAddress
: this->name < other.name
;
}
/*
* If the registers are of different type, there is no meaningful way to sort them, so we just use
* the unique hash.
*/
return this->getHash() < other.getHash();
}
private:
mutable std::optional<std::size_t> cachedHash;
static inline std::atomic<TargetRegisterDescriptorId> lastRegisterDescriptorId = 0;
std::size_t getHash() const;
friend std::hash<Targets::TargetRegisterDescriptor>;
};
using TargetRegisterDescriptors = std::set<TargetRegisterDescriptor>;
using TargetRegisterDescriptorMapping = std::map<TargetRegisterDescriptorId, TargetRegisterDescriptor>;
}
namespace std
{
/**
* Hashing function for TargetRegisterDescriptor type.
*
* This is required in order to use TargetRegisterDescriptor as a key in an std::unordered_map (see the BiMap
* class)
*/
template<>
class hash<Targets::TargetRegisterDescriptor>
{
public:
std::size_t operator()(const Targets::TargetRegisterDescriptor& descriptor) const {
return descriptor.getHash();
}
};
}