Internals: Refactor Tristate pull creation. No functional change.

This commit is contained in:
Wilson Snyder 2021-12-31 14:46:16 -05:00
parent fd45be3def
commit d15e9e2b7a
1 changed files with 13 additions and 19 deletions

View File

@ -377,14 +377,17 @@ class TristateVisitor final : public TristateBaseVisitor {
void associateLogic(AstNode* fromp, AstNode* top) { void associateLogic(AstNode* fromp, AstNode* top) {
if (m_logicp) m_tgraph.associate(fromp, top); if (m_logicp) m_tgraph.associate(fromp, top);
} }
AstConst* newAllZerosOrOnes(AstNode* nodep, bool ones) {
V3Number num{nodep, nodep->width()};
if (ones) num.setAllBits1();
AstConst* const newp = new AstConst{nodep->fileline(), num};
return newp;
}
AstNode* getEnp(AstNode* nodep) { AstNode* getEnp(AstNode* nodep) {
if (!nodep->user1p()) { if (!nodep->user1p()) {
// There's no select being built yet, so add what will become a // There's no select being built yet, so add what will become a
// constant output enable driver of all 1's // constant output enable driver of all 1's
V3Number num(nodep, nodep->width()); nodep->user1p(newAllZerosOrOnes(nodep, true));
num.setAllBits1();
AstNode* const enp = new AstConst(nodep->fileline(), num);
nodep->user1p(enp);
} }
// Otherwise return the previous output enable // Otherwise return the previous output enable
return nodep->user1p(); return nodep->user1p();
@ -486,14 +489,12 @@ class TristateVisitor final : public TristateBaseVisitor {
// This variable is floating, set output enable to // This variable is floating, set output enable to
// always be off on this assign // always be off on this assign
UINFO(8, " Adding driver to var " << varp << endl); UINFO(8, " Adding driver to var " << varp << endl);
AstConst* const constp = new AstConst( AstConst* const constp = newAllZerosOrOnes(varp, false);
varp->fileline(), AstConst::WidthedValue(), varp->width(), 0);
AstVarRef* const varrefp AstVarRef* const varrefp
= new AstVarRef(varp->fileline(), varp, VAccess::WRITE); = new AstVarRef(varp->fileline(), varp, VAccess::WRITE);
AstNode* const newp = new AstAssignW(varp->fileline(), varrefp, constp); AstNode* const newp = new AstAssignW(varp->fileline(), varrefp, constp);
UINFO(9, " newoev " << newp << endl); UINFO(9, " newoev " << newp << endl);
varrefp->user1p(new AstConst(varp->fileline(), AstConst::WidthedValue(), varrefp->user1p(newAllZerosOrOnes(varp, false));
varp->width(), 0));
nodep->addStmtp(newp); nodep->addStmtp(newp);
mapInsertLhsVarRef(varrefp); // insertTristates will convert mapInsertLhsVarRef(varrefp); // insertTristates will convert
// // to a varref to the __out# variable // // to a varref to the __out# variable
@ -602,23 +603,16 @@ class TristateVisitor final : public TristateBaseVisitor {
undrivenp = ((!undrivenp) ? tmp : new AstAnd(refp->fileline(), tmp, undrivenp)); undrivenp = ((!undrivenp) ? tmp : new AstAnd(refp->fileline(), tmp, undrivenp));
} }
if (!undrivenp) { // No drivers on the bus if (!undrivenp) { // No drivers on the bus
V3Number ones(invarp, lhsp->width()); undrivenp = newAllZerosOrOnes(invarp, true);
ones.setAllBits1();
undrivenp = new AstConst(invarp->fileline(), ones);
} }
if (!outvarp) { if (!outvarp) {
// This is the final pre-forced resolution of the tristate, so we apply // This is the final pre-forced resolution of the tristate, so we apply
// the pull direction to any undriven pins. // the pull direction to any undriven pins.
V3Number pull(invarp, lhsp->width()); V3Number pull(invarp, lhsp->width());
const AstPull* const pullp = static_cast<AstPull*>(lhsp->user3p()); const AstPull* const pullp = static_cast<AstPull*>(lhsp->user3p());
if (pullp && pullp->direction() == 1) { bool pull1 = pullp && pullp->direction() == 1; // Else default is down
pull.setAllBits1(); undrivenp
UINFO(9, "Has pullup " << pullp << endl); = new AstAnd{invarp->fileline(), undrivenp, newAllZerosOrOnes(invarp, pull1)};
} else {
pull.setAllBits0(); // Default pull direction is down.
}
undrivenp = new AstAnd(invarp->fileline(), undrivenp,
new AstConst(invarp->fileline(), pull));
orp = new AstOr(invarp->fileline(), orp, undrivenp); orp = new AstOr(invarp->fileline(), orp, undrivenp);
} else { } else {
VL_DO_DANGLING(undrivenp->deleteTree(), undrivenp); VL_DO_DANGLING(undrivenp->deleteTree(), undrivenp);