Internals: Swap lhs/rhs $cast args.
This commit is contained in:
parent
8582aed66a
commit
9c2785b49b
|
|
@ -6025,6 +6025,7 @@ public:
|
||||||
virtual bool cleanLhs() const { return true; }
|
virtual bool cleanLhs() const { return true; }
|
||||||
virtual bool sizeMattersLhs() const { return false; }
|
virtual bool sizeMattersLhs() const { return false; }
|
||||||
AstNode* lhsp() const { return op1p(); }
|
AstNode* lhsp() const { return op1p(); }
|
||||||
|
AstNode* fromp() const { return lhsp(); }
|
||||||
void lhsp(AstNode* nodep) { setOp1p(nodep); }
|
void lhsp(AstNode* nodep) { setOp1p(nodep); }
|
||||||
virtual AstNodeDType* getChildDTypep() const override { return childDTypep(); }
|
virtual AstNodeDType* getChildDTypep() const override { return childDTypep(); }
|
||||||
AstNodeDType* childDTypep() const { return VN_CAST(op2p(), NodeDType); }
|
AstNodeDType* childDTypep() const { return VN_CAST(op2p(), NodeDType); }
|
||||||
|
|
@ -6036,6 +6037,9 @@ class AstCastDynamic final : public AstNodeBiop {
|
||||||
// Task usage of $cast is converted during parse to assert($cast(...))
|
// Task usage of $cast is converted during parse to assert($cast(...))
|
||||||
// Parents: MATH
|
// Parents: MATH
|
||||||
// Children: MATH
|
// Children: MATH
|
||||||
|
// lhsp() is value (we are converting FROM) to match AstCCast etc, this
|
||||||
|
// is opposite of $cast's order, because the first access is to the
|
||||||
|
// value reading from. Suggest use fromp()/top() instead of lhsp/rhsp().
|
||||||
public:
|
public:
|
||||||
AstCastDynamic(FileLine* fl, AstNode* lhsp, AstNode* rhsp)
|
AstCastDynamic(FileLine* fl, AstNode* lhsp, AstNode* rhsp)
|
||||||
: ASTGEN_SUPER(fl, lhsp, rhsp) {}
|
: ASTGEN_SUPER(fl, lhsp, rhsp) {}
|
||||||
|
|
@ -6046,7 +6050,7 @@ public:
|
||||||
virtual AstNode* cloneType(AstNode* lhsp, AstNode* rhsp) override {
|
virtual AstNode* cloneType(AstNode* lhsp, AstNode* rhsp) override {
|
||||||
return new AstCastDynamic(this->fileline(), lhsp, rhsp);
|
return new AstCastDynamic(this->fileline(), lhsp, rhsp);
|
||||||
}
|
}
|
||||||
virtual string emitVerilog() override { return "%f$cast(%r, %l)"; }
|
virtual string emitVerilog() override { return "%f$cast(%l, %r)"; }
|
||||||
// Non-existent filehandle returns EOF
|
// Non-existent filehandle returns EOF
|
||||||
virtual string emitC() override { V3ERROR_NA_RETURN(""); }
|
virtual string emitC() override { V3ERROR_NA_RETURN(""); }
|
||||||
virtual bool cleanOut() const override { return true; }
|
virtual bool cleanOut() const override { return true; }
|
||||||
|
|
@ -6056,6 +6060,8 @@ public:
|
||||||
virtual bool sizeMattersRhs() const override { return false; }
|
virtual bool sizeMattersRhs() const override { return false; }
|
||||||
virtual int instrCount() const override { return widthInstrs() * 20; }
|
virtual int instrCount() const override { return widthInstrs() * 20; }
|
||||||
virtual bool isPure() const override { return true; }
|
virtual bool isPure() const override { return true; }
|
||||||
|
AstNode* fromp() const { return lhsp(); }
|
||||||
|
AstNode* top() const { return rhsp(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class AstCastParse final : public AstNode {
|
class AstCastParse final : public AstNode {
|
||||||
|
|
|
||||||
|
|
@ -79,10 +79,10 @@ private:
|
||||||
virtual void visit(AstCastDynamic* nodep) override {
|
virtual void visit(AstCastDynamic* nodep) override {
|
||||||
VL_RESTORER(m_setRefLvalue);
|
VL_RESTORER(m_setRefLvalue);
|
||||||
{
|
{
|
||||||
m_setRefLvalue = VAccess::WRITE;
|
|
||||||
iterateAndNextNull(nodep->lhsp());
|
|
||||||
m_setRefLvalue = VAccess::NOCHANGE;
|
m_setRefLvalue = VAccess::NOCHANGE;
|
||||||
iterateAndNextNull(nodep->rhsp());
|
iterateAndNextNull(nodep->fromp());
|
||||||
|
m_setRefLvalue = VAccess::WRITE;
|
||||||
|
iterateAndNextNull(nodep->top());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virtual void visit(AstFOpen* nodep) override {
|
virtual void visit(AstFOpen* nodep) override {
|
||||||
|
|
|
||||||
|
|
@ -1652,27 +1652,27 @@ private:
|
||||||
virtual void visit(AstCast* nodep) override {
|
virtual void visit(AstCast* nodep) override {
|
||||||
nodep->dtypep(iterateEditMoveDTypep(nodep, nodep->subDTypep()));
|
nodep->dtypep(iterateEditMoveDTypep(nodep, nodep->subDTypep()));
|
||||||
// if (debug()) nodep->dumpTree(cout, " CastPre: ");
|
// if (debug()) nodep->dumpTree(cout, " CastPre: ");
|
||||||
userIterateAndNext(nodep->lhsp(), WidthVP(SELF, PRELIM).p());
|
userIterateAndNext(nodep->fromp(), WidthVP(SELF, PRELIM).p());
|
||||||
|
|
||||||
// When more general casts are supported, the cast elimination will be done later.
|
// When more general casts are supported, the cast elimination will be done later.
|
||||||
// For now, replace it ASAP, so widthing can propagate easily
|
// For now, replace it ASAP, so widthing can propagate easily
|
||||||
// The cast may change signing, but we don't know the sign yet. Make it so.
|
// The cast may change signing, but we don't know the sign yet. Make it so.
|
||||||
// Note we don't sign lhsp() that would make the algorithm O(n^2) if lots of casting.
|
// Note we don't sign fromp() that would make the algorithm O(n^2) if lots of casting.
|
||||||
AstBasicDType* basicp = nodep->dtypep()->basicp();
|
AstBasicDType* basicp = nodep->dtypep()->basicp();
|
||||||
UASSERT_OBJ(basicp, nodep, "Unimplemented: Casting non-simple data type");
|
UASSERT_OBJ(basicp, nodep, "Unimplemented: Casting non-simple data type");
|
||||||
if (m_vup->prelim()) {
|
if (m_vup->prelim()) {
|
||||||
userIterateAndNext(nodep->lhsp(), WidthVP(SELF, PRELIM).p());
|
userIterateAndNext(nodep->fromp(), WidthVP(SELF, PRELIM).p());
|
||||||
// When implement more complicated types need to convert childDTypep to
|
// When implement more complicated types need to convert childDTypep to
|
||||||
// dtypep() not as a child
|
// dtypep() not as a child
|
||||||
if (!basicp->isDouble() && !nodep->lhsp()->isDouble()) {
|
if (!basicp->isDouble() && !nodep->fromp()->isDouble()) {
|
||||||
// Note castSized might modify nodep->lhsp()
|
// Note castSized might modify nodep->fromp()
|
||||||
int width = nodep->dtypep()->width();
|
int width = nodep->dtypep()->width();
|
||||||
castSized(nodep, nodep->lhsp(), width);
|
castSized(nodep, nodep->fromp(), width);
|
||||||
} else {
|
} else {
|
||||||
iterateCheck(nodep, "value", nodep->lhsp(), SELF, FINAL, nodep->lhsp()->dtypep(),
|
iterateCheck(nodep, "value", nodep->fromp(), SELF, FINAL, nodep->fromp()->dtypep(),
|
||||||
EXTEND_EXP, false);
|
EXTEND_EXP, false);
|
||||||
}
|
}
|
||||||
AstNode* newp = nodep->lhsp()->unlinkFrBack();
|
AstNode* newp = nodep->fromp()->unlinkFrBack();
|
||||||
if (basicp->isDouble() && !newp->isDouble()) {
|
if (basicp->isDouble() && !newp->isDouble()) {
|
||||||
if (newp->isSigned()) {
|
if (newp->isSigned()) {
|
||||||
newp = new AstISToRD(nodep->fileline(), newp);
|
newp = new AstISToRD(nodep->fileline(), newp);
|
||||||
|
|
|
||||||
|
|
@ -3667,7 +3667,7 @@ system_t_call<nodep>: // IEEE: system_tf_call (as task)
|
||||||
| yD_WRITEMEMH '(' expr ',' idClassSel ',' expr ',' expr ')' { $$ = new AstWriteMem($1, true, $3, $5, $7, $9); }
|
| yD_WRITEMEMH '(' expr ',' idClassSel ',' expr ',' expr ')' { $$ = new AstWriteMem($1, true, $3, $5, $7, $9); }
|
||||||
//
|
//
|
||||||
| yD_CAST '(' expr ',' expr ')'
|
| yD_CAST '(' expr ',' expr ')'
|
||||||
{ $$ = new AstAssert($1, new AstCastDynamic($1, $3, $5), nullptr, nullptr, true); }
|
{ $$ = new AstAssert($1, new AstCastDynamic($1, $5, $3), nullptr, nullptr, true); }
|
||||||
//
|
//
|
||||||
// Any system function as a task
|
// Any system function as a task
|
||||||
| system_f_call_or_t { $$ = new AstSysFuncAsTask($<fl>1, $1); }
|
| system_f_call_or_t { $$ = new AstSysFuncAsTask($<fl>1, $1); }
|
||||||
|
|
@ -3677,7 +3677,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); }
|
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_C '(' cStrList ')' { $$ = (v3Global.opt.ignc() ? nullptr : new AstUCFunc($1,$3)); }
|
||||||
| yD_CAST '(' expr ',' expr ')' { $$ = new AstCastDynamic($1, $3, $5); }
|
| yD_CAST '(' expr ',' expr ')' { $$ = new AstCastDynamic($1, $5, $3); }
|
||||||
| yD_SYSTEM '(' expr ')' { $$ = new AstSystemF($1,$3); }
|
| yD_SYSTEM '(' expr ')' { $$ = new AstSystemF($1,$3); }
|
||||||
//
|
//
|
||||||
| system_f_call_or_t { $$ = $1; }
|
| system_f_call_or_t { $$ = $1; }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue