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: Change names for __PVT__'s
|
|
|
|
|
//
|
2008-04-25 12:14:27 +00:00
|
|
|
|
// Code available from: http://www.veripool.org/verilator
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2013-01-01 14:42:59 +00:00
|
|
|
|
// Copyright 2003-2013 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.
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
// V3Name's Transformations:
|
2008-06-10 01:25:10 +00:00
|
|
|
|
//
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Cell/Var's
|
|
|
|
|
// Prepend __PVT__ to variable names
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
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 "V3Name.h"
|
|
|
|
|
#include "V3Ast.h"
|
2009-07-22 19:21:41 +00:00
|
|
|
|
#include "V3LanguageWords.h"
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// Name state, as a visitor of each AstNode
|
|
|
|
|
|
|
|
|
|
class NameVisitor : public AstNVisitor {
|
|
|
|
|
private:
|
|
|
|
|
// NODE STATE
|
|
|
|
|
// Cleared on Netlist
|
2008-11-25 14:03:49 +00:00
|
|
|
|
// AstCell::user1() -> bool. Set true if already processed
|
|
|
|
|
// AstScope::user1() -> bool. Set true if already processed
|
|
|
|
|
// AstVar::user1() -> bool. Set true if already processed
|
|
|
|
|
AstUser1InUse m_inuser1;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
// STATE
|
2009-11-07 11:20:20 +00:00
|
|
|
|
AstNodeModule* m_modp;
|
2009-07-22 19:21:41 +00:00
|
|
|
|
V3LanguageWords m_words; // Reserved word detector
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
2009-01-21 21:56:50 +00:00
|
|
|
|
// METHODS
|
|
|
|
|
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
|
|
|
|
|
2009-07-22 19:21:41 +00:00
|
|
|
|
void rename(AstNode* nodep, bool addPvt) {
|
|
|
|
|
if (!nodep->user1()) { // Not already done
|
|
|
|
|
if (addPvt) {
|
|
|
|
|
string newname = (string)"__PVT__"+nodep->name();
|
|
|
|
|
nodep->name(newname);
|
|
|
|
|
} else {
|
|
|
|
|
string rsvd = m_words.isKeyword(nodep->name());
|
|
|
|
|
if (rsvd != "") {
|
2013-03-12 11:27:17 +00:00
|
|
|
|
nodep->v3warn(SYMRSVDWORD,"Symbol matches "+rsvd+": '"<<nodep->prettyName()<<"'");
|
2009-07-22 19:21:41 +00:00
|
|
|
|
string newname = (string)"__SYM__"+nodep->name();
|
|
|
|
|
nodep->name(newname);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
nodep->user1(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// VISITORS
|
2009-11-07 11:20:20 +00:00
|
|
|
|
virtual void visit(AstNodeModule* nodep, AstNUser*) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
m_modp = nodep;
|
|
|
|
|
nodep->iterateChildren(*this);
|
2006-08-27 14:51:25 +00:00
|
|
|
|
m_modp = NULL;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
// Add __PVT__ to names of local signals
|
|
|
|
|
virtual void visit(AstVar* nodep, AstNUser*) {
|
|
|
|
|
// Don't iterate... Don't need temps for RANGES under the Var.
|
2009-07-22 19:21:41 +00:00
|
|
|
|
rename(nodep, (!m_modp->isTop()
|
|
|
|
|
&& !nodep->isSigPublic()
|
2009-12-04 12:41:18 +00:00
|
|
|
|
&& !nodep->isFuncLocal() // Isn't exposed, and would mess up dpi import wrappers
|
2009-07-22 19:21:41 +00:00
|
|
|
|
&& !nodep->isTemp())); // Don't bother to rename internal signals
|
|
|
|
|
}
|
|
|
|
|
virtual void visit(AstCFunc* nodep, AstNUser*) {
|
2010-01-08 15:46:12 +00:00
|
|
|
|
if (!nodep->user1()) {
|
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
rename(nodep, false);
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
virtual void visit(AstVarRef* nodep, AstNUser*) {
|
|
|
|
|
if (nodep->varp()) {
|
2010-01-08 15:46:12 +00:00
|
|
|
|
nodep->varp()->iterate(*this);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
nodep->name(nodep->varp()->name());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
virtual void visit(AstCell* nodep, AstNUser*) {
|
2010-01-08 15:46:12 +00:00
|
|
|
|
if (!nodep->user1()) {
|
|
|
|
|
rename(nodep, !nodep->modp()->modPublic());
|
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
virtual void visit(AstScope* nodep, AstNUser*) {
|
2012-04-29 12:55:33 +00:00
|
|
|
|
if (!nodep->user1SetOnce()) {
|
2010-01-08 15:46:12 +00:00
|
|
|
|
if (nodep->aboveScopep()) nodep->aboveScopep()->iterate(*this);
|
|
|
|
|
if (nodep->aboveCellp()) nodep->aboveCellp()->iterate(*this);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Always recompute name (as many level above scope may have changed)
|
|
|
|
|
// Same formula as V3Scope
|
|
|
|
|
nodep->name(nodep->isTop() ? "TOP"
|
|
|
|
|
: (nodep->aboveScopep()->name()+"."+nodep->aboveCellp()->name()));
|
2010-01-08 15:46:12 +00:00
|
|
|
|
nodep->iterateChildren(*this);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------
|
|
|
|
|
virtual void visit(AstNode* nodep, AstNUser*) {
|
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
}
|
|
|
|
|
public:
|
|
|
|
|
// CONSTUCTORS
|
2009-10-02 02:33:11 +00:00
|
|
|
|
NameVisitor(AstNetlist* nodep) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
nodep->accept(*this);
|
|
|
|
|
}
|
|
|
|
|
virtual ~NameVisitor() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// Name class functions
|
|
|
|
|
|
|
|
|
|
void V3Name::nameAll(AstNetlist* nodep) {
|
|
|
|
|
UINFO(2,__FUNCTION__<<": "<<endl);
|
|
|
|
|
NameVisitor visitor (nodep);
|
|
|
|
|
}
|