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
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2019-01-04 00:17:22 +00:00
|
|
|
|
// Copyright 2005-2019 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"
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
#include "V3Global.h"
|
|
|
|
|
#include "V3Assert.h"
|
|
|
|
|
#include "V3Ast.h"
|
|
|
|
|
#include "V3GraphDfa.h"
|
|
|
|
|
#include "V3Stats.h"
|
|
|
|
|
|
2018-10-14 17:43:24 +00:00
|
|
|
|
#include <cstdarg>
|
|
|
|
|
#include <iomanip>
|
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//######################################################################
|
|
|
|
|
// Assert class functions
|
|
|
|
|
|
|
|
|
|
class AssertVisitor : public AstNVisitor {
|
|
|
|
|
private:
|
|
|
|
|
// NODE STATE/TYPES
|
|
|
|
|
// Cleared on netlist
|
2019-05-19 20:13:13 +00:00
|
|
|
|
// AstNode::user() -> bool. True if processed
|
|
|
|
|
AstUser1InUse m_inuser1;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
// STATE
|
2019-05-19 20:13:13 +00:00
|
|
|
|
AstNodeModule* m_modp; // Last module
|
|
|
|
|
AstBegin* m_beginp; // Last begin
|
2018-09-23 19:09:47 +00:00
|
|
|
|
unsigned m_modPastNum; // Module past numbering
|
2019-05-19 20:13:13 +00:00
|
|
|
|
V3Double0 m_statAsCover; // Statistic tracking
|
|
|
|
|
V3Double0 m_statAsPsl; // Statistic tracking
|
|
|
|
|
V3Double0 m_statAsFull; // Statistic tracking
|
|
|
|
|
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) {
|
2019-05-19 20:13:13 +00:00
|
|
|
|
return (string("[%0t] "+prefix+": ")+nodep->fileline()->filebasename()
|
|
|
|
|
+":"+cvtToStr(nodep->fileline()->lineno())
|
|
|
|
|
+": Assertion failed in %m"
|
|
|
|
|
+((message != "")?": ":"")+message
|
|
|
|
|
+"\n");
|
2007-03-06 21:43:38 +00:00
|
|
|
|
}
|
|
|
|
|
void replaceDisplay(AstDisplay* nodep, const string& prefix) {
|
2019-05-19 20:13:13 +00:00
|
|
|
|
nodep->displayType(AstDisplayType::DT_WRITE);
|
|
|
|
|
nodep->fmtp()->text(assertDisplayMessage(nodep, prefix, nodep->fmtp()->text()));
|
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
|
AstNode* timenewp = new AstTime(nodep->fileline());
|
|
|
|
|
if (AstNode* timesp = nodep->fmtp()->exprsp()) {
|
|
|
|
|
timesp->unlinkFrBackWithNext();
|
|
|
|
|
timenewp->addNext(timesp);
|
|
|
|
|
}
|
|
|
|
|
nodep->fmtp()->addExprsp(timenewp);
|
|
|
|
|
if (!nodep->fmtp()->scopeNamep() && nodep->fmtp()->formatScopeTracking()) {
|
|
|
|
|
nodep->fmtp()->scopeNamep(new AstScopeName(nodep->fileline()));
|
|
|
|
|
}
|
2007-03-06 21:43:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AstNode* newIfAssertOn(AstNode* nodep) {
|
2019-05-19 20:13:13 +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.
|
2018-10-14 22:39:33 +00:00
|
|
|
|
FileLine* fl = nodep->fileline();
|
2019-05-19 20:13:13 +00:00
|
|
|
|
AstNode* newp
|
2018-10-14 22:39:33 +00:00
|
|
|
|
= new AstIf(fl,
|
2018-08-25 13:52:45 +00:00
|
|
|
|
// If assertions are off, have constant propagation rip them out later
|
|
|
|
|
// This allows syntax errors and such to be detected normally.
|
|
|
|
|
(v3Global.opt.assertOn()
|
2018-10-14 22:39:33 +00:00
|
|
|
|
? static_cast<AstNode*>(new AstCMath(fl, "Verilated::assertOn()", 1))
|
|
|
|
|
: static_cast<AstNode*>(new AstConst(fl, AstConst::LogicFalse()))),
|
2018-08-25 13:52:45 +00:00
|
|
|
|
nodep, NULL);
|
2019-05-19 20:13:13 +00:00
|
|
|
|
newp->user1(true); // Don't assert/cover this if
|
|
|
|
|
return newp;
|
2007-03-06 21:43:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-11 14:37:20 +00:00
|
|
|
|
AstNode* newFireAssertUnchecked(AstNode* nodep, const string& message) {
|
|
|
|
|
// Like newFireAssert() but omits the asserts-on check
|
2019-05-19 20:13:13 +00:00
|
|
|
|
AstDisplay* dispp = new AstDisplay(nodep->fileline(),
|
|
|
|
|
AstDisplayType::DT_ERROR, message, NULL, NULL);
|
|
|
|
|
AstNode* bodysp = dispp;
|
|
|
|
|
replaceDisplay(dispp, "%%Error"); // Convert to standard DISPLAY format
|
2018-08-25 13:52:45 +00:00
|
|
|
|
bodysp->addNext(new AstStop(nodep->fileline()));
|
2018-03-11 14:37:20 +00:00
|
|
|
|
return bodysp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AstNode* newFireAssert(AstNode* nodep, const string& message) {
|
|
|
|
|
AstNode* bodysp = newFireAssertUnchecked(nodep, message);
|
2019-05-19 20:13:13 +00:00
|
|
|
|
bodysp = newIfAssertOn(bodysp);
|
|
|
|
|
return bodysp;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-08-06 16:52:39 +00:00
|
|
|
|
void newPslAssertion(AstNode* nodep, AstNode* propp, AstSenTree* sentreep,
|
2019-05-19 20:13:13 +00:00
|
|
|
|
AstNode* stmtsp, const string& message) {
|
|
|
|
|
propp->unlinkFrBack();
|
|
|
|
|
sentreep->unlinkFrBack();
|
|
|
|
|
if (stmtsp) stmtsp->unlinkFrBack();
|
|
|
|
|
//
|
|
|
|
|
AstNode* bodysp = NULL;
|
|
|
|
|
bool selfDestruct = false;
|
2018-03-11 14:37:20 +00:00
|
|
|
|
AstIf* ifp = NULL;
|
2018-08-23 09:09:12 +00:00
|
|
|
|
if (AstPslCover* snodep = VN_CAST(nodep, PslCover)) {
|
2018-03-11 14:37:20 +00:00
|
|
|
|
++m_statAsCover;
|
2019-05-19 20:13:13 +00:00
|
|
|
|
if (!v3Global.opt.coverageUser()) {
|
|
|
|
|
selfDestruct = true;
|
|
|
|
|
} else {
|
|
|
|
|
// V3Coverage assigned us a bucket to increment.
|
2018-02-02 02:32:58 +00:00
|
|
|
|
AstCoverInc* covincp = VN_CAST(snodep->coverincp(), CoverInc);
|
2019-07-06 16:57:50 +00:00
|
|
|
|
UASSERT_OBJ(covincp, snodep, "Missing AstCoverInc under assertion");
|
2019-05-19 20:13:13 +00:00
|
|
|
|
covincp->unlinkFrBack();
|
|
|
|
|
if (message!="") covincp->declp()->comment(message);
|
|
|
|
|
bodysp = covincp;
|
|
|
|
|
}
|
2018-03-11 14:37:20 +00:00
|
|
|
|
|
|
|
|
|
if (bodysp && stmtsp) bodysp = bodysp->addNext(stmtsp);
|
2018-08-25 13:52:45 +00:00
|
|
|
|
ifp = new AstIf(nodep->fileline(), propp, bodysp, NULL);
|
2018-03-11 14:37:20 +00:00
|
|
|
|
bodysp = ifp;
|
|
|
|
|
|
2018-03-11 14:42:44 +00:00
|
|
|
|
} else if (VN_IS(nodep, PslAssert)) {
|
2018-03-11 14:37:20 +00:00
|
|
|
|
++m_statAsPsl;
|
|
|
|
|
// Insert an automatic error message and $stop after
|
|
|
|
|
// any user-supplied statements.
|
|
|
|
|
AstNode* autoMsgp = newFireAssertUnchecked(nodep, "'assert property' failed.");
|
|
|
|
|
if (stmtsp) {
|
|
|
|
|
stmtsp->addNext(autoMsgp);
|
|
|
|
|
} else {
|
|
|
|
|
stmtsp = autoMsgp;
|
|
|
|
|
}
|
|
|
|
|
ifp = new AstIf(nodep->fileline(), propp, NULL, stmtsp);
|
|
|
|
|
// It's more LIKELY that we'll take the NULL if clause
|
|
|
|
|
// than the sim-killing else clause:
|
|
|
|
|
ifp->branchPred(AstBranchPred::BP_LIKELY);
|
|
|
|
|
bodysp = newIfAssertOn(ifp);
|
2018-09-23 19:20:12 +00:00
|
|
|
|
} else if (VN_IS(nodep, PslRestrict)) {
|
|
|
|
|
// IEEE says simulator ignores these
|
|
|
|
|
pushDeletep(nodep->unlinkFrBack()); VL_DANGLING(nodep);
|
|
|
|
|
return;
|
2019-05-19 20:13:13 +00:00
|
|
|
|
} else {
|
|
|
|
|
nodep->v3fatalSrc("Unknown node type");
|
|
|
|
|
}
|
2018-03-11 14:37:20 +00:00
|
|
|
|
|
2018-08-25 13:52:45 +00:00
|
|
|
|
AstNode* newp = new AstAlways(nodep->fileline(),
|
|
|
|
|
VAlwaysKwd::ALWAYS, sentreep, bodysp);
|
2019-05-19 20:13:13 +00:00
|
|
|
|
// 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); VL_DANGLING(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-03-06 21:43:38 +00:00
|
|
|
|
void newVAssertion(AstVAssert* nodep, AstNode* propp) {
|
2019-05-19 20:13:13 +00:00
|
|
|
|
propp->unlinkFrBackWithNext();
|
|
|
|
|
AstNode* passsp = nodep->passsp(); if (passsp) passsp->unlinkFrBackWithNext();
|
|
|
|
|
AstNode* failsp = nodep->failsp(); if (failsp) failsp->unlinkFrBackWithNext();
|
|
|
|
|
//
|
2018-02-02 02:32:58 +00:00
|
|
|
|
if (VN_IS(nodep, VAssert)) {
|
2019-05-19 20:13:13 +00:00
|
|
|
|
if (passsp) passsp = newIfAssertOn(passsp);
|
|
|
|
|
if (failsp) failsp = newIfAssertOn(failsp);
|
|
|
|
|
} else {
|
|
|
|
|
nodep->v3fatalSrc("Unknown node type");
|
|
|
|
|
}
|
2007-03-06 21:43:38 +00:00
|
|
|
|
|
2018-08-25 13:52:45 +00:00
|
|
|
|
AstIf* ifp = new AstIf(nodep->fileline(), propp, passsp, failsp);
|
2019-05-19 20:13:13 +00:00
|
|
|
|
AstNode* newp = ifp;
|
2018-02-02 02:32:58 +00:00
|
|
|
|
if (VN_IS(nodep, VAssert)) ifp->branchPred(AstBranchPred::BP_UNLIKELY);
|
2019-05-19 20:13:13 +00:00
|
|
|
|
//
|
|
|
|
|
// Install it
|
|
|
|
|
nodep->replaceWith(newp);
|
|
|
|
|
// Bye
|
|
|
|
|
pushDeletep(nodep); VL_DANGLING(nodep);
|
2007-03-06 21:43:38 +00:00
|
|
|
|
}
|
2017-09-11 23:18:58 +00:00
|
|
|
|
|
2018-09-23 19:09:47 +00:00
|
|
|
|
// VISITORS
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstIf* nodep) {
|
2019-05-19 20:13:13 +00:00
|
|
|
|
if (nodep->user1SetOnce()) return;
|
|
|
|
|
if (nodep->uniquePragma() || nodep->unique0Pragma()) {
|
|
|
|
|
AstNodeIf* ifp = nodep;
|
|
|
|
|
AstNode* propp = NULL;
|
|
|
|
|
bool hasDefaultElse = false;
|
|
|
|
|
do {
|
|
|
|
|
// If this statement ends with 'else if', then nextIf will point to the
|
|
|
|
|
// nextIf statement. Otherwise it will be null.
|
|
|
|
|
AstNodeIf* nextifp = dynamic_cast<AstNodeIf*>(ifp->elsesp());
|
2018-05-11 00:55:37 +00:00
|
|
|
|
iterateAndNextNull(ifp->condp());
|
2014-03-17 01:38:29 +00:00
|
|
|
|
|
2019-05-19 20:13:13 +00:00
|
|
|
|
// Recurse into the true case.
|
2018-05-11 00:55:37 +00:00
|
|
|
|
iterateAndNextNull(ifp->ifsp());
|
2017-09-11 23:18:58 +00:00
|
|
|
|
|
2019-05-19 20:13:13 +00:00
|
|
|
|
// If the last else is not an else if, recurse into that too.
|
|
|
|
|
if (ifp->elsesp() && !nextifp) {
|
2018-05-11 00:55:37 +00:00
|
|
|
|
iterateAndNextNull(ifp->elsesp());
|
2019-05-19 20:13:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build a bitmask of the true predicates
|
|
|
|
|
AstNode* predp = ifp->condp()->cloneTree(false);
|
|
|
|
|
if (propp) {
|
|
|
|
|
propp = new AstConcat(nodep->fileline(), predp, propp);
|
|
|
|
|
} else {
|
|
|
|
|
propp = predp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Record if this ends with an 'else' that does not have an if
|
|
|
|
|
if (ifp->elsesp() && !nextifp) {
|
|
|
|
|
hasDefaultElse = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ifp = nextifp;
|
|
|
|
|
} while (ifp);
|
|
|
|
|
|
|
|
|
|
AstNode *newifp = nodep->cloneTree(false);
|
|
|
|
|
bool allow_none = nodep->unique0Pragma();
|
|
|
|
|
|
|
|
|
|
// Empty case means no property
|
|
|
|
|
if (!propp) propp = new AstConst(nodep->fileline(), AstConst::LogicFalse());
|
|
|
|
|
|
|
|
|
|
// Note: if this ends with an 'else', then we don't need to validate that one of the
|
|
|
|
|
// predicates evaluates to true.
|
|
|
|
|
AstNode* ohot = ((allow_none || hasDefaultElse)
|
|
|
|
|
? static_cast<AstNode*>(new AstOneHot0(nodep->fileline(), propp))
|
|
|
|
|
: static_cast<AstNode*>(new AstOneHot(nodep->fileline(), propp)));
|
2018-08-25 13:52:45 +00:00
|
|
|
|
AstIf* checkifp = new AstIf(nodep->fileline(),
|
|
|
|
|
new AstLogNot(nodep->fileline(), ohot),
|
|
|
|
|
newFireAssert(nodep, "'unique if' statement violated"),
|
|
|
|
|
newifp);
|
2019-05-19 20:13:13 +00:00
|
|
|
|
checkifp->branchPred(AstBranchPred::BP_UNLIKELY);
|
|
|
|
|
nodep->replaceWith(checkifp);
|
|
|
|
|
pushDeletep(nodep);
|
|
|
|
|
} else {
|
2018-05-11 00:55:37 +00:00
|
|
|
|
iterateChildren(nodep);
|
2019-05-19 20:13:13 +00:00
|
|
|
|
}
|
2014-03-17 01:38:29 +00:00
|
|
|
|
}
|
2007-03-06 21:43:38 +00:00
|
|
|
|
|
2018-09-23 19:09:47 +00:00
|
|
|
|
//========== Case assertions
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstCase* nodep) {
|
2018-05-11 00:55:37 +00:00
|
|
|
|
iterateChildren(nodep);
|
2019-05-19 20:13:13 +00:00
|
|
|
|
if (!nodep->user1SetOnce()) {
|
|
|
|
|
bool has_default = false;
|
|
|
|
|
for (AstCaseItem* itemp = nodep->itemsp();
|
|
|
|
|
itemp; itemp = VN_CAST(itemp->nextp(), CaseItem)) {
|
|
|
|
|
if (itemp->isDefault()) has_default = true;
|
|
|
|
|
}
|
|
|
|
|
if (nodep->fullPragma() || nodep->priorityPragma()) {
|
|
|
|
|
// Simply need to add a default if there isn't one already
|
|
|
|
|
++m_statAsFull;
|
|
|
|
|
if (!has_default) {
|
|
|
|
|
nodep->addItemsp(new AstCaseItem(nodep->fileline(), NULL/*DEFAULT*/,
|
|
|
|
|
newFireAssert(nodep, "synthesis full_case, but non-match found")));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (nodep->parallelPragma() || nodep->uniquePragma() || nodep->unique0Pragma()) {
|
|
|
|
|
// 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
|
|
|
|
|
++m_statAsFull;
|
|
|
|
|
if (!has_default && !nodep->itemsp()) {
|
|
|
|
|
// Not parallel, but harmlessly so.
|
|
|
|
|
} else {
|
|
|
|
|
AstNode* propp = NULL;
|
|
|
|
|
for (AstCaseItem* itemp = nodep->itemsp();
|
|
|
|
|
itemp; itemp=VN_CAST(itemp->nextp(), CaseItem)) {
|
|
|
|
|
for (AstNode* icondp = itemp->condsp();
|
|
|
|
|
icondp!=NULL; icondp=icondp->nextp()) {
|
|
|
|
|
AstNode* onep;
|
|
|
|
|
if (nodep->casex() || nodep->casez() || nodep->caseInside()) {
|
|
|
|
|
onep = AstEqWild::newTyped(itemp->fileline(),
|
|
|
|
|
nodep->exprp()->cloneTree(false),
|
|
|
|
|
icondp->cloneTree(false));
|
|
|
|
|
} else {
|
|
|
|
|
onep = AstEq::newTyped(icondp->fileline(),
|
|
|
|
|
nodep->exprp()->cloneTree(false),
|
|
|
|
|
icondp->cloneTree(false));
|
|
|
|
|
}
|
|
|
|
|
if (propp) propp = new AstConcat(icondp->fileline(), onep, propp);
|
|
|
|
|
else propp = onep;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Empty case means no property
|
|
|
|
|
if (!propp) propp = new AstConst(nodep->fileline(), AstConst::LogicFalse());
|
|
|
|
|
|
|
|
|
|
bool allow_none = has_default || nodep->unique0Pragma();
|
|
|
|
|
AstNode* ohot
|
|
|
|
|
= (allow_none
|
|
|
|
|
? static_cast<AstNode*>(new AstOneHot0(nodep->fileline(), propp))
|
|
|
|
|
: static_cast<AstNode*>(new AstOneHot(nodep->fileline(), propp)));
|
2018-08-25 13:52:45 +00:00
|
|
|
|
AstIf* ifp = new AstIf(nodep->fileline(),
|
|
|
|
|
new AstLogNot(nodep->fileline(), ohot),
|
|
|
|
|
newFireAssert(nodep, "synthesis parallel_case, but multiple matches found"),
|
|
|
|
|
NULL);
|
2019-05-19 20:13:13 +00:00
|
|
|
|
ifp->branchPred(AstBranchPred::BP_UNLIKELY);
|
|
|
|
|
nodep->addNotParallelp(ifp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-23 19:09:47 +00:00
|
|
|
|
//========== Past
|
|
|
|
|
virtual void visit(AstPast* nodep) {
|
|
|
|
|
iterateChildren(nodep);
|
|
|
|
|
uint32_t ticks = 1;
|
|
|
|
|
if (nodep->ticksp()) {
|
2019-07-06 16:57:50 +00:00
|
|
|
|
UASSERT_OBJ(VN_IS(nodep->ticksp(), Const), nodep,
|
|
|
|
|
"Expected constant ticks, checked in V3Width");
|
2018-09-23 19:09:47 +00:00
|
|
|
|
ticks = VN_CAST(nodep->ticksp(), Const)->toUInt();
|
|
|
|
|
}
|
2019-07-06 16:57:50 +00:00
|
|
|
|
UASSERT_OBJ(ticks>=1, nodep, "0 tick should have been checked in V3Width");
|
2018-09-23 19:09:47 +00:00
|
|
|
|
AstNode* inp = nodep->exprp()->unlinkFrBack();
|
|
|
|
|
AstVar* invarp = NULL;
|
|
|
|
|
AstSenTree* sentreep = nodep->sentreep(); sentreep->unlinkFrBack();
|
|
|
|
|
AstAlways* alwaysp = new AstAlways(nodep->fileline(), VAlwaysKwd::ALWAYS,
|
|
|
|
|
sentreep, NULL);
|
|
|
|
|
m_modp->addStmtp(alwaysp);
|
|
|
|
|
for (uint32_t i=0; i<ticks; ++i) {
|
|
|
|
|
AstVar* outvarp = new AstVar(nodep->fileline(), AstVarType::MODULETEMP,
|
|
|
|
|
"_Vpast_"+cvtToStr(m_modPastNum++)+"_"+cvtToStr(i),
|
|
|
|
|
inp->dtypep());
|
|
|
|
|
m_modp->addStmtp(outvarp);
|
|
|
|
|
AstNode* assp = new AstAssignDly(nodep->fileline(),
|
|
|
|
|
new AstVarRef(nodep->fileline(), outvarp, true),
|
|
|
|
|
inp);
|
|
|
|
|
alwaysp->addStmtp(assp);
|
|
|
|
|
//if (debug()>-9) assp->dumpTree(cout, "-ass: ");
|
|
|
|
|
invarp = outvarp;
|
|
|
|
|
inp = new AstVarRef(nodep->fileline(), invarp, false);
|
|
|
|
|
}
|
|
|
|
|
nodep->replaceWith(inp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//========== Statements
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstDisplay* nodep) {
|
2018-05-11 00:55:37 +00:00
|
|
|
|
iterateChildren(nodep);
|
2019-05-19 20:13:13 +00:00
|
|
|
|
// Replace the special types with standard text
|
|
|
|
|
if (nodep->displayType()==AstDisplayType::DT_INFO) {
|
|
|
|
|
replaceDisplay(nodep, "-Info");
|
|
|
|
|
} else if (nodep->displayType()==AstDisplayType::DT_WARNING) {
|
|
|
|
|
replaceDisplay(nodep, "%%Warning");
|
|
|
|
|
} else if (nodep->displayType()==AstDisplayType::DT_ERROR
|
|
|
|
|
|| nodep->displayType()==AstDisplayType::DT_FATAL) {
|
|
|
|
|
replaceDisplay(nodep, "%%Error");
|
|
|
|
|
}
|
2007-03-06 21:43:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-11 14:37:20 +00:00
|
|
|
|
virtual void visit(AstNodePslCoverOrAssert* nodep) {
|
2018-05-11 00:55:37 +00:00
|
|
|
|
iterateChildren(nodep);
|
2019-05-19 20:13:13 +00:00
|
|
|
|
if (m_beginp && nodep->name() == "") nodep->name(m_beginp->name());
|
|
|
|
|
newPslAssertion(nodep, nodep->propp(), nodep->sentreep(),
|
|
|
|
|
nodep->stmtsp(), nodep->name()); VL_DANGLING(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstVAssert* nodep) {
|
2018-05-11 00:55:37 +00:00
|
|
|
|
iterateChildren(nodep);
|
2019-05-19 20:13:13 +00:00
|
|
|
|
newVAssertion(nodep, nodep->propp()); VL_DANGLING(nodep);
|
|
|
|
|
++m_statAsSV;
|
2007-03-06 21:43:38 +00:00
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstNodeModule* nodep) {
|
2019-05-19 20:13:13 +00:00
|
|
|
|
m_modp = nodep;
|
2018-09-23 19:09:47 +00:00
|
|
|
|
m_modPastNum = 0;
|
2019-05-19 20:13:13 +00:00
|
|
|
|
//
|
2018-05-11 00:55:37 +00:00
|
|
|
|
iterateChildren(nodep);
|
2019-05-19 20:13:13 +00:00
|
|
|
|
// Reset defaults
|
|
|
|
|
m_modp = NULL;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstBegin* nodep) {
|
2019-05-19 20:13:13 +00:00
|
|
|
|
// This code is needed rather than a visitor in V3Begin,
|
|
|
|
|
// because V3Assert is called before V3Begin
|
|
|
|
|
AstBegin* lastp = m_beginp;
|
|
|
|
|
{
|
|
|
|
|
m_beginp = nodep;
|
2018-05-11 00:55:37 +00:00
|
|
|
|
iterateChildren(nodep);
|
2019-05-19 20:13:13 +00:00
|
|
|
|
}
|
|
|
|
|
m_beginp = lastp;
|
2008-08-06 16:52:39 +00:00
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstNode* nodep) {
|
2018-05-11 00:55:37 +00:00
|
|
|
|
iterateChildren(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
public:
|
|
|
|
|
// CONSTRUCTORS
|
2015-10-04 02:33:06 +00:00
|
|
|
|
explicit AssertVisitor(AstNetlist* nodep) {
|
2019-05-19 20:13:13 +00:00
|
|
|
|
m_beginp = NULL;
|
|
|
|
|
m_modp = NULL;
|
2018-09-23 19:09:47 +00:00
|
|
|
|
m_modPastNum = 0;
|
2019-05-19 20:13:13 +00:00
|
|
|
|
// Process
|
2018-05-11 00:55:37 +00:00
|
|
|
|
iterate(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
virtual ~AssertVisitor() {
|
2019-05-19 20:13:13 +00:00
|
|
|
|
V3Stats::addStat("Assertions, PSL asserts", m_statAsPsl);
|
|
|
|
|
V3Stats::addStat("Assertions, SystemVerilog asserts", m_statAsSV);
|
|
|
|
|
V3Stats::addStat("Assertions, cover statements", m_statAsCover);
|
|
|
|
|
V3Stats::addStat("Assertions, full/parallel case", m_statAsFull);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// Top Assert class
|
|
|
|
|
|
|
|
|
|
void V3Assert::assertAll(AstNetlist* nodep) {
|
|
|
|
|
UINFO(2,__FUNCTION__<<": "<<endl);
|
2018-03-10 17:57:50 +00:00
|
|
|
|
{
|
|
|
|
|
AssertVisitor visitor (nodep);
|
|
|
|
|
} // Destruct before checking
|
2017-09-18 02:52:57 +00:00
|
|
|
|
V3Global::dumpCheckGlobalTree("assert", 0, v3Global.opt.dumpTreeLevel(__FILE__) >= 3);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|