- Refactored AVR8 constructor, moving TDF construction to the TargetControllerComponent

- The `TargetControllerComponent` now resolves the target via the new generated mapping approach
- Added `TargetDescriptionFile` derived class
- Removed obsolete JSON map processing code
- Other bits of refactoring and tidying
This commit is contained in:
Nav
2023-12-17 18:12:53 +00:00
parent 866cdbdcc5
commit 66cbd89051
14 changed files with 161 additions and 119 deletions

View File

@@ -15,7 +15,7 @@ namespace Targets::TargetDescription
return GeneratedMapping::map;
}
TargetDescriptionFile::TargetDescriptionFile(const QString& xmlFilePath) {
TargetDescriptionFile::TargetDescriptionFile(const std::string& xmlFilePath) {
this->init(xmlFilePath);
}
@@ -24,7 +24,7 @@ namespace Targets::TargetDescription
}
const std::string& TargetDescriptionFile::getTargetName() const {
return this->targetName;
return this->deviceAttribute("name");
}
TargetFamily TargetDescriptionFile::getFamily() const {
@@ -33,7 +33,7 @@ namespace Targets::TargetDescription
{"RISCV", TargetFamily::RISC_V},
};
const auto familyIt = familiesByName.find(this->familyName);
const auto familyIt = familiesByName.find(this->deviceAttribute("family"));
if (familyIt == familiesByName.end()) {
throw Exception("Failed to resolve target family - invalid family name");
@@ -42,8 +42,8 @@ namespace Targets::TargetDescription
return familyIt->second;
}
void TargetDescriptionFile::init(const QString& xmlFilePath) {
auto file = QFile(xmlFilePath);
void TargetDescriptionFile::init(const std::string& xmlFilePath) {
auto file = QFile(QString::fromStdString(xmlFilePath));
if (!file.exists()) {
// This can happen if someone has been messing with the Resources directory.
throw Exception("Failed to load target description file - file not found");
@@ -65,8 +65,16 @@ namespace Targets::TargetDescription
throw TargetDescriptionParsingFailureException("Device element not found.");
}
this->targetName = device.attributes().namedItem("name").nodeValue().toStdString();
this->familyName = device.attributes().namedItem("family").nodeValue().toLower().toStdString();
const auto deviceAttributes = device.attributes();
for (auto i = 0; i < deviceAttributes.length(); ++i) {
const auto deviceAttribute = deviceAttributes.item(i);
this->deviceAttributesByName.insert(
std::pair(
deviceAttribute.nodeName().toStdString(),
deviceAttribute.nodeValue().toStdString()
)
);
}
this->loadAddressSpaces(document);
this->loadPropertyGroups(document);
@@ -306,6 +314,16 @@ namespace Targets::TargetDescription
return bitField;
}
const std::string& TargetDescriptionFile::deviceAttribute(const std::string& attributeName) const {
const auto attributeIt = this->deviceAttributesByName.find(attributeName);
if (attributeIt == this->deviceAttributesByName.end()) {
throw Exception("Missing target device attribute (\"" + attributeName + "\")");
}
return attributeIt->second;
}
void TargetDescriptionFile::loadAddressSpaces(const QDomDocument& document) {
const auto deviceElement = document.elementsByTagName("device").item(0).toElement();

View File

@@ -59,7 +59,7 @@ namespace Targets::TargetDescription
*
* @param xmlFilePath
*/
explicit TargetDescriptionFile(const QString& xmlFilePath);
explicit TargetDescriptionFile(const std::string& xmlFilePath);
/**
* Will construct a TargetDescriptionFile instance from pre-loaded XML.
@@ -83,9 +83,7 @@ namespace Targets::TargetDescription
[[nodiscard]] TargetFamily getFamily() const;
protected:
std::string targetName;
std::string familyName;
std::map<std::string, std::string> deviceAttributesByName;
std::map<std::string, AddressSpace> addressSpacesMappedById;
std::map<std::string, PropertyGroup> propertyGroupsMappedByName;
std::map<std::string, Module> modulesMappedByName;
@@ -104,8 +102,8 @@ namespace Targets::TargetDescription
TargetDescriptionFile& operator = (const TargetDescriptionFile& other) = default;
TargetDescriptionFile& operator = (TargetDescriptionFile&& other) = default;
virtual void init(const QDomDocument& document);
void init(const QString& xmlFilePath);
void init(const std::string& xmlFilePath);
void init(const QDomDocument& document);
/**
* Constructs an AddressSpace object from an XML element.
@@ -147,6 +145,14 @@ namespace Targets::TargetDescription
*/
static BitField bitFieldFromXml(const QDomElement& xmlElement);
/**
* Fetches a device attribute value by name. Throws an exception if the attribute is not found.
*
* @param attributeName
* @return
*/
const std::string& deviceAttribute(const std::string& attributeName) const;
/**
* Extracts all address spaces and loads them into this->addressSpacesMappedById.
*/