Internals: Cleanup constructors etc. No functional change.

This commit is contained in:
Wilson Snyder 2022-08-29 22:15:06 -04:00
parent 0a3a15a66e
commit d47a37fb76
4 changed files with 56 additions and 56 deletions

View File

@ -739,8 +739,8 @@ class EmitVFileVisitor final : public EmitVBaseVisitor {
public:
EmitVFileVisitor(AstNode* nodep, V3OutFile* ofp, bool trackText, bool suppressUnknown)
: EmitVBaseVisitor{suppressUnknown, nullptr} {
m_ofp = ofp;
: EmitVBaseVisitor{suppressUnknown, nullptr}
, m_ofp{ofp} {
m_trackText = trackText;
iterate(nodep);
}
@ -791,7 +791,7 @@ class EmitVPrefixedFormatter final : public V3OutFormatter {
m_os << " ";
m_os << m_prefix;
}
m_column++;
++m_column;
m_os << chr;
}
}
@ -877,6 +877,6 @@ void V3EmitV::emitvFiles() {
void V3EmitV::debugEmitV(const string& filename) {
UINFO(2, __FUNCTION__ << ": " << endl);
V3OutVFile of(filename);
V3OutVFile of{filename};
{ EmitVFileVisitor{v3Global.rootp(), &of, true, true}; }
}

View File

@ -658,7 +658,7 @@ int V3OutFormatter::endLevels(const char* strg) {
int levels = m_indentLevel;
{
const char* cp = strg;
while (isspace(*cp)) cp++;
while (isspace(*cp)) ++cp;
switch (*cp) {
case '\n': // Newlines.. No need for whitespace before it
return 0;
@ -668,12 +668,12 @@ int V3OutFormatter::endLevels(const char* strg) {
{
// label/public/private: Deindent by 2 spaces
const char* mp = cp;
for (; isalnum(*mp); mp++) {}
for (; isalnum(*mp); ++mp) {}
if (mp[0] == ':' && mp[1] != ':') return (levels - m_blockIndent / 2);
}
}
// We want "} else {" to be one level to the left of normal
for (const char* cp = strg; *cp; cp++) {
for (const char* cp = strg; *cp; ++cp) {
switch (*cp) {
case '}':
case ')': levels -= m_blockIndent; break;
@ -704,7 +704,7 @@ void V3OutFormatter::puts(const char* strg) {
}
bool wordstart = true;
bool equalsForBracket = false; // Looking for "= {"
for (const char* cp = strg; *cp; cp++) {
for (const char* cp = strg; *cp; ++cp) {
putcNoTracking(*cp);
if (isalpha(*cp)) {
if (wordstart && m_lang == LA_VERILOG && tokenStart(cp)) indentInc();
@ -712,7 +712,7 @@ void V3OutFormatter::puts(const char* strg) {
}
switch (*cp) {
case '\n':
m_lineno++;
++m_lineno;
wordstart = true;
if (cp[1] == '\0') {
// Add the indent later, may be a indentInc/indentDec
@ -733,7 +733,7 @@ void V3OutFormatter::puts(const char* strg) {
if (m_lang == LA_C || m_lang == LA_VERILOG) {
if (cp > strg && cp[-1] == '/' && !m_inStringLiteral) {
// Output ignoring contents to EOL
cp++;
++cp;
while (*cp && cp[1] && cp[1] != '\n') putcNoTracking(*cp++);
if (*cp) putcNoTracking(*cp);
}
@ -833,7 +833,7 @@ void V3OutFormatter::putcNoTracking(char chr) {
}
switch (chr) {
case '\n':
m_lineno++;
++m_lineno;
m_column = 0;
m_nobreak = true;
break;
@ -841,9 +841,9 @@ void V3OutFormatter::putcNoTracking(char chr) {
case ' ':
case '(':
case '|':
case '&': m_column++; break;
case '&': ++m_column; break;
default:
m_column++;
++m_column;
m_nobreak = false;
break;
}

View File

@ -156,9 +156,6 @@ public:
puts(strg);
}
bool exceededWidth() const { return m_column > m_commaWidth; }
bool tokenMatch(const char* cp, const char* cmp);
bool tokenStart(const char* cp);
bool tokenEnd(const char* cp);
void indentInc() { m_indentLevel += m_blockIndent; }
void indentDec() {
m_indentLevel -= m_blockIndent;
@ -175,6 +172,9 @@ public:
static string indentSpaces(int num);
// Add escaped characters to strings
static string quoteNameControls(const string& namein, Language lang = LA_C);
static bool tokenMatch(const char* cp, const char* cmp);
static bool tokenStart(const char* cp);
static bool tokenEnd(const char* cp);
// CALLBACKS - MUST OVERRIDE
virtual void putcOutput(char chr) = 0;

View File

@ -66,10 +66,10 @@ private:
// VISITORS
virtual void visit(AstNetlist* nodep) override {
m_vfilep
= new AstVFile(nodep->fileline(), v3Global.opt.makeDir() + "/" + m_libName + ".sv");
= new AstVFile{nodep->fileline(), v3Global.opt.makeDir() + "/" + m_libName + ".sv"};
nodep->addFilesp(m_vfilep);
m_cfilep
= new AstCFile(nodep->fileline(), v3Global.opt.makeDir() + "/" + m_libName + ".cpp");
= new AstCFile{nodep->fileline(), v3Global.opt.makeDir() + "/" + m_libName + ".cpp"};
nodep->addFilesp(m_cfilep);
iterateChildren(nodep);
}
@ -95,7 +95,7 @@ private:
}
void addComment(AstTextBlock* txtp, FileLine* fl, const string& comment) {
txtp->addNodep(new AstComment(fl, comment));
txtp->addNodep(new AstComment{fl, comment});
}
void hashComment(AstTextBlock* txtp, FileLine* fl) {
@ -132,7 +132,7 @@ private:
void createSvFile(FileLine* fl, AstNodeModule* modp) {
// Comments
AstTextBlock* const txtp = new AstTextBlock(fl);
AstTextBlock* const txtp = new AstTextBlock{fl};
addComment(txtp, fl, "Wrapper module for DPI protected library");
addComment(txtp, fl,
"This module requires lib" + m_libName + ".a or lib" + m_libName
@ -142,7 +142,7 @@ private:
" to use DPI libraries\n");
// Module declaration
m_modPortsp = new AstTextBlock(fl, "module " + m_libName + " (\n", false, true);
m_modPortsp = new AstTextBlock{fl, "module " + m_libName + " (\n", false, true};
txtp->addNodep(m_modPortsp);
txtp->addText(fl, ");\n\n");
@ -170,31 +170,31 @@ private:
txtp->addText(fl, "import \"DPI-C\" function chandle " + m_libName
+ "_protectlib_create(string scope__V);\n\n");
comboComment(txtp, fl);
m_comboPortsp = new AstTextBlock(fl,
m_comboPortsp = new AstTextBlock{fl,
"import \"DPI-C\" function longint " + m_libName
+ "_protectlib_combo_update "
"(\n",
false, true);
false, true};
m_comboPortsp->addText(fl, "chandle handle__V\n");
txtp->addNodep(m_comboPortsp);
txtp->addText(fl, ");\n\n");
seqComment(txtp, fl);
if (m_hasClk) {
m_seqPortsp = new AstTextBlock(fl,
m_seqPortsp = new AstTextBlock{fl,
"import \"DPI-C\" function longint " + m_libName
+ "_protectlib_seq_update"
"(\n",
false, true);
false, true};
m_seqPortsp->addText(fl, "chandle handle__V\n");
txtp->addNodep(m_seqPortsp);
txtp->addText(fl, ");\n\n");
}
comboIgnoreComment(txtp, fl);
m_comboIgnorePortsp = new AstTextBlock(fl,
m_comboIgnorePortsp = new AstTextBlock{fl,
"import \"DPI-C\" function void " + m_libName
+ "_protectlib_combo_ignore"
"(\n",
false, true);
false, true};
m_comboIgnorePortsp->addText(fl, "chandle handle__V\n");
txtp->addNodep(m_comboIgnorePortsp);
txtp->addText(fl, ");\n\n");
@ -225,17 +225,17 @@ private:
if (m_hasClk) txtp->addText(fl, "time last_seq_seqnum__V;\n");
txtp->addText(fl, "\n");
m_comboDeclsp = new AstTextBlock(fl);
m_comboDeclsp = new AstTextBlock{fl};
txtp->addNodep(m_comboDeclsp);
m_seqDeclsp = new AstTextBlock(fl);
m_seqDeclsp = new AstTextBlock{fl};
txtp->addNodep(m_seqDeclsp);
m_tmpDeclsp = new AstTextBlock(fl);
m_tmpDeclsp = new AstTextBlock{fl};
txtp->addNodep(m_tmpDeclsp);
// CPP hash value
addComment(txtp, fl, "Hash value to make sure this file and the corresponding");
addComment(txtp, fl, "library agree");
m_hashValuep = new AstTextBlock(fl, "localparam int protectlib_hash__V = 32'd");
m_hashValuep = new AstTextBlock{fl, "localparam int protectlib_hash__V = 32'd"};
txtp->addNodep(m_hashValuep);
txtp->addText(fl, "\n");
@ -249,11 +249,11 @@ private:
// Combinatorial process
addComment(txtp, fl, "Combinatorialy evaluate changes to inputs");
m_comboParamsp = new AstTextBlock(fl,
m_comboParamsp = new AstTextBlock{fl,
"always @(*) begin\n"
"last_combo_seqnum__V = "
+ m_libName + "_protectlib_combo_update(\n",
false, true);
false, true};
m_comboParamsp->addText(fl, "handle__V\n");
txtp->addNodep(m_comboParamsp);
txtp->addText(fl, ");\n");
@ -262,21 +262,21 @@ private:
// Sequential process
if (m_hasClk) {
addComment(txtp, fl, "Evaluate clock edges");
m_clkSensp = new AstTextBlock(fl, "always @(", false, true);
m_clkSensp = new AstTextBlock{fl, "always @(", false, true};
txtp->addNodep(m_clkSensp);
txtp->addText(fl, ") begin\n");
m_comboIgnoreParamsp
= new AstTextBlock(fl, m_libName + "_protectlib_combo_ignore(\n", false, true);
= new AstTextBlock{fl, m_libName + "_protectlib_combo_ignore(\n", false, true};
m_comboIgnoreParamsp->addText(fl, "handle__V\n");
txtp->addNodep(m_comboIgnoreParamsp);
txtp->addText(fl, ");\n");
m_seqParamsp = new AstTextBlock(
m_seqParamsp = new AstTextBlock{
fl, "last_seq_seqnum__V <= " + m_libName + "_protectlib_seq_update(\n", false,
true);
true};
m_seqParamsp->addText(fl, "handle__V\n");
txtp->addNodep(m_seqParamsp);
txtp->addText(fl, ");\n");
m_nbAssignsp = new AstTextBlock(fl);
m_nbAssignsp = new AstTextBlock{fl};
txtp->addNodep(m_nbAssignsp);
txtp->addText(fl, "end\n\n");
}
@ -285,14 +285,14 @@ private:
addComment(txtp, fl, "Select between combinatorial and sequential results");
txtp->addText(fl, "always @(*) begin\n");
if (m_hasClk) {
m_seqAssignsp = new AstTextBlock(fl, "if (last_seq_seqnum__V > "
"last_combo_seqnum__V) begin\n");
m_seqAssignsp = new AstTextBlock{fl, "if (last_seq_seqnum__V > "
"last_combo_seqnum__V) begin\n"};
txtp->addNodep(m_seqAssignsp);
m_comboAssignsp = new AstTextBlock(fl, "end\nelse begin\n");
m_comboAssignsp = new AstTextBlock{fl, "end\nelse begin\n"};
txtp->addNodep(m_comboAssignsp);
txtp->addText(fl, "end\n");
} else {
m_comboAssignsp = new AstTextBlock(fl, "");
m_comboAssignsp = new AstTextBlock{fl, ""};
txtp->addNodep(m_comboAssignsp);
}
txtp->addText(fl, "end\n\n");
@ -313,7 +313,7 @@ private:
void createCppFile(FileLine* fl) {
// Comments
AstTextBlock* const txtp = new AstTextBlock(fl);
AstTextBlock* const txtp = new AstTextBlock{fl};
addComment(txtp, fl, "Wrapper functions for DPI protected library\n");
// Includes
@ -339,7 +339,7 @@ private:
txtp->addText(fl, "void " + m_libName
+ "_protectlib_check_hash"
"(int protectlib_hash__V) {\n");
m_cHashValuep = new AstTextBlock(fl, "const int expected_hash__V = ");
m_cHashValuep = new AstTextBlock{fl, "const int expected_hash__V = "};
txtp->addNodep(m_cHashValuep);
txtp->addText(fl, /**/ "if (protectlib_hash__V != expected_hash__V) {\n");
txtp->addText(fl, /****/ "fprintf(stderr, \"%%Error: cannot use " + m_libName
@ -360,38 +360,38 @@ private:
// Updates
comboComment(txtp, fl);
m_cComboParamsp = new AstTextBlock(
fl, "long long " + m_libName + "_protectlib_combo_update(\n", false, true);
m_cComboParamsp = new AstTextBlock{
fl, "long long " + m_libName + "_protectlib_combo_update(\n", false, true};
m_cComboParamsp->addText(fl, "void* vhandlep__V\n");
txtp->addNodep(m_cComboParamsp);
txtp->addText(fl, ")\n");
m_cComboInsp = new AstTextBlock(fl, "{\n");
m_cComboInsp = new AstTextBlock{fl, "{\n"};
castPtr(fl, m_cComboInsp);
txtp->addNodep(m_cComboInsp);
m_cComboOutsp = new AstTextBlock(fl, "handlep__V->eval();\n");
m_cComboOutsp = new AstTextBlock{fl, "handlep__V->eval();\n"};
txtp->addNodep(m_cComboOutsp);
txtp->addText(fl, "return handlep__V->m_seqnum++;\n");
txtp->addText(fl, "}\n\n");
if (m_hasClk) {
seqComment(txtp, fl);
m_cSeqParamsp = new AstTextBlock(
fl, "long long " + m_libName + "_protectlib_seq_update(\n", false, true);
m_cSeqParamsp = new AstTextBlock{
fl, "long long " + m_libName + "_protectlib_seq_update(\n", false, true};
m_cSeqParamsp->addText(fl, "void* vhandlep__V\n");
txtp->addNodep(m_cSeqParamsp);
txtp->addText(fl, ")\n");
m_cSeqClksp = new AstTextBlock(fl, "{\n");
m_cSeqClksp = new AstTextBlock{fl, "{\n"};
castPtr(fl, m_cSeqClksp);
txtp->addNodep(m_cSeqClksp);
m_cSeqOutsp = new AstTextBlock(fl, "handlep__V->eval();\n");
m_cSeqOutsp = new AstTextBlock{fl, "handlep__V->eval();\n"};
txtp->addNodep(m_cSeqOutsp);
txtp->addText(fl, "return handlep__V->m_seqnum++;\n");
txtp->addText(fl, "}\n\n");
}
comboIgnoreComment(txtp, fl);
m_cIgnoreParamsp = new AstTextBlock(
fl, "void " + m_libName + "_protectlib_combo_ignore(\n", false, true);
m_cIgnoreParamsp = new AstTextBlock{
fl, "void " + m_libName + "_protectlib_combo_ignore(\n", false, true};
m_cIgnoreParamsp->addText(fl, "void* vhandlep__V\n");
txtp->addNodep(m_cIgnoreParamsp);
txtp->addText(fl, ")\n");
@ -472,7 +472,7 @@ private:
static void addLocalVariable(AstTextBlock* textp, AstVar* varp, const char* suffix) {
AstVar* const newVarp
= new AstVar(varp->fileline(), VVarType::VAR, varp->name() + suffix, varp->dtypep());
= new AstVar{varp->fileline(), VVarType::VAR, varp->name() + suffix, varp->dtypep()};
textp->addNodep(newVarp);
}
@ -532,5 +532,5 @@ public:
void V3ProtectLib::protect() {
UINFO(2, __FUNCTION__ << ": " << endl);
ProtectVisitor(v3Global.rootp());
ProtectVisitor{v3Global.rootp()};
}