2012-04-13 01:08:20 +00:00
|
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//*************************************************************************
|
|
|
|
|
// DESCRIPTION: Verilator: Collect and print statistics
|
|
|
|
|
//
|
2008-04-25 12:14:27 +00:00
|
|
|
|
// Code available from: http://www.veripool.org/verilator
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//
|
|
|
|
|
// AUTHORS: Wilson Snyder with Paul Wasson, Duane Gabli
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2012-01-15 15:26:28 +00:00
|
|
|
|
// Copyright 2005-2012 by Wilson Snyder. This program is free software; you can
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// redistribute it and/or modify it under the terms of either the GNU
|
2009-05-04 21:07:57 +00:00
|
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
|
// Version 2.0.
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//
|
|
|
|
|
// Verilator is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
2006-12-18 19:20:45 +00:00
|
|
|
|
#include "config_build.h"
|
|
|
|
|
#include "verilatedos.h"
|
2008-06-30 17:11:25 +00:00
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstdarg>
|
2006-08-26 11:35:28 +00:00
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <iomanip>
|
|
|
|
|
|
|
|
|
|
#include "V3Global.h"
|
|
|
|
|
#include "V3Assert.h"
|
|
|
|
|
#include "V3Ast.h"
|
|
|
|
|
#include "V3GraphDfa.h"
|
|
|
|
|
#include "V3Stats.h"
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// Assert class functions
|
|
|
|
|
|
|
|
|
|
class AssertVisitor : public AstNVisitor {
|
|
|
|
|
private:
|
|
|
|
|
// NODE STATE/TYPES
|
|
|
|
|
// Cleared on netlist
|
|
|
|
|
// AstNode::user() -> bool. True if processed
|
2008-11-25 14:03:49 +00:00
|
|
|
|
AstUser1InUse m_inuser1;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
// STATE
|
2009-11-07 11:20:20 +00:00
|
|
|
|
AstNodeModule* m_modp; // Last module
|
2008-08-06 16:52:39 +00:00
|
|
|
|
AstBegin* m_beginp; // Last begin
|
2006-08-26 11:35:28 +00:00
|
|
|
|
V3Double0 m_statAsCover; // Statistic tracking
|
|
|
|
|
V3Double0 m_statAsPsl; // Statistic tracking
|
|
|
|
|
V3Double0 m_statAsFull; // Statistic tracking
|
2007-03-06 21:43:38 +00:00
|
|
|
|
V3Double0 m_statAsSV; // Statistic tracking
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
// METHODS
|
2007-03-06 21:43:38 +00:00
|
|
|
|
string assertDisplayMessage(AstNode* nodep, const string& prefix, const string& message) {
|
|
|
|
|
return (string("[%0t] "+prefix+": ")+nodep->fileline()->filebasename()
|
|
|
|
|
+":"+cvtToStr(nodep->fileline()->lineno())
|
|
|
|
|
+": Assertion failed in %m"
|
|
|
|
|
+((message != "")?": ":"")+message
|
|
|
|
|
+"\\n");
|
|
|
|
|
}
|
|
|
|
|
void replaceDisplay(AstDisplay* nodep, const string& prefix) {
|
2010-02-02 01:15:48 +00:00
|
|
|
|
nodep->displayType(AstDisplayType::DT_WRITE);
|
2010-01-17 20:53:12 +00:00
|
|
|
|
nodep->fmtp()->text(assertDisplayMessage(nodep, prefix, nodep->fmtp()->text()));
|
|
|
|
|
AstNode* timesp = nodep->fmtp()->exprsp(); if (timesp) timesp->unlinkFrBack();
|
2007-03-06 21:43:38 +00:00
|
|
|
|
timesp = timesp->addNext(new AstTime(nodep->fileline()));
|
2010-01-17 20:53:12 +00:00
|
|
|
|
nodep->fmtp()->exprsp(timesp);
|
|
|
|
|
if (!nodep->fmtp()->scopeNamep() && nodep->fmtp()->formatScopeTracking()) {
|
|
|
|
|
nodep->fmtp()->scopeNamep(new AstScopeName(nodep->fileline()));
|
2007-06-14 16:41:32 +00:00
|
|
|
|
}
|
2007-03-06 21:43:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AstNode* newIfAssertOn(AstNode* nodep) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Add a internal if to check assertions are on.
|
|
|
|
|
// Don't make this a AND term, as it's unlikely to need to test this.
|
2007-03-06 21:43:38 +00:00
|
|
|
|
return new AstIf (nodep->fileline(),
|
|
|
|
|
// If assertions are off, have constant propagation rip them out later
|
|
|
|
|
// This allows syntax errors and such to be detected normally.
|
|
|
|
|
(v3Global.opt.assertOn()
|
|
|
|
|
? (AstNode*)(new AstCMath(nodep->fileline(), "Verilated::assertOn()", 1))
|
2009-11-23 00:57:41 +00:00
|
|
|
|
: (AstNode*)(new AstConst(nodep->fileline(), AstConst::LogicFalse()))),
|
2007-03-06 21:43:38 +00:00
|
|
|
|
nodep, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AstNode* newIfCoverageOn(AstNode* nodep) {
|
|
|
|
|
// Add a internal if to check coverage is on
|
|
|
|
|
// Don't make this a AND term, as it's unlikely to need to test this.
|
|
|
|
|
return new AstIf (nodep->fileline(),
|
|
|
|
|
// If assertions are off, have constant propagation rip them out later
|
|
|
|
|
// This allows syntax errors and such to be detected normally.
|
|
|
|
|
(v3Global.opt.coverage()
|
2009-11-23 00:57:41 +00:00
|
|
|
|
? (AstNode*)(new AstConst(nodep->fileline(), AstConst::LogicTrue()))
|
|
|
|
|
: (AstNode*)(new AstConst(nodep->fileline(), AstConst::LogicFalse()))),
|
2007-03-06 21:43:38 +00:00
|
|
|
|
nodep, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AstNode* newFireAssert(AstNode* nodep, const string& message) {
|
2010-02-02 01:15:48 +00:00
|
|
|
|
AstDisplay* dispp = new AstDisplay (nodep->fileline(), AstDisplayType::DT_ERROR, message, NULL, NULL);
|
2007-03-06 21:43:38 +00:00
|
|
|
|
AstNode* bodysp = dispp;
|
|
|
|
|
replaceDisplay(dispp, "%%Error"); // Convert to standard DISPLAY format
|
|
|
|
|
bodysp->addNext(new AstStop (nodep->fileline()));
|
|
|
|
|
bodysp = newIfAssertOn(bodysp);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
return bodysp;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-06 16:52:39 +00:00
|
|
|
|
void newPslAssertion(AstNode* nodep, AstNode* propp, AstSenTree* sentreep,
|
|
|
|
|
AstNode* stmtsp, const string& message) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
propp->unlinkFrBack();
|
|
|
|
|
sentreep->unlinkFrBack();
|
2008-08-06 16:52:39 +00:00
|
|
|
|
if (stmtsp) stmtsp->unlinkFrBack();
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//
|
|
|
|
|
AstNode* bodysp = NULL;
|
2008-06-10 01:25:10 +00:00
|
|
|
|
bool selfDestruct = false;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
if (AstPslCover* snodep = nodep->castPslCover()) {
|
|
|
|
|
if (!v3Global.opt.coverageUser()) {
|
|
|
|
|
selfDestruct = true;
|
|
|
|
|
} else {
|
|
|
|
|
// V3Coverage assigned us a bucket to increment.
|
|
|
|
|
AstCoverInc* covincp = snodep->coverincp()->castCoverInc();
|
2008-11-05 15:23:03 +00:00
|
|
|
|
if (!covincp) snodep->v3fatalSrc("Missing AstCoverInc under assertion");
|
2006-08-26 11:35:28 +00:00
|
|
|
|
covincp->unlinkFrBack();
|
|
|
|
|
if (message!="") covincp->declp()->comment(message);
|
|
|
|
|
bodysp = covincp;
|
|
|
|
|
}
|
|
|
|
|
} else if (nodep->castPslAssert()) {
|
|
|
|
|
bodysp = newFireAssert(nodep,message);
|
|
|
|
|
// We assert the property is always true... so report when it fails
|
|
|
|
|
// (Note this is opposite the behavior of coverage statements.)
|
2006-09-01 14:05:20 +00:00
|
|
|
|
// Need: 'never' operator: not hold in current or any future cycle
|
2006-08-26 11:35:28 +00:00
|
|
|
|
propp = new AstLogNot (nodep->fileline(), propp);
|
|
|
|
|
} else {
|
|
|
|
|
nodep->v3fatalSrc("Unknown node type");
|
|
|
|
|
}
|
2008-08-06 16:52:39 +00:00
|
|
|
|
if (stmtsp) bodysp = bodysp->addNext(stmtsp);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
AstIf* ifp = new AstIf (nodep->fileline(), propp, bodysp, NULL);
|
|
|
|
|
bodysp = ifp;
|
2010-02-02 01:15:48 +00:00
|
|
|
|
if (nodep->castPslAssert()) ifp->branchPred(AstBranchPred::BP_UNLIKELY);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//
|
|
|
|
|
AstNode* newp = new AstAlways (nodep->fileline(),
|
|
|
|
|
sentreep,
|
|
|
|
|
bodysp);
|
|
|
|
|
// Install it
|
|
|
|
|
if (selfDestruct) {
|
|
|
|
|
// Delete it after making the tree. This way we can tell the user
|
|
|
|
|
// if it wasn't constructed nicely or has other errors without needing --coverage.
|
|
|
|
|
newp->deleteTree();
|
|
|
|
|
nodep->unlinkFrBack();
|
|
|
|
|
} else {
|
|
|
|
|
nodep->replaceWith(newp);
|
|
|
|
|
}
|
|
|
|
|
// Bye
|
|
|
|
|
pushDeletep(nodep); nodep=NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-06 21:43:38 +00:00
|
|
|
|
void newVAssertion(AstVAssert* nodep, AstNode* propp) {
|
|
|
|
|
propp->unlinkFrBackWithNext();
|
|
|
|
|
AstNode* passsp = nodep->passsp(); if (passsp) passsp->unlinkFrBackWithNext();
|
|
|
|
|
AstNode* failsp = nodep->failsp(); if (failsp) failsp->unlinkFrBackWithNext();
|
|
|
|
|
//
|
|
|
|
|
if (nodep->castVAssert()) {
|
|
|
|
|
if (passsp) passsp = newIfAssertOn(passsp);
|
|
|
|
|
if (failsp) failsp = newIfAssertOn(failsp);
|
|
|
|
|
} else {
|
|
|
|
|
nodep->v3fatalSrc("Unknown node type");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AstIf* ifp = new AstIf (nodep->fileline(), propp, passsp, failsp);
|
|
|
|
|
AstNode* newp = ifp;
|
2010-02-02 01:15:48 +00:00
|
|
|
|
if (nodep->castVAssert()) ifp->branchPred(AstBranchPred::BP_UNLIKELY);
|
2007-03-06 21:43:38 +00:00
|
|
|
|
//
|
|
|
|
|
// Install it
|
|
|
|
|
nodep->replaceWith(newp);
|
|
|
|
|
// Bye
|
|
|
|
|
pushDeletep(nodep); nodep=NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// VISITORS //========== Case assertions
|
|
|
|
|
virtual void visit(AstCase* nodep, AstNUser*) {
|
|
|
|
|
nodep->iterateChildren(*this);
|
2010-04-16 00:56:54 +00:00
|
|
|
|
if (!nodep->user1Inc()) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
bool has_default=false;
|
|
|
|
|
for (AstCaseItem* itemp = nodep->itemsp(); itemp; itemp=itemp->nextp()->castCaseItem()) {
|
|
|
|
|
if (itemp->isDefault()) has_default=true;
|
|
|
|
|
}
|
2010-12-26 02:58:28 +00:00
|
|
|
|
if (nodep->fullPragma() || nodep->priorityPragma()) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Simply need to add a default if there isn't one already
|
2011-08-05 01:15:24 +00:00
|
|
|
|
++m_statAsFull;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
if (!has_default) {
|
|
|
|
|
nodep->addItemsp(new AstCaseItem(nodep->fileline(), NULL/*DEFAULT*/,
|
|
|
|
|
newFireAssert(nodep, "synthesis full_case, but non-match found")));
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-12-26 02:58:28 +00:00
|
|
|
|
if (nodep->parallelPragma() || nodep->uniquePragma() || nodep->unique0Pragma()) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Need to check that one, and only one of the case items match at any moment
|
|
|
|
|
// If there's a default, we allow none to match, else exactly one must match
|
2011-08-05 01:15:24 +00:00
|
|
|
|
++m_statAsFull;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
if (!has_default && !nodep->itemsp()) {
|
|
|
|
|
// Not parallel, but harmlessly so.
|
|
|
|
|
} else {
|
|
|
|
|
AstNode* propp = NULL;
|
|
|
|
|
for (AstCaseItem* itemp = nodep->itemsp(); itemp; itemp=itemp->nextp()->castCaseItem()) {
|
|
|
|
|
for (AstNode* icondp = itemp->condsp(); icondp!=NULL; icondp=icondp->nextp()) {
|
|
|
|
|
AstNode* onep = new AstEq(icondp->fileline(),
|
|
|
|
|
nodep->exprp()->cloneTree(false),
|
|
|
|
|
icondp->cloneTree(false));
|
|
|
|
|
if (propp) propp = new AstConcat(icondp->fileline(), onep, propp);
|
|
|
|
|
else propp = onep;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-12-26 02:58:28 +00:00
|
|
|
|
bool allow_none = has_default || nodep->unique0Pragma();
|
|
|
|
|
AstNode* ohot = (allow_none
|
2006-08-26 11:35:28 +00:00
|
|
|
|
? (new AstOneHot0(nodep->fileline(), propp))->castNode()
|
|
|
|
|
: (new AstOneHot (nodep->fileline(), propp))->castNode());
|
|
|
|
|
AstIf* ifp = new AstIf (nodep->fileline(),
|
|
|
|
|
new AstLogNot (nodep->fileline(), ohot),
|
|
|
|
|
newFireAssert(nodep, "synthesis parallel_case, but multiple matches found"),
|
|
|
|
|
NULL);
|
2010-02-02 01:15:48 +00:00
|
|
|
|
ifp->branchPred(AstBranchPred::BP_UNLIKELY);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
nodep->addNotParallelp(ifp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// VISITORS //========== Statements
|
2007-03-06 21:43:38 +00:00
|
|
|
|
virtual void visit(AstDisplay* nodep, AstNUser*) {
|
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
// Replace the special types with standard text
|
2010-02-02 01:15:48 +00:00
|
|
|
|
if (nodep->displayType()==AstDisplayType::DT_INFO) {
|
2007-03-06 21:43:38 +00:00
|
|
|
|
replaceDisplay(nodep, "-Info");
|
2010-02-02 01:15:48 +00:00
|
|
|
|
} else if (nodep->displayType()==AstDisplayType::DT_WARNING) {
|
2007-03-06 21:43:38 +00:00
|
|
|
|
replaceDisplay(nodep, "%%Warning");
|
2010-02-02 01:15:48 +00:00
|
|
|
|
} else if (nodep->displayType()==AstDisplayType::DT_ERROR
|
|
|
|
|
|| nodep->displayType()==AstDisplayType::DT_FATAL) {
|
2007-03-06 21:43:38 +00:00
|
|
|
|
replaceDisplay(nodep, "%%Error");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
virtual void visit(AstPslCover* nodep, AstNUser*) {
|
|
|
|
|
nodep->iterateChildren(*this);
|
2008-08-06 16:52:39 +00:00
|
|
|
|
if (m_beginp && nodep->name() == "") nodep->name(m_beginp->name());
|
|
|
|
|
newPslAssertion(nodep, nodep->propp(), nodep->sentreep(),
|
|
|
|
|
nodep->stmtsp(), nodep->name()); nodep=NULL;
|
2011-08-05 01:15:24 +00:00
|
|
|
|
++m_statAsCover;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
virtual void visit(AstPslAssert* nodep, AstNUser*) {
|
|
|
|
|
nodep->iterateChildren(*this);
|
2008-08-06 16:52:39 +00:00
|
|
|
|
newPslAssertion(nodep, nodep->propp(), nodep->sentreep(),
|
|
|
|
|
NULL, nodep->name()); nodep=NULL;
|
2011-08-05 01:15:24 +00:00
|
|
|
|
++m_statAsPsl;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2007-03-06 21:43:38 +00:00
|
|
|
|
virtual void visit(AstVAssert* nodep, AstNUser*) {
|
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
newVAssertion(nodep, nodep->propp()); nodep=NULL;
|
2011-08-05 01:15:24 +00:00
|
|
|
|
++m_statAsSV;
|
2007-03-06 21:43:38 +00:00
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
2009-11-07 11:20:20 +00:00
|
|
|
|
virtual void visit(AstNodeModule* nodep, AstNUser*) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
m_modp = nodep;
|
|
|
|
|
//
|
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
// Reset defaults
|
|
|
|
|
m_modp = NULL;
|
|
|
|
|
}
|
2008-08-06 16:52:39 +00:00
|
|
|
|
virtual void visit(AstBegin* nodep, AstNUser*) {
|
|
|
|
|
// This code is needed rather than a visitor in V3Begin,
|
|
|
|
|
// because V3Assert is called before V3Begin
|
|
|
|
|
AstBegin* lastp = m_beginp;
|
|
|
|
|
{
|
|
|
|
|
m_beginp = nodep;
|
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
}
|
|
|
|
|
m_beginp = lastp;
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
// VISITORS //========== Temporal Layer
|
|
|
|
|
|
|
|
|
|
// VISITORS //========== Boolean Layer
|
|
|
|
|
virtual void visit(AstPslBool* nodep, AstNUser*) {
|
|
|
|
|
nodep->replaceWith(nodep->exprp()->unlinkFrBack());
|
|
|
|
|
pushDeletep(nodep); nodep=NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void visit(AstNode* nodep, AstNUser*) {
|
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
}
|
|
|
|
|
public:
|
|
|
|
|
// CONSTRUCTORS
|
|
|
|
|
AssertVisitor(AstNetlist* nodep) {
|
2008-08-06 16:52:39 +00:00
|
|
|
|
m_beginp = NULL;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
m_modp = NULL;
|
|
|
|
|
// Process
|
|
|
|
|
nodep->accept(*this);
|
|
|
|
|
}
|
|
|
|
|
virtual ~AssertVisitor() {
|
|
|
|
|
V3Stats::addStat("Assertions, PSL asserts", m_statAsPsl);
|
2007-03-06 21:43:38 +00:00
|
|
|
|
V3Stats::addStat("Assertions, SystemVerilog asserts", m_statAsSV);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
V3Stats::addStat("Assertions, cover statements", m_statAsCover);
|
|
|
|
|
V3Stats::addStat("Assertions, full/parallel case", m_statAsFull);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// Top Assert class
|
|
|
|
|
|
|
|
|
|
void V3Assert::assertAll(AstNetlist* nodep) {
|
|
|
|
|
UINFO(2,__FUNCTION__<<": "<<endl);
|
|
|
|
|
AssertVisitor visitor (nodep);
|
|
|
|
|
}
|