Internals: Add lib-create const and improve comments.

This commit is contained in:
Wilson Snyder 2021-11-14 12:01:02 -05:00
parent d6195e354f
commit cfa401e01d
2 changed files with 24 additions and 23 deletions

View File

@ -531,7 +531,7 @@ class EmitCModel final : public EmitCFunc {
putSectionDelimiter("Invoke final blocks"); putSectionDelimiter("Invoke final blocks");
// ::final // ::final
puts("\nVL_ATTR_COLD void " + topClassName() + "::final() {\n"); puts("\nVL_ATTR_COLD void " + topClassName() + "::final() {\n");
puts(topModNameProtected + "__" + protect("_final") + "(&(vlSymsp->TOP));\n"); puts(/**/ topModNameProtected + "__" + protect("_final") + "(&(vlSymsp->TOP));\n");
puts("}\n"); puts("}\n");
} }
@ -564,15 +564,15 @@ class EmitCModel final : public EmitCFunc {
puts("}\n"); puts("}\n");
// Forward declaration // Forward declaration
puts("\nvoid " + topModNameProtected + "__" + protect("trace_register") + "(" puts("\nVL_ATTR_COLD void " + topModNameProtected + "__" + protect("trace_register") + "("
+ topModNameProtected + "* vlSelf, " + v3Global.opt.traceClassBase() + topModNameProtected + "* vlSelf, " + v3Global.opt.traceClassBase()
+ "* tracep);\n"); + "* tracep);\n");
// ::trace // ::trace
puts("\nVL_ATTR_COLD void " + topClassName() + "::trace("); puts("\nVL_ATTR_COLD void " + topClassName() + "::trace(");
puts(v3Global.opt.traceClassBase() + "C* tfp, int, int) {\n"); puts(v3Global.opt.traceClassBase() + "C* tfp, int, int) {\n");
puts("tfp->spTrace()->addInitCb(&" + protect("trace_init") + ", &(vlSymsp->TOP));\n"); puts(/**/ "tfp->spTrace()->addInitCb(&" + protect("trace_init") + ", &(vlSymsp->TOP));\n");
puts(topModNameProtected + "__" + protect("trace_register") puts(/**/ topModNameProtected + "__" + protect("trace_register")
+ "(&(vlSymsp->TOP), tfp->spTrace());\n"); + "(&(vlSymsp->TOP), tfp->spTrace());\n");
puts("}\n"); puts("}\n");
} }
@ -582,16 +582,16 @@ class EmitCModel final : public EmitCFunc {
puts("\nVerilatedSerialize& operator<<(VerilatedSerialize& os, " + topClassName() puts("\nVerilatedSerialize& operator<<(VerilatedSerialize& os, " + topClassName()
+ "& rhs) {\n"); + "& rhs) {\n");
puts("Verilated::quiesce();\n"); puts(/**/ "Verilated::quiesce();\n");
puts("rhs.vlSymsp->" + protect("__Vserialize") + "(os);\n"); puts(/**/ "rhs.vlSymsp->" + protect("__Vserialize") + "(os);\n");
puts("return os;\n"); puts(/**/ "return os;\n");
puts("}\n"); puts("}\n");
puts("\nVerilatedDeserialize& operator>>(VerilatedDeserialize& os, " + topClassName() puts("\nVerilatedDeserialize& operator>>(VerilatedDeserialize& os, " + topClassName()
+ "& rhs) {\n"); + "& rhs) {\n");
puts("Verilated::quiesce();\n"); puts(/**/ "Verilated::quiesce();\n");
puts("rhs.vlSymsp->" + protect("__Vdeserialize") + "(os);\n"); puts(/**/ "rhs.vlSymsp->" + protect("__Vdeserialize") + "(os);\n");
puts("return os;\n"); puts(/**/ "return os;\n");
puts("}\n"); puts("}\n");
} }

View File

