Skip to content

Optional sources generation #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jul 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion astyle-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if [ $? -ne 0 ]; then
exit 1
fi

FILES=`find . | grep -P "^(?!(.*\/thirdparty|.*\/lib\/dbc|.*\/bin|.*\/doc|.*\/utl|.*\/tst|.*\/generated*)).*\.(c|cpp|h)$"`
FILES=`find . | grep -P "^(?!(.*\/test\/gencode)).*\.(c|cpp|h)$"`
for FILE in $FILES; do
# compare files
# $ASTYLE $OPTIONS < $FILE | cmp -s $FILE -
Expand Down
9 changes: 9 additions & 0 deletions docs/RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## v2.4 24.07.2022

### Added

- Three new CLI keys to optionally disable some source code generation (see help)
- Added more tests

---

## v2.3 19.07.2022

### Changed
Expand Down
1 change: 1 addition & 0 deletions rm-driver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(cd test/gencode && rm -r *)
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ add_executable(coderdbc
${CMAKE_CURRENT_SOURCE_DIR}/helpers/formatter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/parser/dbclineparser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/parser/dbcscanner.cpp
${CMAKE_CURRENT_SOURCE_DIR}/options-parser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/app.cpp
${CMAKE_CURRENT_SOURCE_DIR}/maincli.cpp
)
Expand All @@ -37,7 +38,10 @@ enable_testing()

add_executable(
cctest
${CMAKE_CURRENT_SOURCE_DIR}/helpers/formatter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/options-parser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tests/args-test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tests/bitext-test.cpp
)

target_link_libraries(
Expand Down
74 changes: 23 additions & 51 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,6 @@ void CoderApp::Run()
}
}

bool CoderApp::ParseParams()
{
for (size_t i = 0; i < Params.size(); i++)
{
if (Params[i].first.compare("-dbc") == 0)
{
dbc.value = Params[i].second;
dbc.ok = true;
}
else if (Params[i].first.compare("-out") == 0)
{
outdir.value = Params[i].second;
outdir.ok = true;
}
else if (Params[i].first.compare("-drvname") == 0)
{
drvname.value = make_c_name(Params[i].second);
drvname.ok = true;

if (drvname.value.length() == 0)
{
drvname.ok = false;
}
}
else if (Params[i].first.compare("-rw") == 0)
{
rewrite_src = true;
}
else if (Params[i].first.compare("-nodeutils") == 0)
{
gen_nodeutils = true;
}
else if (Params[i].first.compare("-help") == 0)
{
return false;
}
}

return (dbc.ok && outdir.ok && drvname.ok);
}

void CoderApp::GenerateCode()
{
auto scanner = std::make_unique<DbcScanner>();
Expand All @@ -76,17 +35,17 @@ void CoderApp::GenerateCode()

std::ifstream reader;

std::cout << "dbc file : " << dbc.value << std::endl;
std::cout << "gen path : " << outdir.value << std::endl;
std::cout << "drv name : " << drvname.value << std::endl;
std::cout << "dbc file : " << Params.dbc.value << std::endl;
std::cout << "gen path : " << Params.outdir.value << std::endl;
std::cout << "drv name : " << Params.drvname.value << std::endl;

if (std::filesystem::exists(dbc.value) == false)
if (std::filesystem::exists(Params.dbc.value) == false)
{
std::cout << "DBC file is not exists!" << std::endl;
return;
}

reader.open(dbc.value);
reader.open(Params.dbc.value);

std::istream& s = reader;

Expand All @@ -95,7 +54,13 @@ void CoderApp::GenerateCode()
std::string info("");

// create main destination directory
auto ret = fscreator->PrepareDirectory(drvname.value.c_str(), outdir.value.c_str(), rewrite_src, info);
fscreator->Configure(Params.drvname.value, Params.outdir.value, info, scanner->dblist.ver.hi, scanner->dblist.ver.low);

auto ret = fscreator->PrepareDirectory(Params.is_rewrite);

fscreator->FS.gen.no_config = Params.is_noconfig;
fscreator->FS.gen.no_inc = Params.is_nocanmon;
fscreator->FS.gen.no_fmon = Params.is_nofmon;

if (ret)
{
Expand All @@ -108,7 +73,7 @@ void CoderApp::GenerateCode()

// check if option --node-utils is requested, when requested binutil generation
// wiil be performed on each node from DBC file in accordance to its RX / TX subscription
if (gen_nodeutils)
if (Params.is_nodeutils)
{
std::vector<std::string> nodes;

Expand Down Expand Up @@ -144,7 +109,7 @@ void CoderApp::GenerateCode()
// for each node in collection perform specific bin-util generation
for (size_t node = 0; node < nodes.size(); node++)
{
std::string util_name = nodes[node] + "_" + drvname.value;
std::string util_name = nodes[node] + "_" + Params.drvname.value;

// set new driver name for current node
fscreator->FS.gen.drvname = str_tolower(util_name);
Expand Down Expand Up @@ -183,7 +148,7 @@ void CoderApp::GenerateCode()

if (ret)
{
ciugen->Generate(scanner->dblist, fscreator->FS, groups, drvname.value);
ciugen->Generate(scanner->dblist, fscreator->FS, groups, Params.drvname.value);
}
}
}
Expand All @@ -198,11 +163,15 @@ void CoderApp::GenerateCode()

if (ret)
{
ciugen->Generate(scanner->dblist, fscreator->FS, groups, drvname.value);
ciugen->Generate(scanner->dblist, fscreator->FS, groups, Params.drvname.value);
}
}
}

