From 590ad964b1d5f3e6a0d3c1b3066a48453d219faf Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 13 Aug 2017 18:08:44 -0400 Subject: [PATCH] Add assertion on bad formed lvalues, used to debug bug1187. --- src/V3Ast.h | 1 + src/V3AstNodes.h | 7 +++++++ src/V3Broken.cpp | 9 +++++++++ 3 files changed, 17 insertions(+) diff --git a/src/V3Ast.h b/src/V3Ast.h index 2f8a75bab..12e6e0506 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -1512,6 +1512,7 @@ public: virtual V3Hash sameHash() const { return V3Hash(); } virtual bool same(AstNode*) const { return true; } virtual string verilogKwd() const { return "="; } + virtual bool brokeLhsMustBeLvalue() const = 0; }; class AstNodeFor : public AstNodeStmt { diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index 5587c71d5..c93324dd9 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -2039,6 +2039,7 @@ public: } ASTNODE_NODE_FUNCS(Assign) virtual AstNode* cloneType(AstNode* lhsp, AstNode* rhsp) { return new AstAssign(this->fileline(), lhsp, rhsp); } + virtual bool brokeLhsMustBeLvalue() const { return true; } }; class AstAssignAlias : public AstNodeAssign { @@ -2049,6 +2050,7 @@ public: : AstNodeAssign(fileline, lhsp, rhsp) {} ASTNODE_NODE_FUNCS(AssignAlias) virtual AstNode* cloneType(AstNode* lhsp, AstNode* rhsp) { V3ERROR_NA; return NULL; } + virtual bool brokeLhsMustBeLvalue() const { return false; } }; class AstAssignDly : public AstNodeAssign { @@ -2059,6 +2061,7 @@ public: virtual AstNode* cloneType(AstNode* lhsp, AstNode* rhsp) { return new AstAssignDly(this->fileline(), lhsp, rhsp); } virtual bool isGateOptimizable() const { return false; } virtual string verilogKwd() const { return "<="; } + virtual bool brokeLhsMustBeLvalue() const { return true; } }; class AstAssignW : public AstNodeAssign { @@ -2068,6 +2071,7 @@ public: : AstNodeAssign(fileline, lhsp, rhsp) { } ASTNODE_NODE_FUNCS(AssignW) virtual AstNode* cloneType(AstNode* lhsp, AstNode* rhsp) { return new AstAssignW(this->fileline(), lhsp, rhsp); } + virtual bool brokeLhsMustBeLvalue() const { return true; } AstAlways* convertToAlways() { AstNode* lhs1p = lhsp()->unlinkFrBack(); AstNode* rhs1p = rhsp()->unlinkFrBack(); @@ -2087,6 +2091,7 @@ public: } ASTNODE_NODE_FUNCS(AssignVarScope) virtual AstNode* cloneType(AstNode* lhsp, AstNode* rhsp) { return new AstAssignVarScope(this->fileline(), lhsp, rhsp); } + virtual bool brokeLhsMustBeLvalue() const { return false; } }; class AstPull : public AstNode { @@ -2113,6 +2118,7 @@ public: : AstNodeAssign(fileline, lhsp, rhsp) {} ASTNODE_NODE_FUNCS(AssignPre) virtual AstNode* cloneType(AstNode* lhsp, AstNode* rhsp) { return new AstAssignPre(this->fileline(), lhsp, rhsp); } + virtual bool brokeLhsMustBeLvalue() const { return true; } }; class AstAssignPost : public AstNodeAssign { @@ -2122,6 +2128,7 @@ public: : AstNodeAssign(fileline, lhsp, rhsp) {} ASTNODE_NODE_FUNCS(AssignPost) virtual AstNode* cloneType(AstNode* lhsp, AstNode* rhsp) { return new AstAssignPost(this->fileline(), lhsp, rhsp); } + virtual bool brokeLhsMustBeLvalue() const { return true; } }; class AstComment : public AstNodeStmt { diff --git a/src/V3Broken.cpp b/src/V3Broken.cpp index c490b6f08..090b8d5fa 100644 --- a/src/V3Broken.cpp +++ b/src/V3Broken.cpp @@ -236,6 +236,15 @@ private: nodep->iterateChildrenConst(*this); BrokenTable::setUnder(nodep,false); } + virtual void visit(AstNodeAssign* nodep) { + processAndIterate(nodep); + if (v3Global.assertDTypesResolved() + && nodep->brokeLhsMustBeLvalue() + && nodep->lhsp()->castNodeVarRef() + && !nodep->lhsp()->castNodeVarRef()->lvalue()) { + nodep->v3fatalSrc("Assignment LHS is not an lvalue"); + } + } virtual void visit(AstNode* nodep) { processAndIterate(nodep); }