mirror of
https://github.com/verilator/verilator.git
synced 2025-01-08 23:57:35 +00:00
Internals: Rename AstVar::initp to valuep as it's a constant, not initial value
This commit is contained in:
parent
e4f1e5f4c3
commit
2da9d46ca6
@ -352,8 +352,8 @@ public:
|
||||
void name(const string& flag) { m_name = flag; }
|
||||
AstRange* rangep() const { return op1p()->castRange(); } // op1 = Range for name appending
|
||||
void rangep(AstNode* nodep) { addOp1p(nodep); }
|
||||
AstNode* initp() const { return op2p(); } // op2 = Value
|
||||
void initp(AstNode* nodep) { addOp2p(nodep); }
|
||||
AstNode* valuep() const { return op2p(); } // op2 = Value
|
||||
void valuep(AstNode* nodep) { addOp2p(nodep); }
|
||||
};
|
||||
|
||||
struct AstEnumItemRef : public AstNodeMath {
|
||||
@ -613,8 +613,8 @@ public:
|
||||
AstBasicDType* basicp() const { return dtypep()->basicp(); } // (Slow) recurse down to find basic data type (Note don't need virtual - AstVar isn't a NodeDType)
|
||||
AstNodeDType* dtypeDimensionp(int depth) const;
|
||||
uint32_t dimensions() const;
|
||||
AstNode* initp() const { return op3p()->castNode(); } // op3 = Initial value that never changes (static const)
|
||||
void initp(AstNode* nodep) { setOp3p(nodep); }
|
||||
AstNode* valuep() const { return op3p()->castNode(); } // op3 = Initial value that never changes (static const)
|
||||
void valuep(AstNode* nodep) { setOp3p(nodep); } // It's valuep, not constp, as may be more complicated than a AstConst
|
||||
void addAttrsp(AstNode* nodep) { addNOp4p(nodep); }
|
||||
AstNode* attrsp() const { return op4p()->castNode(); } // op4 = Attributes during early parse
|
||||
bool hasSimpleInit() const { return (op3p() && !op3p()->castInitArray()); }
|
||||
|
@ -1064,14 +1064,14 @@ private:
|
||||
if (!nodep->varp()) nodep->v3fatalSrc("Not linked");
|
||||
bool did=false;
|
||||
if (!m_cpp && nodep->varp()->hasSimpleInit() && !nodep->backp()->castAttrOf()) {
|
||||
//if (debug()) nodep->varp()->initp()->dumpTree(cout," visitvaref: ");
|
||||
nodep->varp()->initp()->iterateAndNext(*this);
|
||||
if (operandConst(nodep->varp()->initp())
|
||||
//if (debug()) nodep->varp()->valuep()->dumpTree(cout," visitvaref: ");
|
||||
nodep->varp()->valuep()->iterateAndNext(*this);
|
||||
if (operandConst(nodep->varp()->valuep())
|
||||
&& !nodep->lvalue()
|
||||
&& ((v3Global.opt.oConst() && !m_params // Can reduce constant wires into equations
|
||||
&& !nodep->varp()->isSigPublic())
|
||||
|| nodep->varp()->isParam())) {
|
||||
AstConst* constp = nodep->varp()->initp()->castConst();
|
||||
AstConst* constp = nodep->varp()->valuep()->castConst();
|
||||
const V3Number& num = constp->num();
|
||||
//UINFO(2,"constVisit "<<(void*)constp<<" "<<num<<endl);
|
||||
replaceNum(nodep, num); nodep=NULL;
|
||||
@ -1086,11 +1086,11 @@ private:
|
||||
nodep->iterateChildren(*this);
|
||||
if (!nodep->itemp()) nodep->v3fatalSrc("Not linked");
|
||||
bool did=false;
|
||||
if (nodep->itemp()->initp()) {
|
||||
//if (debug()) nodep->varp()->initp()->dumpTree(cout," visitvaref: ");
|
||||
nodep->itemp()->initp()->iterateAndNext(*this);
|
||||
if (AstConst* initp = nodep->itemp()->initp()->castConst()) {
|
||||
const V3Number& num = initp->num();
|
||||
if (nodep->itemp()->valuep()) {
|
||||
//if (debug()) nodep->varp()->valuep()->dumpTree(cout," visitvaref: ");
|
||||
nodep->itemp()->valuep()->iterateAndNext(*this);
|
||||
if (AstConst* valuep = nodep->itemp()->valuep()->castConst()) {
|
||||
const V3Number& num = valuep->num();
|
||||
replaceNum(nodep, num); nodep=NULL;
|
||||
did=true;
|
||||
}
|
||||
@ -1317,7 +1317,7 @@ private:
|
||||
&& m_modp && operandConst(nodep->rhsp())
|
||||
&& !nodep->rhsp()->castConst()->num().isFourState()
|
||||
&& varrefp // Don't do messes with BITREFs/ARRAYREFs
|
||||
&& !varrefp->varp()->initp() // Not already constified
|
||||
&& !varrefp->varp()->valuep() // Not already constified
|
||||
&& !varrefp->varScopep() // Not scoped (or each scope may have different initial value)
|
||||
&& !m_params) {
|
||||
// ASSIGNW (VARREF, const) -> INITIAL ( ASSIGN (VARREF, const) )
|
||||
@ -1333,7 +1333,7 @@ private:
|
||||
nodep->unlinkFrBack()->deleteTree(); nodep=NULL;
|
||||
// Set the initial value right in the variable so we can constant propagate
|
||||
AstNode* initvaluep = exprp->cloneTree(false);
|
||||
varrefp->varp()->initp(initvaluep);
|
||||
varrefp->varp()->valuep(initvaluep);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1785,7 +1785,7 @@ AstNode* V3Const::constifyParamsEdit(AstNode* nodep) {
|
||||
// If a var wants to be constified, it's really a param, and
|
||||
// we want the value to be constant. We aren't passed just the
|
||||
// init value because we need widthing above to handle the var's type.
|
||||
if (varp->initp()) visitor.mainAcceptEdit(varp->initp());
|
||||
if (varp->valuep()) visitor.mainAcceptEdit(varp->valuep());
|
||||
} else {
|
||||
nodep = visitor.mainAcceptEdit(nodep);
|
||||
}
|
||||
|
@ -1263,9 +1263,9 @@ void EmitCImp::emitVarResets(AstNodeModule* modp) {
|
||||
}
|
||||
else if (varp->isParam()) {
|
||||
if (!varp->hasSimpleInit()) nodep->v3fatalSrc("No init for a param?");
|
||||
//puts("// parameter "+varp->name()+" = "+varp->initp()->name()+"\n");
|
||||
//puts("// parameter "+varp->name()+" = "+varp->valuep()->name()+"\n");
|
||||
}
|
||||
else if (AstInitArray* initarp = varp->initp()->castInitArray()) {
|
||||
else if (AstInitArray* initarp = varp->valuep()->castInitArray()) {
|
||||
AstConst* constsp = initarp->initsp()->castConst();
|
||||
if (AstArrayDType* arrayp = varp->dtypeSkipRefp()->castArrayDType()) {
|
||||
for (int i=0; i<arrayp->elementsConst(); i++) {
|
||||
@ -1682,18 +1682,18 @@ void EmitCImp::emitInt(AstNodeModule* modp) {
|
||||
for (AstNode* nodep=modp->stmtsp(); nodep; nodep = nodep->nextp()) {
|
||||
if (AstVar* varp = nodep->castVar()) {
|
||||
if (varp->isParam() && (varp->isUsedParam() || varp->isSigPublic())) {
|
||||
if (!varp->initp()) nodep->v3fatalSrc("No init for a param?");
|
||||
if (!varp->valuep()) nodep->v3fatalSrc("No init for a param?");
|
||||
// These should be static const values, however microsloth VC++ doesn't
|
||||
// support them. They also cause problems with GDB under GCC2.95.
|
||||
if (varp->isWide()) { // Unsupported for output
|
||||
puts("// enum WData "+varp->name()+" //wide");
|
||||
} else if (!varp->initp()->castConst()) { // Unsupported for output
|
||||
} else if (!varp->valuep()->castConst()) { // Unsupported for output
|
||||
puts("// enum IData "+varp->name()+" //not simple value");
|
||||
} else {
|
||||
puts("enum ");
|
||||
puts(varp->isQuad()?"_QData":"_IData");
|
||||
puts(""+varp->name()+" { "+varp->name()+" = ");
|
||||
varp->initp()->iterateAndNext(*this);
|
||||
varp->valuep()->iterateAndNext(*this);
|
||||
puts("};");
|
||||
}
|
||||
puts("\n");
|
||||
|
@ -437,7 +437,7 @@ void GateVisitor::optimizeSignals(bool allowMultiIn) {
|
||||
if (vvertexp->inEmpty()) {
|
||||
vvertexp->clearReducible("inEmpty"); // Can't deal with no sources
|
||||
if (!vvertexp->isTop() // Ok if top inputs are driverless
|
||||
&& !vvertexp->varScp()->varp()->initp()
|
||||
&& !vvertexp->varScp()->varp()->valuep()
|
||||
&& !vvertexp->varScp()->varp()->isSigPublic()) {
|
||||
UINFO(4, "No drivers "<<vvertexp->varScp()<<endl);
|
||||
if (0) {
|
||||
|
@ -196,7 +196,7 @@ private:
|
||||
string name = m_cellp->name() + "__DOT__" + nodep->name();
|
||||
if (!nodep->isFuncLocal()) nodep->inlineAttrReset(name);
|
||||
if (debug()>=9) { nodep->dumpTree(cout,"varchanged:"); }
|
||||
if (debug()>=9) { nodep->initp()->dumpTree(cout,"varchangei:"); }
|
||||
if (debug()>=9) { nodep->valuep()->dumpTree(cout,"varchangei:"); }
|
||||
}
|
||||
if (nodep) nodep->iterateChildren(*this);
|
||||
}
|
||||
|
@ -243,10 +243,10 @@ private:
|
||||
AstNode* addp = NULL;
|
||||
for (int i=msb; i!=(lsb+increment); i+=increment, offset_from_init++) {
|
||||
string name = nodep->name() + cvtToStr(i);
|
||||
AstNode* initp = NULL;
|
||||
if (nodep->initp()) initp = new AstAdd(nodep->fileline(), nodep->initp()->cloneTree(true),
|
||||
new AstConst(nodep->fileline(), AstConst::Unsized32(), offset_from_init));
|
||||
addp = addp->addNextNull(new AstEnumItem(nodep->fileline(), name, NULL, initp));
|
||||
AstNode* valuep = NULL;
|
||||
if (nodep->valuep()) valuep = new AstAdd(nodep->fileline(), nodep->valuep()->cloneTree(true),
|
||||
new AstConst(nodep->fileline(), AstConst::Unsized32(), offset_from_init));
|
||||
addp = addp->addNextNull(new AstEnumItem(nodep->fileline(), name, NULL, valuep));
|
||||
}
|
||||
nodep->replaceWith(addp);
|
||||
nodep->deleteTree();
|
||||
|
@ -132,7 +132,7 @@ private:
|
||||
void moveVars() {
|
||||
for (vector<AstVar*>::iterator it = m_varps.begin(); it != m_varps.end(); ++it) {
|
||||
AstVar* nodep = *it;
|
||||
if (nodep->initp()) clearOptimizable(nodep,"HasInitValue");
|
||||
if (nodep->valuep()) clearOptimizable(nodep,"HasInitValue");
|
||||
if (!VarFlags(nodep).m_stdFuncAsn) clearStdOptimizable(nodep,"NoStdAssign");
|
||||
VarFlags flags (nodep);
|
||||
if ((nodep->isMovableToBlock() // Blocktemp
|
||||
|
@ -278,7 +278,7 @@ void ParamVisitor::visit(AstCell* nodep, AstNUser*) {
|
||||
pinp->v3error("Attempted parameter setting of non-parameter: Param "<<pinp->name()<<" of "<<nodep->prettyName());
|
||||
} else {
|
||||
AstConst* constp = pinp->exprp()->castConst();
|
||||
AstConst* origconstp = modvarp->initp()->castConst();
|
||||
AstConst* origconstp = modvarp->valuep()->castConst();
|
||||
if (!constp) {
|
||||
//if (debug()) pinp->dumpTree(cout,"error:");
|
||||
pinp->v3error("Can't convert defparam value to constant: Param "<<pinp->name()<<" of "<<nodep->prettyName());
|
||||
@ -352,9 +352,9 @@ void ParamVisitor::visit(AstCell* nodep, AstNUser*) {
|
||||
if (modvarp) {
|
||||
AstConst* constp = pinp->exprp()->castConst();
|
||||
// Remove any existing parameter
|
||||
if (modvarp->initp()) modvarp->initp()->unlinkFrBack()->deleteTree();
|
||||
if (modvarp->valuep()) modvarp->valuep()->unlinkFrBack()->deleteTree();
|
||||
// Set this parameter to value requested by cell
|
||||
modvarp->initp(constp->cloneTree(false));
|
||||
modvarp->valuep(constp->cloneTree(false));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -196,7 +196,7 @@ private:
|
||||
new AstBasicDType(fl, AstLogicPacked(), m_outVarps.size()),
|
||||
new AstRange (fl, VL_MASK_I(m_inWidth), 0)));
|
||||
chgVarp->isConst(true);
|
||||
chgVarp->initp(new AstInitArray (nodep->fileline(), NULL));
|
||||
chgVarp->valuep(new AstInitArray (nodep->fileline(), NULL));
|
||||
m_modp->addStmtp(chgVarp);
|
||||
AstVarScope* chgVscp = new AstVarScope (chgVarp->fileline(), m_scopep, chgVarp);
|
||||
m_scopep->addVarp(chgVscp);
|
||||
@ -241,7 +241,7 @@ private:
|
||||
new AstRange (fl, VL_MASK_I(m_inWidth), 0)));
|
||||
tablevarp->isConst(true);
|
||||
tablevarp->isStatic(true);
|
||||
tablevarp->initp(new AstInitArray (nodep->fileline(), NULL));
|
||||
tablevarp->valuep(new AstInitArray (nodep->fileline(), NULL));
|
||||
m_modp->addStmtp(tablevarp);
|
||||
AstVarScope* tablevscp = new AstVarScope(tablevarp->fileline(), m_scopep, tablevarp);
|
||||
m_scopep->addVarp(tablevscp);
|
||||
@ -323,7 +323,7 @@ private:
|
||||
setp = new AstConst (outnump->fileline(), *outnump);
|
||||
}
|
||||
// Note InitArray requires us to have the values in inValue order
|
||||
m_tableVarps[outnum]->varp()->initp()->castInitArray()->addInitsp(setp);
|
||||
m_tableVarps[outnum]->varp()->valuep()->castInitArray()->addInitsp(setp);
|
||||
outnum++;
|
||||
}
|
||||
|
||||
@ -331,7 +331,7 @@ private:
|
||||
if (inValue != inValueNextInitArray++)
|
||||
nodep->v3fatalSrc("InitArray requires us to have the values in inValue order");
|
||||
AstNode* setp = new AstConst (nodep->fileline(), outputChgMask);
|
||||
chgVscp->varp()->initp()->castInitArray()->addInitsp(setp);
|
||||
chgVscp->varp()->valuep()->castInitArray()->addInitsp(setp);
|
||||
}
|
||||
} // each value
|
||||
}
|
||||
@ -345,8 +345,8 @@ private:
|
||||
AstVar* var2p = vsc2p->varp();
|
||||
if (var1p->width() == var2p->width()
|
||||
&& var1p->arrayElements() == var2p->arrayElements()) {
|
||||
AstNode* init1p = var1p->initp()->castInitArray();
|
||||
AstNode* init2p = var2p->initp()->castInitArray();
|
||||
AstNode* init1p = var1p->valuep()->castInitArray();
|
||||
AstNode* init2p = var2p->valuep()->castInitArray();
|
||||
if (init1p->sameTree(init2p)) {
|
||||
UINFO(8," Duplicate table var "<<vsc2p<<" == "<<vsc1p<<endl);
|
||||
vsc1p->unlinkFrBack()->deleteTree();
|
||||
|
@ -532,18 +532,18 @@ private:
|
||||
AstBasicDType* bdtypep = nodep->dtypep()->castBasicDType();
|
||||
if (nodep->isParam() && bdtypep && bdtypep->implicit()) {
|
||||
width = mwidth = 0;
|
||||
if (nodep->initp()) {
|
||||
nodep->initp()->iterateAndNext(*this,WidthVP(width,0,PRELIM).p());
|
||||
if (nodep->valuep()) {
|
||||
nodep->valuep()->iterateAndNext(*this,WidthVP(width,0,PRELIM).p());
|
||||
// Although nodep will get a different width for parameters just below,
|
||||
// we want the init numbers to retain their width/minwidth until parameters are replaced.
|
||||
// This prevents width warnings at the location the parameter is substituted in
|
||||
nodep->initp()->iterateAndNext(*this,WidthVP(width,0,FINAL).p());
|
||||
if (nodep->initp()->widthSized()) {
|
||||
width = mwidth = nodep->initp()->width();
|
||||
nodep->valuep()->iterateAndNext(*this,WidthVP(width,0,FINAL).p());
|
||||
if (nodep->valuep()->widthSized()) {
|
||||
width = mwidth = nodep->valuep()->width();
|
||||
} else {
|
||||
if (nodep->initp()->width()>32) nodep->initp()->v3warn(WIDTH,"Assigning >32 bit to unranged parameter (defaults to 32 bits)");
|
||||
if (nodep->valuep()->width()>32) nodep->valuep()->v3warn(WIDTH,"Assigning >32 bit to unranged parameter (defaults to 32 bits)");
|
||||
width = 32;
|
||||
mwidth = nodep->initp()->widthMin();
|
||||
mwidth = nodep->valuep()->widthMin();
|
||||
}
|
||||
}
|
||||
// Parameter sizes can come from the thing they get assigned from
|
||||
@ -556,14 +556,14 @@ private:
|
||||
else { // non param or sized param
|
||||
nodep->dtypep()->iterateAndNext(*this,WidthVP(ANYSIZE,0,BOTH).p());
|
||||
width = nodep->dtypep()->width(); mwidth = nodep->dtypep()->widthMin();
|
||||
if (nodep->initp()) {
|
||||
nodep->initp()->iterateAndNext(*this,WidthVP(width,0,BOTH).p());
|
||||
if (nodep->valuep()) {
|
||||
nodep->valuep()->iterateAndNext(*this,WidthVP(width,0,BOTH).p());
|
||||
//if (debug()) nodep->dumpTree(cout," final: ");
|
||||
}
|
||||
}
|
||||
nodep->width(width,mwidth);
|
||||
// See above note about initp()->...FINAL
|
||||
if (nodep->initp()) widthCheck(nodep,"Initial value",nodep->initp(),width,mwidth);
|
||||
// See above note about valuep()->...FINAL
|
||||
if (nodep->valuep()) widthCheck(nodep,"Initial value",nodep->valuep(),width,mwidth);
|
||||
UINFO(4,"varWidthed "<<nodep<<endl);
|
||||
//if (debug()) nodep->dumpTree(cout," InitOut: ");
|
||||
}
|
||||
@ -593,16 +593,16 @@ private:
|
||||
V3Number one (nodep->fileline(), nodep->width(), 1);
|
||||
map<V3Number,AstEnumItem*> inits;
|
||||
for (AstEnumItem* itemp = nodep->itemsp(); itemp; itemp=itemp->nextp()->castEnumItem()) {
|
||||
if (itemp->initp()) {
|
||||
if (debug()>=9) { UINFO(0,"EnumInit "<<itemp<<endl); itemp->initp()->dumpTree(cout,"-EnumInit: "); }
|
||||
V3Const::constifyParamsEdit(itemp->initp()); // itemp may change
|
||||
if (!itemp->initp()->castConst()) {
|
||||
itemp->initp()->v3error("Enum value isn't a constant");
|
||||
itemp->initp()->unlinkFrBack()->deleteTree();
|
||||
if (itemp->valuep()) {
|
||||
if (debug()>=9) { UINFO(0,"EnumInit "<<itemp<<endl); itemp->valuep()->dumpTree(cout,"-EnumInit: "); }
|
||||
V3Const::constifyParamsEdit(itemp->valuep()); // itemp may change
|
||||
if (!itemp->valuep()->castConst()) {
|
||||
itemp->valuep()->v3error("Enum value isn't a constant");
|
||||
itemp->valuep()->unlinkFrBack()->deleteTree();
|
||||
}
|
||||
}
|
||||
if (!itemp->initp()) itemp->initp(new AstConst(itemp->fileline(), num));
|
||||
num.opAssign(itemp->initp()->castConst()->num());
|
||||
if (!itemp->valuep()) itemp->valuep(new AstConst(itemp->fileline(), num));
|
||||
num.opAssign(itemp->valuep()->castConst()->num());
|
||||
// Look for duplicates
|
||||
if (inits.find(num) != inits.end()) {
|
||||
itemp->v3error("Overlapping enumeration value: "<<itemp->prettyName());
|
||||
@ -610,16 +610,16 @@ private:
|
||||
} else {
|
||||
inits.insert(make_pair(num,itemp));
|
||||
}
|
||||
num.opAdd(one, itemp->initp()->castConst()->num());
|
||||
num.opAdd(one, itemp->valuep()->castConst()->num());
|
||||
}
|
||||
}
|
||||
virtual void visit(AstEnumItem* nodep, AstNUser* vup) {
|
||||
int width = vup->c()->width();
|
||||
int mwidth = vup->c()->widthMin();
|
||||
nodep->width(width, mwidth);
|
||||
if (nodep->initp()) {
|
||||
nodep->initp()->iterateAndNext(*this,WidthVP(width,mwidth,BOTH).p());
|
||||
widthCheck(nodep,"Enum value",nodep->initp(),width,mwidth);
|
||||
if (nodep->valuep()) {
|
||||
nodep->valuep()->iterateAndNext(*this,WidthVP(width,mwidth,BOTH).p());
|
||||
widthCheck(nodep,"Enum value",nodep->valuep(),width,mwidth);
|
||||
}
|
||||
}
|
||||
virtual void visit(AstEnumItemRef* nodep, AstNUser* vup) {
|
||||
@ -632,7 +632,7 @@ private:
|
||||
if (!enump) nodep->v3fatalSrc("EnumItem not under a Enum");
|
||||
enump->iterate(*this);
|
||||
}
|
||||
nodep->widthFrom(nodep->itemp()->initp());
|
||||
nodep->widthFrom(nodep->itemp()->valuep());
|
||||
}
|
||||
virtual void visit(AstPslClocked* nodep, AstNUser*) {
|
||||
nodep->propp()->iterateAndNext(*this,WidthVP(1,1,BOTH).p());
|
||||
|
@ -1592,7 +1592,7 @@ delayrange<dtypep>:
|
||||
param_assignment<varp>: // ==IEEE: param_assignment
|
||||
// // IEEE: constant_param_expression
|
||||
// // constant_param_expression: '$' is in expr
|
||||
sigId sigAttrListE '=' expr { $$ = $1; $1->addAttrsp($2); $$->initp($4); }
|
||||
sigId sigAttrListE '=' expr { $$ = $1; $1->addAttrsp($2); $$->valuep($4); }
|
||||
//UNSUP: exprOrDataType instead of expr
|
||||
;
|
||||
|
||||
@ -2233,7 +2233,7 @@ tf_port_itemAssignment<varp>: // IEEE: part of tf_port_item, which has assignmen
|
||||
id variable_dimensionListE sigAttrListE
|
||||
{ $$ = VARDONEA(*$1, $2, $3); }
|
||||
| id variable_dimensionListE sigAttrListE '=' expr
|
||||
{ $$ = VARDONEA(*$1, $2, $3); $$->initp($5); }
|
||||
{ $$ = VARDONEA(*$1, $2, $3); $$->valuep($5); }
|
||||
;
|
||||
|
||||
parenE:
|
||||
|
Loading…
Reference in New Issue
Block a user