Skip to content

Commit

Permalink
Added: option "-n sfdOverwriteName" (#392) (#605)
Browse files Browse the repository at this point in the history
* Added: option "-n sfdOverwriteName"

* fixed remaining issues

Co-authored-by: Thorsten de Buhr <[email protected]>
  • Loading branch information
grasci-arm and thorstendb-ARM authored Dec 1, 2022
1 parent 70d4208 commit 8499b00
Show file tree
Hide file tree
Showing 9 changed files with 298 additions and 71 deletions.
1 change: 1 addition & 0 deletions tools/svdconv/SVDConv/include/ParseOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ParseOptions
bool SetTestFile(const std::string &filename);
bool SetOutputDirectory(const std::string& filename);
bool SetLogFile(const std::string &m_logFile);
bool SetOutFilenameOverride(const std::string& filename);
bool AddDiagSuppress(const std::string &suppress);
bool SetVerbose(bool bVerbose);
bool ConfigureProgramName(std::string programPath);
Expand Down
47 changes: 25 additions & 22 deletions tools/svdconv/SVDConv/include/SvdOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class SvdOptions {
void SetSuppressWarnings(bool bSuppress = true);
void SetStrict(bool bStrict = true);
bool MakeSurePathExists(const std::string& path);
bool SetOutFilenameOverride(const std::string& filename);
const std::string& GetOutFilenameOverride() const;

std::string GetCurrentDateTime();
std::string GetHeader();
Expand All @@ -49,17 +51,17 @@ class SvdOptions {
void SetCreateFieldsAnsiC (bool bCreateFieldsAnsiC = true) { n_bCreateFieldsAnsiC = bCreateFieldsAnsiC ; }
void SetCreateMacros (bool bCreateMacros = true) { m_bCreateMacros = bCreateMacros ; }
void SetCreateEnumValues (bool bCreateEnumValues = true) { m_bCreateEnumValues = bCreateEnumValues ; }
void SetSuppressPath (bool bSuppressPath = true) { m_bSuppressPath = bSuppressPath ; }
void SetCreateFolder (bool bCreateFolder = true) { m_bCreateFolder = bCreateFolder ; }
void SetShowMissingEnums (bool bShowMissingEnums = true) { m_bShowMissingEnums = bShowMissingEnums ; }
void SetUnderTest (bool bUnderTest = true) { m_bUnderTest = bUnderTest ; }
void SetNoCleanup (bool bNoCleanup = true) { m_bNoCleanup = bNoCleanup ; }
void SetDebugStruct (bool bDebugStruct = true) { m_bDebugStruct = bDebugStruct ; }
void SetDebugHeaderfile (bool bDebugHeaderfile = true) { m_bDebugHeaderfile = bDebugHeaderfile ; }
void SetDebugSfd (bool bDebugSfd = true) { m_bDebugSfd = bDebugSfd ; }
void SetGenerateMapPeripheral (bool bGenerateMapPeripheral = true) { m_bGenerateMapPeripheral = bGenerateMapPeripheral ; }
void SetGenerateMapRegister (bool bGenerateMapRegister = true) { m_bGenerateMapRegister = bGenerateMapRegister ; }
void SetGenerateMapField (bool bGenerateMapField = true) { m_bGenerateMapField = bGenerateMapField ; }
void SetSuppressPath (bool bSuppressPath = true) { m_bSuppressPath = bSuppressPath ; }
void SetCreateFolder (bool bCreateFolder = true) { m_bCreateFolder = bCreateFolder ; }
void SetShowMissingEnums (bool bShowMissingEnums = true) { m_bShowMissingEnums = bShowMissingEnums ; }
void SetUnderTest (bool bUnderTest = true) { m_bUnderTest = bUnderTest ; }
void SetNoCleanup (bool bNoCleanup = true) { m_bNoCleanup = bNoCleanup ; }
void SetDebugStruct (bool bDebugStruct = true) { m_bDebugStruct = bDebugStruct ; }
void SetDebugHeaderfile (bool bDebugHeaderfile = true) { m_bDebugHeaderfile = bDebugHeaderfile ; }
void SetDebugSfd (bool bDebugSfd = true) { m_bDebugSfd = bDebugSfd ; }
void SetGenerateMapPeripheral (bool bGenerateMapPeripheral = true) { m_bGenerateMapPeripheral = bGenerateMapPeripheral ; }
void SetGenerateMapRegister (bool bGenerateMapRegister = true) { m_bGenerateMapRegister = bGenerateMapRegister ; }
void SetGenerateMapField (bool bGenerateMapField = true) { m_bGenerateMapField = bGenerateMapField ; }


bool IsGenerateHeader () const { return m_bGenerateHeader ; }
Expand All @@ -70,17 +72,17 @@ class SvdOptions {
bool IsCreateFieldsAnsiC () const { return n_bCreateFieldsAnsiC ; }
bool IsCreateMacros () const { return m_bCreateMacros ; }
bool IsCreateEnumValues () const { return m_bCreateEnumValues ; }
bool IsSuppressPath () const { return m_bSuppressPath ; }
bool IsCreateFolder () const { return m_bCreateFolder ; }
bool IsShowMissingEnums () const { return m_bShowMissingEnums ; }
bool IsUnderTest () const { return m_bUnderTest ; }
bool IsNoCleanup () const { return m_bNoCleanup ; }
bool IsDebugStruct () const { return m_bDebugStruct ; }
bool IsDebugHeaderfile () const { return m_bDebugHeaderfile ; }
bool IsDebugSfd () const { return m_bDebugSfd ; }
bool IsGenerateMapPeripheral () const { return m_bGenerateMapPeripheral ; }
bool IsGenerateMapRegister () const { return m_bGenerateMapRegister ; }
bool IsGenerateMapField () const { return m_bGenerateMapField ; }
bool IsSuppressPath () const { return m_bSuppressPath ; }
bool IsCreateFolder () const { return m_bCreateFolder ; }
bool IsShowMissingEnums () const { return m_bShowMissingEnums ; }
bool IsUnderTest () const { return m_bUnderTest ; }
bool IsNoCleanup () const { return m_bNoCleanup ; }
bool IsDebugStruct () const { return m_bDebugStruct ; }
bool IsDebugHeaderfile () const { return m_bDebugHeaderfile ; }
bool IsDebugSfd () const { return m_bDebugSfd ; }
bool IsGenerateMapPeripheral () const { return m_bGenerateMapPeripheral ; }
bool IsGenerateMapRegister () const { return m_bGenerateMapRegister ; }
bool IsGenerateMapField () const { return m_bGenerateMapField ; }

bool IsGenerateMap() const;

Expand Down Expand Up @@ -110,6 +112,7 @@ class SvdOptions {
std::string m_logPath;
std::string m_programName;
std::string m_outputDir;
std::string m_outfileOverride;
};

#endif // PACKOPTIONS_H
31 changes: 24 additions & 7 deletions tools/svdconv/SVDConv/src/ParseOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,19 @@ bool ParseOptions::SetLogFile(const string& logFile)
return m_options.SetLogFile(logFile);
}

/**
* @brief option "n"
* @param filename Override output file name
* @return
*/
bool ParseOptions::SetOutFilenameOverride(const string& filename)
{
return m_options.SetOutFilenameOverride(filename);
}

/**
* @brief option "generate="
* @param
* @param
* @return passed / failed
*/
bool ParseOptions::ParseOptGenerate(const string& opt)
Expand All @@ -124,6 +134,7 @@ bool ParseOptions::ParseOptGenerate(const string& opt)
m_options.SetGenerateSfd();
}
else if(opt == "sfr") {
m_options.SetGenerateSfd();
m_options.SetGenerateSfr();
}
else if(opt == "peripheralMap") {
Expand All @@ -141,7 +152,7 @@ bool ParseOptions::ParseOptGenerate(const string& opt)

/**
* @brief option "fields="
* @param
* @param
* @return passed / failed
*/
bool ParseOptions::ParseOptFields(const string& opt)
Expand All @@ -161,13 +172,13 @@ bool ParseOptions::ParseOptFields(const string& opt)
else if(tmpOpt == "enum") {
m_options.SetCreateEnumValues();
}

return true;
}

/**
* @brief option "debug="
* @param
* @param
* @return passed / failed
*/
bool ParseOptions::ParseOptDebug(const string& opt)
Expand All @@ -186,7 +197,7 @@ bool ParseOptions::ParseOptDebug(const string& opt)
else if(tmpOpt == "break") {
m_options.HaltProgramExecution();
}

return true;
}

Expand Down Expand Up @@ -287,7 +298,7 @@ ParseOptions::Result ParseOptions::ParseOptsFileLine(const string& line, vector<
}

if(!bStringFound && c == '#') { // comment, skip line from here
break;
break;
}

if(!bStringFound && isspace(c)) {
Expand Down Expand Up @@ -411,6 +422,7 @@ ParseOptions::Result ParseOptions::ParseOpts(int argc, const char* argv[])
( "nocleanup" , "Do not delete intermediate files" , cxxopts::value<bool>()->default_value("false") )
( "quiet" , "No output on console" , cxxopts::value<bool>()->default_value("false") )
( "debug" , "Add information to generated files: struct/header/sfd/break" , cxxopts::value<std::vector<std::string>>() )
( "n" , "SFD Output file name" , cxxopts::value<string>() )
( "version" , "Show program version")
( "h,help" , "Print usage")
;
Expand Down Expand Up @@ -442,6 +454,11 @@ ParseOptions::Result ParseOptions::ParseOpts(int argc, const char* argv[])
bOk = false;
}
}
if(parseResult.count("n")) {
if(!SetOutFilenameOverride(parseResult["n"].as<string>())) {
bOk = false;
}
}
if(parseResult.count("v")) {
if(!SetVerbose(true)) {
bOk = false;
Expand Down Expand Up @@ -534,7 +551,7 @@ ParseOptions::Result ParseOptions::ParseOpts(int argc, const char* argv[])
cerr << fileName << " error: " << e.what() << endl;
return Result::Error;
}

if(!bOk) {
return Result::Error;
}
Expand Down
12 changes: 12 additions & 0 deletions tools/svdconv/SVDConv/src/SvdOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,18 @@ bool SvdOptions::MakeSurePathExists(const string& path)
return RteFsUtils::CreateDirectories(path);
}

