Support cast operator with expression size, bug865.

This commit is contained in:
Wilson Snyder
2014-12-23 22:11:31 -05:00
parent 9f7c473376
commit 8b0af19351
5 changed files with 40 additions and 3 deletions
+15
View File
@@ -3485,6 +3485,21 @@ public:
AstNodeDType* childDTypep() const { return op2p()->castNodeDType(); }
};
class AstCastParse : public AstNode {
// Cast to appropriate type, where we haven't determined yet what the data type is
public:
AstCastParse(FileLine* fl, AstNode* lhsp, AstNode* dtp) : AstNode(fl) {
setOp1p(lhsp); setOp2p(dtp);
}
ASTNODE_NODE_FUNCS(CastParse, CASTPARSE)
virtual string emitVerilog() { return "((%d)'(%l))"; }
virtual string emitC() { V3ERROR_NA; return ""; }
virtual bool cleanOut() { V3ERROR_NA; return true;} virtual bool cleanLhs() {return true;}
virtual bool sizeMattersLhs() {return false;}
AstNode* lhsp() const { return op1p(); }
AstNode* dtp() const { return op2p(); }
};
class AstCastSize : public AstNode {
// Cast to specific size; signed/twostate inherited from lower element per IEEE
public:
+15
View File
@@ -945,6 +945,21 @@ private:
nodep->iterateChildren(*this);
nodep->dtypep(iterateEditDTypep(nodep, nodep->subDTypep()));
}
virtual void visit(AstCastParse* nodep, AstNUser* vup) {
// nodep->dtp could be data type, or a primary_constant
// Don't iterate lhsp, will deal with that once convert the type
V3Const::constifyParamsEdit(nodep->dtp()); // itemp may change
if (AstConst* constp = nodep->dtp()->castConst()) {
constp->unlinkFrBack();
AstNode* newp = new AstCastSize(nodep->fileline(), nodep->lhsp()->unlinkFrBack(), constp);
nodep->replaceWith(newp);
pushDeletep(nodep); nodep=NULL;
newp->accept(*this,vup);
} else {
nodep->v3error("Unsupported: Cast to "<<nodep->dtp()->prettyTypeName());
nodep->replaceWith(nodep->lhsp()->unlinkFrBack());
}
}
virtual void visit(AstCast* nodep, AstNUser* vup) {
if (nodep->childDTypep()) nodep->dtypep(moveChildDTypeEdit(nodep));
nodep->dtypep(iterateEditDTypep(nodep, nodep->dtypep()));
+1 -2
View File
@@ -2977,8 +2977,7 @@ expr<nodep>: // IEEE: part of expression/constant_expression/primary
| yUNSIGNED yP_TICK '(' expr ')' { $$ = new AstUnsigned($1,$4); }
// // Spec only allows primary with addition of a type reference
// // We'll be more general, and later assert LHS was a type.
//UNSUP ~l~expr yP_TICK '(' expr ')' { UNSUP }
| yaINTNUM yP_TICK '(' expr ')' { $$ = new AstCastSize($2,$4,new AstConst($1->fileline(),*$1)); }
| ~l~expr yP_TICK '(' expr ')' { $$ = new AstCastParse($2,$4,$1); }
//
// // IEEE: assignment_pattern_expression
// // IEEE: streaming_concatenation