2012-04-13 03:08:20 +02:00
|
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
2006-08-26 13:35:28 +02:00
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
// DESCRIPTION: Verilator: Collect and print statistics
|
|
|
|
|
|
//
|
2008-04-25 14:14:27 +02:00
|
|
|
|
// Code available from: http://www.veripool.org/verilator
|
2006-08-26 13:35:28 +02:00
|
|
|
|
//
|
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
//
|
2018-01-03 00:05:06 +01:00
|
|
|
|
// Copyright 2005-2018 by Wilson Snyder. This program is free software; you can
|
2006-08-26 13:35:28 +02:00
|
|
|
|
// redistribute it and/or modify it under the terms of either the GNU
|
2009-05-04 23:07:57 +02:00
|
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
|
|
// Version 2.0.
|
2006-08-26 13:35:28 +02: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.
|
|
|
|
|
|
//
|
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
// Pre steps:
|
|
|
|
|
|
// Attach clocks to each assertion
|
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
|
2006-12-18 20:20:45 +01:00
|
|
|
|
#include "config_build.h"
|
|
|
|
|
|
#include "verilatedos.h"
|
2008-06-30 19:11:25 +02:00
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
#include <cstdarg>
|
2006-08-26 13:35:28 +02:00
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
#include <iomanip>
|
|
|
|
|
|
|
|
|
|
|
|
#include "V3Global.h"
|
|
|
|
|
|
#include "V3AssertPre.h"
|
|
|
|
|
|
#include "V3Ast.h"
|
|
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
|
// 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:
|
2008-11-20 13:55:54 +01:00
|
|
|
|
AstNodeSenItem* m_seniDefaultp; // Default sensitivity (from AstDefClock)
|
2006-08-26 13:35:28 +02:00
|
|
|
|
// Reset each assertion:
|
2008-11-20 13:55:54 +01:00
|
|
|
|
AstNodeSenItem* m_senip; // Last sensitivity
|
2006-08-26 13:35:28 +02:00
|
|
|
|
|
|
|
|
|
|
// METHODS
|
2009-01-21 22:56:50 +01:00
|
|
|
|
static int debug() {
|
|
|
|
|
|
static int level = -1;
|
|
|
|
|
|
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
|
|
|
|
|
|
return level;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-08-26 13:35:28 +02:00
|
|
|
|
AstSenTree* newSenTree(AstNode* nodep) {
|
|
|
|
|
|
// Create sentree based on clocked or default clock
|
|
|
|
|
|
// Return NULL for always
|
|
|
|
|
|
AstSenTree* newp = NULL;
|
2008-11-20 13:55:54 +01:00
|
|
|
|
AstNodeSenItem* senip = m_senip ? m_senip : m_seniDefaultp;
|
2008-08-06 23:51:36 +02:00
|
|
|
|
if (!senip) {
|
|
|
|
|
|
nodep->v3error("Unsupported: Unclocked assertion");
|
|
|
|
|
|
newp = new AstSenTree(nodep->fileline(), NULL);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
newp = new AstSenTree(nodep->fileline(), senip->cloneTree(true));
|
|
|
|
|
|
}
|
2006-08-26 13:35:28 +02:00
|
|
|
|
return newp;
|
|
|
|
|
|
}
|
2008-08-06 18:52:39 +02:00
|
|
|
|
void clearAssertInfo() {
|
|
|
|
|
|
m_senip = NULL;
|
|
|
|
|
|
}
|
2006-08-26 13:35:28 +02:00
|
|
|
|
|
|
|
|
|
|
// VISITORS //========== Statements
|
2016-11-27 14:11:38 +01:00
|
|
|
|
virtual void visit(AstClocking* nodep) {
|
2008-08-06 18:52:39 +02:00
|
|
|
|
UINFO(8," CLOCKING"<<nodep<<endl);
|
2008-08-06 23:51:36 +02: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();
|
2008-08-06 18:52:39 +02:00
|
|
|
|
}
|
2015-10-04 19:16:35 +02:00
|
|
|
|
pushDeletep(nodep); VL_DANGLING(nodep);
|
2008-08-06 18:52:39 +02:00
|
|
|
|
}
|
2006-08-26 13:35:28 +02:00
|
|
|
|
|
2016-11-27 14:11:38 +01:00
|
|
|
|
virtual void visit(AstPslCover* nodep) {
|
2008-08-06 18:52:39 +02:00
|
|
|
|
if (nodep->sentreep()) return; // Already processed
|
|
|
|
|
|
clearAssertInfo();
|
2006-08-26 13:35:28 +02:00
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
|
nodep->sentreep(newSenTree(nodep));
|
2008-08-06 18:52:39 +02:00
|
|
|
|
clearAssertInfo();
|
2006-08-26 13:35:28 +02:00
|
|
|
|
}
|
2016-11-27 14:11:38 +01:00
|
|
|
|
virtual void visit(AstPslClocked* nodep) {
|
2006-08-26 13:35:28 +02:00
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
|
if (m_senip) {
|
2010-01-16 02:07:16 +01:00
|
|
|
|
nodep->v3error("Unsupported: Only one PSL clock allowed per assertion");
|
2006-08-26 13:35:28 +02:00
|
|
|
|
}
|
2008-08-06 18:52:39 +02:00
|
|
|
|
// Block is the new expression to evaluate
|
2006-08-26 13:35:28 +02:00
|
|
|
|
AstNode* blockp = nodep->propp()->unlinkFrBack();
|
2008-08-06 18:52:39 +02:00
|
|
|
|
if (nodep->disablep()) {
|
|
|
|
|
|
blockp = new AstAnd(nodep->disablep()->fileline(),
|
|
|
|
|
|
new AstNot(nodep->disablep()->fileline(),
|
|
|
|
|
|
nodep->disablep()->unlinkFrBack()),
|
|
|
|
|
|
blockp);
|
|
|
|
|
|
}
|
|
|
|
|
|
// Unlink and just keep a pointer to it, convert to sentree as needed
|
2006-08-26 13:35:28 +02:00
|
|
|
|
m_senip = nodep->sensesp();
|
|
|
|
|
|
nodep->replaceWith(blockp);
|
2015-10-04 19:16:35 +02:00
|
|
|
|
pushDeletep(nodep); VL_DANGLING(nodep);
|
2006-08-26 13:35:28 +02:00
|
|
|
|
}
|
2016-11-27 14:11:38 +01:00
|
|
|
|
virtual void visit(AstNodeModule* nodep) {
|
2006-08-26 13:35:28 +02:00
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
|
// Reset defaults
|
|
|
|
|
|
m_seniDefaultp = NULL;
|
|
|
|
|
|
}
|
2016-11-27 14:11:38 +01:00
|
|
|
|
virtual void visit(AstNode* nodep) {
|
2006-08-26 13:35:28 +02:00
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
// CONSTRUCTORS
|
2015-10-04 04:33:06 +02:00
|
|
|
|
explicit AssertPreVisitor(AstNetlist* nodep) {
|
2006-08-26 13:35:28 +02:00
|
|
|
|
m_seniDefaultp = NULL;
|
2008-08-06 18:52:39 +02:00
|
|
|
|
clearAssertInfo();
|
2006-08-26 13:35:28 +02:00
|
|
|
|
// Process
|
|
|
|
|
|
nodep->accept(*this);
|
|
|
|
|
|
}
|
|
|
|
|
|
virtual ~AssertPreVisitor() {}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
|
// Top Assert class
|
|
|
|
|
|
|
|
|
|
|
|
void V3AssertPre::assertPreAll(AstNetlist* nodep) {
|
|
|
|
|
|
UINFO(2,__FUNCTION__<<": "<<endl);
|
2018-03-10 18:57:50 +01:00
|
|
|
|
{
|
|
|
|
|
|
AssertPreVisitor visitor (nodep);
|
|
|
|
|
|
} // Destruct before checking
|
2017-09-18 04:52:57 +02:00
|
|
|
|
V3Global::dumpCheckGlobalTree("assertpre", 0, v3Global.opt.dumpTreeLevel(__FILE__) >= 3);
|
2006-08-26 13:35:28 +02:00
|
|
|
|
}
|