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: Clocking POS/NEGEDGE insertion
|
|
|
|
|
//
|
2008-04-25 12:14:27 +00:00
|
|
|
|
// Code available from: http://www.veripool.org/verilator
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2018-01-02 23:05:06 +00:00
|
|
|
|
// Copyright 2003-2018 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.
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
// V3Clock's Transformations:
|
2008-06-10 01:25:10 +00:00
|
|
|
|
//
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Top Scope:
|
|
|
|
|
// Check created ACTIVEs
|
|
|
|
|
// Compress adjacent ACTIVEs with same sensitivity list
|
|
|
|
|
// Form master _eval function
|
|
|
|
|
// Add around the SENTREE a (IF POSEDGE(..))
|
|
|
|
|
// Add a __Vlast_{clock} for the comparison
|
|
|
|
|
// Set the __Vlast_{clock} at the end of the block
|
|
|
|
|
// Replace UNTILSTABLEs with loops until specified signals become const.
|
|
|
|
|
// Create global calling function for any per-scope functions. (For FINALs).
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
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 <algorithm>
|
|
|
|
|
|
|
|
|
|
#include "V3Global.h"
|
|
|
|
|
#include "V3Clock.h"
|
|
|
|
|
#include "V3Ast.h"
|
2006-08-30 21:07:55 +00:00
|
|
|
|
#include "V3EmitCBase.h"
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// Clock state, as a visitor of each AstNode
|
|
|
|
|
|
|
|
|
|
class ClockVisitor : public AstNVisitor {
|
|
|
|
|
private:
|
|
|
|
|
// NODE STATE
|
|
|
|
|
// Cleared each Module:
|
2008-11-25 14:03:49 +00:00
|
|
|
|
// AstVarScope::user1p() -> AstVarScope*. Temporary signal that was created.
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// AstVarScope::user2p() -> AstVarScope*. Temporary signal for change detects
|
2008-11-25 14:03:49 +00:00
|
|
|
|
AstUser1InUse m_inuser1;
|
|
|
|
|
AstUser2InUse m_inuser2;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
// TYPES
|
|
|
|
|
enum { DOUBLE_OR_RATE = 10 }; // How many | per ||, Determined experimentally as best
|
|
|
|
|
|
|
|
|
|
// STATE
|
2009-11-07 11:20:20 +00:00
|
|
|
|
AstNodeModule* m_modp; // Current module
|
2006-08-26 11:35:28 +00:00
|
|
|
|
AstTopScope* m_topScopep; // Current top scope
|
|
|
|
|
AstScope* m_scopep; // Current scope
|
|
|
|
|
AstCFunc* m_evalFuncp; // Top eval function we are creating
|
|
|
|
|
AstCFunc* m_initFuncp; // Top initial function we are creating
|
|
|
|
|
AstCFunc* m_finalFuncp; // Top final function we are creating
|
|
|
|
|
AstCFunc* m_settleFuncp; // Top settlement function we are creating
|
|
|
|
|
AstSenTree* m_lastSenp; // Last sensitivity match, so we can detect duplicates.
|
|
|
|
|
AstIf* m_lastIfp; // Last sensitivity if active to add more under
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
AstVarScope* getCreateLastClk(AstVarScope* vscp) {
|
2008-11-25 14:03:49 +00:00
|
|
|
|
if (vscp->user1p()) return ((AstVarScope*)vscp->user1p());
|
2006-08-26 11:35:28 +00:00
|
|
|
|
AstVar* varp = vscp->varp();
|
2011-11-30 23:50:21 +00:00
|
|
|
|
if (!varp->width1()) varp->v3error("Unsupported: Clock edge on non-single bit signal: "<<varp->prettyName());
|
2012-11-02 23:55:34 +00:00
|
|
|
|
string newvarname = ((string)"__Vclklast__"+vscp->scopep()->nameDotless()+"__"+varp->name());
|
2012-03-31 15:10:34 +00:00
|
|
|
|
AstVar* newvarp = new AstVar (vscp->fileline(), AstVarType::MODULETEMP, newvarname, VFlagLogicPacked(), 1);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
m_modp->addStmtp(newvarp);
|
|
|
|
|
AstVarScope* newvscp = new AstVarScope(vscp->fileline(), m_scopep, newvarp);
|
2008-11-25 14:03:49 +00:00
|
|
|
|
vscp->user1p(newvscp);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
m_scopep->addVarp(newvscp);
|
|
|
|
|
// At bottom, assign them
|
|
|
|
|
AstAssign* finalp
|
|
|
|
|
= new AstAssign (vscp->fileline(),
|
|
|
|
|
new AstVarRef(vscp->fileline(), newvscp, true),
|
|
|
|
|
new AstVarRef(vscp->fileline(), vscp, false));
|
|
|
|
|
m_evalFuncp->addFinalsp(finalp);
|
|
|
|
|
//
|
|
|
|
|
UINFO(4,"New Last: "<<newvscp<<endl);
|
|
|
|
|
return newvscp;
|
|
|
|
|
}
|
2008-11-20 12:55:54 +00:00
|
|
|
|
AstNode* createSenItemEquation(AstSenItem* nodep) {
|
|
|
|
|
// We know the var is clean, and one bit, so we use binary ops
|
|
|
|
|
// for speed instead of logical ops.
|
|
|
|
|
// POSEDGE: var & ~var_last
|
|
|
|
|
// NEGEDGE: ~var & var_last
|
|
|
|
|
// BOTHEDGE: var ^ var_last
|
|
|
|
|
// HIGHEDGE: var
|
|
|
|
|
// LOWEDGE: ~var
|
|
|
|
|
AstNode* newp = NULL;
|
2016-12-21 23:23:14 +00:00
|
|
|
|
if (nodep->edgeType()==AstEdgeType::ET_ILLEGAL) {
|
|
|
|
|
if (!v3Global.opt.bboxUnsup()) {
|
|
|
|
|
nodep->v3error("Unsupported: Complicated event expression in sensitive activity list");
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2008-11-20 12:55:54 +00:00
|
|
|
|
AstVarScope* clkvscp = nodep->varrefp()->varScopep();
|
2010-02-02 01:15:48 +00:00
|
|
|
|
if (nodep->edgeType()==AstEdgeType::ET_POSEDGE) {
|
2008-11-20 12:55:54 +00:00
|
|
|
|
AstVarScope* lastVscp = getCreateLastClk(clkvscp);
|
|
|
|
|
newp = new AstAnd(nodep->fileline(),
|
|
|
|
|
new AstVarRef(nodep->fileline(),
|
|
|
|
|
nodep->varrefp()->varScopep(), false),
|
|
|
|
|
new AstNot(nodep->fileline(),
|
|
|
|
|
new AstVarRef(nodep->fileline(),
|
|
|
|
|
lastVscp, false)));
|
2010-02-02 01:15:48 +00:00
|
|
|
|
} else if (nodep->edgeType()==AstEdgeType::ET_NEGEDGE) {
|
2008-11-20 12:55:54 +00:00
|
|
|
|
AstVarScope* lastVscp = getCreateLastClk(clkvscp);
|
|
|
|
|
newp = new AstAnd(nodep->fileline(),
|
|
|
|
|
new AstNot(nodep->fileline(),
|
|
|
|
|
new AstVarRef(nodep->fileline(),
|
|
|
|
|
nodep->varrefp()->varScopep(), false)),
|
|
|
|
|
new AstVarRef(nodep->fileline(), lastVscp, false));
|
2010-02-02 01:15:48 +00:00
|
|
|
|
} else if (nodep->edgeType()==AstEdgeType::ET_BOTHEDGE) {
|
2008-11-20 12:55:54 +00:00
|
|
|
|
AstVarScope* lastVscp = getCreateLastClk(clkvscp);
|
|
|
|
|
newp = new AstXor(nodep->fileline(),
|
|
|
|
|
new AstVarRef(nodep->fileline(),
|
|
|
|
|
nodep->varrefp()->varScopep(), false),
|
|
|
|
|
new AstVarRef(nodep->fileline(), lastVscp, false));
|
2010-02-02 01:15:48 +00:00
|
|
|
|
} else if (nodep->edgeType()==AstEdgeType::ET_HIGHEDGE) {
|
2008-11-20 12:55:54 +00:00
|
|
|
|
newp = new AstVarRef(nodep->fileline(),
|
|
|
|
|
clkvscp, false);
|
2010-02-02 01:15:48 +00:00
|
|
|
|
} else if (nodep->edgeType()==AstEdgeType::ET_LOWEDGE) {
|
2008-11-20 12:55:54 +00:00
|
|
|
|
newp = new AstNot(nodep->fileline(),
|
|
|
|
|
new AstVarRef(nodep->fileline(),
|
|
|
|
|
clkvscp, false));
|
|
|
|
|
} else {
|
|
|
|
|
nodep->v3fatalSrc("Bad edge type");
|
|
|
|
|
}
|
|
|
|
|
return newp;
|
|
|
|
|
}
|
2009-01-07 14:37:59 +00:00
|
|
|
|
AstNode* createSenGateEquation(AstSenGate* nodep) {
|
|
|
|
|
AstNode* newp = new AstAnd(nodep->fileline(),
|
|
|
|
|
createSenseEquation(nodep->sensesp()),
|
|
|
|
|
nodep->rhsp()->cloneTree(true));
|
|
|
|
|
return newp;
|
|
|
|
|
}
|
|
|
|
|
AstNode* createSenseEquation(AstNodeSenItem* nodesp) {
|
|
|
|
|
// Nodep may be a list of elements; we need to walk it
|
2006-08-26 11:35:28 +00:00
|
|
|
|
AstNode* senEqnp = NULL;
|
2018-02-02 02:32:58 +00:00
|
|
|
|
for (AstNodeSenItem* senp = nodesp; senp; senp=VN_CAST(senp->nextp(), NodeSenItem)) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
AstNode* senOnep = NULL;
|
2018-02-02 02:32:58 +00:00
|
|
|
|
if (AstSenItem* itemp = VN_CAST(senp, SenItem)) {
|
2008-11-20 12:55:54 +00:00
|
|
|
|
senOnep = createSenItemEquation(itemp);
|
2018-02-02 02:32:58 +00:00
|
|
|
|
} else if (AstSenGate* itemp = VN_CAST(senp, SenGate)) {
|
2009-01-07 14:37:59 +00:00
|
|
|
|
senOnep = createSenGateEquation(itemp);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
} else {
|
2008-11-20 12:55:54 +00:00
|
|
|
|
senp->v3fatalSrc("Strange node under sentree");
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
if (senEqnp) {
|
|
|
|
|
// Add new OR to the sensitivity list equation
|
|
|
|
|
senEqnp = new AstOr(senp->fileline(), senEqnp, senOnep);
|
|
|
|
|
} else {
|
|
|
|
|
senEqnp = senOnep;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return senEqnp;
|
|
|
|
|
}
|
|
|
|
|
AstIf* makeActiveIf(AstSenTree* sensesp) {
|
2009-01-07 14:37:59 +00:00
|
|
|
|
AstNode* senEqnp = createSenseEquation(sensesp->sensesp());
|
2006-08-26 11:35:28 +00:00
|
|
|
|
if (!senEqnp) sensesp->v3fatalSrc("No sense equation, shouldn't be in sequent activation.");
|
|
|
|
|
AstIf* newifp = new AstIf (sensesp->fileline(),
|
|
|
|
|
senEqnp, NULL, NULL);
|
|
|
|
|
return (newifp);
|
|
|
|
|
}
|
|
|
|
|
void clearLastSen() {
|
|
|
|
|
m_lastSenp = NULL;
|
|
|
|
|
m_lastIfp = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// VISITORS
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstTopScope* nodep) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
UINFO(4," TOPSCOPE "<<nodep<<endl);
|
|
|
|
|
m_topScopep=nodep;
|
2006-08-29 19:10:55 +00:00
|
|
|
|
m_scopep = nodep->scopep();
|
2017-04-29 00:09:27 +00:00
|
|
|
|
if (!m_scopep) nodep->v3fatalSrc("No scope found on top level, perhaps you have no statements?");
|
2008-11-25 14:03:49 +00:00
|
|
|
|
//VV***** We reset all user1p()
|
|
|
|
|
AstNode::user1ClearTree();
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Make top functions
|
|
|
|
|
{
|
2006-08-30 21:07:55 +00:00
|
|
|
|
AstCFunc* funcp = new AstCFunc(nodep->fileline(), "_eval", m_scopep);
|
|
|
|
|
funcp->argTypes(EmitCBaseVisitor::symClassVar());
|
|
|
|
|
funcp->dontCombine(true);
|
|
|
|
|
funcp->symProlog(true);
|
2006-08-30 22:00:55 +00:00
|
|
|
|
funcp->isStatic(true);
|
2006-09-26 15:05:35 +00:00
|
|
|
|
funcp->entryPoint(true);
|
2006-08-30 21:07:55 +00:00
|
|
|
|
m_scopep->addActivep(funcp);
|
|
|
|
|
m_evalFuncp = funcp;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
{
|
2006-08-30 21:07:55 +00:00
|
|
|
|
AstCFunc* funcp = new AstCFunc(nodep->fileline(), "_eval_initial", m_scopep);
|
|
|
|
|
funcp->argTypes(EmitCBaseVisitor::symClassVar());
|
|
|
|
|
funcp->dontCombine(true);
|
|
|
|
|
funcp->slow(true);
|
|
|
|
|
funcp->symProlog(true);
|
2006-08-30 22:00:55 +00:00
|
|
|
|
funcp->isStatic(true);
|
2006-09-26 15:05:35 +00:00
|
|
|
|
funcp->entryPoint(true);
|
2006-08-30 21:07:55 +00:00
|
|
|
|
m_scopep->addActivep(funcp);
|
|
|
|
|
m_initFuncp = funcp;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
{
|
2006-08-30 21:07:55 +00:00
|
|
|
|
AstCFunc* funcp = new AstCFunc(nodep->fileline(), "final", m_scopep);
|
|
|
|
|
funcp->skipDecl(true);
|
|
|
|
|
funcp->dontCombine(true);
|
|
|
|
|
funcp->slow(true);
|
2006-08-30 22:00:55 +00:00
|
|
|
|
funcp->isStatic(false);
|
2006-09-26 15:05:35 +00:00
|
|
|
|
funcp->entryPoint(true);
|
2009-12-03 00:32:41 +00:00
|
|
|
|
funcp->addInitsp(new AstCStmt(nodep->fileline(),
|
|
|
|
|
EmitCBaseVisitor::symClassVar()+" = this->__VlSymsp;\n"));
|
2009-12-02 02:55:56 +00:00
|
|
|
|
funcp->addInitsp(new AstCStmt(nodep->fileline(), EmitCBaseVisitor::symTopAssign()+"\n"));
|
2006-08-30 21:07:55 +00:00
|
|
|
|
m_scopep->addActivep(funcp);
|
|
|
|
|
m_finalFuncp = funcp;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
{
|
2006-08-30 21:07:55 +00:00
|
|
|
|
AstCFunc* funcp = new AstCFunc(nodep->fileline(), "_eval_settle", m_scopep);
|
|
|
|
|
funcp->argTypes(EmitCBaseVisitor::symClassVar());
|
|
|
|
|
funcp->dontCombine(true);
|
|
|
|
|
funcp->slow(true);
|
2006-08-30 22:00:55 +00:00
|
|
|
|
funcp->isStatic(true);
|
2006-08-30 21:07:55 +00:00
|
|
|
|
funcp->symProlog(true);
|
2006-09-26 15:05:35 +00:00
|
|
|
|
funcp->entryPoint(true);
|
2006-08-30 21:07:55 +00:00
|
|
|
|
m_scopep->addActivep(funcp);
|
|
|
|
|
m_settleFuncp = funcp;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
// Process the activates
|
2018-05-11 00:55:37 +00:00
|
|
|
|
iterateChildren(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Done, clear so we can detect errors
|
|
|
|
|
UINFO(4," TOPSCOPEDONE "<<nodep<<endl);
|
|
|
|
|
clearLastSen();
|
|
|
|
|
m_topScopep=NULL;
|
|
|
|
|
m_scopep = NULL;
|
|
|
|
|
}
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstNodeModule* nodep) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//UINFO(4," MOD "<<nodep<<endl);
|
|
|
|
|
m_modp = nodep;
|
2018-05-11 00:55:37 +00:00
|
|
|
|
iterateChildren(nodep);
|
2008-11-12 20:32:09 +00:00
|
|
|
|
m_modp= NULL;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstScope* nodep) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//UINFO(4," SCOPE "<<nodep<<endl);
|
|
|
|
|
m_scopep = nodep;
|
2018-05-11 00:55:37 +00:00
|
|
|
|
iterateChildren(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
if (AstNode* movep = nodep->finalClksp()) {
|
|
|
|
|
if (!m_topScopep) nodep->v3fatalSrc("Final clocks under non-top scope");
|
|
|
|
|
movep->unlinkFrBackWithNext();
|
|
|
|
|
m_evalFuncp->addFinalsp(movep);
|
|
|
|
|
}
|
|
|
|
|
m_scopep = NULL;
|
|
|
|
|
}
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstAlways* nodep) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
AstNode* cmtp = new AstComment(nodep->fileline(), nodep->typeName());
|
|
|
|
|
nodep->replaceWith(cmtp);
|
2009-10-02 02:33:11 +00:00
|
|
|
|
if (AstNode* stmtsp = nodep->bodysp()) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
stmtsp->unlinkFrBackWithNext();
|
|
|
|
|
cmtp->addNextHere(stmtsp);
|
|
|
|
|
}
|
2015-10-04 17:16:35 +00:00
|
|
|
|
nodep->deleteTree(); VL_DANGLING(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstAlwaysPost* nodep) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
AstNode* cmtp = new AstComment(nodep->fileline(), nodep->typeName());
|
|
|
|
|
nodep->replaceWith(cmtp);
|
2009-10-02 02:33:11 +00:00
|
|
|
|
if (AstNode* stmtsp = nodep->bodysp()) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
stmtsp->unlinkFrBackWithNext();
|
|
|
|
|
cmtp->addNextHere(stmtsp);
|
|
|
|
|
}
|
2015-10-04 17:16:35 +00:00
|
|
|
|
nodep->deleteTree(); VL_DANGLING(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstCoverToggle* nodep) {
|
2008-12-12 20:34:02 +00:00
|
|
|
|
//nodep->dumpTree(cout,"ct:");
|
|
|
|
|
//COVERTOGGLE(INC, ORIG, CHANGE) ->
|
|
|
|
|
// IF(ORIG ^ CHANGE) { INC; CHANGE = ORIG; }
|
|
|
|
|
AstNode* incp = nodep->incp()->unlinkFrBack();
|
|
|
|
|
AstNode* origp = nodep->origp()->unlinkFrBack();
|
|
|
|
|
AstNode* changep = nodep->changep()->unlinkFrBack();
|
|
|
|
|
AstIf* newp = new AstIf(nodep->fileline(),
|
|
|
|
|
new AstXor(nodep->fileline(),
|
|
|
|
|
origp,
|
|
|
|
|
changep),
|
|
|
|
|
incp, NULL);
|
|
|
|
|
// We could add another IF to detect posedges, and only increment if so.
|
|
|
|
|
// It's another whole branch though verus a potential memory miss.
|
|
|
|
|
// We'll go with the miss.
|
|
|
|
|
newp->addIfsp(new AstAssign(nodep->fileline(),
|
|
|
|
|
changep->cloneTree(false),
|
|
|
|
|
origp->cloneTree(false)));
|
2015-10-04 17:16:35 +00:00
|
|
|
|
nodep->replaceWith(newp); nodep->deleteTree(); VL_DANGLING(nodep);
|
2008-12-12 20:34:02 +00:00
|
|
|
|
}
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstInitial* nodep) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
AstNode* cmtp = new AstComment(nodep->fileline(), nodep->typeName());
|
|
|
|
|
nodep->replaceWith(cmtp);
|
2009-10-02 02:33:11 +00:00
|
|
|
|
if (AstNode* stmtsp = nodep->bodysp()) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
stmtsp->unlinkFrBackWithNext();
|
|
|
|
|
cmtp->addNextHere(stmtsp);
|
|
|
|
|
}
|
2015-10-04 17:16:35 +00:00
|
|
|
|
nodep->deleteTree(); VL_DANGLING(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstCFunc* nodep) {
|
2018-05-11 00:55:37 +00:00
|
|
|
|
iterateChildren(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Link to global function
|
|
|
|
|
if (nodep->formCallTree()) {
|
2013-07-30 01:47:23 +00:00
|
|
|
|
UINFO(4, " formCallTree "<<nodep<<endl);
|
|
|
|
|
AstCCall* callp = new AstCCall(nodep->fileline(), nodep);
|
|
|
|
|
callp->argTypes("vlSymsp");
|
|
|
|
|
m_finalFuncp->addStmtsp(callp);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstSenTree* nodep) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Delete it later; Actives still pointing to it
|
|
|
|
|
nodep->unlinkFrBack();
|
|
|
|
|
pushDeletep(nodep);
|
|
|
|
|
}
|
|
|
|
|
void addToEvalLoop(AstNode* stmtsp) {
|
2017-11-28 23:29:14 +00:00
|
|
|
|
m_evalFuncp->addStmtsp(stmtsp); // add to top level function
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
void addToSettleLoop(AstNode* stmtsp) {
|
2017-11-28 23:29:14 +00:00
|
|
|
|
m_settleFuncp->addStmtsp(stmtsp); // add to top level function
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2014-04-02 02:01:25 +00:00
|
|
|
|
void addToInitial(AstNode* stmtsp) {
|
2017-11-28 23:29:14 +00:00
|
|
|
|
m_initFuncp->addStmtsp(stmtsp); // add to top level function
|
2014-04-02 02:01:25 +00:00
|
|
|
|
}
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstActive* nodep) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Careful if adding variables here, ACTIVES can be under other ACTIVES
|
|
|
|
|
// Need to save and restore any member state in AstUntilStable block
|
2014-04-02 02:01:25 +00:00
|
|
|
|
if (!m_topScopep || !nodep->stmtsp()) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Not at the top or empty block...
|
|
|
|
|
// Only empty blocks should be leftover on the non-top. Killem.
|
|
|
|
|
if (nodep->stmtsp()) nodep->v3fatalSrc("Non-empty lower active");
|
2015-10-04 17:16:35 +00:00
|
|
|
|
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
} else {
|
|
|
|
|
UINFO(4," ACTIVE "<<nodep<<endl);
|
|
|
|
|
AstNode* stmtsp = nodep->stmtsp()->unlinkFrBackWithNext();
|
|
|
|
|
if (nodep->hasClocked()) {
|
|
|
|
|
// Remember the latest sensitivity so we can compare it next time
|
2014-04-02 02:01:25 +00:00
|
|
|
|
if (nodep->hasInitial()) nodep->v3fatalSrc("Initial block should not have clock sensitivity");
|
2006-08-26 11:35:28 +00:00
|
|
|
|
if (m_lastSenp && nodep->sensesp()->sameTree(m_lastSenp)) {
|
|
|
|
|
UINFO(4," sameSenseTree\n");
|
|
|
|
|
} else {
|
|
|
|
|
clearLastSen();
|
|
|
|
|
m_lastSenp = nodep->sensesp();
|
|
|
|
|
// Make a new if statement
|
|
|
|
|
m_lastIfp = makeActiveIf(m_lastSenp);
|
|
|
|
|
addToEvalLoop(m_lastIfp);
|
|
|
|
|
}
|
|
|
|
|
// Move statements to if
|
|
|
|
|
m_lastIfp->addIfsp(stmtsp);
|
2014-04-02 02:01:25 +00:00
|
|
|
|
} else if (nodep->hasInitial()) {
|
|
|
|
|
// Don't need to: clearLastSen();, as we're adding it to different cfunc
|
|
|
|
|
// Move statements to function
|
|
|
|
|
addToInitial(stmtsp);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
} else if (nodep->hasSettle()) {
|
2006-10-26 01:20:49 +00:00
|
|
|
|
// Don't need to: clearLastSen();, as we're adding it to different cfunc
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Move statements to function
|
|
|
|
|
addToSettleLoop(stmtsp);
|
|
|
|
|
} else {
|
|
|
|
|
// Combo
|
|
|
|
|
clearLastSen();
|
|
|
|
|
// Move statements to function
|
|
|
|
|
addToEvalLoop(stmtsp);
|
|
|
|
|
}
|
2015-10-04 17:16:35 +00:00
|
|
|
|
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------
|
|
|
|
|
// Default: Just iterate
|
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:
|
|
|
|
|
// CONSTUCTORS
|
2015-10-04 02:33:06 +00:00
|
|
|
|
explicit ClockVisitor(AstNetlist* nodep) {
|
2018-06-14 22:59:24 +00:00
|
|
|
|
m_modp = NULL;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
m_evalFuncp = NULL;
|
2018-06-14 22:59:24 +00:00
|
|
|
|
m_initFuncp = NULL;
|
|
|
|
|
m_finalFuncp = NULL;
|
|
|
|
|
m_settleFuncp = NULL;
|
|
|
|
|
m_topScopep = NULL;
|
|
|
|
|
m_lastSenp = NULL;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
m_lastIfp = NULL;
|
|
|
|
|
m_scopep = NULL;
|
|
|
|
|
//
|
2018-05-11 00:55:37 +00:00
|
|
|
|
iterate(nodep);
|
2017-11-30 23:53:57 +00:00
|
|
|
|
// Allow downstream modules to find _eval()
|
|
|
|
|
// easily without iterating through the tree.
|
|
|
|
|
nodep->evalp(m_evalFuncp);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
virtual ~ClockVisitor() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// Clock class functions
|
|
|
|
|
|
|
|
|
|
void V3Clock::clockAll(AstNetlist* nodep) {
|
|
|
|
|
UINFO(2,__FUNCTION__<<": "<<endl);
|
2018-03-10 17:57:50 +00:00
|
|
|
|
{
|
|
|
|
|
ClockVisitor visitor (nodep);
|
|
|
|
|
} // Destruct before checking
|
2017-09-18 02:52:57 +00:00
|
|
|
|
V3Global::dumpCheckGlobalTree("clock", 0, v3Global.opt.dumpTreeLevel(__FILE__) >= 3);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|