Skip to content

Commit e06f777

Browse files
committed
Added start info as user defined text.
1 parent 12c735f commit e06f777

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

src/codegen/c-main-generator.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ void CiMainGenerator::Generate(std::vector<MessageDescriptor_t*>& msgs, const Fs
5050

5151
void CiMainGenerator::Gen_MainHeader()
5252
{
53+
// write comment start text
54+
if (fdesc->start_info.size() > 0)
55+
{
56+
// replace all '\n' on "\n //" for c code comment text
57+
fwriter->AppendLine("// " + std::regex_replace(fdesc->start_info, std::regex("\n"), "\n// "));
58+
}
59+
5360
fwriter->AppendLine("#pragma once", 2);
5461
fwriter->AppendLine("#ifdef __cplusplus\nextern \"C\" {\n#endif", 2);
5562
fwriter->AppendLine("#include <stdint.h>", 2);
@@ -196,6 +203,12 @@ void CiMainGenerator::Gen_MainHeader()
196203

197204
void CiMainGenerator::Gen_MainSource()
198205
{
206+
if (fdesc->start_info.size() > 0)
207+
{
208+
// replace all '\n' on "\n //" for c code comment text
209+
fwriter->AppendLine("// " + std::regex_replace(fdesc->start_info, std::regex("\n"), "\n// "));
210+
}
211+
199212
// include main header file
200213
fwriter->AppendLine(StrPrint("#include \"%s\"", fdesc->core_h.fname.c_str()), 3);
201214

@@ -257,6 +270,12 @@ void CiMainGenerator::Gen_MainSource()
257270

258271
void CiMainGenerator::Gen_ConfigHeader()
259272
{
273+
if (fdesc->start_info.size() > 0)
274+
{
275+
// replace all '\n' on "\n //" for c code comment text
276+
fwriter->AppendLine("// " + std::regex_replace(fdesc->start_info, std::regex("\n"), "\n// "));
277+
}
278+
260279
fwriter->AppendLine("#pragma once", 2);
261280

262281
fwriter->AppendLine("/* include common dbccode configurations */");
@@ -331,6 +350,12 @@ void CiMainGenerator::Gen_ConfigHeader()
331350

332351
void CiMainGenerator::Gen_FMonHeader()
333352
{
353+
if (fdesc->start_info.size() > 0)
354+
{
355+
// replace all '\n' on "\n //" for c code comment text
356+
fwriter->AppendLine("// " + std::regex_replace(fdesc->start_info, std::regex("\n"), "\n// "));
357+
}
358+
334359
fwriter->AppendLine("#pragma once", 2);
335360

336361
fwriter->AppendLine("#ifdef __cplusplus\nextern \"C\" {\n#endif", 2);
@@ -363,6 +388,12 @@ separated .c file. If it won't be done the linkage error will happen\n*/", 2);
363388

364389
void CiMainGenerator::Gen_FMonSource()
365390
{
391+
if (fdesc->start_info.size() > 0)
392+
{
393+
// replace all '\n' on "\n //" for c code comment text
394+
fwriter->AppendLine("// " + std::regex_replace(fdesc->start_info, std::regex("\n"), "\n// "));
395+
}
396+
366397
fwriter->AppendLine(StrPrint("#include \"%s\"", fdesc->fmon_h.fname.c_str()), 2);
367398
// put diagmonitor ifdef selection for including @drv-fmon header
368399
// with FMon_* signatures to call from unpack function
@@ -376,7 +407,7 @@ next generation will completely clear all manually added code (!)\n\
376407
for (size_t num = 0; num < sigprt->sigs_expr.size(); num++)
377408
{
378409
auto msg = &(sigprt->sigs_expr[num]->msg);
379-
fwriter->AppendLine(StrPrint("void FMon_%s_%s(FrameMonitor_t* _mon)\n{\n}\n",
410+
fwriter->AppendLine(StrPrint("void FMon_%s_%s(FrameMonitor_t* _mon)\n{\n (void)_mon;\n}\n",
380411
msg->Name.c_str(), fdesc->drvname.c_str()));
381412
}
382413

src/codegen/c-util-generator.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "c-util-generator.h"
22
#include "helpers/formatter.h"
33
#include <algorithm>
4+
#include <regex>
45

56
static const std::string openguard = "#ifdef __cplusplus\n\
67
extern \"C\" {\n\
@@ -96,6 +97,11 @@ void CiUtilGenerator::PrintHeader()
9697
{
9798
tof->Flush();
9899

100+
if (fdesc->start_info.size() > 0)
101+
{
102+
tof->AppendLine("// " + std::regex_replace(fdesc->start_info, std::regex("\n"), "\n// "));
103+
}
104+
99105
tof->AppendLine("#pragma once", 2);
100106

101107
tof->AppendLine(openguard.c_str(), 2);
@@ -171,6 +177,11 @@ void CiUtilGenerator::PrintHeader()
171177

172178
void CiUtilGenerator::PrintSource()
173179
{
180+
if (fdesc->start_info.size() > 0)
181+
{
182+
tof->AppendLine("// " + std::regex_replace(fdesc->start_info, std::regex("\n"), "\n// "));
183+
}
184+
174185
tof->AppendLine(StrPrint("#include \"%s\"", fdesc->util_h.fname.c_str()), 2);
175186

176187
// optional RX and TX struct allocations

src/codegen/fs-creator.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ FsCreator::FsCreator()
1111
{
1212
}
1313

14-
bool FsCreator::PrepareDirectory(std::string drvname, std::string basepath, bool)
14+
bool FsCreator::PrepareDirectory(std::string drvname, std::string basepath, bool, std::string& strinfo)
1515
{
1616
bool ret = false;
1717

@@ -96,6 +96,14 @@ bool FsCreator::PrepareDirectory(std::string drvname, std::string basepath, bool
9696

9797
snprintf(_tmpb, kTmpLen, "%s_AUTO_CSM", FS.DRVNAME.c_str());
9898
FS.usecsm_def = _tmpb;
99+
100+
// load start info to fdescriptor
101+
FS.start_info.clear();
102+
103+
if (strinfo.size() > 0)
104+
{
105+
FS.start_info = strinfo;
106+
}
99107
}
100108

101109
return ret;

src/codegen/fs-creator.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ typedef struct
2828
std::string usesigfloat_def;
2929
std::string useroll_def;
3030
std::string usecsm_def;
31+
// inforamtion to be placed at the start of each source file
32+
std::string start_info;
3133

3234
} FsDescriptor_t;
3335

@@ -40,7 +42,7 @@ class FsCreator {
4042
public:
4143
FsCreator();
4244

43-
bool PrepareDirectory(std::string drvname, std::string basepath, bool rw);
45+
bool PrepareDirectory(std::string drvname, std::string basepath, bool rw, std::string& info);
4446

4547
FsDescriptor_t FS;
4648

0 commit comments

Comments
 (0)