From 2da9d46ca66ab23d60a006bb9b5cb4dc3e4bd022 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 21 Jan 2010 18:20:47 -0500 Subject: [PATCH] Internals: Rename AstVar::initp to valuep as it's a constant, not initial value --- src/V3AstNodes.h | 8 ++++---- src/V3Const.cpp | 24 +++++++++++------------ src/V3EmitC.cpp | 10 +++++----- src/V3Gate.cpp | 2 +- src/V3Inline.cpp | 2 +- src/V3LinkParse.cpp | 8 ++++---- src/V3Localize.cpp | 2 +- src/V3Param.cpp | 6 +++--- src/V3Table.cpp | 12 ++++++------ src/V3Width.cpp | 48 ++++++++++++++++++++++----------------------- src/verilog.y | 4 ++-- 11 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index daf17d877..e7e816e36 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -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()); } diff --git a/src/V3Const.cpp b/src/V3Const.cpp index 8eb7feca9..63476045c 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -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<<" "<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); } diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index ddbede2fa..b4beefc56 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -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; ielementsConst(); 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"); diff --git a/src/V3Gate.cpp b/src/V3Gate.cpp index ff7f79f10..cb7090fee 100644 --- a/src/V3Gate.cpp +++ b/src/V3Gate.cpp @@ -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 "<varScp()<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); } diff --git a/src/V3LinkParse.cpp b/src/V3LinkParse.cpp index 3e5977fff..21def993c 100644 --- a/src/V3LinkParse.cpp +++ b/src/V3LinkParse.cpp @@ -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(); diff --git a/src/V3Localize.cpp b/src/V3Localize.cpp index 0fd9119a0..8e83a6161 100644 --- a/src/V3Localize.cpp +++ b/src/V3Localize.cpp @@ -132,7 +132,7 @@ private: void moveVars() { for (vector::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 diff --git a/src/V3Param.cpp b/src/V3Param.cpp index db5f0f594..19e726457 100644 --- a/src/V3Param.cpp +++ b/src/V3Param.cpp @@ -278,7 +278,7 @@ void ParamVisitor::visit(AstCell* nodep, AstNUser*) { pinp->v3error("Attempted parameter setting of non-parameter: Param "<name()<<" of "<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 "<name()<<" of "<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 { diff --git a/src/V3Table.cpp b/src/V3Table.cpp index f39a9132d..79e86c065 100644 --- a/src/V3Table.cpp +++ b/src/V3Table.cpp @@ -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 "<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 "<dumpTree(cout," InitOut: "); } @@ -593,16 +593,16 @@ private: V3Number one (nodep->fileline(), nodep->width(), 1); map inits; for (AstEnumItem* itemp = nodep->itemsp(); itemp; itemp=itemp->nextp()->castEnumItem()) { - if (itemp->initp()) { - if (debug()>=9) { UINFO(0,"EnumInit "<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 "<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: "<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()); diff --git a/src/verilog.y b/src/verilog.y index 240771f5e..88c0f670a 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -1592,7 +1592,7 @@ delayrange: param_assignment: // ==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: // 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: