2006-08-26 11:35:28 +00:00
|
|
|
|
//*************************************************************************
|
|
|
|
|
// DESCRIPTION: Verilator: Ast node structures
|
|
|
|
|
//
|
2008-04-25 12:14:27 +00:00
|
|
|
|
// Code available from: http://www.veripool.org/verilator
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//
|
|
|
|
|
// AUTHORS: Wilson Snyder with Paul Wasson, Duane Gabli
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2009-01-02 16:47:39 +00:00
|
|
|
|
// Copyright 2003-2009 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
|
|
|
|
|
// General Public License or the Perl Artistic License.
|
|
|
|
|
//
|
|
|
|
|
// 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.
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
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 <fstream>
|
|
|
|
|
#include <iomanip>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
|
|
#include "V3Ast.h"
|
|
|
|
|
#include "V3File.h"
|
|
|
|
|
#include "V3Global.h"
|
|
|
|
|
|
|
|
|
|
//======================================================================
|
|
|
|
|
// Special methods
|
|
|
|
|
|
|
|
|
|
// We need these here, because the classes they point to aren't defined when we declare the class
|
|
|
|
|
bool AstNodeVarRef::broken() const { return ((m_varScopep && !m_varScopep->brokeExists())
|
|
|
|
|
|| (m_varp && !m_varp->brokeExists())); }
|
|
|
|
|
|
|
|
|
|
void AstNodeVarRef::cloneRelink() {
|
|
|
|
|
if (m_varp && m_varp->clonep()) { m_varp = m_varp->clonep()->castVar(); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AstNodeSel::bitConst() const {
|
2008-10-06 13:59:22 +00:00
|
|
|
|
AstConst* constp=bitp()->castConst(); return (constp?constp->toSInt():0);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AstVar::isSigPublic() const {
|
2008-09-30 12:58:07 +00:00
|
|
|
|
return (m_sigPublic || (v3Global.opt.allPublic() && !isTemp() && !isGenVar()));
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AstVar::isScQuad() const {
|
|
|
|
|
return (isSc()&&isQuad()&&v3Global.opt.pins64());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AstVar::isScWide() const {
|
|
|
|
|
return (isWide() || isSc()&&isQuad()&&!v3Global.opt.pins64());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AstVar::combineType(AstVarType type) {
|
|
|
|
|
if (type == AstVarType::SUPPLY0) type = AstVarType::WIRE;
|
|
|
|
|
if (type == AstVarType::SUPPLY1) type = AstVarType::WIRE;
|
|
|
|
|
m_varType=type; // For debugging prints only
|
|
|
|
|
// These flags get combined with the existing settings of the flags.
|
|
|
|
|
if (type==AstVarType::INPUT || type==AstVarType::INOUT)
|
|
|
|
|
m_input = true;
|
|
|
|
|
if (type==AstVarType::OUTPUT || type==AstVarType::INOUT)
|
|
|
|
|
m_output = true;
|
|
|
|
|
if (type==AstVarType::INOUT || type==AstVarType::TRIWIRE)
|
|
|
|
|
m_tristate = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AstVar::widthAlignBytes() const {
|
|
|
|
|
if (width()<=8) return 1;
|
|
|
|
|
else if (width()<=16) return 2;
|
|
|
|
|
else if (isSc() ? isScQuad() : isQuad()) return 8;
|
|
|
|
|
else return 4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AstVar::widthTotalBytes() const {
|
|
|
|
|
if (width()<=8) return 1;
|
|
|
|
|
else if (width()<=16) return 2;
|
|
|
|
|
else if (isSc() ? isScQuad() : isQuad()) return 8;
|
|
|
|
|
else return widthWords()*(VL_WORDSIZE/8);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string AstVar::verilogKwd() const {
|
2006-09-25 20:40:52 +00:00
|
|
|
|
if (isInout()) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
return "inout";
|
|
|
|
|
} else if (isInput()) {
|
|
|
|
|
return "input";
|
|
|
|
|
} else if (isOutput()) {
|
|
|
|
|
return "output";
|
|
|
|
|
} else if (isInteger()) {
|
|
|
|
|
return "integer";
|
2006-09-25 20:40:52 +00:00
|
|
|
|
} else if (isTristate()) {
|
|
|
|
|
return "tri";
|
2006-08-26 11:35:28 +00:00
|
|
|
|
} else if (varType()==AstVarType::WIRE) {
|
|
|
|
|
return "wire";
|
|
|
|
|
} else {
|
|
|
|
|
return "reg";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string AstVar::cType() const {
|
2006-10-05 14:53:17 +00:00
|
|
|
|
if (widthMin() == 1) {
|
|
|
|
|
return "bool";
|
|
|
|
|
} else if (widthMin() <= VL_WORDSIZE) {
|
|
|
|
|
return "uint32_t";
|
|
|
|
|
} else if (isScWide()) {
|
|
|
|
|
return "uint32_t"; // []'s added later
|
|
|
|
|
} else {
|
|
|
|
|
return "uint64_t";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string AstVar::scType() const {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
if (widthMin() == 1) {
|
|
|
|
|
return "bool";
|
|
|
|
|
} else if (widthMin() <= VL_WORDSIZE) {
|
|
|
|
|
return "uint32_t";
|
|
|
|
|
} else if (isScWide()) {
|
|
|
|
|
return (string("sc_bv<")+cvtToStr(widthMin())+"> "); // Keep the space so don't get >>
|
|
|
|
|
} else {
|
|
|
|
|
return "uint64_t";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AstRange* AstVar::arrayp(int dimension) const {
|
|
|
|
|
for (AstRange* arrayp=this->arraysp(); arrayp; arrayp = arrayp->nextp()->castRange()) {
|
|
|
|
|
if ((dimension--)==0) return arrayp;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t AstVar::arrayElements() const {
|
|
|
|
|
uint32_t entries=1;
|
|
|
|
|
for (AstRange* arrayp=this->arraysp(); arrayp; arrayp = arrayp->nextp()->castRange()) {
|
|
|
|
|
entries *= arrayp->elementsConst();
|
|
|
|
|
}
|
|
|
|
|
return entries;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AstScope::broken() const {
|
|
|
|
|
return ((m_aboveScopep && !m_aboveScopep->brokeExists())
|
|
|
|
|
|| (m_aboveCellp && !m_aboveCellp->brokeExists())
|
2006-10-05 00:45:39 +00:00
|
|
|
|
|| !m_modp || !m_modp->brokeExists());
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AstScope::cloneRelink() {
|
|
|
|
|
if (m_aboveScopep && m_aboveScopep->clonep()) m_aboveScopep->clonep()->castScope();
|
|
|
|
|
if (m_aboveCellp && m_aboveCellp->clonep()) m_aboveCellp->clonep()->castCell();
|
|
|
|
|
if (m_modp && ((AstNode*)m_modp)->clonep()) ((AstNode*)m_modp)->clonep()->castModule();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string AstScope::nameDotless() const {
|
|
|
|
|
string dotless = shortName();
|
|
|
|
|
string::size_type pos;
|
|
|
|
|
while ((pos=dotless.find(".")) != string::npos) {
|
|
|
|
|
dotless.replace(pos, 1, "__");
|
|
|
|
|
}
|
|
|
|
|
return dotless;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AstSenTree::hasClocked() {
|
|
|
|
|
if (!sensesp()) this->v3fatalSrc("SENTREE without any SENITEMs under it");
|
2008-11-20 12:55:54 +00:00
|
|
|
|
for (AstNodeSenItem* senp = sensesp(); senp; senp=senp->nextp()->castNodeSenItem()) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
if (senp->isClocked()) return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
bool AstSenTree::hasSettle() {
|
|
|
|
|
if (!sensesp()) this->v3fatalSrc("SENTREE without any SENITEMs under it");
|
2008-11-20 12:55:54 +00:00
|
|
|
|
for (AstNodeSenItem* senp = sensesp(); senp; senp=senp->nextp()->castNodeSenItem()) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
if (senp->isSettle()) return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
bool AstSenTree::hasInitial() {
|
|
|
|
|
if (!sensesp()) this->v3fatalSrc("SENTREE without any SENITEMs under it");
|
2008-11-20 12:55:54 +00:00
|
|
|
|
for (AstNodeSenItem* senp = sensesp(); senp; senp=senp->nextp()->castNodeSenItem()) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
if (senp->isInitial()) return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
bool AstSenTree::hasCombo() {
|
|
|
|
|
if (!sensesp()) this->v3fatalSrc("SENTREE without any SENITEMs under it");
|
2008-11-20 12:55:54 +00:00
|
|
|
|
for (AstNodeSenItem* senp = sensesp(); senp; senp=senp->nextp()->castNodeSenItem()) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
if (senp->isCombo()) return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//======================================================================
|
|
|
|
|
// Per-type Debugging
|
|
|
|
|
|
|
|
|
|
void AstNode::dump(ostream& os) {
|
|
|
|
|
os<<typeName()<<" "<<(void*)this
|
|
|
|
|
//<<" "<<(void*)this->m_backp
|
|
|
|
|
<<" <e"<<dec<<editCount()
|
|
|
|
|
<<((editCount()>=editCountLast())?"#>":">")
|
|
|
|
|
<<" {"<<dec<<fileline()->lineno()<<"}"
|
|
|
|
|
<<" "<<(isSigned()?"s":"")
|
|
|
|
|
<<"w"<<(widthSized()?"":"u")<<width();
|
|
|
|
|
if (!widthSized()) os<<"/"<<widthMin();
|
|
|
|
|
if (name()!="") os<<" "<<name();
|
|
|
|
|
}
|
|
|
|
|
void AstCast::dump(ostream& str) {
|
|
|
|
|
this->AstNode::dump(str);
|
|
|
|
|
str<<" sz"<<size();
|
|
|
|
|
}
|
|
|
|
|
void AstCell::dump(ostream& str) {
|
|
|
|
|
this->AstNode::dump(str);
|
|
|
|
|
if (modp()) { str<<" -> "; modp()->dump(str); }
|
|
|
|
|
else { str<<" ->UNLINKED:"<<modName(); }
|
2007-03-14 13:06:08 +00:00
|
|
|
|
if (pinStar()) str<<" [.*]";
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
void AstCellInline::dump(ostream& str) {
|
|
|
|
|
this->AstNode::dump(str);
|
|
|
|
|
str<<" -> "<<origModName();
|
|
|
|
|
}
|
2008-03-26 14:58:30 +00:00
|
|
|
|
void AstDisplay::dump(ostream& str) {
|
|
|
|
|
this->AstNode::dump(str);
|
|
|
|
|
//str<<" "<<displayType().ascii();
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
void AstPin::dump(ostream& str) {
|
|
|
|
|
this->AstNode::dump(str);
|
|
|
|
|
if (modVarp()) { str<<" -> "; modVarp()->dump(str); }
|
|
|
|
|
else { str<<" ->UNLINKED"; }
|
2007-03-14 13:06:08 +00:00
|
|
|
|
if (svImplicit()) str<<" [.SV]";
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
void AstVarXRef::dump(ostream& str) {
|
|
|
|
|
this->AstNode::dump(str);
|
|
|
|
|
if (lvalue()) str<<" [LV] => ";
|
|
|
|
|
else str<<" [RV] <- ";
|
|
|
|
|
str<<dotted()<<". - ";
|
|
|
|
|
if (inlinedDots()!="") str<<" flat.="<<inlinedDots()<<" - ";
|
|
|
|
|
if (varScopep()) { varScopep()->dump(str); }
|
|
|
|
|
else if (varp()) { varp()->dump(str); }
|
|
|
|
|
else { str<<"UNLINKED"; }
|
|
|
|
|
}
|
|
|
|
|
void AstModule::dump(ostream& str) {
|
|
|
|
|
this->AstNode::dump(str);
|
|
|
|
|
str<<" L"<<level();
|
|
|
|
|
if (modPublic()) str<<" [P]";
|
|
|
|
|
if (inLibrary()) str<<" [LIB]";
|
|
|
|
|
}
|
|
|
|
|
void AstVarScope::dump(ostream& str) {
|
|
|
|
|
this->AstNode::dump(str);
|
|
|
|
|
if (isCircular()) str<<" [CIRC]";
|
|
|
|
|
if (varp()) { str<<" -> "; varp()->dump(str); }
|
|
|
|
|
else { str<<" ->UNLINKED"; }
|
|
|
|
|
}
|
|
|
|
|
void AstVarRef::dump(ostream& str) {
|
|
|
|
|
this->AstNode::dump(str);
|
|
|
|
|
if (lvalue()) str<<" [LV] => ";
|
|
|
|
|
else str<<" [RV] <- ";
|
|
|
|
|
if (varScopep()) { varScopep()->dump(str); }
|
|
|
|
|
else if (varp()) { varp()->dump(str); }
|
|
|
|
|
else { str<<"UNLINKED"; }
|
|
|
|
|
}
|
|
|
|
|
void AstVar::dump(ostream& str) {
|
|
|
|
|
this->AstNode::dump(str);
|
|
|
|
|
if (isSc()) str<<" [SC]";
|
2006-09-25 20:40:52 +00:00
|
|
|
|
if (isPrimaryIO()) str<<(isInout()?" [PIO]":(isInput()?" [PI]":" [PO]"));
|
|
|
|
|
else {
|
|
|
|
|
if (isInout()) str<<" [IO]";
|
|
|
|
|
else if (isInput()) str<<" [I]";
|
|
|
|
|
else if (isOutput()) str<<" [O]";
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
if (isUsedClock()) str<<" [C]";
|
|
|
|
|
if (isSigPublic()) str<<" [P]";
|
|
|
|
|
if (attrClockEn()) str<<" [aCLKEN]";
|
2007-01-18 00:51:26 +00:00
|
|
|
|
if (attrIsolateAssign()) str<<" [aISO]";
|
2006-08-26 11:35:28 +00:00
|
|
|
|
if (attrFileDescr()) str<<" [aFD]";
|
2006-10-11 15:41:42 +00:00
|
|
|
|
if (isFuncReturn()) str<<" [FUNCRTN]";
|
|
|
|
|
else if (isFuncLocal()) str<<" [FUNC]";
|
2006-08-26 11:35:28 +00:00
|
|
|
|
str<<" "<<varType();
|
|
|
|
|
}
|
|
|
|
|
void AstSenTree::dump(ostream& str) {
|
|
|
|
|
this->AstNode::dump(str);
|
|
|
|
|
if (isMulti()) str<<" [MULTI]";
|
|
|
|
|
}
|
|
|
|
|
void AstSenItem::dump(ostream& str) {
|
|
|
|
|
this->AstNode::dump(str);
|
2006-12-21 21:53:51 +00:00
|
|
|
|
str<<" ["<<edgeType().ascii()<<"]";
|
|
|
|
|
}
|
|
|
|
|
void AstParseRef::dump(ostream& str) {
|
|
|
|
|
this->AstNode::dump(str);
|
|
|
|
|
str<<" ["<<expect().ascii()<<"]";
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
void AstActive::dump(ostream& str) {
|
|
|
|
|
this->AstNode::dump(str);
|
|
|
|
|
str<<" => ";
|
|
|
|
|
if (sensesp()) { sensesp()->dump(str); }
|
|
|
|
|
else { str<<"UNLINKED"; }
|
|
|
|
|
}
|
|
|
|
|
void AstNodeFTaskRef::dump(ostream& str) {
|
|
|
|
|
this->AstNode::dump(str);
|
|
|
|
|
str<<" -> ";
|
|
|
|
|
if (dotted()!="") { str<<dotted()<<". - "; }
|
|
|
|
|
if (taskp()) { taskp()->dump(str); }
|
|
|
|
|
else { str<<"UNLINKED"; }
|
|
|
|
|
}
|
|
|
|
|
void AstNodeFTask::dump(ostream& str) {
|
|
|
|
|
this->AstNode::dump(str);
|
2006-10-11 15:41:42 +00:00
|
|
|
|
if (taskPublic()) str<<" [PUBLIC]";
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
void AstCoverDecl::dump(ostream& str) {
|
|
|
|
|
this->AstNode::dump(str);
|
2008-12-12 20:34:02 +00:00
|
|
|
|
if (this->dataDeclNullp()) {
|
|
|
|
|
str<<" -> ";
|
|
|
|
|
this->dataDeclNullp()->dump(str);
|
|
|
|
|
} else {
|
|
|
|
|
if (binNum()) { str<<" bin"<<dec<<binNum(); }
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
void AstCoverInc::dump(ostream& str) {
|
|
|
|
|
this->AstNode::dump(str);
|
|
|
|
|
str<<" -> ";
|
|
|
|
|
if (declp()) { declp()->dump(str); }
|
|
|
|
|
else { str<<"%Error:UNLINKED"; }
|
|
|
|
|
}
|
|
|
|
|
void AstTraceInc::dump(ostream& str) {
|
|
|
|
|
this->AstNode::dump(str);
|
|
|
|
|
str<<" -> ";
|
|
|
|
|
if (declp()) { declp()->dump(str); }
|
|
|
|
|
else { str<<"%Error:UNLINKED"; }
|
|
|
|
|
}
|
|
|
|
|
void AstCFile::dump(ostream& str) {
|
|
|
|
|
this->AstNode::dump(str);
|
|
|
|
|
if (source()) str<<" [SRC]";
|
|
|
|
|
if (slow()) str<<" [SLOW]";
|
|
|
|
|
}
|
|
|
|
|
void AstCCall::dump(ostream& str) {
|
|
|
|
|
this->AstNode::dump(str);
|
|
|
|
|
if (funcp()) {
|
|
|
|
|
str<<" "<<funcp()->name()<<" => ";
|
|
|
|
|
funcp()->dump(str);
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-08-06 21:09:33 +00:00
|
|
|
|
void AstCFunc::dump(ostream& str) {
|
|
|
|
|
this->AstNode::dump(str);
|
|
|
|
|
if (slow()) str<<" [SLOW]";
|
|
|
|
|
}
|