bool CoderApp::ParseParams()
{
return (Params.dbc.ok && Params.outdir.ok && Params.drvname.ok) && (Params.is_help == false);
}

void CoderApp::PrintHelp()
{
Expand All @@ -222,6 +191,9 @@ void CoderApp::PrintHelp()
std::cout << " \t\t will create new sud-directory with source files (000, 001, ... etc)" << std::endl;
std::cout << " \t\t '-rw' option enables rewriting: all source files previously generated" << std::endl;
std::cout << " \t\t will be replaced by new ones" << std::endl;
std::cout << " -noconfig:\t no {drivername}-config and dbccodeconfig generation" << std::endl;
std::cout << " -noinc:\t no canmonitorutil.h generation" << std::endl;
std::cout << " -nofmon:\t no ***-fmon.c generation" << std::endl;
std::cout << std::endl;

std::cout << "examples:" << std::endl;
Expand Down
18 changes: 3 additions & 15 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
#include <stdint.h>
#include <vector>
#include <string>
#include <options-parser.h>

class CoderApp {
public:
CoderApp(const std::vector<std::pair<std::string, std::string>>& params) : Params(params) {}
CoderApp(const OptionsParser::Pairs& params) : Params(params) {}

void Run();

Expand All @@ -15,18 +16,5 @@ class CoderApp {
void GenerateCode();
void PrintHelp();

typedef struct app
{
std::string value;
bool ok{false};
} StrParam_t;

const std::vector<std::pair<std::string, std::string>>& Params;

StrParam_t dbc{};
StrParam_t outdir{};
StrParam_t drvname{};

bool rewrite_src{false};
bool gen_nodeutils{false};
const OptionsParser::Pairs& Params;
};
97 changes: 22 additions & 75 deletions src/codegen/c-main-generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ CiMainGenerator::CiMainGenerator()

void CiMainGenerator::Generate(DbcMessageList_t& dlist, const AppSettings_t& fsd)
{
p_dlist = &dlist;
// Load income messages to sig printer
sigprt->LoadMessages(dlist.msgs);

Expand All @@ -61,17 +60,26 @@ void CiMainGenerator::Generate(DbcMessageList_t& dlist, const AppSettings_t& fsd
// 4 step is to pring fmon head file
Gen_FMonHeader();

// 5 step is to print fmon source file
Gen_FMonSource();
if (!fsd.gen.no_fmon)
{
// 5 step is to print fmon source file
Gen_FMonSource();
}

// 6 step is to print template for drv-config.h
Gen_ConfigHeader();
if (!fsd.gen.no_config)
{
// 6 step is to print template for drv-config.h
Gen_ConfigHeader();

// 7 step is to print canmonitorutil.h template code
Gen_CanMonUtil();
// 8 step is to print dbccodeconf.h template
Gen_DbcCodeConf();
}

// 8 step is to print dbccodeconf.h template
Gen_DbcCodeConf();
if (!fsd.gen.no_inc)
{
// 7 step is to print canmonitorutil.h template code
Gen_CanMonUtil();
}
}

void CiMainGenerator::Gen_MainHeader()
Expand All @@ -91,8 +99,8 @@ void CiMainGenerator::Gen_MainHeader()
fwriter->Append();

fwriter->Append("// DBC file version");
fwriter->Append("#define %s (%uU)", fdesc->gen.verhigh_def.c_str(), p_dlist->ver.hi);
fwriter->Append("#define %s (%uU)", fdesc->gen.verlow_def.c_str(), p_dlist->ver.low);
fwriter->Append("#define %s (%uU)", fdesc->gen.verhigh_def.c_str(), fdesc->gen.hiver);
fwriter->Append("#define %s (%uU)", fdesc->gen.verlow_def.c_str(), fdesc->gen.lowver);
fwriter->Append();

fwriter->Append("// include current dbc-driver compilation config");
Expand Down Expand Up @@ -290,7 +298,7 @@ void CiMainGenerator::Gen_MainSource()

fwriter->Append("// DBC file version");
fwriter->Append("#if (%s != (%uU)) || (%s != (%uU))",
fdesc->gen.verhigh_def.c_str(), p_dlist->ver.hi, fdesc->gen.verlow_def.c_str(), p_dlist->ver.low);
fdesc->gen.verhigh_def.c_str(), fdesc->gen.hiver, fdesc->gen.verlow_def.c_str(), fdesc->gen.lowver);

fwriter->Append("#error The %s dbc source files have different versions", fdesc->gen.DRVNAME.c_str());
fwriter->Append("#endif");
Expand Down Expand Up @@ -376,76 +384,15 @@ void CiMainGenerator::Gen_ConfigHeader()

void CiMainGenerator::Gen_FMonHeader()
{
if (fdesc->gen.start_info.size() > 0)
{
// replace all '\n' on "\n //" for c code comment text
fwriter->Append("// " + std::regex_replace(fdesc->gen.start_info, std::regex("\n"), "\n// "));
}

fwriter->Append("#pragma once");
fwriter->Append();

fwriter->Append("#ifdef __cplusplus\nextern \"C\" {\n#endif");
fwriter->Append();

fwriter->Append("// DBC file version");
fwriter->Append("#define %s_FMON (%uU)", fdesc->gen.verhigh_def.c_str(), p_dlist->ver.hi);
fwriter->Append("#define %s_FMON (%uU)", fdesc->gen.verlow_def.c_str(), p_dlist->ver.low);
fwriter->Append();

fwriter->Append("#include <%s-config.h>", fdesc->gen.drvname.c_str());
fwriter->Append();

// put diagmonitor ifdef selection for including @drv-fmon header
// with FMon_* signatures to call from unpack function
fwriter->Append("#ifdef %s", fdesc->gen.usemon_def.c_str());
fwriter->Append();
fwriter->Append("#include <canmonitorutil.h>");
fwriter->Append("/*\n\
This file contains the prototypes of all the functions that will be called\n\
from each Unpack_*name* function to detect DBC related errors\n\
It is the user responsibility to defined these functions in the\n\
separated .c file. If it won't be done the linkage error will happen\n*/");
fwriter->Append();

MonGenerator mongen;

mongen.FillHeader((*fwriter), sigprt->sigs_expr, fdesc->gen);

fwriter->Append("#endif // %s", fdesc->gen.usemon_def.c_str());
fwriter->Append();

fwriter->Append("#ifdef __cplusplus\n}\n#endif");

mongen.FillHeader((*fwriter), sigprt->sigs_expr, *fdesc);
fwriter->Flush(fdesc->file.fmon_h.fpath);
}

void CiMainGenerator::Gen_FMonSource()
{
if (fdesc->gen.start_info.size() > 0)
{
// replace all '\n' on "\n //" for c code comment text
fwriter->Append("// " + std::regex_replace(fdesc->gen.start_info, std::regex("\n"), "\n// "));
}

fwriter->Append("#include <%s>", fdesc->file.fmon_h.fname.c_str());
fwriter->Append();
// put diagmonitor ifdef selection for including @drv-fmon header
// with FMon_* signatures to call from unpack function
fwriter->Append("#ifdef %s", fdesc->gen.usemon_def.c_str());
fwriter->Append();

fwriter->Append("/*\n\
Put the monitor function content here, keep in mind -\n\
next generation will completely clear all manually added code (!)\n\
*/\n\n");

MonGenerator mongen;

mongen.FillSource((*fwriter), sigprt->sigs_expr, fdesc->gen);

fwriter->Append("#endif // %s", fdesc->gen.usemon_def.c_str());

mongen.FillSource((*fwriter), sigprt->sigs_expr, *fdesc);
fwriter->Flush(fdesc->file.fmon_c.fpath);
}

Expand Down
1 change: 0 additions & 1 deletion src/codegen/c-main-generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ class CiMainGenerator {
std::unique_ptr<CSigPrinter> sigprt;
std::unique_ptr<FileWriter> fwriter;
const AppSettings_t* fdesc;
const DbcMessageList_t* p_dlist;
};
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy