Fix assertions broken from bug725, bug743.

This commit is contained in:
Wilson Snyder 2014-04-16 22:33:25 -04:00
parent 2e10555f03
commit c41dfcf6ad
6 changed files with 42 additions and 34 deletions

View File

@ -73,25 +73,31 @@ private:
AstNode* newIfAssertOn(AstNode* nodep) {
// Add a internal if to check assertions are on.
// Don't make this a AND term, as it's unlikely to need to test this.
return new AstIf (nodep->fileline(),
// If assertions are off, have constant propagation rip them out later
// 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(), AstConst::LogicFalse()))),
nodep, NULL);
AstNode* newp
= new AstIf (nodep->fileline(),
// If assertions are off, have constant propagation rip them out later
// 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(), AstConst::LogicFalse()))),
nodep, NULL);
newp->user1(true); // Don't assert/cover this if
return newp;
}
AstNode* newIfCoverageOn(AstNode* nodep) {
// Add a internal if to check coverage is on
// Don't make this a AND term, as it's unlikely to need to test this.
return new AstIf (nodep->fileline(),
// 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(), AstConst::LogicTrue()))
: (AstNode*)(new AstConst(nodep->fileline(), AstConst::LogicFalse()))),
nodep, NULL);
AstNode* newp
= new AstIf (nodep->fileline(),
// 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(), AstConst::LogicTrue()))
: (AstNode*)(new AstConst(nodep->fileline(), AstConst::LogicFalse()))),
nodep, NULL);
newp->user1(true); // Don't assert/cover this if
return newp;
}
AstNode* newFireAssert(AstNode* nodep, const string& message) {
@ -176,6 +182,7 @@ private:
}
virtual void visit(AstIf* nodep, AstNUser*) {
if (nodep->user1SetOnce()) return;
if (nodep->uniquePragma() || nodep->unique0Pragma()) {
AstNodeIf* ifp = nodep;
AstNode* propp = NULL;
@ -184,13 +191,14 @@ private:
// If this statement ends with 'else if', then nextIf will point to the
// nextIf statement. Otherwise it will be null.
AstNodeIf* nextifp = dynamic_cast<AstNodeIf*>(ifp->elsesp());
ifp->condp()->iterateAndNext(*this);
// Recurse into the true case.
ifp->ifsp()->iterateChildren(*this);
ifp->ifsp()->iterateAndNext(*this);
// If the last else is not an else if, recurse into that too.
if (ifp->elsesp() && !nextifp) {
ifp->elsesp()->iterateChildren(*this);
ifp->elsesp()->iterateAndNext(*this);
}
// Build a bitmask of the true predicates
@ -225,8 +233,7 @@ private:
nodep->replaceWith(checkifp);
pushDeletep(nodep);
} else {
nodep->ifsp()->iterateChildren(*this);
nodep->elsesp()->iterateChildren(*this);
nodep->iterateChildren(*this);
}
}

View File

@ -94,9 +94,9 @@ private:
public:
// CONSTUCTORS
BranchVisitor(AstNetlist* rootp) {
BranchVisitor(AstNetlist* nodep) {
reset();
rootp->iterateChildren(*this);
nodep->iterateChildren(*this);
}
virtual ~BranchVisitor() {}
};

View File

