diff --git a/src/V3Assert.cpp b/src/V3Assert.cpp index 76d166ed0..66b05e274 100644 --- a/src/V3Assert.cpp +++ b/src/V3Assert.cpp @@ -80,7 +80,7 @@ private: // This allows syntax errors and such to be detected normally. (v3Global.opt.assertOn() ? (AstNode*)(new AstCMath(nodep->fileline(), "Verilated::assertOn()", 1)) - : (AstNode*)(new AstConst(nodep->fileline(), V3Number(nodep->fileline(), 1, 0)))), + : (AstNode*)(new AstConst(nodep->fileline(), AstConst::LogicFalse()))), nodep, NULL); } @@ -91,8 +91,8 @@ private: // If assertions are off, have constant propagation rip them out later // This allows syntax errors and such to be detected normally. (v3Global.opt.coverage() - ? (AstNode*)(new AstConst(nodep->fileline(), V3Number(nodep->fileline(), 1, 1))) - : (AstNode*)(new AstConst(nodep->fileline(), V3Number(nodep->fileline(), 1, 0)))), + ? (AstNode*)(new AstConst(nodep->fileline(), AstConst::LogicTrue())) + : (AstNode*)(new AstConst(nodep->fileline(), AstConst::LogicFalse()))), nodep, NULL); } diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index 1fc1c22ec..d554fed05 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -59,6 +59,15 @@ public: AstConst(FileLine* fl, Unsized32, uint32_t num) // Unsized 32-bit integer of specified value :AstNodeMath(fl) ,m_num(V3Number(fl,32,num)) { m_num.width(32,false); width(32,m_num.minWidth()); } + class LogicFalse {}; + AstConst(FileLine* fl, LogicFalse) // Shorthand const 0, know the dtype should be a logic of size 1 + :AstNodeMath(fl) + ,m_num(V3Number(fl,1,0)) { width(1,0); } + class LogicTrue {}; + AstConst(FileLine* fl, LogicTrue) // Shorthand const 1, know the dtype should be a logic of size 1 + :AstNodeMath(fl) + ,m_num(V3Number(fl,1,1)) { width(1,0); } + ASTNODE_NODE_FUNCS(Const, CONST) virtual string name() const { return num().ascii(); } // * = Value virtual const V3Number& num() const { return m_num; } // * = Value diff --git a/src/V3Case.cpp b/src/V3Case.cpp index 52d507148..db73d72f4 100644 --- a/src/V3Case.cpp +++ b/src/V3Case.cpp @@ -308,7 +308,7 @@ private: for (AstCaseItem* itemp = nodep->itemsp(); itemp; itemp=itemp->nextp()->castCaseItem()) { if (!itemp->condsp()) { // Default clause. Just make true, we'll optimize it away later - itemp->condsp(new AstConst(itemp->fileline(), V3Number(itemp->fileline(), 1,1))); + itemp->condsp(new AstConst(itemp->fileline(), AstConst::LogicTrue())); hadDefault = true; } else { // Expressioned clause @@ -326,8 +326,8 @@ private: icondp->deleteTree(); icondp=NULL; iconstp=NULL; // For simplicity, make expression that is not equal, and let later // optimizations remove it - and1p = new AstConst(itemp->fileline(), V3Number(itemp->fileline(),1,0)); - and2p = new AstConst(itemp->fileline(), V3Number(itemp->fileline(),1,1)); + and1p = new AstConst(itemp->fileline(), AstConst::LogicFalse()); + and2p = new AstConst(itemp->fileline(), AstConst::LogicTrue()); } else if (iconstp && iconstp->num().isFourState() && (nodep->casex() || nodep->casez())) { V3Number nummask (itemp->fileline(), iconstp->width()); @@ -361,7 +361,7 @@ private: // If there was no default, add a empty one, this greatly simplifies below code // and constant propagation will just eliminate it for us later. nodep->addItemsp(new AstCaseItem(nodep->fileline(), - new AstConst(nodep->fileline(), V3Number(nodep->fileline(),1,1)), + new AstConst(nodep->fileline(), AstConst::LogicTrue()), NULL)); } if (debug()>=9) nodep->dumpTree(cout," _comp_COND: "); @@ -398,7 +398,7 @@ private: AstNode* itemexprp = ifexprp; ifexprp=NULL; if (depth == (CASE_ENCODER_GROUP_DEPTH)) { // End of group - can skip the condition itemexprp->deleteTree(); itemexprp=NULL; - itemexprp = new AstConst(itemp->fileline(), V3Number(itemp->fileline(),1,1)); + itemexprp = new AstConst(itemp->fileline(), AstConst::LogicTrue()); } AstIf* newp = new AstIf(itemp->fileline(), itemexprp, istmtsp, NULL); if (itemnextp) itemnextp->addElsesp(newp); diff --git a/src/V3Trace.cpp b/src/V3Trace.cpp index 8ae59b2a5..9458b6590 100644 --- a/src/V3Trace.cpp +++ b/src/V3Trace.cpp @@ -330,7 +330,7 @@ private: new AstSel (fl, new AstVarRef(fl, m_activityVscp, true), new AstConst(fl, acode), new AstConst(fl, 1)), - new AstConst (fl, V3Number(fl, 1, 1)))); + new AstConst (fl, AstConst::LogicTrue()))); } } } diff --git a/src/verilog.y b/src/verilog.y index 111dae5f6..c090ab505 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -1738,7 +1738,7 @@ statement_item: // IEEE: statement_item //UNSUP yP_MINUSGT hierarchical_identifier/*event*/ ';' { UNSUP } //UNSUP yP_MINUSGTGT delay_or_event_controlE hierarchical_identifier/*event*/ ';' { UNSUP } // // IEEE: loop_statement - | yFOREVER stmtBlock { $$ = new AstWhile($1,new AstConst($1,V3Number($1,1,1)),$2); } + | yFOREVER stmtBlock { $$ = new AstWhile($1,new AstConst($1,AstConst::LogicTrue()),$2); } | yREPEAT '(' expr ')' stmtBlock { $$ = new AstRepeat($1,$3,$5);} | yWHILE '(' expr ')' stmtBlock { $$ = new AstWhile($1,$3,$5);} // // for's first ';' is in for_initalization @@ -2816,7 +2816,7 @@ pslSere: // This can be bypassed with the _(...) embedding of any arbitrary expression. pslExpr: exprPsl { $$ = new AstPslBool($1->fileline(), $1); } - | yTRUE { $$ = new AstPslBool($1, new AstConst($1, V3Number($1,1,1))); } + | yTRUE { $$ = new AstPslBool($1, new AstConst($1, AstConst::LogicTrue())); } ; //**********************************************************************