@ -102,9 +102,9 @@ private:
} }
void initialComment(AstTextBlock* txtp, FileLine* fl) { void initialComment(AstTextBlock* txtp, FileLine* fl) {
addComment(txtp, fl, "Creates an instance of the secret module at initial-time"); addComment(txtp, fl, "Creates an instance of the library module at initial-time");
addComment(txtp, fl, "(one for each instance in the user's design) also evaluates"); addComment(txtp, fl, "(one for each instance in the user's design) also evaluates");
addComment(txtp, fl, "the secret module's initial process"); addComment(txtp, fl, "the library module's initial process");
} }
void comboComment(AstTextBlock* txtp, FileLine* fl) { void comboComment(AstTextBlock* txtp, FileLine* fl) {
@ -121,7 +121,7 @@ private:
} }
void finalComment(AstTextBlock* txtp, FileLine* fl) { void finalComment(AstTextBlock* txtp, FileLine* fl) {
addComment(txtp, fl, "Evaluates the secret module's final process"); addComment(txtp, fl, "Evaluates the library module's final process");
} }
void createSvFile(FileLine* fl, AstNodeModule* modp) { void createSvFile(FileLine* fl, AstNodeModule* modp) {
@ -192,6 +192,7 @@ private:
m_comboIgnorePortsp->addText(fl, "chandle handle__V\n"); m_comboIgnorePortsp->addText(fl, "chandle handle__V\n");
txtp->addNodep(m_comboIgnorePortsp); txtp->addNodep(m_comboIgnorePortsp);
txtp->addText(fl, ");\n\n"); txtp->addText(fl, ");\n\n");
finalComment(txtp, fl); finalComment(txtp, fl);
txtp->addText(fl, "import \"DPI-C\" function void " + m_libName txtp->addText(fl, "import \"DPI-C\" function void " + m_libName
+ "_protectlib_final(chandle handle__V);\n\n"); + "_protectlib_final(chandle handle__V);\n\n");
@ -287,7 +288,7 @@ private:
void castPtr(FileLine* fl, AstTextBlock* txtp) { void castPtr(FileLine* fl, AstTextBlock* txtp) {
txtp->addText(fl, m_topName txtp->addText(fl, m_topName
+ "_container* handlep__V = " // LCOV_EXCL_LINE // lcov bug + "_container* const handlep__V = " // LCOV_EXCL_LINE // lcov bug
"static_cast<" "static_cast<"
+ m_topName + "_container*>(vhandlep__V);\n"); + m_topName + "_container*>(vhandlep__V);\n");
} }
@ -320,23 +321,23 @@ private:
txtp->addText(fl, "void " + m_libName txtp->addText(fl, "void " + m_libName
+ "_protectlib_check_hash" + "_protectlib_check_hash"
"(int protectlib_hash__V) {\n"); "(int protectlib_hash__V) {\n");
m_cHashValuep = new AstTextBlock(fl, "int expected_hash__V = "); m_cHashValuep = new AstTextBlock(fl, "const int expected_hash__V = ");
txtp->addNodep(m_cHashValuep); txtp->addNodep(m_cHashValuep);
txtp->addText(fl, "if (protectlib_hash__V != expected_hash__V) {\n"); txtp->addText(fl, /**/ "if (protectlib_hash__V != expected_hash__V) {\n");
txtp->addText(fl, "fprintf(stderr, \"%%Error: cannot use " + m_libName txtp->addText(fl, /****/ "fprintf(stderr, \"%%Error: cannot use " + m_libName
+ " library, " + " library, "
"Verliog (%u) and library (%u) hash values do not " "Verliog (%u) and library (%u) hash values do not "
"agree\\n\", protectlib_hash__V, expected_hash__V);\n"); "agree\\n\", protectlib_hash__V, expected_hash__V);\n");
txtp->addText(fl, "std::exit(EXIT_FAILURE);\n"); txtp->addText(fl, /****/ "std::exit(EXIT_FAILURE);\n");
txtp->addText(fl, "}\n"); txtp->addText(fl, /**/ "}\n");
txtp->addText(fl, "}\n\n"); txtp->addText(fl, "}\n\n");
// Initial // Initial
initialComment(txtp, fl); initialComment(txtp, fl);
txtp->addText(fl, "void* " + m_libName + "_protectlib_create(const char* scopep__V) {\n"); txtp->addText(fl, "void* " + m_libName + "_protectlib_create(const char* scopep__V) {\n");
txtp->addText(fl, m_topName + "_container* handlep__V = new " + m_topName txtp->addText(fl, /**/ m_topName + "_container* const handlep__V = new " + m_topName
+ "_container(scopep__V);\n"); + "_container(scopep__V);\n");
txtp->addText(fl, "return handlep__V;\n"); txtp->addText(fl, /**/ "return handlep__V;\n");
txtp->addText(fl, "}\n\n"); txtp->addText(fl, "}\n\n");
// Updates // Updates
@ -382,8 +383,8 @@ private:
finalComment(txtp, fl); finalComment(txtp, fl);
txtp->addText(fl, "void " + m_libName + "_protectlib_final(void* vhandlep__V) {\n"); txtp->addText(fl, "void " + m_libName + "_protectlib_final(void* vhandlep__V) {\n");
castPtr(fl, txtp); castPtr(fl, txtp);
txtp->addText(fl, "handlep__V->final();\n"); txtp->addText(fl, /**/ "handlep__V->final();\n");
txtp->addText(fl, "delete handlep__V;\n"); txtp->addText(fl, /**/ "delete handlep__V;\n");
txtp->addText(fl, "}\n\n"); txtp->addText(fl, "}\n\n");
txtp->addText(fl, "}\n"); txtp->addText(fl, "}\n");