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: Replicate modules for parameterization
|
|
|
|
|
//
|
2008-04-25 12:14:27 +00:00
|
|
|
|
// Code available from: http://www.veripool.org/verilator
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2012-01-15 15:26:28 +00:00
|
|
|
|
// Copyright 2003-2012 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.
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
// PARAM TRANSFORMATIONS:
|
|
|
|
|
// Top down traversal:
|
|
|
|
|
// For each cell:
|
|
|
|
|
// If parameterized,
|
|
|
|
|
// Determine all parameter widths, constant values
|
|
|
|
|
// Clone module cell calls, renaming with __{par1}_{par2}_...
|
|
|
|
|
// Substitute constants for cell's module's parameters
|
|
|
|
|
// Relink pins and cell to point to new module
|
2012-03-24 19:54:06 +00:00
|
|
|
|
// Then process all modules called by that cell
|
|
|
|
|
// (Cells never referenced after parameters expanded must be ignored.)
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
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 <vector>
|
2012-03-24 19:54:06 +00:00
|
|
|
|
#include <deque>
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
#include "V3Global.h"
|
|
|
|
|
#include "V3Param.h"
|
|
|
|
|
#include "V3Ast.h"
|
|
|
|
|
#include "V3Case.h"
|
|
|
|
|
#include "V3Const.h"
|
|
|
|
|
#include "V3Width.h"
|
|
|
|
|
#include "V3Unroll.h"
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// Param state, as a visitor of each AstNode
|
|
|
|
|
|
|
|
|
|
class ParamVisitor : public AstNVisitor {
|
|
|
|
|
private:
|
|
|
|
|
// NODE STATE
|
2012-03-24 19:54:06 +00:00
|
|
|
|
// AstNodeModule::user5() // bool True if processed
|
2012-07-21 21:12:42 +00:00
|
|
|
|
// AstGenFor::user5() // bool True if processed
|
2012-03-24 19:54:06 +00:00
|
|
|
|
// AstVar::user5() // bool True if constant propagated
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// AstVar::user4() // int Global parameter number (for naming new module)
|
2009-10-25 20:53:55 +00:00
|
|
|
|
// // (0=not processed, 1=iterated, but no number, 65+ parameter numbered)
|
2008-11-25 14:03:49 +00:00
|
|
|
|
AstUser4InUse m_inuser4;
|
2010-05-25 23:37:45 +00:00
|
|
|
|
AstUser5InUse m_inuser5;
|
2009-10-25 20:53:55 +00:00
|
|
|
|
// User1/2/3 used by constant function simulations
|
2008-11-21 20:50:33 +00:00
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// STATE
|
|
|
|
|
typedef std::map<AstVar*,AstVar*> VarCloneMap;
|
|
|
|
|
struct ModInfo {
|
2009-11-07 11:20:20 +00:00
|
|
|
|
AstNodeModule* m_modp; // Module with specified name
|
2006-08-26 11:35:28 +00:00
|
|
|
|
VarCloneMap m_cloneMap; // Map of old-varp -> new cloned varp
|
2009-11-07 11:20:20 +00:00
|
|
|
|
ModInfo(AstNodeModule* modp) { m_modp=modp; }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
};
|
|
|
|
|
typedef std::map<string,ModInfo> ModNameMap;
|
|
|
|
|
ModNameMap m_modNameMap; // Hash of created module flavors by name
|
|
|
|
|
|
|
|
|
|
typedef std::map<string,string> LongMap;
|
|
|
|
|
LongMap m_longMap; // Hash of very long names to unique identity number
|
|
|
|
|
int m_longId;
|
|
|
|
|
|
2012-03-24 19:54:06 +00:00
|
|
|
|
typedef deque<AstNodeModule*> ModDeque;
|
|
|
|
|
ModDeque m_todoModps; // Modules left to process
|
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// METHODS
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-07 11:20:20 +00:00
|
|
|
|
void makeSmallNames(AstNodeModule* modp) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
vector<int> usedLetter; usedLetter.resize(256);
|
|
|
|
|
// Pass 1, assign first letter to each gparam's name
|
|
|
|
|
for (AstNode* stmtp = modp->stmtsp(); stmtp; stmtp=stmtp->nextp()) {
|
|
|
|
|
if (AstVar* varp = stmtp->castVar()) {
|
|
|
|
|
if (varp->isGParam()) {
|
|
|
|
|
char ch = varp->name()[0];
|
|
|
|
|
ch = toupper(ch); if (ch<'A' || ch>'Z') ch='Z';
|
|
|
|
|
varp->user4(usedLetter[ch]*256 + ch);
|
|
|
|
|
usedLetter[ch]++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-11-07 11:20:20 +00:00
|
|
|
|
string paramSmallName(AstNodeModule* modp, AstVar* varp) {
|
2009-10-25 20:53:55 +00:00
|
|
|
|
if (varp->user4()<=1) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
makeSmallNames(modp);
|
|
|
|
|
}
|
|
|
|
|
int index = varp->user4()/256;
|
|
|
|
|
char ch = varp->user4()&255;
|
|
|
|
|
string st = cvtToStr(ch);
|
|
|
|
|
while (index) {
|
|
|
|
|
st += cvtToStr(char((index%26)+'A'));
|
|
|
|
|
index /= 26;
|
|
|
|
|
}
|
|
|
|
|
return st;
|
|
|
|
|
}
|
|
|
|
|
void relinkPins(VarCloneMap* clonemapp, AstPin* startpinp) {
|
|
|
|
|
for (AstPin* pinp = startpinp; pinp; pinp=pinp->nextp()->castPin()) {
|
|
|
|
|
if (!pinp->modVarp()) pinp->v3fatalSrc("Not linked?\n");
|
|
|
|
|
// Find it in the clone structure
|
|
|
|
|
//UINFO(8,"Clone find 0x"<<hex<<(uint32_t)pinp->modVarp()<<endl);
|
|
|
|
|
VarCloneMap::iterator cloneiter = clonemapp->find(pinp->modVarp());
|
|
|
|
|
UASSERT(cloneiter != clonemapp->end(), "Couldn't find pin in clone list");
|
|
|
|
|
pinp->modVarp(cloneiter->second);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-24 19:54:06 +00:00
|
|
|
|
void visitModules() {
|
|
|
|
|
// Loop on all modules left to process
|
|
|
|
|
// Hitting a cell adds to the END of this list, so since cells originally exist top->bottom
|
|
|
|
|
// we process in top->bottom order too.
|
|
|
|
|
while (!m_todoModps.empty()) {
|
|
|
|
|
AstNodeModule* nodep = m_todoModps.front(); m_todoModps.pop_front();
|
2012-04-29 12:55:33 +00:00
|
|
|
|
if (!nodep->user5SetOnce()) { // Process once; note clone() must clear so we do it again
|
2012-03-24 19:54:06 +00:00
|
|
|
|
UINFO(4," MOD "<<nodep<<endl);
|
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
// Note this may add to m_todoModps
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
// VISITORS
|
|
|
|
|
virtual void visit(AstNetlist* nodep, AstNUser*) {
|
|
|
|
|
// Modules must be done in top-down-order
|
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
}
|
2009-11-07 11:20:20 +00:00
|
|
|
|
virtual void visit(AstNodeModule* nodep, AstNUser*) {
|
2012-07-21 21:12:42 +00:00
|
|
|
|
if (nodep->dead()) {
|
|
|
|
|
UINFO(4," MOD-dead. "<<nodep<<endl); // Marked by LinkDot
|
|
|
|
|
} else if (nodep->level() <= 2) { // Haven't added top yet, so level 2 is the top
|
2012-03-24 19:54:06 +00:00
|
|
|
|
// Add request to END of modules left to process
|
|
|
|
|
m_todoModps.push_back(nodep);
|
|
|
|
|
visitModules();
|
|
|
|
|
} else if (nodep->user5()) {
|
|
|
|
|
UINFO(4," MOD-done "<<nodep<<endl); // Already did it
|
|
|
|
|
} else {
|
|
|
|
|
UINFO(4," MOD-dead? "<<nodep<<endl); // Should have been done by now, if not dead
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
virtual void visit(AstCell* nodep, AstNUser*);
|
|
|
|
|
|
2009-07-16 18:49:34 +00:00
|
|
|
|
// Make sure all parameters are constantified
|
|
|
|
|
virtual void visit(AstVar* nodep, AstNUser*) {
|
2012-04-29 12:55:33 +00:00
|
|
|
|
if (!nodep->user5SetOnce()) { // Process once
|
2009-10-25 20:53:55 +00:00
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
if (nodep->isParam()) {
|
|
|
|
|
if (!nodep->hasSimpleInit()) { nodep->v3fatalSrc("Parameter without initial value"); }
|
|
|
|
|
V3Const::constifyParamsEdit(nodep); // The variable, not just the var->init()
|
|
|
|
|
}
|
2009-07-16 18:49:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-10-25 20:53:55 +00:00
|
|
|
|
// Make sure varrefs cause vars to constify before things above
|
|
|
|
|
virtual void visit(AstVarRef* nodep, AstNUser*) {
|
|
|
|
|
if (nodep->varp()) nodep->varp()->iterate(*this);
|
|
|
|
|
}
|
2009-07-16 18:49:34 +00:00
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Generate Statements
|
|
|
|
|
virtual void visit(AstGenerate* nodep, AstNUser*) {
|
|
|
|
|
if (debug()>=9) nodep->dumpTree(cout,"-genin: ");
|
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
// After expanding the generate, all statements under it can be moved
|
|
|
|
|
// up, and the generate block deleted as it's not relevant
|
2006-09-11 20:42:47 +00:00
|
|
|
|
if (AstNode* stmtsp = nodep->stmtsp()) {
|
|
|
|
|
stmtsp->unlinkFrBackWithNext();
|
|
|
|
|
nodep->replaceWith(stmtsp);
|
|
|
|
|
if (debug()>=9) stmtsp->dumpTree(cout,"-genout: ");
|
|
|
|
|
} else {
|
|
|
|
|
nodep->unlinkFrBack();
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
nodep->deleteTree(); nodep=NULL;
|
|
|
|
|
}
|
|
|
|
|
virtual void visit(AstGenIf* nodep, AstNUser*) {
|
2012-03-10 00:34:02 +00:00
|
|
|
|
UINFO(9," GENIF "<<nodep<<endl);
|
2009-10-25 20:53:55 +00:00
|
|
|
|
nodep->condp()->iterateAndNext(*this);
|
2012-04-20 02:53:52 +00:00
|
|
|
|
// We suppress errors when widthing params since short-circuiting in
|
|
|
|
|
// the conditional evaluation may mean these error can never occur. We
|
|
|
|
|
// then make sure that short-circuiting is used by constifyParamsEdit.
|
|
|
|
|
V3Width::widthGenerateParamsEdit(nodep); // Param typed widthing will
|
|
|
|
|
// NOT recurse the body.
|
|
|
|
|
V3Const::constifyGenerateParamsEdit(nodep->condp()); // condp may change
|
2006-08-26 11:35:28 +00:00
|
|
|
|
if (AstConst* constp = nodep->condp()->castConst()) {
|
|
|
|
|
AstNode* keepp = (constp->isZero()
|
|
|
|
|
? nodep->elsesp()
|
|
|
|
|
: nodep->ifsp());
|
|
|
|
|
if (keepp) {
|
|
|
|
|
keepp->unlinkFrBackWithNext();
|
|
|
|
|
nodep->replaceWith(keepp);
|
|
|
|
|
} else {
|
|
|
|
|
nodep->unlinkFrBack();
|
|
|
|
|
}
|
|
|
|
|
nodep->deleteTree(); nodep=NULL;
|
2009-10-16 01:47:15 +00:00
|
|
|
|
// Normal edit rules will now recurse the replacement
|
2006-08-26 11:35:28 +00:00
|
|
|
|
} else {
|
|
|
|
|
nodep->condp()->v3error("Generate If condition must evaluate to constant");
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-20 02:53:52 +00:00
|
|
|
|
|
|
|
|
|
//! Parameter subsitution for generated for loops.
|
|
|
|
|
//! @todo Unlike generated IF, we don't have to worry about short-circuiting the conditional
|
|
|
|
|
//! expression, since this is currently restricted to simple comparisons. If we ever do
|
|
|
|
|
//! move to more generic constant expressions, such code will be neede here.
|
2012-07-21 21:12:42 +00:00
|
|
|
|
virtual void visit(AstBegin* nodep, AstNUser*) {
|
|
|
|
|
if (nodep->genforp()) {
|
|
|
|
|
AstGenFor* forp = nodep->genforp()->castGenFor();
|
|
|
|
|
if (!forp) nodep->v3fatalSrc("Non-GENFOR under generate-for BEGIN");
|
|
|
|
|
// We should have a GENFOR under here. We will be replacing the begin,
|
|
|
|
|
// so process here rather than at the generate to avoid iteration problems
|
|
|
|
|
UINFO(9," BEGIN "<<nodep<<endl);
|
|
|
|
|
UINFO(9," GENFOR "<<forp<<endl);
|
|
|
|
|
V3Width::widthParamsEdit(forp); // Param typed widthing will NOT recurse the body
|
|
|
|
|
// Outer wrapper around generate used to hold genvar, and to insure genvar
|
|
|
|
|
// doesn't conflict in V3LinkDot resolution with other genvars
|
|
|
|
|
// Now though we need to change BEGIN("zzz",GENFOR(...)) to
|
|
|
|
|
// a BEGIN("zzz__BRA__{loop#}__KET__")
|
|
|
|
|
string beginName = nodep->name();
|
|
|
|
|
// Leave the original Begin, as need a container for the (possible) GENVAR
|
|
|
|
|
// Note V3Unroll will replace some AstVarRef's to the loop variable with constants
|
|
|
|
|
V3Unroll::unrollGen(forp, beginName); forp=NULL;
|
|
|
|
|
// Blocks were constructed under the special begin, move them up
|
|
|
|
|
// Note forp is null, so grab statements again
|
|
|
|
|
if (AstNode* stmtsp = nodep->genforp()) {
|
|
|
|
|
stmtsp->unlinkFrBackWithNext();
|
|
|
|
|
nodep->addNextHere(stmtsp);
|
|
|
|
|
// Note this clears nodep->genforp(), so begin is no longer special
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
virtual void visit(AstGenFor* nodep, AstNUser*) {
|
2012-07-21 21:12:42 +00:00
|
|
|
|
nodep->v3fatalSrc("GENFOR should have been wrapped in BEGIN");
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
virtual void visit(AstGenCase* nodep, AstNUser*) {
|
2012-03-10 00:34:02 +00:00
|
|
|
|
UINFO(9," GENCASE "<<nodep<<endl);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
AstNode* keepp = NULL;
|
2009-10-25 20:53:55 +00:00
|
|
|
|
nodep->exprp()->iterateAndNext(*this);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
V3Case::caseLint(nodep);
|
2012-04-20 02:53:52 +00:00
|
|
|
|
V3Width::widthParamsEdit(nodep); // Param typed widthing will NOT recurse the body,
|
|
|
|
|
// don't trigger errors yet.
|
2009-10-15 00:13:04 +00:00
|
|
|
|
V3Const::constifyParamsEdit(nodep->exprp()); // exprp may change
|
2006-08-26 11:35:28 +00:00
|
|
|
|
AstConst* exprp = nodep->exprp()->castConst();
|
|
|
|
|
// Constify
|
|
|
|
|
for (AstCaseItem* itemp = nodep->itemsp(); itemp; itemp=itemp->nextp()->castCaseItem()) {
|
|
|
|
|
for (AstNode* ep = itemp->condsp(); ep; ) {
|
|
|
|
|
AstNode* nextp = ep->nextp(); //May edit list
|
2009-10-25 20:53:55 +00:00
|
|
|
|
ep->iterateAndNext(*this);
|
2009-10-15 00:13:04 +00:00
|
|
|
|
V3Const::constifyParamsEdit(ep); ep=NULL; // ep may change
|
2006-08-26 11:35:28 +00:00
|
|
|
|
ep = nextp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Item match
|
|
|
|
|
for (AstCaseItem* itemp = nodep->itemsp(); itemp; itemp=itemp->nextp()->castCaseItem()) {
|
|
|
|
|
if (!itemp->isDefault()) {
|
|
|
|
|
for (AstNode* ep = itemp->condsp(); ep; ep=ep->nextp()) {
|
|
|
|
|
if (AstConst* ccondp = ep->castConst()) {
|
|
|
|
|
V3Number match (nodep->fileline(), 1);
|
|
|
|
|
match.opEq(ccondp->num(), exprp->num());
|
|
|
|
|
if (!keepp && match.isNeqZero()) {
|
|
|
|
|
keepp = itemp->bodysp();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
itemp->v3error("Generate Case item does not evaluate to constant");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Else default match
|
|
|
|
|
for (AstCaseItem* itemp = nodep->itemsp(); itemp; itemp=itemp->nextp()->castCaseItem()) {
|
|
|
|
|
if (itemp->isDefault()) {
|
|
|
|
|
if (!keepp) keepp=itemp->bodysp();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Replace
|
|
|
|
|
if (keepp) {
|
|
|
|
|
keepp->unlinkFrBackWithNext();
|
|
|
|
|
nodep->replaceWith(keepp);
|
|
|
|
|
}
|
|
|
|
|
else nodep->unlinkFrBack();
|
|
|
|
|
nodep->deleteTree(); nodep=NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Default: Just iterate
|
|
|
|
|
virtual void visit(AstNode* nodep, AstNUser*) {
|
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
// CONSTUCTORS
|
|
|
|
|
ParamVisitor(AstNetlist* nodep) {
|
|
|
|
|
m_longId = 0;
|
|
|
|
|
//
|
|
|
|
|
nodep->accept(*this);
|
|
|
|
|
}
|
|
|
|
|
virtual ~ParamVisitor() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
// VISITs
|
|
|
|
|
|
|
|
|
|
void ParamVisitor::visit(AstCell* nodep, AstNUser*) {
|
|
|
|
|
// Cell: Check for parameters in the instantiation.
|
2009-10-25 20:53:55 +00:00
|
|
|
|
nodep->iterateChildren(*this);
|
2009-01-26 12:57:59 +00:00
|
|
|
|
if (!nodep->modp()) { nodep->dumpTree(cerr,"error:"); nodep->v3fatalSrc("Not linked?"); }
|
2008-06-10 01:25:10 +00:00
|
|
|
|
if (nodep->paramsp()) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
UINFO(4,"De-parameterize: "<<nodep<<endl);
|
|
|
|
|
// Create new module name with _'s between the constants
|
|
|
|
|
if (debug()>9) nodep->dumpTree(cout,"cell:\t");
|
|
|
|
|
// Evaluate all module constants
|
2009-10-15 00:13:04 +00:00
|
|
|
|
V3Const::constifyParamsEdit(nodep);
|
2009-01-08 14:22:31 +00:00
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Make sure constification worked
|
|
|
|
|
// Must be a separate loop, as constant conversion may have changed some pointers.
|
|
|
|
|
//if (debug()) nodep->dumpTree(cout,"cel2:\t");
|
|
|
|
|
string longname = nodep->modp()->name();
|
2009-01-08 14:22:31 +00:00
|
|
|
|
bool any_overrides = false;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
longname += "_";
|
|
|
|
|
if (debug()>8) nodep->paramsp()->dumpTreeAndNext(cout,"-cellparams:\t");
|
|
|
|
|
for (AstPin* pinp = nodep->paramsp(); pinp; pinp=pinp->nextp()->castPin()) {
|
|
|
|
|
if (!pinp) nodep->v3fatalSrc("Non pin under cell params\n");
|
2012-04-26 23:01:11 +00:00
|
|
|
|
if (!pinp->exprp()) continue; // No-connect
|
2006-08-26 11:35:28 +00:00
|
|
|
|
AstVar* modvarp = pinp->modVarp();
|
|
|
|
|
if (!modvarp) {
|
|
|
|
|
pinp->v3error("Parameter not found in sub-module: Param "<<pinp->name()<<" of "<<nodep->prettyName());
|
|
|
|
|
} else if (!modvarp->isGParam()) {
|
|
|
|
|
pinp->v3error("Attempted parameter setting of non-parameter: Param "<<pinp->name()<<" of "<<nodep->prettyName());
|
|
|
|
|
} else {
|
|
|
|
|
AstConst* constp = pinp->exprp()->castConst();
|
2010-01-21 23:20:47 +00:00
|
|
|
|
AstConst* origconstp = modvarp->valuep()->castConst();
|
2006-08-26 11:35:28 +00:00
|
|
|
|
if (!constp) {
|
|
|
|
|
//if (debug()) pinp->dumpTree(cout,"error:");
|
|
|
|
|
pinp->v3error("Can't convert defparam value to constant: Param "<<pinp->name()<<" of "<<nodep->prettyName());
|
2012-04-29 14:14:13 +00:00
|
|
|
|
pinp->exprp()->replaceWith(new AstConst(pinp->fileline(), V3Number(pinp->fileline(), modvarp->width(), 0)));
|
2009-01-08 14:22:31 +00:00
|
|
|
|
} else if (origconstp && constp->sameTree(origconstp)) {
|
|
|
|
|
// Setting parameter to its default value. Just ignore it.
|
|
|
|
|
// This prevents making additional modules, and makes coverage more
|
|
|
|
|
// obvious as it won't show up under a unique module page name.
|
2006-08-26 11:35:28 +00:00
|
|
|
|
} else {
|
|
|
|
|
longname += "_" + paramSmallName(nodep->modp(),pinp->modVarp())+constp->num().ascii(false);
|
2009-01-08 14:22:31 +00:00
|
|
|
|
any_overrides = true;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-08 14:22:31 +00:00
|
|
|
|
if (!any_overrides) {
|
|
|
|
|
UINFO(8,"Cell parameters all match original values, skipping expansion.\n");
|
|
|
|
|
} else {
|
|
|
|
|
// If the name is very long, we don't want to overwhelm the filename limit
|
|
|
|
|
// We don't do this always, as it aids debugability to have intuitive naming.
|
|
|
|
|
string newname = longname;
|
|
|
|
|
if (longname.length()>30) {
|
|
|
|
|
LongMap::iterator iter = m_longMap.find(longname);
|
|
|
|
|
if (iter != m_longMap.end()) {
|
|
|
|
|
newname = iter->second;
|
|
|
|
|
} else {
|
|
|
|
|
newname = nodep->modp()->name();
|
|
|
|
|
newname += "__pi"+cvtToStr(++m_longId); // We use all upper case above, so lower here can't conflict
|
|
|
|
|
m_longMap.insert(make_pair(longname, newname));
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2009-01-08 14:22:31 +00:00
|
|
|
|
UINFO(4,"Name: "<<nodep->modp()->name()<<"->"<<longname<<"->"<<newname<<endl);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
2009-01-08 14:22:31 +00:00
|
|
|
|
//
|
|
|
|
|
// Already made this flavor?
|
2009-11-07 11:20:20 +00:00
|
|
|
|
AstNodeModule* modp = NULL;
|
2009-01-08 14:22:31 +00:00
|
|
|
|
ModNameMap::iterator iter = m_modNameMap.find(newname);
|
|
|
|
|
if (iter != m_modNameMap.end()) modp = iter->second.m_modp;
|
|
|
|
|
if (!modp) {
|
|
|
|
|
// Deep clone of new module
|
|
|
|
|
// Note all module internal variables will be re-linked to the new modules by clone
|
|
|
|
|
// However links outside the module (like on the upper cells) will not.
|
|
|
|
|
modp = nodep->modp()->cloneTree(false);
|
|
|
|
|
modp->name(newname);
|
2012-04-29 12:55:33 +00:00
|
|
|
|
modp->user5(false); // We need to re-recurse this module once changed
|
2009-01-08 14:22:31 +00:00
|
|
|
|
nodep->modp()->addNextHere(modp); // Keep tree sorted by cell occurrences
|
2012-03-20 20:01:53 +00:00
|
|
|
|
|
2009-01-08 14:22:31 +00:00
|
|
|
|
m_modNameMap.insert(make_pair(modp->name(), ModInfo(modp)));
|
|
|
|
|
iter = m_modNameMap.find(newname);
|
|
|
|
|
VarCloneMap* clonemapp = &(iter->second.m_cloneMap);
|
|
|
|
|
UINFO(4," De-parameterize to new: "<<modp<<endl);
|
2012-03-20 20:01:53 +00:00
|
|
|
|
|
2009-01-08 14:22:31 +00:00
|
|
|
|
// Grab all I/O so we can remap our pins later
|
|
|
|
|
// Note we allow multiple users of a parameterized model, thus we need to stash this info.
|
|
|
|
|
for (AstNode* stmtp=modp->stmtsp(); stmtp; stmtp = stmtp->nextp()) {
|
|
|
|
|
if (AstVar* varp = stmtp->castVar()) {
|
|
|
|
|
if (varp->isIO() || varp->isGParam()) {
|
|
|
|
|
// Cloning saved a pointer to the new node for us, so just follow that link.
|
|
|
|
|
AstVar* oldvarp = varp->clonep()->castVar();
|
|
|
|
|
//UINFO(8,"Clone list 0x"<<hex<<(uint32_t)oldvarp<<" -> 0x"<<(uint32_t)varp<<endl);
|
|
|
|
|
clonemapp->insert(make_pair(oldvarp, varp));
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-20 20:01:53 +00:00
|
|
|
|
|
2009-01-08 14:22:31 +00:00
|
|
|
|
// Relink parameter vars to the new module
|
|
|
|
|
relinkPins(clonemapp, nodep->paramsp());
|
2012-03-20 20:01:53 +00:00
|
|
|
|
|
2009-01-08 14:22:31 +00:00
|
|
|
|
// Assign parameters to the constants specified
|
|
|
|
|
for (AstPin* pinp = nodep->paramsp(); pinp; pinp=pinp->nextp()->castPin()) {
|
|
|
|
|
AstVar* modvarp = pinp->modVarp();
|
2012-04-26 23:01:11 +00:00
|
|
|
|
if (modvarp && pinp->exprp()) {
|
2009-01-08 14:22:31 +00:00
|
|
|
|
AstConst* constp = pinp->exprp()->castConst();
|
|
|
|
|
// Remove any existing parameter
|
2010-01-21 23:20:47 +00:00
|
|
|
|
if (modvarp->valuep()) modvarp->valuep()->unlinkFrBack()->deleteTree();
|
2009-01-08 14:22:31 +00:00
|
|
|
|
// Set this parameter to value requested by cell
|
2010-01-21 23:20:47 +00:00
|
|
|
|
modvarp->valuep(constp->cloneTree(false));
|
2009-01-08 14:22:31 +00:00
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2009-01-08 14:22:31 +00:00
|
|
|
|
} else {
|
|
|
|
|
UINFO(4," De-parameterize to old: "<<modp<<endl);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2012-03-20 20:01:53 +00:00
|
|
|
|
|
2009-01-08 14:22:31 +00:00
|
|
|
|
// Have child use this module instead.
|
|
|
|
|
nodep->modp(modp);
|
|
|
|
|
nodep->modName(newname);
|
2012-03-20 20:01:53 +00:00
|
|
|
|
|
2009-01-08 14:22:31 +00:00
|
|
|
|
// We need to relink the pins to the new module
|
|
|
|
|
VarCloneMap* clonemapp = &(iter->second.m_cloneMap);
|
|
|
|
|
relinkPins(clonemapp, nodep->pinsp());
|
|
|
|
|
UINFO(8," Done with "<<modp<<endl);
|
|
|
|
|
} // if any_overrides
|
2012-03-20 20:01:53 +00:00
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Delete the parameters from the cell; they're not relevant any longer.
|
2009-01-08 14:22:31 +00:00
|
|
|
|
nodep->paramsp()->unlinkFrBackWithNext()->deleteTree();
|
|
|
|
|
UINFO(8," Done with "<<nodep<<endl);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2012-03-24 19:54:06 +00:00
|
|
|
|
|
|
|
|
|
// Now remember to process the child module at the end of the module
|
|
|
|
|
m_todoModps.push_back(nodep->modp());
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// Param class functions
|
|
|
|
|
|
|
|
|
|
void V3Param::param(AstNetlist* rootp) {
|
|
|
|
|
UINFO(2,__FUNCTION__<<": "<<endl);
|
|
|
|
|
ParamVisitor visitor (rootp);
|
|
|
|
|
}
|