svd2cpp/Src/main.cpp

52 lines
1.9 KiB
C++
Raw Normal View History

2019-11-14 09:34:46 +00:00
#include <iostream>
2019-11-14 07:18:00 +00:00
#include <cxxopts.hpp>
2019-11-14 09:34:46 +00:00
#include <XmlParser.hpp>
2019-11-22 11:57:17 +00:00
#include <ClassBuilder.hpp>
#include <OutputFile.hpp>
2019-11-14 07:18:00 +00:00
2019-11-14 09:34:46 +00:00
int main(int argc, char** argv){
// Create and configure options for the program
cxxopts::Options options("svd2cpp", "Parser from svd files to C++ header");
options.add_options()
("i, input", "File with .svd extention to be parsed", cxxopts::value<std::string>())
("o, output", "Output file", cxxopts::value<std::string>())
("h, help", "Print help");
2019-11-14 09:34:46 +00:00
std::string inputFile, outputFile;
2019-11-22 11:57:17 +00:00
auto result = options.parse(argc, argv);
2019-11-14 09:34:46 +00:00
try
{
if(result.count("help")){
std::cout << options.help() << std::endl;
return 0;
}
2019-11-14 09:34:46 +00:00
if(result.count("input") != 1){
std::cout << "Missing input file!" << std::endl;
return 1;
}
if(result.count("output") != 1){
std::cout << "Missing output file!" << std::endl;
return 1;
}
inputFile = result["input"].as<std::string>();
outputFile = result["output"].as<std::string>();
// std::cout << "Input: " << inputFile << "\tOutput: " << outputFile << std::endl;
2019-11-14 09:34:46 +00:00
}
catch(cxxopts::OptionException& ex){
std::cout << ex.what() << std::endl;
return 2;
2019-11-14 09:34:46 +00:00
}
//Try to parse the file
2019-11-14 09:34:46 +00:00
XmlParser xmlParser(inputFile);
if (auto err = xmlParser.isError()){
std::cout << "There was an error while reading " << inputFile << ":" << std::endl << *err << std::endl;
return 3;
}
xmlParser.parseXml();
2019-11-22 11:57:17 +00:00
ClassBuilder classBuilder(result, xmlParser.getDeviceInfo(), xmlParser.getPeripherals());
classBuilder.setupBuilders();
classBuilder.build();
OutputFile oFile(outputFile);
std::cout << (oFile.save(classBuilder.getStream()) ? "Successfuly created " : "Failed to create ") << outputFile << std::endl;
2019-11-14 06:36:44 +00:00
}