mirror of
https://github.com/supleed2/svd2cpp.git
synced 2024-12-22 13:45:50 +00:00
Added support for saving to file, fixed bug with parsing addresses
This commit is contained in:
parent
c05c8fa341
commit
19cd372ec0
|
@ -9,8 +9,9 @@ include_directories(tinyxml2)
|
||||||
|
|
||||||
add_library(ClassBuilder Src/ClassBuilder.cpp)
|
add_library(ClassBuilder Src/ClassBuilder.cpp)
|
||||||
add_library(Builders Src/Builders.cpp)
|
add_library(Builders Src/Builders.cpp)
|
||||||
|
add_library(OutputFile Src/OutputFile.cpp)
|
||||||
add_library(XmlParser Src/XmlParser.cpp)
|
add_library(XmlParser Src/XmlParser.cpp)
|
||||||
add_library(tinyxml2 tinyxml2/tinyxml2.cpp)
|
add_library(tinyxml2 tinyxml2/tinyxml2.cpp)
|
||||||
|
|
||||||
add_executable(svd2cpp Src/main.cpp)
|
add_executable(svd2cpp Src/main.cpp)
|
||||||
target_link_libraries(svd2cpp ClassBuilder Builders XmlParser tinyxml2)
|
target_link_libraries(svd2cpp ClassBuilder Builders OutputFile XmlParser tinyxml2)
|
|
@ -22,7 +22,7 @@ void PeripheralBuilder::build(std::stringstream& ss) const{
|
||||||
for(auto& registe : peripheral.registers){
|
for(auto& registe : peripheral.registers){
|
||||||
RegisterBuilder(registe, peripheral.baseAddress).build(ss);
|
RegisterBuilder(registe, peripheral.baseAddress).build(ss);
|
||||||
}
|
}
|
||||||
ss << "}\n";
|
ss << "}\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterBuilder::build(std::stringstream& ss) const{
|
void RegisterBuilder::build(std::stringstream& ss) const{
|
||||||
|
|
|
@ -22,5 +22,8 @@ void ClassBuilder::build(){
|
||||||
for(auto& builder : builders){
|
for(auto& builder : builders){
|
||||||
builder->build(outputStream);
|
builder->build(outputStream);
|
||||||
}
|
}
|
||||||
std::cout << outputStream.str();
|
}
|
||||||
|
|
||||||
|
const std::stringstream& ClassBuilder::getStream() const{
|
||||||
|
return outputStream;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ struct ClassBuilder
|
||||||
const std::vector<Peripheral>& peripherals_);
|
const std::vector<Peripheral>& peripherals_);
|
||||||
void setupBuilders();
|
void setupBuilders();
|
||||||
void build();
|
void build();
|
||||||
|
const std::stringstream& getStream() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const cxxopts::ParseResult& results;
|
const cxxopts::ParseResult& results;
|
||||||
|
|
|
@ -41,12 +41,12 @@ void XmlParser::parseXml(){
|
||||||
|
|
||||||
void XmlParser::setDeviceInfoAttrib(tinyxml2::XMLElement* deviceRoot, const char* name, std::string &field) const{
|
void XmlParser::setDeviceInfoAttrib(tinyxml2::XMLElement* deviceRoot, const char* name, std::string &field) const{
|
||||||
tinyxml2::XMLElement* deviceEntry = deviceRoot->FirstChildElement(name);
|
tinyxml2::XMLElement* deviceEntry = deviceRoot->FirstChildElement(name);
|
||||||
field = deviceEntry != nullptr ? std::string(deviceEntry->GetText()) : noValue;
|
field = deviceEntry ? std::string(deviceEntry->GetText()) : noValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlParser::setDeviceInfoAttrib(tinyxml2::XMLElement* deviceRoot, const char* name, unsigned int &field) const{
|
void XmlParser::setDeviceInfoAttrib(tinyxml2::XMLElement* deviceRoot, const char* name, unsigned int &field) const{
|
||||||
tinyxml2::XMLElement* deviceEntry = deviceRoot->FirstChildElement(name);
|
tinyxml2::XMLElement* deviceEntry = deviceRoot->FirstChildElement(name);
|
||||||
field = deviceEntry != nullptr ? std::stol(deviceEntry->GetText(), 0, 16) : 0;
|
field = deviceEntry ? (std::stol(deviceEntry->GetText()) ?: std::stol(deviceEntry->GetText(), 0, 16)) : 0;
|
||||||
}
|
}
|
||||||
void XmlParser::setDeviceInfoAttrib(tinyxml2::XMLElement* deviceRoot, const char* name, EAccess &field) const{
|
void XmlParser::setDeviceInfoAttrib(tinyxml2::XMLElement* deviceRoot, const char* name, EAccess &field) const{
|
||||||
tinyxml2::XMLElement* deviceEntry = deviceRoot->FirstChildElement(name);
|
tinyxml2::XMLElement* deviceEntry = deviceRoot->FirstChildElement(name);
|
||||||
|
|
15
Src/main.cpp
15
Src/main.cpp
|
@ -2,18 +2,24 @@
|
||||||
#include <cxxopts.hpp>
|
#include <cxxopts.hpp>
|
||||||
#include <XmlParser.hpp>
|
#include <XmlParser.hpp>
|
||||||
#include <ClassBuilder.hpp>
|
#include <ClassBuilder.hpp>
|
||||||
|
#include <OutputFile.hpp>
|
||||||
|
|
||||||
int main(int argc, char** argv){
|
int main(int argc, char** argv){
|
||||||
// Create and configure options for the program
|
// Create and configure options for the program
|
||||||
cxxopts::Options options("svd2cpp", "Parser from svd files to C++ header");
|
cxxopts::Options options("svd2cpp", "Parser from svd files to C++ header");
|
||||||
options.add_options()
|
options.add_options()
|
||||||
("i, input", "File to be parsed", cxxopts::value<std::string>())
|
("i, input", "File with .svd extention to be parsed", cxxopts::value<std::string>())
|
||||||
("o, output", "OutputFile", cxxopts::value<std::string>());
|
("o, output", "Output file", cxxopts::value<std::string>())
|
||||||
|
("h, help", "Print help");
|
||||||
|
|
||||||
std::string inputFile, outputFile;
|
std::string inputFile, outputFile;
|
||||||
auto result = options.parse(argc, argv);
|
auto result = options.parse(argc, argv);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if(result.count("help")){
|
||||||
|
std::cout << options.help() << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if(result.count("input") != 1){
|
if(result.count("input") != 1){
|
||||||
std::cout << "Missing input file!" << std::endl;
|
std::cout << "Missing input file!" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -40,4 +46,7 @@ int main(int argc, char** argv){
|
||||||
ClassBuilder classBuilder(result, xmlParser.getDeviceInfo(), xmlParser.getPeripherals());
|
ClassBuilder classBuilder(result, xmlParser.getDeviceInfo(), xmlParser.getPeripherals());
|
||||||
classBuilder.setupBuilders();
|
classBuilder.setupBuilders();
|
||||||
classBuilder.build();
|
classBuilder.build();
|
||||||
|
|
||||||
|
OutputFile oFile(outputFile);
|
||||||
|
std::cout << (oFile.save(classBuilder.getStream()) ? "Successfuly created " : "Failed to create ") << outputFile << std::endl;
|
||||||
}
|
}
|
Loading…
Reference in a new issue