@ -245,23 +245,23 @@ class EmitVBaseVisitor : public EmitCBaseVisitor {
virtual void visit(AstFOpen* nodep, AstNUser*) {
putfs(nodep,nodep->verilogKwd());
putbs(" (");
if (nodep->filep()) nodep->filep()->iterateChildren(*this);
if (nodep->filep()) nodep->filep()->iterateAndNext(*this);
putbs(",");
if (nodep->filenamep()) nodep->filenamep()->iterateChildren(*this);
if (nodep->filenamep()) nodep->filenamep()->iterateAndNext(*this);
putbs(",");
if (nodep->modep()) nodep->modep()->iterateChildren(*this);
if (nodep->modep()) nodep->modep()->iterateAndNext(*this);
puts(");\n");
}
virtual void visit(AstFClose* nodep, AstNUser*) {
putfs(nodep,nodep->verilogKwd());
putbs(" (");
if (nodep->filep()) nodep->filep()->iterateChildren(*this);
if (nodep->filep()) nodep->filep()->iterateAndNext(*this);
puts(");\n");
}
virtual void visit(AstFFlush* nodep, AstNUser*) {
putfs(nodep,nodep->verilogKwd());
putbs(" (");
if (nodep->filep()) nodep->filep()->iterateChildren(*this);
if (nodep->filep()) nodep->filep()->iterateAndNext(*this);
puts(");\n");
}
virtual void visit(AstJumpGo* nodep, AstNUser*) {
@ -269,23 +269,23 @@ class EmitVBaseVisitor : public EmitCBaseVisitor {
}
virtual void visit(AstJumpLabel* nodep, AstNUser*) {
putbs("begin : "+cvtToStr((void*)(nodep))+"\n");
if (nodep->stmtsp()) nodep->stmtsp()->iterateChildren(*this);
if (nodep->stmtsp()) nodep->stmtsp()->iterateAndNext(*this);
puts("end\n");
}
virtual void visit(AstReadMem* nodep, AstNUser*) {
putfs(nodep,nodep->verilogKwd());
putbs(" (");
if (nodep->filenamep()) nodep->filenamep()->iterateChildren(*this);
if (nodep->filenamep()) nodep->filenamep()->iterateAndNext(*this);
putbs(",");
if (nodep->memp()) nodep->memp()->iterateChildren(*this);
if (nodep->lsbp()) { putbs(","); nodep->lsbp()->iterateChildren(*this); }
if (nodep->msbp()) { putbs(","); nodep->msbp()->iterateChildren(*this); }
if (nodep->memp()) nodep->memp()->iterateAndNext(*this);
if (nodep->lsbp()) { putbs(","); nodep->lsbp()->iterateAndNext(*this); }
if (nodep->msbp()) { putbs(","); nodep->msbp()->iterateAndNext(*this); }
puts(");\n");
}
virtual void visit(AstSysIgnore* nodep, AstNUser*) {
putfs(nodep,nodep->verilogKwd());
putbs(" (");
nodep->exprsp()->iterateChildren(*this);
nodep->exprsp()->iterateAndNext(*this);
puts(");\n");
}
virtual void visit(AstNodeFor* nodep, AstNUser*) {

View File

@ -115,7 +115,7 @@ private:
}
virtual void visit(AstActive* nodep, AstNUser*) {
m_activep = nodep;
nodep->sensesp()->iterateChildren(*this);
nodep->sensesp()->iterateChildren(*this); // iterateAndNext?
m_activep = NULL;
nodep->iterateChildren(*this);
}
@ -201,7 +201,7 @@ private:
virtual void visit(AstActive* nodep, AstNUser*) {
UINFO(8,"ACTIVE "<<nodep<<endl);
m_activep = nodep;
nodep->sensesp()->iterateChildren(*this);
nodep->sensesp()->iterateChildren(*this); // iterateAndNext?
m_activep = NULL;
nodep->iterateChildren(*this);
}

View File

@ -1711,7 +1711,7 @@ private:
virtual void visit(AstPslCover* nodep, AstNUser*) {
// TOP LEVEL NODE
nodep->propp()->iterateAndNext(*this,WidthVP(1,1,BOTH).p());
nodep->stmtsp()->iterateChildren(*this,WidthVP(ANYSIZE,0,BOTH).p());
nodep->stmtsp()->iterateAndNext(*this);
widthCheckReduce(nodep,"Property",nodep->propp()); // it's like an if() condition.
}
virtual void visit(AstPslAssert* nodep, AstNUser*) {

View File

@ -27,6 +27,7 @@ module t (/*AUTOARG*/
if (cyc!=0) begin
cyc <= cyc + 1;
toggle <= !cyc[0];
if (cyc==7) assert (cyc[0] == cyc[1]); // bug743
if (cyc==9) begin
`ifdef FAILING_ASSERTIONS
assert (0) else $info;