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
|
|
|
|
//
|
2019-11-08 03:33:59 +00:00
|
|
|
// Code available from: https://verilator.org
|
2006-08-26 11:35:28 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
//
|
2020-03-21 15:24:24 +00:00
|
|
|
// Copyright 2005-2020 by Wilson Snyder. This program is free software; you
|
|
|
|
// can 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.
|
2020-03-21 15:24:24 +00:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
2006-08-26 11:35:28 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
// Pre steps:
|
2019-05-19 20:13:13 +00:00
|
|
|
// Attach clocks to each assertion
|
2006-08-26 11:35:28 +00:00
|
|
|
//*************************************************************************
|
2019-10-05 00:17:11 +00:00
|
|
|
|
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 "V3AssertPre.h"
|
2018-10-14 17:43:24 +00:00
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
//######################################################################
|
|
|
|
// Assert class functions
|
|
|
|
|
|
|
|
class AssertPreVisitor : public AstNVisitor {
|
|
|
|
// Removes clocks and other pre-optimizations
|
|
|
|
// Eventually inlines calls to sequences, properties, etc.
|
|
|
|
// We're not parsing the tree, or anything more complicated.
|
|
|
|
private:
|
|
|
|
// NODE STATE/TYPES
|
|
|
|
// STATE
|
|
|
|
// Reset each module:
|
2018-09-23 19:09:47 +00:00
|
|
|
AstNodeSenItem* m_seniDefaultp; // Default sensitivity (from AstDefClock)
|
2006-08-26 11:35:28 +00:00
|
|
|
// Reset each assertion:
|
2018-09-23 19:09:47 +00:00
|
|
|
AstNodeSenItem* m_senip; // Last sensitivity
|
|
|
|
// Reset each always:
|
|
|
|
AstNodeSenItem* m_seniAlwaysp; // Last sensitivity in always
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
// METHODS
|
2018-05-14 10:50:47 +00:00
|
|
|
VL_DEBUG_FUNC; // Declare debug()
|
2009-01-21 21:56:50 +00:00
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
AstSenTree* newSenTree(AstNode* nodep) {
|
2019-05-19 20:13:13 +00:00
|
|
|
// Create sentree based on clocked or default clock
|
|
|
|
// Return NULL for always
|
|
|
|
AstSenTree* newp = NULL;
|
2018-09-23 19:09:47 +00:00
|
|
|
AstNodeSenItem* senip = m_senip;
|
|
|
|
if (!senip) senip = m_seniDefaultp;
|
|
|
|
if (!senip) senip = m_seniAlwaysp;
|
2019-05-19 20:13:13 +00:00
|
|
|
if (!senip) {
|
2020-06-09 23:20:16 +00:00
|
|
|
nodep->v3warn(E_UNSUPPORTED, "Unsupported: Unclocked assertion");
|
2019-05-19 20:13:13 +00:00
|
|
|
newp = new AstSenTree(nodep->fileline(), NULL);
|
|
|
|
} else {
|
|
|
|
newp = new AstSenTree(nodep->fileline(), senip->cloneTree(true));
|
|
|
|
}
|
|
|
|
return newp;
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
2020-04-14 02:51:35 +00:00
|
|
|
void clearAssertInfo() { m_senip = NULL; }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
2018-09-23 19:09:47 +00:00
|
|
|
// VISITORS
|
|
|
|
//========== Statements
|
2020-01-21 22:35:56 +00:00
|
|
|
virtual void visit(AstClocking* nodep) VL_OVERRIDE {
|
2020-04-14 02:51:35 +00:00
|
|
|
UINFO(8, " CLOCKING" << nodep << endl);
|
2019-05-19 20:13:13 +00:00
|
|
|
// Store the new default clock, reset on new module
|
|
|
|
m_seniDefaultp = nodep->sensesp();
|
|
|
|
// Trash it, keeping children
|
|
|
|
if (nodep->bodysp()) {
|
|
|
|
nodep->replaceWith(nodep->bodysp()->unlinkFrBack());
|
|
|
|
} else {
|
|
|
|
nodep->unlinkFrBack();
|
|
|
|
}
|
2020-01-17 01:17:11 +00:00
|
|
|
VL_DO_DANGLING(pushDeletep(nodep), nodep);
|
2008-08-06 16:52:39 +00:00
|
|
|
}
|
2020-01-21 22:35:56 +00:00
|
|
|
virtual void visit(AstAlways* nodep) VL_OVERRIDE {
|
2018-09-23 19:09:47 +00:00
|
|
|
iterateAndNextNull(nodep->sensesp());
|
2020-04-14 02:51:35 +00:00
|
|
|
if (nodep->sensesp()) m_seniAlwaysp = nodep->sensesp()->sensesp();
|
2018-09-23 19:09:47 +00:00
|
|
|
iterateAndNextNull(nodep->bodysp());
|
|
|
|
m_seniAlwaysp = NULL;
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
2020-01-21 22:35:56 +00:00
|
|
|
virtual void visit(AstNodeCoverOrAssert* nodep) VL_OVERRIDE {
|
2019-05-19 20:13:13 +00:00
|
|
|
if (nodep->sentreep()) return; // Already processed
|
|
|
|
clearAssertInfo();
|
2019-12-17 02:43:52 +00:00
|
|
|
// Find Clocking's buried under nodep->exprsp
|
2018-05-11 00:55:37 +00:00
|
|
|
iterateChildren(nodep);
|
2020-04-14 02:51:35 +00:00
|
|
|
if (!nodep->immediate()) nodep->sentreep(newSenTree(nodep));
|
2019-05-19 20:13:13 +00:00
|
|
|
clearAssertInfo();
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
2020-01-21 22:35:56 +00:00
|
|
|
virtual void visit(AstPast* nodep) VL_OVERRIDE {
|
2018-09-23 19:09:47 +00:00
|
|
|
if (nodep->sentreep()) return; // Already processed
|
2018-05-11 00:55:37 +00:00
|
|
|
iterateChildren(nodep);
|
2018-09-23 19:09:47 +00:00
|
|
|
nodep->sentreep(newSenTree(nodep));
|
|
|
|
}
|
2020-01-21 22:35:56 +00:00
|
|
|
virtual void visit(AstPropClocked* nodep) VL_OVERRIDE {
|
2018-09-23 19:09:47 +00:00
|
|
|
// No need to iterate the body, once replace will get iterated
|
|
|
|
iterateAndNextNull(nodep->sensesp());
|
2020-06-09 23:20:16 +00:00
|
|
|
if (m_senip)
|
|
|
|
nodep->v3warn(E_UNSUPPORTED, "Unsupported: Only one PSL clock allowed per assertion");
|
2019-05-19 20:13:13 +00:00
|
|
|
// Block is the new expression to evaluate
|
|
|
|
AstNode* blockp = nodep->propp()->unlinkFrBack();
|
|
|
|
if (nodep->disablep()) {
|
2019-12-22 20:49:10 +00:00
|
|
|
if (VN_IS(nodep->backp(), Cover)) {
|
2020-04-14 02:51:35 +00:00
|
|
|
blockp = new AstAnd(
|
|
|
|
nodep->disablep()->fileline(),
|
|
|
|
new AstNot(nodep->disablep()->fileline(), nodep->disablep()->unlinkFrBack()),
|
|
|
|
blockp);
|
2019-12-22 20:49:10 +00:00
|
|
|
} else {
|
|
|
|
blockp = new AstOr(nodep->disablep()->fileline(),
|
2020-04-14 02:51:35 +00:00
|
|
|
nodep->disablep()->unlinkFrBack(), blockp);
|
2019-12-22 20:49:10 +00:00
|
|
|
}
|
2019-05-19 20:13:13 +00:00
|
|
|
}
|
|
|
|
// Unlink and just keep a pointer to it, convert to sentree as needed
|
|
|
|
m_senip = nodep->sensesp();
|
|
|
|
nodep->replaceWith(blockp);
|
2020-01-17 01:17:11 +00:00
|
|
|
VL_DO_DANGLING(pushDeletep(nodep), nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
2020-01-21 22:35:56 +00:00
|
|
|
virtual void visit(AstNodeModule* nodep) VL_OVERRIDE {
|
2018-05-11 00:55:37 +00:00
|
|
|
iterateChildren(nodep);
|
2019-05-19 20:13:13 +00:00
|
|
|
// Reset defaults
|
|
|
|
m_seniDefaultp = NULL;
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
2020-04-04 12:31:14 +00:00
|
|
|
virtual void visit(AstNode* nodep) VL_OVERRIDE { iterateChildren(nodep); }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
// CONSTRUCTORS
|
2015-10-04 02:33:06 +00:00
|
|
|
explicit AssertPreVisitor(AstNetlist* nodep) {
|
2019-05-19 20:13:13 +00:00
|
|
|
m_seniDefaultp = NULL;
|
2018-09-23 19:09:47 +00:00
|
|
|
m_seniAlwaysp = NULL;
|
2019-05-19 20:13:13 +00:00
|
|
|
clearAssertInfo();
|
|
|
|
// Process
|
2018-05-11 00:55:37 +00:00
|
|
|
iterate(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
|
|
|
virtual ~AssertPreVisitor() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
// Top Assert class
|
|
|
|
|
|
|
|
void V3AssertPre::assertPreAll(AstNetlist* nodep) {
|
2020-04-14 02:51:35 +00:00
|
|
|
UINFO(2, __FUNCTION__ << ": " << endl);
|
|
|
|
{ AssertPreVisitor visitor(nodep); } // Destruct before checking
|
2017-09-18 02:52:57 +00:00
|
|
|
V3Global::dumpCheckGlobalTree("assertpre", 0, v3Global.opt.dumpTreeLevel(__FILE__) >= 3);
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|