diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index cdf9c249d..90a33155f 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -2796,10 +2796,8 @@ struct AstTraceDecl : public AstNodeStmt { private: string m_showname; // Name of variable uint32_t m_code; // Trace identifier code; converted to ASCII by trace routines - int m_right; // Property of var the trace details - int m_left; // Property of var the trace details - uint32_t m_arrayLsb; // Property of var the trace details - uint32_t m_arrayMsb; // Property of var the trace details + VNumRange m_bitRange; // Property of var the trace details + VNumRange m_arrayRange; // Property of var the trace details uint32_t m_codeInc; // Code increment public: AstTraceDecl(FileLine* fl, const string& showname, AstVar* varp) @@ -2809,14 +2807,9 @@ public: m_code = 0; m_codeInc = varp->dtypep()->arrayUnpackedElements() * varp->dtypep()->widthWords(); AstBasicDType* bdtypep = varp->basicp(); - m_left = bdtypep ? bdtypep->left() : 0; - m_right = bdtypep ? bdtypep->right() : 0; + if (bdtypep) m_bitRange = bdtypep->nrange(); if (AstUnpackArrayDType* adtypep = varp->dtypeSkipRefp()->castUnpackArrayDType()) { - m_arrayLsb = adtypep->lsb(); - m_arrayMsb = adtypep->msb(); - } else { - m_arrayLsb = 0; - m_arrayMsb = 0; + m_arrayRange = adtypep->declRange(); } } virtual int instrCount() const { return 100; } // Large... @@ -2830,11 +2823,8 @@ public: uint32_t code() const { return m_code; } void code(uint32_t code) { m_code=code; } uint32_t codeInc() const { return m_codeInc; } - int left() const { return m_left; } // Note msb maybe < lsb if little endian - int right() const { return m_right; } - uint32_t arrayMsb() const { return m_arrayMsb; } - uint32_t arrayLsb() const { return m_arrayLsb; } - uint32_t arrayWidth() const { if (!arrayMsb()) return 0; return arrayMsb()-arrayLsb()+1; } + const VNumRange& bitRange() const { return m_bitRange; } + const VNumRange& arrayRange() const { return m_arrayRange; } }; struct AstTraceInc : public AstNodeStmt { diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index 397fed373..3c9070c8e 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -2190,23 +2190,23 @@ class EmitCTrace : EmitCStmts { puts("vcdp->declArray"); } else if (nodep->isQuad()) { puts("vcdp->declQuad "); - } else if (nodep->left() || nodep->right()) { + } else if (nodep->bitRange().ranged()) { puts("vcdp->declBus "); } else { puts("vcdp->declBit "); } puts("(c+"+cvtToStr(nodep->code())); - if (nodep->arrayWidth()) puts("+i*"+cvtToStr(nodep->widthWords())); + if (nodep->arrayRange().ranged()) puts("+i*"+cvtToStr(nodep->widthWords())); puts(","); putsQuoted(nodep->showname()); - if (nodep->arrayWidth()) { - puts(",(i+"+cvtToStr(nodep->arrayLsb())+")"); + if (nodep->arrayRange().ranged()) { + puts(",(i+"+cvtToStr(nodep->arrayRange().lo())+")"); } else { puts(",-1"); } if (!nodep->isDouble() // When float/double no longer have widths this can go - && (nodep->left() || nodep->right())) { - puts(","+cvtToStr(nodep->left())+","+cvtToStr(nodep->right())); + && nodep->bitRange().ranged()) { + puts(","+cvtToStr(nodep->bitRange().left())+","+cvtToStr(nodep->bitRange().right())); } puts(");"); } @@ -2222,7 +2222,7 @@ class EmitCTrace : EmitCStmts { puts("vcdp->"+full+"Array"); } else if (nodep->isQuad()) { puts("vcdp->"+full+"Quad "); - } else if (nodep->declp()->left() || nodep->declp()->right()) { + } else if (nodep->declp()->bitRange().ranged()) { puts("vcdp->"+full+"Bus "); } else { puts("vcdp->"+full+"Bit "); @@ -2232,7 +2232,7 @@ class EmitCTrace : EmitCStmts { puts(","); emitTraceValue(nodep, arrayindex); if (!nodep->isDouble() // When float/double no longer have widths this can go - && (nodep->declp()->left() || nodep->declp()->right() || emitTraceIsScBv(nodep) || emitTraceIsScBigUint(nodep))) { + && (nodep->declp()->bitRange().ranged() || emitTraceIsScBv(nodep) || emitTraceIsScBigUint(nodep))) { puts(","+cvtToStr(nodep->declp()->widthMin())); } puts(");\n"); @@ -2319,8 +2319,8 @@ class EmitCTrace : EmitCStmts { m_funcp = NULL; } virtual void visit(AstTraceDecl* nodep, AstNUser*) { - if (nodep->arrayWidth()) { - puts("{int i; for (i=0; i<"+cvtToStr(nodep->arrayWidth())+"; i++) {\n"); + if (nodep->arrayRange().ranged()) { + puts("{int i; for (i=0; i<"+cvtToStr(nodep->arrayRange().elements())+"; i++) {\n"); emitTraceInitOne(nodep); puts("}}\n"); } else { @@ -2329,9 +2329,9 @@ class EmitCTrace : EmitCStmts { } } virtual void visit(AstTraceInc* nodep, AstNUser*) { - if (nodep->declp()->arrayWidth()) { + if (nodep->declp()->arrayRange().ranged()) { // It traces faster if we unroll the loop - for (unsigned i=0; ideclp()->arrayWidth(); i++) { + for (int i=0; ideclp()->arrayRange().elements(); i++) { emitTraceChangeOne(nodep, i); } } else {