bool SvdOptions::SetOutFilenameOverride(const string& filename)
{
m_outfileOverride = RteUtils::ExtractFileBaseName(filename);

return true;
}

const string& SvdOptions::GetOutFilenameOverride() const
{
return m_outfileOverride;
}

/**
* @brief set output directory
* @param filename string name
Expand Down
7 changes: 2 additions & 5 deletions tools/svdconv/SVDGenerator/src/SfrccInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SfrccInterface::SfrccInterface()
#endif

string modPath = modulePath;
string::size_type pos = modPath.find_last_of('/');
string::size_type pos = modPath.find_last_of('\\'); // do not change this to slash!
if(pos != string::npos && pos > 1) {
modPath.erase(pos, modPath.length());
SetModulePath(modPath);
Expand Down Expand Up @@ -104,10 +104,7 @@ bool SfrccInterface::Compile(const string& fileName, bool bCleanup /*= true*/)
int32_t ret = _pclose(pPipe);
delete[] logBuf;

if(ret) {
LogMsg("M132", MSG(sfrccMsg)); // on error or warning of SfrCC2
}
else {
if(!sfrccMsg.empty()) {
LogMsg("M125", MSG(sfrccMsg)); // verbose message
}

Expand Down
37 changes: 23 additions & 14 deletions tools/svdconv/SVDGenerator/src/SvdGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bool SvdGenerator::CmsisHeaderFile(SvdDevice *device, const string &path)

FileHeaderInfo fileHeaderInfo;
SetFileHeader(fileHeaderInfo, device);

HeaderData *headerData = new HeaderData(fileHeaderInfo, m_options);
headerData->Create(device, fileName);

Expand All @@ -91,7 +91,7 @@ bool SvdGenerator::CmsisPartitionFile(SvdDevice *device, const string &path)

FileHeaderInfo fileHeaderInfo;
SetFileHeader(fileHeaderInfo, device);

PartitionData *partitionData = new PartitionData(fileHeaderInfo, m_options);
partitionData->Create(device, fileName);

Expand All @@ -108,10 +108,10 @@ bool SvdGenerator::SfdFile(SvdDevice *device, const string &path)

FileHeaderInfo fileHeaderInfo;
SetFileHeader(fileHeaderInfo, device);

const auto sfdData = new SfdData(fileHeaderInfo, m_options);
sfdData->Create(device, fileName);

delete sfdData;

return true;
Expand All @@ -125,7 +125,7 @@ bool SvdGenerator::SfrFile(SvdDevice *device, const string &path)

const auto sfrIf = new SfrccInterface();
bool status = sfrIf->Compile(sfdFileName);

delete sfrIf;

return status;
Expand All @@ -139,9 +139,9 @@ bool SvdGenerator::PeripheralListing(SvdDevice *device, const string &path)

FileHeaderInfo fileHeaderInfo;
SetFileHeader(fileHeaderInfo, device);

const auto memoryMap = new MemoryMap(fileHeaderInfo);
memoryMap->CreateMap(device, fileName, MAPLEVEL_PERIPHERAL);
memoryMap->CreateMap(device, fileName, MAPLEVEL_PERIPHERAL);
delete memoryMap;

return true;
Expand All @@ -155,9 +155,9 @@ bool SvdGenerator::RegisterListing(SvdDevice *device, const string &path)

FileHeaderInfo fileHeaderInfo;
SetFileHeader(fileHeaderInfo, device);

const auto memoryMap = new MemoryMap(fileHeaderInfo);
memoryMap->CreateMap(device, fileName, MAPLEVEL_REGISTER);
memoryMap->CreateMap(device, fileName, MAPLEVEL_REGISTER);
delete memoryMap;

return true;
Expand All @@ -171,17 +171,17 @@ bool SvdGenerator::FieldListing(SvdDevice *device, const string &path)

FileHeaderInfo fileHeaderInfo;
SetFileHeader(fileHeaderInfo, device);

const auto memoryMap = new MemoryMap(fileHeaderInfo);
memoryMap->CreateMap(device, fileName, MAPLEVEL_FIELD);
memoryMap->CreateMap(device, fileName, MAPLEVEL_FIELD);
delete memoryMap;

return true;
}

const string SvdGenerator::GetDeviceName()
{
return m_deviceName;
return m_deviceName;
}

string SvdGenerator::GetCmsisHeaderFileName()
Expand All @@ -200,9 +200,18 @@ string SvdGenerator::GetSfdFileName()
{
string name = GetOutPath();
if(!name.empty()) {
name += '/';
name += "/";
}
name += GetDeviceName();

const string& overrideName = m_options.GetOutFilenameOverride();

if(!overrideName.empty()) {
name += overrideName;
}
else {
name += GetDeviceName();
}

name += ".sfd";

return name;
Expand Down
Loading

0 comments on commit 8499b00

Please sign in to comment.