diff --git a/include/verilated.cpp b/include/verilated.cpp index d632eb1ce..2d04d44eb 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -999,8 +999,12 @@ void VerilatedScope::configure(VerilatedSyms* symsp, const char* prefixp, const // We don't want the space and reference-count access overhead of strings. m_symsp = symsp; char* namep = new char[strlen(prefixp)+strlen(suffixp)+2]; - strcpy(namep, prefixp); - strcat(namep, suffixp); + if (!*prefixp && *suffixp && suffixp[0]=='.') { // Special case of top module with empty name - drop the dots + strcpy(namep, suffixp+1); + } else { + strcpy(namep, prefixp); + strcat(namep, suffixp); + } m_namep = namep; VerilatedImp::scopeInsert(this); } diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index e6d8fa128..9be407c5e 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -1712,7 +1712,11 @@ void EmitCImp::emitInt(AstNodeModule* modp) { puts("VL_CTOR("+modClassName(modp)+");\n"); puts("~"+modClassName(modp)+"();\n"); } else { - if (modp->isTop()) puts("/// Construct the model; called by application code\n"); + if (modp->isTop()) { + puts("/// Construct the model; called by application code\n"); + puts("/// The special name "" may be used to make a wrapper with a\n"); + puts("/// single model invisible WRT DPI scope names.\n"); + } puts(modClassName(modp)+"(const char* name=\"TOP\");\n"); if (modp->isTop()) puts("/// Destroy the model; called (often implicitly) by application code\n"); puts("~"+modClassName(modp)+"();\n"); diff --git a/test_regress/t/t_dpi_export.pl b/test_regress/t/t_dpi_export.pl index c2e42f04f..b42417818 100755 --- a/test_regress/t/t_dpi_export.pl +++ b/test_regress/t/t_dpi_export.pl @@ -11,7 +11,7 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di compile ( # Amazingly VCS, NC and Verilator all just accept the C file here! - v_flags2 => ["t/t_dpi_export_c.cpp"], + v_flags2 => ["t/t_dpi_export_c.cpp", "-no-l2name"], ); execute ( diff --git a/test_regress/t/t_dpi_export_c.cpp b/test_regress/t/t_dpi_export_c.cpp index 8a13edece..8a9419315 100644 --- a/test_regress/t/t_dpi_export_c.cpp +++ b/test_regress/t/t_dpi_export_c.cpp @@ -122,13 +122,8 @@ int dpix_run_tests() { CHECK_RESULT (dpix_f_longint(1), 0xfffffffffffffffeULL); CHECK_RESULT (dpix_f_chandle((void*)(12345)), (void*)(12345)); -#ifdef VERILATOR - if (int bad=check_sub("top.v.a",1)) return bad; - if (int bad=check_sub("top.v.b",2)) return bad; -#else if (int bad=check_sub("top.t.a",1)) return bad; if (int bad=check_sub("top.t.b",2)) return bad; -#endif return -1; // OK status }