diff --git a/src/V3Global.cpp b/src/V3Global.cpp index a2d1e5088..89fac8f91 100644 --- a/src/V3Global.cpp +++ b/src/V3Global.cpp @@ -35,16 +35,13 @@ void V3Global::boot() { m_rootp = new AstNetlist; } -void V3Global::clear() { +void V3Global::shutdown() { + VL_DO_CLEAR(delete m_hierPlanp, m_hierPlanp = nullptr); // delete nullptr is safe #ifdef VL_LEAK_CHECKS if (m_rootp) VL_DO_CLEAR(m_rootp->deleteTree(), m_rootp = nullptr); #endif } -void V3Global::shutdown() { - VL_DO_CLEAR(delete m_hierPlanp, m_hierPlanp = nullptr); // delete nullptr is safe -} - void V3Global::checkTree() const { rootp()->checkTree(); } void V3Global::readFiles() { diff --git a/src/V3Global.h b/src/V3Global.h index 365cf44db..228440e3a 100644 --- a/src/V3Global.h +++ b/src/V3Global.h @@ -126,7 +126,6 @@ public: // CONSTRUCTORS V3Global() {} void boot(); - void clear(); void shutdown(); // Release allocated resources // ACCESSORS (general) AstNetlist* rootp() const VL_MT_SAFE { return m_rootp; } diff --git a/src/V3PreLex.h b/src/V3PreLex.h index 2fa5e74f3..b6718d264 100644 --- a/src/V3PreLex.h +++ b/src/V3PreLex.h @@ -92,6 +92,7 @@ class V3PreProcImp; # define yytext V3PreLextext # define yyerror V3PreLexerror # define yyerrorf V3PreLexerrorf +# define yylex_destroy V3PreLexlex_destroy #endif #ifndef yyourleng @@ -117,6 +118,7 @@ extern void yyourtext(const char* textp, size_t size); // Must call with static YY_BUFFER_STATE yy_create_buffer(FILE* file, int size); void yy_switch_to_buffer(YY_BUFFER_STATE new_buffer); void yy_delete_buffer(YY_BUFFER_STATE b); +int yylex_destroy(); //====================================================================== @@ -190,6 +192,7 @@ public: // Used only by V3PreLex.cpp and V3PreProc.cpp m_streampStack.pop(); } VL_DO_CLEAR(yy_delete_buffer(m_bufferState), m_bufferState = nullptr); + yylex_destroy(); } // Called by V3PreLex.l from lexer diff --git a/src/V3PreShell.cpp b/src/V3PreShell.cpp index d03088f4e..087b25a75 100644 --- a/src/V3PreShell.cpp +++ b/src/V3PreShell.cpp @@ -78,6 +78,10 @@ protected: } } + void shutdown() { + if (s_preprocp) VL_DO_DANGLING(delete s_preprocp, s_preprocp); + } + bool preproc(FileLine* fl, const string& modname, VInFilter* filterp, V3ParseImp* parsep, const string& errmsg) { // "" for no error // Preprocess the given module, putting output in vppFilename @@ -153,6 +157,7 @@ VInFilter* V3PreShellImp::s_filterp = nullptr; // V3PreShell void V3PreShell::boot() { V3PreShellImp::s_preImp.boot(); } +void V3PreShell::shutdown() { V3PreShellImp::s_preImp.shutdown(); } bool V3PreShell::preproc(FileLine* fl, const string& modname, VInFilter* filterp, V3ParseImp* parsep, const string& errmsg) { return V3PreShellImp::s_preImp.preproc(fl, modname, filterp, parsep, errmsg); diff --git a/src/V3PreShell.h b/src/V3PreShell.h index 7812d760d..eb6a426cd 100644 --- a/src/V3PreShell.h +++ b/src/V3PreShell.h @@ -33,6 +33,7 @@ class V3PreShell final { // Static class for calling preprocessor public: static void boot(); + static void shutdown(); static bool preproc(FileLine* fl, const string& modname, VInFilter* filterp, V3ParseImp* parsep, const string& errmsg); static void preprocInclude(FileLine* fl, const string& modname); diff --git a/src/Verilator.cpp b/src/Verilator.cpp index 1faf1f627..76956b5e8 100644 --- a/src/Verilator.cpp +++ b/src/Verilator.cpp @@ -672,9 +672,6 @@ static void verilate(const string& argString) { // Final writing shouldn't throw warnings, but... V3Error::abortIfWarnings(); - // Cleanup memory for valgrind leak analysis - v3Global.clear(); - FileLine::deleteAllRemaining(); } static string buildMakeCmd(const string& makefile, const string& target) { @@ -763,7 +760,9 @@ int main(int argc, char** argv) { } // Explicitly release resources + V3PreShell::shutdown(); v3Global.shutdown(); + FileLine::deleteAllRemaining(); UINFO(1, "Done, Exiting...\n"); }