Convert cast tasks to assertions

This commit is contained in:
Wilson Snyder 2020-10-24 20:30:52 -04:00
parent 51d1235cda
commit 835905bdae
6 changed files with 24 additions and 5 deletions

View File

@ -5835,6 +5835,10 @@ public:
};
class AstCastDynamic : public AstNodeBiop {
// Verilog $cast used as a function
// Task usage of $cast is converted during parse to assert($cast(...))
// Parents: MATH
// Children: MATH
public:
AstCastDynamic(FileLine* fl, AstNode* lhsp, AstNode* rhsp)
: ASTGEN_SUPER(fl, lhsp, rhsp) {}

View File

@ -76,6 +76,15 @@ private:
iterateAndNextNull(nodep->rhsp());
}
}
virtual void visit(AstCastDynamic* nodep) override {
VL_RESTORER(m_setRefLvalue);
{
m_setRefLvalue = VAccess::WRITE;
iterateAndNextNull(nodep->lhsp());
m_setRefLvalue = false;
iterateAndNextNull(nodep->rhsp());
}
}
virtual void visit(AstFOpen* nodep) override {
VL_RESTORER(m_setRefLvalue);
{

View File

@ -1599,9 +1599,10 @@ private:
nodep->widthFromSub(nodep->subDTypep());
}
virtual void visit(AstCastDynamic* nodep) override {
nodep->dtypeChgWidthSigned(32, 1, VSigning::SIGNED); // Spec says integer return
nodep->v3warn(E_UNSUPPORTED, "Unsupported: $cast. Suggest try static cast.");
AstNode* newp = new AstConst(nodep->fileline(), 1);
newp->dtypeSetSigned32(); // Spec says integer return
newp->dtypeFrom(nodep);
nodep->replaceWith(newp);
VL_DO_DANGLING(pushDeletep(nodep), nodep);
}

View File

@ -3624,6 +3624,9 @@ system_t_call<nodep>: // IEEE: system_tf_call (as task)
| yD_WRITEMEMH '(' expr ',' idClassSel ',' expr ')' { $$ = new AstWriteMem($1, true, $3, $5, $7, nullptr); }
| yD_WRITEMEMH '(' expr ',' idClassSel ',' expr ',' expr ')' { $$ = new AstWriteMem($1, true, $3, $5, $7, $9); }
//
| yD_CAST '(' expr ',' expr ')'
{ $$ = new AstAssert($1, new AstCastDynamic($1, $3, $5), nullptr, nullptr, true); }
//
// Any system function as a task
| system_f_call_or_t { $$ = new AstSysFuncAsTask($<fl>1, $1); }
;
@ -3632,6 +3635,7 @@ system_f_call<nodep>: // IEEE: system_tf_call (as func)
yaD_PLI systemDpiArgsE { $$ = new AstFuncRef($<fl>1, *$1, $2); VN_CAST($$, FuncRef)->pli(true); }
//
| yD_C '(' cStrList ')' { $$ = (v3Global.opt.ignc() ? nullptr : new AstUCFunc($1,$3)); }
| yD_CAST '(' expr ',' expr ')' { $$ = new AstCastDynamic($1, $3, $5); }
| yD_SYSTEM '(' expr ')' { $$ = new AstSystemF($1,$3); }
//
| system_f_call_or_t { $$ = $1; }
@ -3654,7 +3658,6 @@ system_f_call_or_t<nodep>: // IEEE: part of system_tf_call (can be task or func)
| yD_BITS '(' exprOrDataType ',' expr ')' { $$ = new AstAttrOf($1,AstAttrType::DIM_BITS,$3,$5); }
| yD_BITSTOREAL '(' expr ')' { $$ = new AstBitsToRealD($1,$3); }
| yD_BITSTOSHORTREAL '(' expr ')' { $$ = new AstBitsToRealD($1,$3); UNSUPREAL($1); }
| yD_CAST '(' expr ',' expr ')' { $$ = new AstCastDynamic($1, $3, $5); }
| yD_CEIL '(' expr ')' { $$ = new AstCeilD($1,$3); }
| yD_CHANGED '(' expr ')' { $$ = new AstLogNot($1, new AstStable($1, $3)); }
| yD_CHANGED '(' expr ',' expr ')' { $$ = $3; BBUNSUP($1, "Unsupported: $changed and clock arguments"); }

View File

@ -22,8 +22,8 @@
: ... In instance t
51 | i = $cast(bbo, b);
| ^~~~~
%Error-UNSUPPORTED: t/t_castdyn.v:57:11: Unsupported: $cast. Suggest try static cast.
%Error-UNSUPPORTED: t/t_castdyn.v:58:11: Unsupported: $cast. Suggest try static cast.
: ... In instance t
57 | i = $cast(bao, b);
58 | i = $cast(bao, b);
| ^~~~~
%Error: Exiting due to

View File

@ -53,9 +53,11 @@ module t (/*AUTOARG*/);
if (b != bb) $stop;
bb = new;
b = b;
b = bb;
bao = ba;
i = $cast(bao, b);
if (i != 0) $stop;
if (bao != ba) $stop; // Unchanged
$write("*-* All Finished *-*\n");
$finish;