From 0de1bbc85b281f811e3f539b2b297d39d2c31eac Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Tue, 5 Jul 2022 14:20:37 +0100 Subject: [PATCH] Add and use VL_CONSTEXPR_CXX17 --- include/verilatedos.h | 10 ++++++++++ src/V3Ast.h | 8 ++++---- src/V3AstUserAllocator.h | 27 ++++++++++++--------------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/include/verilatedos.h b/include/verilatedos.h index 6bacfe27b..2b0cdd8ce 100644 --- a/include/verilatedos.h +++ b/include/verilatedos.h @@ -234,6 +234,16 @@ # error "Verilator requires a C++11 or newer compiler" #endif +//========================================================================= +// C++-2017 + +#if __cplusplus >= 201703L +# define VL_CONSTEXPR_CXX17 constexpr +#else +# define VL_CONSTEXPR_CXX17 +#endif + + //========================================================================= // Optimization diff --git a/src/V3Ast.h b/src/V3Ast.h index dc4cf6d8e..868fc73f8 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -1948,7 +1948,7 @@ private: ASTNODE_PREFETCH(nodep->op2p()); ASTNODE_PREFETCH(nodep->op3p()); ASTNODE_PREFETCH(nodep->op4p()); - if /* TODO: 'constexpr' in C++17 */ (VisitNext) ASTNODE_PREFETCH(nodep->nextp()); + if VL_CONSTEXPR_CXX17 (VisitNext) ASTNODE_PREFETCH(nodep->nextp()); // Apply function in pre-order if (privateTypeTest::type>(nodep)) { @@ -1964,7 +1964,7 @@ private: } // Traverse 'nextp()' chain if requested - if /* TODO: 'constexpr' in C++17 */ (VisitNext) { + if VL_CONSTEXPR_CXX17 (VisitNext) { nodep = nodep->nextp(); } else { break; @@ -1987,7 +1987,7 @@ private: ASTNODE_PREFETCH(nodep->op2p()); ASTNODE_PREFETCH(nodep->op3p()); ASTNODE_PREFETCH(nodep->op4p()); - if /* TODO: 'constexpr' in C++17 */ (VisitNext) ASTNODE_PREFETCH(nodep->nextp()); + if VL_CONSTEXPR_CXX17 (VisitNext) ASTNODE_PREFETCH(nodep->nextp()); // Apply function in pre-order if (privateTypeTest::type>(nodep)) { @@ -2011,7 +2011,7 @@ private: } // Traverse 'nextp()' chain if requested - if /* TODO: 'constexpr' in C++17 */ (VisitNext) { + if VL_CONSTEXPR_CXX17 (VisitNext) { nodep = nodep->nextp(); } else { break; diff --git a/src/V3AstUserAllocator.h b/src/V3AstUserAllocator.h index 8d63ad5a9..f8982bf16 100644 --- a/src/V3AstUserAllocator.h +++ b/src/V3AstUserAllocator.h @@ -35,17 +35,16 @@ private: std::vector m_allocated; inline T_Data* getUserp(const T_Node* nodep) const { - // This simplifies statically as T_UserN is constant. In C++17, use 'if constexpr'. - if (T_UserN == 1) { + if VL_CONSTEXPR_CXX17 (T_UserN == 1) { const VNUser user = nodep->user1u(); return user.to(); - } else if (T_UserN == 2) { + } else if VL_CONSTEXPR_CXX17 (T_UserN == 2) { const VNUser user = nodep->user2u(); return user.to(); - } else if (T_UserN == 3) { + } else if VL_CONSTEXPR_CXX17 (T_UserN == 3) { const VNUser user = nodep->user3u(); return user.to(); - } else if (T_UserN == 4) { + } else if VL_CONSTEXPR_CXX17 (T_UserN == 4) { const VNUser user = nodep->user4u(); return user.to(); } else { @@ -55,14 +54,13 @@ private: } inline void setUserp(T_Node* nodep, T_Data* userp) const { - // This simplifies statically as T_UserN is constant. In C++17, use 'if constexpr'. - if (T_UserN == 1) { + if VL_CONSTEXPR_CXX17 (T_UserN == 1) { nodep->user1u(VNUser(userp)); - } else if (T_UserN == 2) { + } else if VL_CONSTEXPR_CXX17 (T_UserN == 2) { nodep->user2u(VNUser(userp)); - } else if (T_UserN == 3) { + } else if VL_CONSTEXPR_CXX17 (T_UserN == 3) { nodep->user3u(VNUser(userp)); - } else if (T_UserN == 4) { + } else if VL_CONSTEXPR_CXX17 (T_UserN == 4) { nodep->user4u(VNUser(userp)); } else { nodep->user5u(VNUser(userp)); @@ -71,14 +69,13 @@ private: protected: AstUserAllocatorBase() { - // This simplifies statically as T_UserN is constant. In C++17, use 'if constexpr'. - if (T_UserN == 1) { + if VL_CONSTEXPR_CXX17 (T_UserN == 1) { VNUser1InUse::check(); - } else if (T_UserN == 2) { + } else if VL_CONSTEXPR_CXX17 (T_UserN == 2) { VNUser2InUse::check(); - } else if (T_UserN == 3) { + } else if VL_CONSTEXPR_CXX17 (T_UserN == 3) { VNUser3InUse::check(); - } else if (T_UserN == 4) { + } else if VL_CONSTEXPR_CXX17 (T_UserN == 4) { VNUser4InUse::check(); } else { VNUser5InUse::check();