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: Resolve module/signal name references
|
|
|
|
|
//
|
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.
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
2009-10-31 14:14:04 +00:00
|
|
|
|
// NO EDITS: Don't replace or delete nodes, as the parser symbol table
|
|
|
|
|
// has pointers into the ast tree.
|
|
|
|
|
//
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// LINK TRANSFORMATIONS:
|
|
|
|
|
// Top-down traversal
|
|
|
|
|
// Cells:
|
|
|
|
|
// Read module if needed
|
|
|
|
|
// Link to module that instantiates it
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
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 <map>
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <vector>
|
2017-10-18 22:22:58 +00:00
|
|
|
|
#include VL_INCLUDE_UNORDERED_SET
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
#include "V3Global.h"
|
|
|
|
|
#include "V3LinkCells.h"
|
|
|
|
|
#include "V3SymTable.h"
|
2009-10-31 14:08:38 +00:00
|
|
|
|
#include "V3Parse.h"
|
2006-08-26 11:35:28 +00:00
|
|
|
|
#include "V3Ast.h"
|
|
|
|
|
#include "V3Graph.h"
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// Graph subclasses
|
|
|
|
|
|
|
|
|
|
class LinkCellsGraph : public V3Graph {
|
|
|
|
|
public:
|
|
|
|
|
LinkCellsGraph() {}
|
|
|
|
|
virtual ~LinkCellsGraph() {}
|
|
|
|
|
virtual void loopsMessageCb(V3GraphVertex* vertexp);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class LinkCellsVertex : public V3GraphVertex {
|
2009-11-07 11:20:20 +00:00
|
|
|
|
AstNodeModule* m_modp;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
public:
|
2009-11-07 11:20:20 +00:00
|
|
|
|
LinkCellsVertex(V3Graph* graphp, AstNodeModule* modp)
|
2006-08-26 11:35:28 +00:00
|
|
|
|
: V3GraphVertex(graphp), m_modp(modp) {}
|
|
|
|
|
virtual ~LinkCellsVertex() {}
|
2009-11-07 11:20:20 +00:00
|
|
|
|
AstNodeModule* modp() const { return m_modp; }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
virtual string name() const { return modp()->name(); }
|
2017-11-18 22:42:35 +00:00
|
|
|
|
// Recursive modules get space for maximum recursion
|
|
|
|
|
virtual uint32_t rankAdder() const { return m_modp->recursiveClone() ? (1+v3Global.opt.moduleRecursionDepth()) : 1; }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class LibraryVertex : public V3GraphVertex {
|
|
|
|
|
public:
|
2015-10-04 02:33:06 +00:00
|
|
|
|
explicit LibraryVertex(V3Graph* graphp)
|
2006-08-26 11:35:28 +00:00
|
|
|
|
: V3GraphVertex(graphp) {}
|
|
|
|
|
virtual ~LibraryVertex() {}
|
|
|
|
|
virtual string name() const { return "*LIBRARY*"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void LinkCellsGraph::loopsMessageCb(V3GraphVertex* vertexp) {
|
|
|
|
|
if (LinkCellsVertex* vvertexp = dynamic_cast<LinkCellsVertex*>(vertexp)) {
|
2017-11-18 22:42:35 +00:00
|
|
|
|
vvertexp->modp()->v3error("Unsupported: Recursive multiple modules (module instantiates something leading back to itself): "
|
2013-03-12 11:27:17 +00:00
|
|
|
|
<<vvertexp->modp()->prettyName());
|
2017-11-18 22:42:35 +00:00
|
|
|
|
vvertexp->modp()->v3error("Note self-recursion (module instantiating itself directly) is supported.");
|
2006-08-26 11:35:28 +00:00
|
|
|
|
V3Error::abortIfErrors();
|
|
|
|
|
} else { // Everything should match above, but...
|
|
|
|
|
v3fatalSrc("Recursive instantiations");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// Link state, as a visitor of each AstNode
|
|
|
|
|
|
|
|
|
|
class LinkCellsVisitor : public AstNVisitor {
|
|
|
|
|
private:
|
|
|
|
|
// NODE STATE
|
|
|
|
|
// Entire netlist:
|
2009-11-07 11:20:20 +00:00
|
|
|
|
// AstNodeModule::user1p() // V3GraphVertex* Vertex describing this module
|
2017-11-18 22:42:35 +00:00
|
|
|
|
// AstNodeModule::user2p() // AstNodeModule* clone used for de-recursing
|
|
|
|
|
// AstCell::user1p() // ==V3NodeModule* if done, != if unprocessed
|
|
|
|
|
// AstCell::user2() // bool clone renaming completed
|
2009-10-31 14:14:04 +00:00
|
|
|
|
// Allocated across all readFiles in V3Global::readFiles:
|
2012-06-20 10:13:28 +00:00
|
|
|
|
// AstNode::user4p() // VSymEnt* Package and typedef symbol names
|
2008-11-25 14:03:49 +00:00
|
|
|
|
AstUser1InUse m_inuser1;
|
2017-11-18 22:42:35 +00:00
|
|
|
|
AstUser2InUse m_inuser2;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
// STATE
|
2010-01-20 12:15:51 +00:00
|
|
|
|
V3InFilter* m_filterp; // Parser filter
|
2012-08-16 01:28:30 +00:00
|
|
|
|
V3ParseSym* m_parseSymp; // Parser symbol table
|
2010-01-20 12:15:51 +00:00
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Below state needs to be preserved between each module call.
|
2009-11-07 11:20:20 +00:00
|
|
|
|
AstNodeModule* m_modp; // Current module
|
2012-06-20 10:13:28 +00:00
|
|
|
|
VSymGraph m_mods; // Symbol table of all module names
|
2006-08-26 11:35:28 +00:00
|
|
|
|
LinkCellsGraph m_graph; // Linked graph of all cell interconnects
|
|
|
|
|
LibraryVertex* m_libVertexp; // Vertex at root of all libraries
|
2009-04-07 17:23:25 +00:00
|
|
|
|
V3GraphVertex* m_topVertexp; // Vertex of top module
|
2017-10-18 22:22:58 +00:00
|
|
|
|
vl_unordered_set<string> m_declfnWarned; // Files we issued DECLFILENAME on
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
2009-01-21 21:56:50 +00:00
|
|
|
|
static int debug() {
|
|
|
|
|
static int level = -1;
|
|
|
|
|
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
|
|
|
|
|
return level;
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
// METHODS
|
2009-11-07 11:20:20 +00:00
|
|
|
|
V3GraphVertex* vertex(AstNodeModule* nodep) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Return corresponding vertex for this module
|
2008-11-25 14:03:49 +00:00
|
|
|
|
if (!nodep->user1p()) {
|
|
|
|
|
nodep->user1p(new LinkCellsVertex(&m_graph, nodep));
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2016-11-27 14:40:12 +00:00
|
|
|
|
return (nodep->user1u().toGraphVertex());
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-03 02:02:00 +00:00
|
|
|
|
AstNodeModule* findModuleSym(const string& modName) {
|
|
|
|
|
VSymEnt* foundp = m_mods.rootp()->findIdFallback(modName);
|
|
|
|
|
if (!foundp) return NULL;
|
2018-02-02 02:32:58 +00:00
|
|
|
|
else return VN_CAST(foundp->nodep(), NodeModule);
|
2016-02-03 02:02:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-01-15 04:19:44 +00:00
|
|
|
|
AstNodeModule* resolveModule(AstNode* nodep, const string& modName) {
|
2016-02-03 02:02:00 +00:00
|
|
|
|
AstNodeModule* modp = findModuleSym(modName);
|
2013-01-15 04:19:44 +00:00
|
|
|
|
if (!modp) {
|
|
|
|
|
// Read-subfile
|
|
|
|
|
// If file not found, make AstNotFoundModule, rather than error out.
|
|
|
|
|
// We'll throw the error when we know the module will really be needed.
|
2013-03-12 11:27:17 +00:00
|
|
|
|
string prettyName = AstNode::prettyName(modName);
|
2013-01-15 04:19:44 +00:00
|
|
|
|
V3Parse parser (v3Global.rootp(), m_filterp, m_parseSymp);
|
2013-03-12 11:27:17 +00:00
|
|
|
|
parser.parseFile(nodep->fileline(), prettyName, false, "");
|
2013-01-15 04:19:44 +00:00
|
|
|
|
V3Error::abortIfErrors();
|
|
|
|
|
// We've read new modules, grab new pointers to their names
|
|
|
|
|
readModNames();
|
|
|
|
|
// Check again
|
2016-02-03 02:02:00 +00:00
|
|
|
|
modp = findModuleSym(modName);
|
2013-01-15 04:19:44 +00:00
|
|
|
|
if (!modp) {
|
2013-02-18 16:05:47 +00:00
|
|
|
|
// This shouldn't throw a message as parseFile will create a AstNotFoundModule for us
|
2013-03-12 11:27:17 +00:00
|
|
|
|
nodep->v3error("Can't resolve module reference: "<<prettyName);
|
2013-01-15 04:19:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return modp;
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// VISITs
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstNetlist* nodep) {
|
2008-11-25 14:03:49 +00:00
|
|
|
|
AstNode::user1ClearTree();
|
2006-08-26 11:35:28 +00:00
|
|
|
|
readModNames();
|
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
// Find levels in graph
|
|
|
|
|
m_graph.removeRedundantEdges(&V3GraphEdge::followAlwaysTrue);
|
|
|
|
|
m_graph.dumpDotFilePrefixed("linkcells");
|
|
|
|
|
m_graph.rank();
|
|
|
|
|
for (V3GraphVertex* itp = m_graph.verticesBeginp(); itp; itp=itp->verticesNextp()) {
|
|
|
|
|
if (LinkCellsVertex* vvertexp = dynamic_cast<LinkCellsVertex*>(itp)) {
|
|
|
|
|
// +1 so we leave level 1 for the new wrapper we'll make in a moment
|
2009-11-07 11:20:20 +00:00
|
|
|
|
AstNodeModule* modp = vvertexp->modp();
|
2009-04-24 14:32:11 +00:00
|
|
|
|
modp->level(vvertexp->rank()+1);
|
|
|
|
|
if (vvertexp == m_topVertexp && modp->level() != 2) {
|
2011-10-28 22:19:04 +00:00
|
|
|
|
AstNodeModule* abovep = NULL;
|
|
|
|
|
if (V3GraphEdge* edgep = vvertexp->inBeginp()) {
|
|
|
|
|
if (LinkCellsVertex* eFromVertexp = dynamic_cast<LinkCellsVertex*>(edgep->fromp())) {
|
|
|
|
|
abovep = eFromVertexp->modp();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
v3error("Specified --top-module '"<<v3Global.opt.topModule()
|
|
|
|
|
<<"' isn't at the top level, it's under another cell '"
|
|
|
|
|
<<(abovep ? abovep->prettyName() : "UNKNOWN")<<"'");
|
2009-04-24 14:32:11 +00:00
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-04-07 17:23:25 +00:00
|
|
|
|
if (v3Global.opt.topModule()!=""
|
|
|
|
|
&& !m_topVertexp) {
|
|
|
|
|
v3error("Specified --top-module '"<<v3Global.opt.topModule()<<"' was not found in design.");
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstNodeModule* nodep) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Module: Pick up modnames, so we can resolve cells later
|
|
|
|
|
m_modp = nodep;
|
|
|
|
|
UINFO(2,"Link Module: "<<nodep<<endl);
|
2012-06-14 02:18:12 +00:00
|
|
|
|
if (nodep->fileline()->filebasenameNoExt() != nodep->prettyName()
|
2013-01-17 23:36:20 +00:00
|
|
|
|
&& !v3Global.opt.isLibraryFile(nodep->fileline()->filename())
|
2017-11-22 03:01:28 +00:00
|
|
|
|
&& !nodep->recursiveClone()
|
2013-01-17 23:36:20 +00:00
|
|
|
|
&& !nodep->internal()) {
|
2012-06-14 02:18:12 +00:00
|
|
|
|
// We only complain once per file, otherwise library-like files have a huge mess of warnings
|
|
|
|
|
if (m_declfnWarned.find(nodep->fileline()->filename()) == m_declfnWarned.end()) {
|
|
|
|
|
m_declfnWarned.insert(nodep->fileline()->filename());
|
|
|
|
|
nodep->v3warn(DECLFILENAME, "Filename '"<<nodep->fileline()->filebasenameNoExt()
|
|
|
|
|
<<"' does not match "<<nodep->typeName()<<" name: "<<nodep->prettyName());
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-02 02:32:58 +00:00
|
|
|
|
if (VN_IS(nodep, Iface) || VN_IS(nodep, Package)) nodep->inLibrary(true); // Interfaces can't be at top, unless asked
|
2013-03-12 11:27:17 +00:00
|
|
|
|
bool topMatch = (v3Global.opt.topModule()==nodep->prettyName());
|
2009-04-24 14:32:11 +00:00
|
|
|
|
if (topMatch) {
|
|
|
|
|
m_topVertexp = vertex(nodep);
|
|
|
|
|
UINFO(2,"Link --top-module: "<<nodep<<endl);
|
|
|
|
|
nodep->inLibrary(false); // Safer to make sure it doesn't disappear
|
|
|
|
|
}
|
2009-04-07 17:23:25 +00:00
|
|
|
|
if (v3Global.opt.topModule()==""
|
|
|
|
|
? nodep->inLibrary() // Library cells are lower
|
|
|
|
|
: !topMatch) { // Any non-specified module is lower
|
|
|
|
|
// Put under a fake vertex so that the graph ranking won't indicate
|
|
|
|
|
// this is a top level module
|
2006-08-26 11:35:28 +00:00
|
|
|
|
if (!m_libVertexp) m_libVertexp = new LibraryVertex(&m_graph);
|
|
|
|
|
new V3GraphEdge(&m_graph, m_libVertexp, vertex(nodep), 1, false);
|
|
|
|
|
}
|
2013-01-15 04:19:44 +00:00
|
|
|
|
// Note AstBind also has iteration on cells
|
2006-08-26 11:35:28 +00:00
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
nodep->checkTree();
|
|
|
|
|
m_modp = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstIfaceRefDType* nodep) {
|
2013-05-28 01:39:19 +00:00
|
|
|
|
// Cell: Resolve its filename. If necessary, parse it.
|
|
|
|
|
UINFO(4,"Link IfaceRef: "<<nodep<<endl);
|
|
|
|
|
// Use findIdUpward instead of findIdFlat; it doesn't matter for now
|
|
|
|
|
// but we might support modules-under-modules someday.
|
|
|
|
|
AstNodeModule* modp = resolveModule(nodep, nodep->ifaceName());
|
|
|
|
|
if (modp) {
|
2018-02-02 02:32:58 +00:00
|
|
|
|
if (VN_IS(modp, Iface)) {
|
2013-05-28 01:39:19 +00:00
|
|
|
|
// Track module depths, so can sort list from parent down to children
|
|
|
|
|
new V3GraphEdge(&m_graph, vertex(m_modp), vertex(modp), 1, false);
|
2018-02-02 02:32:58 +00:00
|
|
|
|
if (!nodep->cellp()) nodep->ifacep(VN_CAST(modp, Iface));
|
|
|
|
|
} else if (VN_IS(modp, NotFoundModule)) { // Will error out later
|
2013-05-28 01:39:19 +00:00
|
|
|
|
} else {
|
|
|
|
|
nodep->v3error("Non-interface used as an interface: "<<nodep->prettyName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Note cannot do modport resolution here; modports are allowed underneath generates
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstPackageImport* nodep) {
|
2012-04-25 01:21:26 +00:00
|
|
|
|
// Package Import: We need to do the package before the use of a package
|
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
if (!nodep->packagep()) nodep->v3fatalSrc("Unlinked package"); // Parser should set packagep
|
|
|
|
|
new V3GraphEdge(&m_graph, vertex(m_modp), vertex(nodep->packagep()), 1, false);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstBind* nodep) {
|
2013-01-15 04:19:44 +00:00
|
|
|
|
// Bind: Has cells underneath that need to be put into the new module, and cells which need resolution
|
|
|
|
|
// TODO this doesn't allow bind to dotted hier names, that would require
|
|
|
|
|
// this move to post param, which would mean we do not auto-read modules
|
|
|
|
|
// and means we cannot compute module levels until later.
|
|
|
|
|
UINFO(4,"Link Bind: "<<nodep<<endl);
|
2017-11-18 22:42:35 +00:00
|
|
|
|
AstNodeModule* modp = resolveModule(nodep,nodep->name());
|
2013-01-15 04:19:44 +00:00
|
|
|
|
if (modp) {
|
|
|
|
|
AstNode* cellsp = nodep->cellsp()->unlinkFrBackWithNext();
|
|
|
|
|
// Module may have already linked, so need to pick up these new cells
|
|
|
|
|
AstNodeModule* oldModp = m_modp;
|
|
|
|
|
{
|
|
|
|
|
m_modp = modp;
|
|
|
|
|
modp->addStmtp(cellsp); // Important that this adds to end, as next iterate assumes does all cells
|
|
|
|
|
cellsp->iterateAndNext(*this);
|
|
|
|
|
}
|
|
|
|
|
m_modp = oldModp;
|
|
|
|
|
}
|
|
|
|
|
pushDeletep(nodep->unlinkFrBack());
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstCell* nodep) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Cell: Resolve its filename. If necessary, parse it.
|
2017-11-18 22:42:35 +00:00
|
|
|
|
// Execute only once. Complication is that cloning may result in user1 being set (for pre-clone)
|
|
|
|
|
// so check if user1() matches the m_mod, if 0 never did it, if !=, it is an unprocessed clone
|
|
|
|
|
bool cloned = (nodep->user1p() && nodep->user1p()!=m_modp);
|
|
|
|
|
if (nodep->user1p()==m_modp) return; // AstBind and AstNodeModule may call a cell twice
|
|
|
|
|
nodep->user1p(m_modp);
|
|
|
|
|
//
|
|
|
|
|
if (!nodep->modp() || cloned) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
UINFO(4,"Link Cell: "<<nodep<<endl);
|
2012-06-20 10:09:07 +00:00
|
|
|
|
// Use findIdFallback instead of findIdFlat; it doesn't matter for now
|
2009-03-24 13:22:58 +00:00
|
|
|
|
// but we might support modules-under-modules someday.
|
2017-11-18 22:40:10 +00:00
|
|
|
|
AstNodeModule* cellmodp = resolveModule(nodep, nodep->modName());
|
|
|
|
|
if (cellmodp) {
|
2017-11-18 22:42:35 +00:00
|
|
|
|
if (cellmodp == m_modp
|
|
|
|
|
|| cellmodp->user2p() == m_modp) {
|
|
|
|
|
UINFO(1,"Self-recursive module "<<cellmodp<<endl);
|
|
|
|
|
cellmodp->recursive(true);
|
|
|
|
|
nodep->recursive(true);
|
|
|
|
|
if (!cellmodp->recursiveClone()) {
|
|
|
|
|
// In the non-Vrcm, which needs to point to Vrcm flavor
|
|
|
|
|
//
|
|
|
|
|
// Make a clone which this cell points to
|
|
|
|
|
// Later, the clone's cells will also point clone'd name
|
|
|
|
|
// This lets us link the XREFs between the (uncloned) children so
|
|
|
|
|
// they don't point to the same module which would
|
|
|
|
|
// break parameter resolution.
|
2018-02-02 02:32:58 +00:00
|
|
|
|
AstNodeModule* otherModp = VN_CAST(cellmodp->user2p(), NodeModule);
|
2017-11-18 22:42:35 +00:00
|
|
|
|
if (!otherModp) {
|
|
|
|
|
otherModp = cellmodp->cloneTree(false);
|
|
|
|
|
otherModp->name(otherModp->name()+"__Vrcm");
|
|
|
|
|
otherModp->user1p(NULL); // Need new vertex
|
|
|
|
|
otherModp->user2p(cellmodp);
|
|
|
|
|
otherModp->recursiveClone(true);
|
|
|
|
|
// user1 etc will retain its pre-clone value
|
|
|
|
|
cellmodp->user2p(otherModp);
|
|
|
|
|
v3Global.rootp()->addModulep(otherModp);
|
|
|
|
|
new V3GraphEdge(&m_graph, vertex(cellmodp), vertex(otherModp), 1, false);
|
|
|
|
|
}
|
|
|
|
|
cellmodp = otherModp;
|
|
|
|
|
nodep->modp(cellmodp);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// In the Vrcm, which needs to point back to Vrcm flavor
|
|
|
|
|
// The cell already has the correct resolution (to Vrcm)
|
|
|
|
|
nodep->modp(cellmodp);
|
|
|
|
|
// We don't create a V3GraphEdge (as it would be circular)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else { // Non-recursive
|
|
|
|
|
// Track module depths, so can sort list from parent down to children
|
|
|
|
|
nodep->modp(cellmodp);
|
|
|
|
|
new V3GraphEdge(&m_graph, vertex(m_modp), vertex(cellmodp), 1, false);
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-01-29 23:00:48 +00:00
|
|
|
|
// Remove AstCell(AstPin("",NULL)), it's a side effect of how we parse "()"
|
|
|
|
|
// the empty middle is identical to the empty rule that must find pins in "(,)".
|
|
|
|
|
if (nodep->pinsp() && !nodep->pinsp()->nextp()
|
|
|
|
|
&& nodep->pinsp()->name() == ""
|
|
|
|
|
&& !nodep->pinsp()->exprp()) {
|
|
|
|
|
pushDeletep(nodep->pinsp()->unlinkFrBackWithNext());
|
|
|
|
|
}
|
|
|
|
|
if (nodep->paramsp() && !nodep->paramsp()->nextp()
|
|
|
|
|
&& nodep->paramsp()->name() == ""
|
|
|
|
|
&& !nodep->paramsp()->exprp()) {
|
|
|
|
|
pushDeletep(nodep->paramsp()->unlinkFrBackWithNext());
|
|
|
|
|
}
|
2007-03-14 13:06:08 +00:00
|
|
|
|
// Convert .* to list of pins
|
2009-05-07 22:28:05 +00:00
|
|
|
|
bool pinStar = false;
|
|
|
|
|
for (AstPin* nextp, *pinp = nodep->pinsp(); pinp; pinp=nextp) {
|
2018-02-02 02:32:58 +00:00
|
|
|
|
nextp = VN_CAST(pinp->nextp(), Pin);
|
2009-05-07 22:28:05 +00:00
|
|
|
|
if (pinp->dotStar()) {
|
|
|
|
|
if (pinStar) pinp->v3error("Duplicate .* in a cell");
|
|
|
|
|
pinStar = true;
|
|
|
|
|
// Done with this fake pin
|
2015-10-04 17:16:35 +00:00
|
|
|
|
pinp->unlinkFrBack()->deleteTree(); VL_DANGLING(pinp);
|
2009-05-07 22:28:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-26 22:43:12 +00:00
|
|
|
|
// Convert unnamed pins to pin number based assignments
|
2018-02-02 02:32:58 +00:00
|
|
|
|
for (AstPin* pinp = nodep->pinsp(); pinp; pinp=VN_CAST(pinp->nextp(), Pin)) {
|
2012-04-26 22:43:12 +00:00
|
|
|
|
if (pinp->name()=="") pinp->name("__pinNumber"+cvtToStr(pinp->pinNum()));
|
|
|
|
|
}
|
2018-02-02 02:32:58 +00:00
|
|
|
|
for (AstPin* pinp = nodep->paramsp(); pinp; pinp=VN_CAST(pinp->nextp(), Pin)) {
|
2013-12-14 23:04:10 +00:00
|
|
|
|
pinp->param(true);
|
2012-04-26 22:43:12 +00:00
|
|
|
|
if (pinp->name()=="") pinp->name("__paramNumber"+cvtToStr(pinp->pinNum()));
|
|
|
|
|
}
|
|
|
|
|
if (nodep->modp()) {
|
2017-11-18 22:42:35 +00:00
|
|
|
|
nodep->modName(nodep->modp()->name());
|
2007-03-14 13:06:08 +00:00
|
|
|
|
// Note what pins exist
|
2017-10-18 22:22:58 +00:00
|
|
|
|
vl_unordered_set<string> ports; // Symbol table of all connected port names
|
2018-02-02 02:32:58 +00:00
|
|
|
|
for (AstPin* pinp = nodep->pinsp(); pinp; pinp=VN_CAST(pinp->nextp(), Pin)) {
|
2007-03-14 13:06:08 +00:00
|
|
|
|
if (pinp->name()=="") pinp->v3error("Connect by position is illegal in .* connected cells");
|
2014-03-28 01:36:52 +00:00
|
|
|
|
if (!pinp->exprp()) {
|
|
|
|
|
if (pinp->name().substr(0, 11) == "__pinNumber") {
|
|
|
|
|
pinp->v3warn(PINNOCONNECT,"Cell pin is not connected: "<<pinp->prettyName());
|
|
|
|
|
} else {
|
|
|
|
|
pinp->v3warn(PINCONNECTEMPTY,"Cell pin connected by name with empty reference: "<<pinp->prettyName());
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-20 10:09:07 +00:00
|
|
|
|
if (ports.find(pinp->name()) == ports.end()) {
|
|
|
|
|
ports.insert(pinp->name());
|
2007-03-14 13:06:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-11-30 22:12:53 +00:00
|
|
|
|
// We search ports, rather than in/out declarations as they aren't resolved yet,
|
2012-07-18 01:29:10 +00:00
|
|
|
|
// and it's easier to do it now than in V3LinkDot when we'd need to repeat steps.
|
2007-03-14 13:06:08 +00:00
|
|
|
|
for (AstNode* portnodep = nodep->modp()->stmtsp(); portnodep; portnodep=portnodep->nextp()) {
|
2018-02-02 02:32:58 +00:00
|
|
|
|
if (const AstPort* portp = VN_CAST(portnodep, Port)) {
|
2012-06-20 10:09:07 +00:00
|
|
|
|
if (ports.find(portp->name()) == ports.end()
|
|
|
|
|
&& ports.find("__pinNumber"+cvtToStr(portp->pinNum())) == ports.end()) {
|
2012-04-26 22:43:12 +00:00
|
|
|
|
if (pinStar) {
|
|
|
|
|
UINFO(9," need .* PORT "<<portp<<endl);
|
|
|
|
|
// Create any not already connected
|
|
|
|
|
AstPin* newp = new AstPin(nodep->fileline(),0,portp->name(),
|
2017-06-20 22:40:18 +00:00
|
|
|
|
new AstParseRef(nodep->fileline(),
|
|
|
|
|
AstParseRefExp::PX_TEXT, portp->name(), NULL, NULL));
|
2012-04-26 22:43:12 +00:00
|
|
|
|
newp->svImplicit(true);
|
|
|
|
|
nodep->addPinsp(newp);
|
|
|
|
|
} else { // warn on the CELL that needs it, not the port
|
|
|
|
|
nodep->v3warn(PINMISSING, "Cell has missing pin: "<<portp->prettyName());
|
|
|
|
|
AstPin* newp = new AstPin(nodep->fileline(),0,portp->name(),NULL);
|
|
|
|
|
nodep->addPinsp(newp);
|
|
|
|
|
}
|
2007-03-14 13:06:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-02 02:32:58 +00:00
|
|
|
|
if (VN_IS(nodep->modp(), Iface)) {
|
2013-05-28 01:39:19 +00:00
|
|
|
|
// Cell really is the parent's instantiation of an interface, not a normal module
|
|
|
|
|
// Make sure we have a variable to refer to this cell, so can <ifacename>.<innermember>
|
|
|
|
|
// in the same way that a child does. Rename though to avoid conflict with cell.
|
|
|
|
|
// This is quite similar to how classes work; when unpacked classes are better supported
|
|
|
|
|
// may remap interfaces to be more like a class.
|
|
|
|
|
if (!nodep->hasIfaceVar()) {
|
2015-10-24 03:06:24 +00:00
|
|
|
|
string varName = nodep->name() + "__Viftop"; // V3LinkDot looks for this naming
|
2015-12-05 22:12:03 +00:00
|
|
|
|
AstIfaceRefDType* idtypep = new AstIfaceRefDType(nodep->fileline(), nodep->name(),
|
2015-10-24 03:06:24 +00:00
|
|
|
|
nodep->modp()->name());
|
|
|
|
|
idtypep->ifacep(NULL); // cellp overrides
|
2015-12-06 00:39:40 +00:00
|
|
|
|
// In the case of arrayed interfaces, we replace cellp when de-arraying in V3Inst
|
|
|
|
|
idtypep->cellp(nodep); // Only set when real parent cell known.
|
2015-12-05 22:12:03 +00:00
|
|
|
|
AstVar* varp;
|
2015-10-24 03:06:24 +00:00
|
|
|
|
if (nodep->rangep()) {
|
2018-03-10 21:32:04 +00:00
|
|
|
|
AstNodeArrayDType* arrp
|
|
|
|
|
= new AstUnpackArrayDType(nodep->fileline(), VFlagChildDType(),
|
|
|
|
|
idtypep, nodep->rangep()->cloneTree(true));
|
2015-10-24 03:06:24 +00:00
|
|
|
|
varp = new AstVar(nodep->fileline(), AstVarType::IFACEREF, varName,
|
|
|
|
|
VFlagChildDType(), arrp);
|
|
|
|
|
} else {
|
|
|
|
|
varp = new AstVar(nodep->fileline(), AstVarType::IFACEREF, varName,
|
|
|
|
|
VFlagChildDType(), idtypep);
|
2015-10-23 00:13:49 +00:00
|
|
|
|
}
|
2015-10-24 03:06:24 +00:00
|
|
|
|
varp->isIfaceParent(true);
|
|
|
|
|
nodep->addNextHere(varp);
|
|
|
|
|
nodep->hasIfaceVar(true);
|
2013-05-28 01:39:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
if (nodep->modp()) {
|
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
}
|
2012-08-16 01:28:30 +00:00
|
|
|
|
UINFO(4," Link Cell done: "<<nodep<<endl);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Accelerate the recursion
|
|
|
|
|
// Must do statements to support Generates, math though...
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstNodeMath* nodep) {}
|
|
|
|
|
virtual void visit(AstNode* nodep) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Default: Just iterate
|
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// METHODS
|
|
|
|
|
void readModNames() {
|
|
|
|
|
// Look at all modules, and store pointers to all module names
|
2010-01-08 01:25:15 +00:00
|
|
|
|
for (AstNodeModule* nextp,* nodep = v3Global.rootp()->modulesp(); nodep; nodep=nextp) {
|
2018-02-02 02:32:58 +00:00
|
|
|
|
nextp = VN_CAST(nodep->nextp(), NodeModule);
|
2016-02-03 02:02:00 +00:00
|
|
|
|
AstNodeModule* foundp = findModuleSym(nodep->name());
|
2008-04-09 13:56:40 +00:00
|
|
|
|
if (foundp && foundp != nodep) {
|
2010-01-08 01:25:15 +00:00
|
|
|
|
if (!(foundp->fileline()->warnIsOff(V3ErrorCode::MODDUP) || nodep->fileline()->warnIsOff(V3ErrorCode::MODDUP))) {
|
2012-05-22 01:24:17 +00:00
|
|
|
|
nodep->v3warn(MODDUP,"Duplicate declaration of module: "<<nodep->prettyName()<<endl
|
|
|
|
|
<<foundp->warnMore()<<"... Location of original declaration");
|
2010-01-08 01:25:15 +00:00
|
|
|
|
}
|
2010-01-08 19:03:00 +00:00
|
|
|
|
nodep->unlinkFrBack();
|
2015-10-04 17:16:35 +00:00
|
|
|
|
pushDeletep(nodep); VL_DANGLING(nodep);
|
2008-04-09 13:56:40 +00:00
|
|
|
|
} else if (!foundp) {
|
2012-06-20 10:13:28 +00:00
|
|
|
|
m_mods.rootp()->insert(nodep->name(), new VSymEnt(&m_mods, nodep));
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-10-31 14:08:38 +00:00
|
|
|
|
//if (debug()>=9) m_mods.dump(cout, "-syms: ");
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
// CONSTUCTORS
|
2012-08-16 01:28:30 +00:00
|
|
|
|
LinkCellsVisitor(AstNetlist* rootp, V3InFilter* filterp, V3ParseSym* parseSymp)
|
2012-06-20 10:13:28 +00:00
|
|
|
|
: m_mods(rootp) {
|
2010-01-20 12:15:51 +00:00
|
|
|
|
m_filterp = filterp;
|
2012-08-16 01:28:30 +00:00
|
|
|
|
m_parseSymp = parseSymp;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
m_modp = NULL;
|
|
|
|
|
m_libVertexp = NULL;
|
2009-04-07 17:23:25 +00:00
|
|
|
|
m_topVertexp = NULL;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
rootp->accept(*this);
|
|
|
|
|
}
|
2009-10-02 02:33:11 +00:00
|
|
|
|
virtual ~LinkCellsVisitor() {}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// Link class functions
|
|
|
|
|
|
2012-08-16 01:28:30 +00:00
|
|
|
|
void V3LinkCells::link(AstNetlist* rootp, V3InFilter* filterp, V3ParseSym* parseSymp) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
UINFO(4,__FUNCTION__<<": "<<endl);
|
2012-08-16 01:28:30 +00:00
|
|
|
|
LinkCellsVisitor visitor (rootp, filterp, parseSymp);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|