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: Break always into sensitivity active domains
|
|
|
|
//
|
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 2003-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
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
// V3Active's Transformations:
|
2008-06-10 01:25:10 +00:00
|
|
|
//
|
2006-08-26 11:35:28 +00:00
|
|
|
// Note this can be called multiple times.
|
|
|
|
// Across all ACTIVES
|
2019-05-19 20:13:13 +00:00
|
|
|
// SenTrees are now under each ACTIVE statement, we want them global:
|
|
|
|
// Find SenTree in under global TopScope, or create it there
|
|
|
|
// Move SenTree the global SenTree
|
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 "V3ActiveTop.h"
|
|
|
|
#include "V3Ast.h"
|
|
|
|
#include "V3SenTree.h"
|
2009-01-07 14:37:59 +00:00
|
|
|
#include "V3Const.h"
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
// Active class functions
|
|
|
|
|
|
|
|
class ActiveTopVisitor : public AstNVisitor {
|
|
|
|
private:
|
|
|
|
// NODE STATE
|
|
|
|
// Entire netlist
|
2019-05-19 20:13:13 +00:00
|
|
|
// AstNode::user() bool. True if processed
|
2009-01-07 14:37:59 +00:00
|
|
|
// Each call to V3Const::constify
|
2019-05-19 20:13:13 +00:00
|
|
|
// AstNode::user4() Used by V3Const::constify, called below
|
2020-04-14 02:51:35 +00:00
|
|
|
AstUser1InUse m_inuser1;
|
2008-11-21 20:50:33 +00:00
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
// STATE
|
2020-04-14 02:51:35 +00:00
|
|
|
AstTopScope* m_topscopep; // Top scope for adding sentrees under
|
|
|
|
SenTreeFinder m_finder; // Find global sentree's and add them
|
2009-01-21 21:56:50 +00:00
|
|
|
|
|
|
|
// METHODS
|
2018-05-14 10:50:47 +00:00
|
|
|
VL_DEBUG_FUNC; // Declare debug()
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
// VISITORS
|
2020-08-15 14:03:34 +00:00
|
|
|
virtual void visit(AstTopScope* nodep) override {
|
2019-05-19 20:13:13 +00:00
|
|
|
m_topscopep = nodep;
|
2020-06-06 16:25:20 +00:00
|
|
|
m_finder.init(m_topscopep);
|
2018-05-11 00:55:37 +00:00
|
|
|
iterateChildren(nodep);
|
2019-05-19 20:13:13 +00:00
|
|
|
m_topscopep = NULL;
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
2020-08-15 14:03:34 +00:00
|
|
|
virtual void visit(AstNodeModule* nodep) override {
|
2019-05-19 20:13:13 +00:00
|
|
|
// Create required actives and add to module
|
|
|
|
// We can start ordering at a module, or a scope
|
2020-04-14 02:51:35 +00:00
|
|
|
UINFO(4, " MOD " << nodep << endl);
|
2018-05-11 00:55:37 +00:00
|
|
|
iterateChildren(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
2020-08-15 14:03:34 +00:00
|
|
|
virtual void visit(AstActive* nodep) override {
|
2020-04-14 02:51:35 +00:00
|
|
|
UINFO(4, " ACTIVE " << nodep << endl);
|
|
|
|
// Remove duplicate clocks and such; sensesp() may change!
|
|
|
|
V3Const::constifyExpensiveEdit(nodep);
|
2019-05-19 20:13:13 +00:00
|
|
|
AstSenTree* sensesp = nodep->sensesp();
|
2019-07-06 16:57:50 +00:00
|
|
|
UASSERT_OBJ(sensesp, nodep, "NULL");
|
2020-04-14 02:51:35 +00:00
|
|
|
if (sensesp->sensesp() && VN_IS(sensesp->sensesp(), SenItem)
|
2018-02-02 02:32:58 +00:00
|
|
|
&& VN_CAST(sensesp->sensesp(), SenItem)->isNever()) {
|
2019-05-19 20:13:13 +00:00
|
|
|
// Never executing. Kill it.
|
2019-07-06 16:57:50 +00:00
|
|
|
UASSERT_OBJ(!sensesp->sensesp()->nextp(), nodep,
|
|
|
|
"Never senitem should be alone, else the never should be eliminated.");
|
2020-01-17 01:17:11 +00:00
|
|
|
VL_DO_DANGLING(nodep->unlinkFrBack()->deleteTree(), nodep);
|
2019-05-19 20:13:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Copy combo tree to settlement tree with duplicated statements
|
|
|
|
if (sensesp->hasCombo()) {
|
2020-04-14 02:51:35 +00:00
|
|
|
AstSenTree* newsentreep = new AstSenTree(
|
|
|
|
nodep->fileline(), new AstSenItem(nodep->fileline(), AstSenItem::Settle()));
|
|
|
|
AstActive* newp = new AstActive(nodep->fileline(), "settle", newsentreep);
|
2019-05-19 20:13:13 +00:00
|
|
|
newp->sensesStorep(newsentreep);
|
|
|
|
if (nodep->stmtsp()) newp->addStmtsp(nodep->stmtsp()->cloneTree(true));
|
|
|
|
nodep->addNextHere(newp);
|
|
|
|
}
|
|
|
|
// Move the SENTREE for each active up to the global level.
|
|
|
|
// This way we'll easily see what clock domains are identical
|
2020-06-01 16:49:42 +00:00
|
|
|
AstSenTree* wantp = m_finder.getSenTree(sensesp);
|
2020-04-14 02:51:35 +00:00
|
|
|
UINFO(4, " lookdone\n");
|
2019-05-19 20:13:13 +00:00
|
|
|
if (wantp != sensesp) {
|
|
|
|
// Move the active's contents to the other active
|
2020-04-14 02:51:35 +00:00
|
|
|
UINFO(4, " merge active " << sensesp << " into " << wantp << endl);
|
2019-05-19 20:13:13 +00:00
|
|
|
if (nodep->sensesStorep()) {
|
2019-07-06 16:57:50 +00:00
|
|
|
UASSERT_OBJ(sensesp == nodep->sensesStorep(), nodep,
|
|
|
|
"sensesStore should have been deleted earlier if different");
|
2019-05-19 20:13:13 +00:00
|
|
|
sensesp->unlinkFrBack();
|
|
|
|
// There may be other references to same sense tree,
|
|
|
|
// we'll be removing all references when we get to them,
|
|
|
|
// but don't dangle our pointer yet!
|
|
|
|
pushDeletep(sensesp);
|
|
|
|
}
|
|
|
|
nodep->sensesp(wantp);
|
|
|
|
}
|
|
|
|
// No need to do statements under it, they're already moved.
|
2020-04-14 02:51:35 +00:00
|
|
|
// iterateChildren(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
2020-08-15 14:03:34 +00:00
|
|
|
virtual void visit(AstNodeProcedure* nodep) override { // LCOV_EXCL_LINE
|
2019-05-19 20:13:13 +00:00
|
|
|
nodep->v3fatalSrc("Node should have been under ACTIVE");
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
2020-08-15 14:03:34 +00:00
|
|
|
virtual void visit(AstAssignAlias* nodep) override { // LCOV_EXCL_LINE
|
2019-05-19 20:13:13 +00:00
|
|
|
nodep->v3fatalSrc("Node should have been under ACTIVE");
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
2020-08-15 14:03:34 +00:00
|
|
|
virtual void visit(AstAssignW* nodep) override { // LCOV_EXCL_LINE
|
2019-05-19 20:13:13 +00:00
|
|
|
nodep->v3fatalSrc("Node should have been under ACTIVE");
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
2020-08-15 14:03:34 +00:00
|
|
|
virtual void visit(AstAlwaysPublic* nodep) override { // LCOV_EXCL_LINE
|
2019-05-19 20:13:13 +00:00
|
|
|
nodep->v3fatalSrc("Node should have been under ACTIVE");
|
2010-04-06 00:01:17 +00:00
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
//--------------------
|
2020-08-15 14:03:34 +00:00
|
|
|
virtual void visit(AstNodeMath*) override {} // Accelerate
|
|
|
|
virtual void visit(AstVarScope*) override {} // Accelerate
|
|
|
|
virtual void visit(AstNode* nodep) override { iterateChildren(nodep); }
|
2020-04-04 02:31:54 +00:00
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
public:
|
2019-09-12 11:22:22 +00:00
|
|
|
// CONSTRUCTORS
|
2020-04-04 02:31:54 +00:00
|
|
|
explicit ActiveTopVisitor(AstNetlist* nodep)
|
|
|
|
: m_topscopep(NULL) {
|
2018-05-11 00:55:37 +00:00
|
|
|
iterate(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
|
|
|
virtual ~ActiveTopVisitor() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
// Active class functions
|
|
|
|
|
|
|
|
void V3ActiveTop::activeTopAll(AstNetlist* nodep) {
|
2020-04-14 02:51:35 +00:00
|
|
|
UINFO(2, __FUNCTION__ << ": " << endl);
|
|
|
|
{ ActiveTopVisitor visitor(nodep); } // Destruct before checking
|
2017-09-18 02:52:57 +00:00
|
|
|
V3Global::dumpCheckGlobalTree("activetop", 0, v3Global.opt.dumpTreeLevel(__FILE__) >= 3);
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|