From f74ef650acfa36177fe4b262d1ebafeb124d8e03 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 23 Oct 2016 14:27:57 -0400 Subject: [PATCH] Honor --output-split on coverage constructors, bug1098. --- Changes | 2 + src/Makefile_obj.in | 2 +- src/{V3VarResets.cpp => V3CCtors.cpp} | 61 ++++++++++++++++++--------- src/{V3VarResets.h => V3CCtors.h} | 10 ++--- src/V3EmitC.cpp | 12 +----- src/Verilator.cpp | 4 +- 6 files changed, 54 insertions(+), 37 deletions(-) rename src/{V3VarResets.cpp => V3CCtors.cpp} (57%) rename src/{V3VarResets.h => V3CCtors.h} (85%) diff --git a/Changes b/Changes index 5153176c7..7944b2a17 100644 --- a/Changes +++ b/Changes @@ -5,6 +5,8 @@ The contributors that suggested a given feature are shown in []. Thanks! * Verilator 3.889 devel +*** Honor --output-split on coverage constructors, bug1098. [Johan Bjork] + **** Fix error on bad interface name, bug1097. [Todd Strader] diff --git a/src/Makefile_obj.in b/src/Makefile_obj.in index bcea27115..f2a4b757d 100644 --- a/src/Makefile_obj.in +++ b/src/Makefile_obj.in @@ -166,6 +166,7 @@ RAW_OBJS = \ V3Begin.o \ V3Branch.o \ V3Broken.o \ + V3CCtors.o \ V3Case.o \ V3Cast.o \ V3Cdc.o \ @@ -237,7 +238,6 @@ RAW_OBJS = \ V3Undriven.o \ V3Unknown.o \ V3Unroll.o \ - V3VarResets.o \ V3Width.o \ V3WidthSel.o \ diff --git a/src/V3VarResets.cpp b/src/V3CCtors.cpp similarity index 57% rename from src/V3VarResets.cpp rename to src/V3CCtors.cpp index 2c5cf0f65..3d5051691 100644 --- a/src/V3VarResets.cpp +++ b/src/V3CCtors.cpp @@ -1,6 +1,6 @@ // -*- mode: C++; c-file-style: "cc-mode" -*- //************************************************************************* -// DESCRIPTION: Verilator: Generate AstCReset nodes. +// DESCRIPTION: Verilator: Generate C language constructors and AstCReset nodes. // // Code available from: http://www.veripool.org/verilator // @@ -17,9 +17,12 @@ // GNU General Public License for more details. // //************************************************************************* -// V3VarReset's Transformations: -// Iterates over all modules and creates a _ctor_var_reset AstCFunc +// V3CCtors's Transformations: +// Iterates over all modules and +// for all AstVar, create a creates a AstCReset node in an _ctor_var_reset AstCFunc. +// for all AstCoverDecl, move the declaration into a _configure_coverage AstCFunc. // For each variable that needs reset, add a AstCReset node. +// // This transformation honors outputSplitCFuncs. //************************************************************************* #include "config_build.h" @@ -33,62 +36,82 @@ #include #include "V3Global.h" -#include "V3VarResets.h" +#include "V3EmitCBase.h" +#include "V3CCtors.h" -class V3VarReset { +class V3CCtorsVisitor { private: + string m_basename; + string m_argsp; + string m_callargsp; AstNodeModule* m_modp; // Current module AstCFunc* m_tlFuncp; // Top level function being built AstCFunc* m_funcp; // Current function int m_numStmts; // Number of statements output int m_funcNum; // Function number being built - void initializeVar(AstVar* nodep) { +public: + void add(AstNode* nodep) { if (v3Global.opt.outputSplitCFuncs() && v3Global.opt.outputSplitCFuncs() < m_numStmts) { m_funcp = NULL; } if (!m_funcp) { - m_funcp = new AstCFunc(m_modp->fileline(), "_ctor_var_reset_" + cvtToStr(++m_funcNum), NULL, "void"); + m_funcp = new AstCFunc(m_modp->fileline(), m_basename + "_" + cvtToStr(++m_funcNum), NULL, "void"); m_funcp->isStatic(false); m_funcp->declPrivate(true); m_funcp->slow(true); + m_funcp->argTypes(m_argsp); m_modp->addStmtp(m_funcp); // Add a top call to it AstCCall* callp = new AstCCall(m_modp->fileline(), m_funcp); + callp->argTypes(m_callargsp); m_tlFuncp->addStmtsp(callp); m_numStmts = 0; } - m_funcp->addStmtsp(new AstCReset(nodep->fileline(), new AstVarRef(nodep->fileline(), nodep, true))); + m_funcp->addStmtsp(nodep); m_numStmts += 1; } -public: - V3VarReset(AstNodeModule* nodep) { + V3CCtorsVisitor(AstNodeModule* nodep, string basename, string argsp="", string callargsp="") { + m_basename = basename; + m_argsp = argsp; + m_callargsp = callargsp; m_modp = nodep; m_numStmts = 0; m_funcNum = 0; - m_tlFuncp = new AstCFunc(nodep->fileline(), "_ctor_var_reset", NULL, "void"); + m_tlFuncp = new AstCFunc(nodep->fileline(), basename, NULL, "void"); m_tlFuncp->declPrivate(true); m_tlFuncp->isStatic(false); m_tlFuncp->slow(true); + m_tlFuncp->argTypes(m_argsp); m_funcp = m_tlFuncp; m_modp->addStmtp(m_tlFuncp); - for (AstNode* np = m_modp->stmtsp(); np; np = np->nextp()) { - AstVar* varp = np->castVar(); - if (varp) initializeVar(varp); - } } }; //###################################################################### -void V3VarResets::emitResets() { +void V3CCtors::cctorsAll() { UINFO(2,__FUNCTION__<<": "<modulesp(); nodep; nodep=nodep->nextp()->castNodeModule()) { - // Process each module in turn - V3VarReset v(nodep); + for (AstNodeModule* modp = v3Global.rootp()->modulesp(); modp; modp=modp->nextp()->castNodeModule()) { + // Process each module in turn + V3CCtorsVisitor var_reset (modp, "_ctor_var_reset"); + V3CCtorsVisitor configure_coverage (modp, "_configure_coverage", + EmitCBaseVisitor::symClassVar()+ ", bool first", "vlSymsp, first"); + + for (AstNode* np = modp->stmtsp(); np; np = np->nextp()) { + AstVar* varp = np->castVar(); + if (varp) var_reset.add(new AstCReset(varp->fileline(), new AstVarRef(varp->fileline(), varp, true))); + AstCoverDecl* coverp = np->castCoverDecl(); + if (coverp) { + AstNode* backp = coverp->backp(); + coverp->unlinkFrBack(); + configure_coverage.add(coverp); + np = backp; + } + } } } diff --git a/src/V3VarResets.h b/src/V3CCtors.h similarity index 85% rename from src/V3VarResets.h rename to src/V3CCtors.h index 0ff70037d..673dd9caf 100644 --- a/src/V3VarResets.h +++ b/src/V3CCtors.h @@ -1,6 +1,6 @@ // -*- mode: C++; c-file-style: "cc-mode" -*- //************************************************************************* -// DESCRIPTION: Verilator: Emit C++ code for module tree +// DESCRIPTION: Verilator: Emit CFunc's for class construction and configuration // // Code available from: http://www.veripool.org/verilator // @@ -18,8 +18,8 @@ // //************************************************************************* -#ifndef _V3VARRESETS_H_ -#define _V3VARRESETS_H_ 1 +#ifndef _V3CCTORS_H_ +#define _V3CCTORS_H_ 1 #include "config_build.h" #include "verilatedos.h" #include "V3Error.h" @@ -27,9 +27,9 @@ //============================================================================ -class V3VarResets { +class V3CCtors { public: - static void emitResets(); + static void cctorsAll(); }; diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index 4124771b0..bf85f4e94 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -1510,16 +1510,8 @@ void EmitCImp::emitConfigureImp(AstNodeModule* modp) { puts("\nvoid "+modClassName(modp)+"::__Vconfigure("+symClassName()+"* vlSymsp, bool first) {\n"); puts( "if (0 && first) {} // Prevent unused\n"); puts( "this->__VlSymsp = vlSymsp;\n"); // First, as later stuff needs it. - bool first=true; - for (AstNode* nodep=modp->stmtsp(); nodep; nodep = nodep->nextp()) { - if (nodep->castCoverDecl()) { - if (first) { - first = false; - putsDecoration("// Coverage Declarations\n"); - } - nodep->accept(*this); - splitSizeInc(nodep); - } + if (v3Global.opt.coverage() ) { + puts("this->_configure_coverage(vlSymsp, first);\n"); } puts("}\n"); splitSizeInc(10); diff --git a/src/Verilator.cpp b/src/Verilator.cpp index 89d9752f0..e275f4681 100644 --- a/src/Verilator.cpp +++ b/src/Verilator.cpp @@ -39,7 +39,7 @@ #include "V3Const.h" #include "V3Coverage.h" #include "V3CoverageJoin.h" -#include "V3VarResets.h" +#include "V3CCtors.h" #include "V3Dead.h" #include "V3Delayed.h" #include "V3Depth.h" @@ -500,7 +500,7 @@ void process () { V3Error::abortIfErrors(); if (!v3Global.opt.lintOnly() && !v3Global.opt.xmlOnly()) { - V3VarResets::emitResets(); + V3CCtors::cctorsAll(); } // Output the text