diff --git a/src/V3Ast.h b/src/V3Ast.h index 8ac87c735..1753b7075 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -2918,10 +2918,6 @@ public: virtual void dump(std::ostream& str) const override; }; -//###################################################################### - -#include "V3AstNodes.h" - //###################################################################### // Inline AstNVisitor METHODS @@ -2947,71 +2943,7 @@ inline AstNode* AstNVisitor::iterateSubtreeReturnEdits(AstNode* nodep) { } //###################################################################### -// Inline ACCESSORS -inline int AstNode::width() const { return dtypep() ? dtypep()->width() : 0; } -inline int AstNode::widthMin() const { return dtypep() ? dtypep()->widthMin() : 0; } -inline bool AstNode::width1() const { // V3Const uses to know it can optimize - return dtypep() && dtypep()->width() == 1; -} -inline int AstNode::widthInstrs() const { - return (!dtypep() ? 1 : (dtypep()->isWide() ? dtypep()->widthWords() : 1)); -} -inline bool AstNode::isDouble() const { - return dtypep() && VN_IS(dtypep(), BasicDType) && VN_CAST(dtypep(), BasicDType)->isDouble(); -} -inline bool AstNode::isString() const { - return dtypep() && dtypep()->basicp() && dtypep()->basicp()->isString(); -} -inline bool AstNode::isSigned() const { return dtypep() && dtypep()->isSigned(); } - -inline bool AstNode::isZero() const { - return (VN_IS(this, Const) && VN_CAST_CONST(this, Const)->num().isEqZero()); -} -inline bool AstNode::isNeqZero() const { - return (VN_IS(this, Const) && VN_CAST_CONST(this, Const)->num().isNeqZero()); -} -inline bool AstNode::isOne() const { - return (VN_IS(this, Const) && VN_CAST_CONST(this, Const)->num().isEqOne()); -} -inline bool AstNode::isAllOnes() const { - return (VN_IS(this, Const) && VN_CAST_CONST(this, Const)->isEqAllOnes()); -} -inline bool AstNode::isAllOnesV() const { - return (VN_IS(this, Const) && VN_CAST_CONST(this, Const)->isEqAllOnesV()); -} -inline bool AstNode::sameTree(const AstNode* node2p) const { - return sameTreeIter(this, node2p, true, false); -} -inline bool AstNode::sameGateTree(const AstNode* node2p) const { - return sameTreeIter(this, node2p, true, true); -} - -inline void AstNodeVarRef::varp(AstVar* varp) { - m_varp = varp; - dtypeFrom(varp); -} - -inline bool AstNodeDType::isFourstate() const { return basicp()->isFourstate(); } - -inline void AstNodeArrayDType::rangep(AstRange* nodep) { setOp2p(nodep); } -inline int AstNodeArrayDType::left() const { return rangep()->leftConst(); } -inline int AstNodeArrayDType::right() const { return rangep()->rightConst(); } -inline int AstNodeArrayDType::hi() const { return rangep()->hiConst(); } -inline int AstNodeArrayDType::lo() const { return rangep()->loConst(); } -inline int AstNodeArrayDType::elementsConst() const { return rangep()->elementsConst(); } -inline VNumRange AstNodeArrayDType::declRange() const { return VNumRange{left(), right()}; } - -inline const char* AstNodeFTaskRef::broken() const { - BROKEN_RTN(m_taskp && !m_taskp->brokeExists()); - BROKEN_RTN(m_classOrPackagep && !m_classOrPackagep->brokeExists()); - return nullptr; -} - -inline void AstIfaceRefDType::cloneRelink() { - if (m_cellp && m_cellp->clonep()) m_cellp = m_cellp->clonep(); - if (m_ifacep && m_ifacep->clonep()) m_ifacep = m_ifacep->clonep(); - if (m_modportp && m_modportp->clonep()) m_modportp = m_modportp->clonep(); -} +#include "V3AstNodes.h" #endif // Guard diff --git a/src/V3AstInlines.h b/src/V3AstInlines.h new file mode 100644 index 000000000..2ee0ff9ae --- /dev/null +++ b/src/V3AstInlines.h @@ -0,0 +1,93 @@ +// -*- mode: C++; c-file-style: "cc-mode" -*- +//************************************************************************* +// DESCRIPTION: Verilator: Ast node inline functions +// +// Code available from: https://verilator.org +// +//************************************************************************* +// +// Copyright 2003-2021 by Wilson Snyder. This program is free software; you +// can redistribute it and/or modify it under the terms of either the GNU +// Lesser General Public License Version 3 or the Perl Artistic License +// Version 2.0. +// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 +// +//************************************************************************* + +#ifndef VERILATOR_V3ASTINLINES_H_ +#define VERILATOR_V3ASTINLINES_H_ + +#ifndef VERILATOR_V3ASTNODES_H_ +#error "Use V3Ast.h as the include" +#include "V3AstNodes.h" // This helps code analysis tools pick up symbols in V3Ast.h and V3AstNodes.h +#endif + +//###################################################################### +// Inline ACCESSORS + +inline int AstNode::width() const { return dtypep() ? dtypep()->width() : 0; } +inline int AstNode::widthMin() const { return dtypep() ? dtypep()->widthMin() : 0; } +inline bool AstNode::width1() const { // V3Const uses to know it can optimize + return dtypep() && dtypep()->width() == 1; +} +inline int AstNode::widthInstrs() const { + return (!dtypep() ? 1 : (dtypep()->isWide() ? dtypep()->widthWords() : 1)); +} +inline bool AstNode::isDouble() const { + return dtypep() && VN_IS(dtypep(), BasicDType) && VN_CAST(dtypep(), BasicDType)->isDouble(); +} +inline bool AstNode::isString() const { + return dtypep() && dtypep()->basicp() && dtypep()->basicp()->isString(); +} +inline bool AstNode::isSigned() const { return dtypep() && dtypep()->isSigned(); } + +inline bool AstNode::isZero() const { + return (VN_IS(this, Const) && VN_CAST_CONST(this, Const)->num().isEqZero()); +} +inline bool AstNode::isNeqZero() const { + return (VN_IS(this, Const) && VN_CAST_CONST(this, Const)->num().isNeqZero()); +} +inline bool AstNode::isOne() const { + return (VN_IS(this, Const) && VN_CAST_CONST(this, Const)->num().isEqOne()); +} +inline bool AstNode::isAllOnes() const { + return (VN_IS(this, Const) && VN_CAST_CONST(this, Const)->isEqAllOnes()); +} +inline bool AstNode::isAllOnesV() const { + return (VN_IS(this, Const) && VN_CAST_CONST(this, Const)->isEqAllOnesV()); +} +inline bool AstNode::sameTree(const AstNode* node2p) const { + return sameTreeIter(this, node2p, true, false); +} +inline bool AstNode::sameGateTree(const AstNode* node2p) const { + return sameTreeIter(this, node2p, true, true); +} + +inline void AstNodeVarRef::varp(AstVar* varp) { + m_varp = varp; + dtypeFrom(varp); +} + +inline bool AstNodeDType::isFourstate() const { return basicp()->isFourstate(); } + +inline void AstNodeArrayDType::rangep(AstRange* nodep) { setOp2p(nodep); } +inline int AstNodeArrayDType::left() const { return rangep()->leftConst(); } +inline int AstNodeArrayDType::right() const { return rangep()->rightConst(); } +inline int AstNodeArrayDType::hi() const { return rangep()->hiConst(); } +inline int AstNodeArrayDType::lo() const { return rangep()->loConst(); } +inline int AstNodeArrayDType::elementsConst() const { return rangep()->elementsConst(); } +inline VNumRange AstNodeArrayDType::declRange() const { return VNumRange{left(), right()}; } + +inline const char* AstNodeFTaskRef::broken() const { + BROKEN_RTN(m_taskp && !m_taskp->brokeExists()); + BROKEN_RTN(m_classOrPackagep && !m_classOrPackagep->brokeExists()); + return nullptr; +} + +inline void AstIfaceRefDType::cloneRelink() { + if (m_cellp && m_cellp->clonep()) m_cellp = m_cellp->clonep(); + if (m_ifacep && m_ifacep->clonep()) m_ifacep = m_ifacep->clonep(); + if (m_modportp && m_modportp->clonep()) m_modportp = m_modportp->clonep(); +} + +#endif // Guard diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index 9cc94e42d..deba4c885 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -19,6 +19,7 @@ #ifndef VERILATOR_V3AST_H_ #error "Use V3Ast.h as the include" +#include "V3Ast.h" // This helps code analysis tools pick up symbols in V3Ast.h #endif //###################################################################### @@ -9154,4 +9155,6 @@ public: //###################################################################### +#include "V3AstInlines.h" + #endif // Guard