2021-04-04 21:04:12 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <QFile>
|
|
|
|
|
#include <QDomDocument>
|
2024-02-12 19:23:00 +00:00
|
|
|
#include <QDomElement>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <optional>
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <vector>
|
2021-04-04 21:04:12 +01:00
|
|
|
|
|
|
|
|
#include "AddressSpace.hpp"
|
|
|
|
|
#include "MemorySegment.hpp"
|
|
|
|
|
#include "PropertyGroup.hpp"
|
2024-02-13 20:22:18 +00:00
|
|
|
#include "MemorySegmentSection.hpp"
|
2021-04-04 21:04:12 +01:00
|
|
|
#include "RegisterGroup.hpp"
|
|
|
|
|
#include "Module.hpp"
|
|
|
|
|
#include "Variant.hpp"
|
|
|
|
|
#include "Pinout.hpp"
|
2021-06-26 03:47:23 +01:00
|
|
|
#include "Interface.hpp"
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2023-12-13 00:50:10 +00:00
|
|
|
#include "src/Targets/TargetFamily.hpp"
|
|
|
|
|
|
2023-12-12 23:19:21 +00:00
|
|
|
#include GENERATED_TDF_MAPPING_PATH
|
|
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
namespace Targets::TargetDescription
|
2021-04-04 21:04:12 +01:00
|
|
|
{
|
|
|
|
|
/**
|
2021-05-31 01:01:14 +01:00
|
|
|
* A target description file (TDF) is an XML file that describes a particular target. All supported targets come
|
|
|
|
|
* with a target description file.
|
2021-04-04 21:04:12 +01:00
|
|
|
*
|
2021-05-31 01:01:14 +01:00
|
|
|
* Target description files are part of the Bloom codebase.
|
|
|
|
|
* For target description files, see the directory "src/Targets/TargetDescriptionFiles/".
|
2021-04-04 21:04:12 +01:00
|
|
|
*
|
2021-05-31 01:01:14 +01:00
|
|
|
* During the build process, all target description files are copied to the distribution directory, ready
|
|
|
|
|
* to be shipped with the Bloom binary.
|
2021-04-04 21:04:12 +01:00
|
|
|
*
|
2021-05-31 01:01:14 +01:00
|
|
|
* Processing of target description files is done in this class.
|
|
|
|
|
*
|
|
|
|
|
* This class may be extended to further reflect a TDF that is specific to a particular target, target architecture
|
|
|
|
|
* or target family. For example, the Targets::Microchip::Avr::Avr8Bit::TargetDescription::TargetDescriptionFile
|
|
|
|
|
* class inherits from this class, to represent TDFs for AVR8 targets. The derived class provides access to
|
|
|
|
|
* additional data that is only found in AVR8 TDFs (such as AVR target signature, AVR Family, etc).
|
2021-06-20 17:41:47 +01:00
|
|
|
*
|
|
|
|
|
* For more information of TDFs, see src/Targets/TargetDescription/README.md
|
2021-04-04 21:04:12 +01:00
|
|
|
*/
|
2021-05-31 01:01:14 +01:00
|
|
|
class TargetDescriptionFile
|
2021-04-04 21:04:12 +01:00
|
|
|
{
|
2021-10-06 21:12:31 +01:00
|
|
|
public:
|
2023-12-12 23:19:21 +00:00
|
|
|
/**
|
|
|
|
|
* Returns a mapping of target configuration values to instances of the GeneratedMapping::BriefTargetDescriptor
|
|
|
|
|
* struct.
|
|
|
|
|
*
|
|
|
|
|
* The mapping is generated pre-build.
|
|
|
|
|
*
|
|
|
|
|
* The GeneratedMapping::BriefTargetDescriptor struct holds some brief info about a particular target, such as
|
|
|
|
|
* target name, family and TDF path. See the GeneratedMapping.hpp.in template for more.
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
static const std::map<std::string, GeneratedMapping::BriefTargetDescriptor>& mapping();
|
|
|
|
|
|
2021-10-06 21:12:31 +01:00
|
|
|
/**
|
|
|
|
|
* Will construct a TargetDescriptionFile instance from the XML of a target description file, the path to which
|
|
|
|
|
* is given via xmlFilePath.
|
|
|
|
|
*
|
|
|
|
|
* @param xmlFilePath
|
|
|
|
|
*/
|
2023-12-17 18:12:53 +00:00
|
|
|
explicit TargetDescriptionFile(const std::string& xmlFilePath);
|
2021-10-06 21:12:31 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Will construct a TargetDescriptionFile instance from pre-loaded XML.
|
|
|
|
|
*
|
|
|
|
|
* @param xml
|
|
|
|
|
*/
|
2023-12-12 23:19:21 +00:00
|
|
|
explicit TargetDescriptionFile(const QDomDocument& xml);
|
2021-10-06 21:12:31 +01:00
|
|
|
|
|
|
|
|
/**
|
2023-03-05 23:30:42 +00:00
|
|
|
* Returns the target name extracted from the TDF.
|
2021-10-06 21:12:31 +01:00
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2023-03-05 23:30:42 +00:00
|
|
|
[[nodiscard]] const std::string& getTargetName() const;
|
|
|
|
|
|
|
|
|
|
/**
|
2023-12-13 00:50:10 +00:00
|
|
|
* Returns the target family extracted from the TDF.
|
2023-03-05 23:30:42 +00:00
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2023-12-13 00:50:10 +00:00
|
|
|
[[nodiscard]] TargetFamily getFamily() const;
|
2021-10-06 21:12:31 +01:00
|
|
|
|
2024-02-12 19:23:00 +00:00
|
|
|
[[nodiscard]] std::optional<std::reference_wrapper<const PropertyGroup>> tryGetPropertyGroup(
|
|
|
|
|
std::string_view keyStr
|
|
|
|
|
) const;
|
|
|
|
|
[[nodiscard]] const PropertyGroup& getPropertyGroup(std::string_view keyStr) const;
|
2024-02-13 20:22:18 +00:00
|
|
|
|
|
|
|
|
[[nodiscard]] std::optional<std::reference_wrapper<const AddressSpace>> tryGetAddressSpace(
|
|
|
|
|
std::string_view key
|
|
|
|
|
) const;
|
|
|
|
|
[[nodiscard]] const AddressSpace& getAddressSpace(std::string_view key) const;
|
|
|
|
|
|
2021-05-31 01:01:14 +01:00
|
|
|
protected:
|
2023-12-17 18:12:53 +00:00
|
|
|
std::map<std::string, std::string> deviceAttributesByName;
|
2024-02-13 20:22:18 +00:00
|
|
|
std::map<std::string, AddressSpace, std::less<void>> addressSpacesByKey;
|
2024-02-12 19:23:00 +00:00
|
|
|
std::map<std::string, PropertyGroup, std::less<void>> propertyGroupsMappedByKey;
|
2021-06-06 20:06:43 +01:00
|
|
|
std::map<std::string, Module> modulesMappedByName;
|
|
|
|
|
std::map<std::string, Module> peripheralModulesMappedByName;
|
2021-08-27 23:51:21 +01:00
|
|
|
std::map<std::string, std::vector<RegisterGroup>> peripheralRegisterGroupsMappedByModuleRegisterGroupName;
|
2021-06-06 20:06:43 +01:00
|
|
|
std::vector<Variant> variants;
|
|
|
|
|
std::map<std::string, Pinout> pinoutsMappedByName;
|
2021-06-26 03:47:23 +01:00
|
|
|
std::map<std::string, Interface> interfacesByName;
|
2021-06-06 20:06:43 +01:00
|
|
|
|
2021-10-17 21:12:17 +01:00
|
|
|
TargetDescriptionFile() = default;
|
2022-01-11 21:12:25 +00:00
|
|
|
virtual ~TargetDescriptionFile() = default;
|
|
|
|
|
|
|
|
|
|
TargetDescriptionFile(const TargetDescriptionFile& other) = default;
|
|
|
|
|
TargetDescriptionFile(TargetDescriptionFile&& other) = default;
|
|
|
|
|
|
|
|
|
|
TargetDescriptionFile& operator = (const TargetDescriptionFile& other) = default;
|
|
|
|
|
TargetDescriptionFile& operator = (TargetDescriptionFile&& other) = default;
|
2021-06-06 20:06:43 +01:00
|
|
|
|
2023-12-17 18:12:53 +00:00
|
|
|
void init(const std::string& xmlFilePath);
|
|
|
|
|
void init(const QDomDocument& document);
|
2021-05-31 01:01:14 +01:00
|
|
|
|
2024-02-12 19:23:00 +00:00
|
|
|
static std::optional<std::string> tryGetAttribute(const QDomElement& element, const QString& attributeName);
|
|
|
|
|
static std::string getAttribute(const QDomElement& element, const QString& attributeName);
|
|
|
|
|
|
|
|
|
|
static PropertyGroup propertyGroupFromXml(const QDomElement& xmlElement);
|
|
|
|
|
static Property propertyFromXml(const QDomElement& xmlElement);
|
|
|
|
|
|
2021-04-04 21:04:12 +01:00
|
|
|
/**
|
2021-06-06 19:14:36 +01:00
|
|
|
* Constructs an AddressSpace object from an XML element.
|
2021-04-04 21:04:12 +01:00
|
|
|
*
|
|
|
|
|
* @param xmlElement
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2023-12-10 13:04:05 +00:00
|
|
|
static AddressSpace addressSpaceFromXml(const QDomElement& xmlElement);
|
2021-04-04 21:04:12 +01:00
|
|
|
|
|
|
|
|
/**
|
2021-06-06 19:14:36 +01:00
|
|
|
* Constructs a MemorySegment object from an XML element.
|
2021-04-04 21:04:12 +01:00
|
|
|
*
|
|
|
|
|
* @param xmlElement
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2023-12-10 13:04:05 +00:00
|
|
|
static MemorySegment memorySegmentFromXml(const QDomElement& xmlElement);
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2024-02-13 20:22:18 +00:00
|
|
|
/**
|
|
|
|
|
* Constructs a MemorySegmentSection from an XML element.
|
|
|
|
|
*
|
|
|
|
|
* @param xmlElement
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
static MemorySegmentSection memorySegmentSectionFromXml(const QDomElement& xmlElement);
|
|
|
|
|
|
2021-06-06 19:14:36 +01:00
|
|
|
/**
|
|
|
|
|
* Constructs a RegisterGroup object from an XML element.
|
|
|
|
|
*
|
|
|
|
|
* @param xmlElement
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2023-12-10 13:04:05 +00:00
|
|
|
static RegisterGroup registerGroupFromXml(const QDomElement& xmlElement);
|
2021-06-06 19:14:36 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructs a Register object from an XML element.
|
|
|
|
|
*
|
|
|
|
|
* @param xmlElement
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2023-12-10 13:04:05 +00:00
|
|
|
static Register registerFromXml(const QDomElement& xmlElement);
|
2022-03-04 15:33:31 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Consturcts a BitField object from an XML element.
|
|
|
|
|
*
|
|
|
|
|
* @param xmlElement
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2023-12-10 13:04:05 +00:00
|
|
|
static BitField bitFieldFromXml(const QDomElement& xmlElement);
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2023-12-17 18:12:53 +00:00
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
|
2021-06-06 20:06:43 +01:00
|
|
|
/**
|
|
|
|
|
* Extracts all modules and loads them into this->modulesMappedByName.
|
|
|
|
|
*/
|
2023-03-05 23:30:42 +00:00
|
|
|
void loadModules(const QDomDocument& document);
|
2021-06-06 20:06:43 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extracts all peripheral modules and loads them into this->peripheralModulesMappedByName.
|
|
|
|
|
*/
|
2023-03-05 23:30:42 +00:00
|
|
|
void loadPeripheralModules(const QDomDocument& document);
|
2021-06-06 20:06:43 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extracts all variants and loads them into this->variants.
|
|
|
|
|
*/
|
2023-03-05 23:30:42 +00:00
|
|
|
void loadVariants(const QDomDocument& document);
|
2021-06-06 20:06:43 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extracts all pinouts and loads them into this->pinoutsMappedByName.
|
|
|
|
|
*/
|
2023-03-05 23:30:42 +00:00
|
|
|
void loadPinouts(const QDomDocument& document);
|
2021-06-06 20:06:43 +01:00
|
|
|
|
2021-06-26 03:47:23 +01:00
|
|
|
/**
|
|
|
|
|
* Extracts all interfaces and loads them into this->interfacesByName
|
|
|
|
|
*/
|
2023-03-05 23:30:42 +00:00
|
|
|
void loadInterfaces(const QDomDocument& document);
|
2021-04-04 21:04:12 +01:00
|
|
|
};
|
|
|
|
|
}
|