diff --git a/docs/clang-format.txt b/docs/clang-format.txt index a4b6bcd1f..d21358c90 100644 --- a/docs/clang-format.txt +++ b/docs/clang-format.txt @@ -10,7 +10,6 @@ be made to a file. The following files are not yet clang-format clean: clang-format -i include/verilated.h clang-format -i include/verilated_dpi.h -clang-format -i include/verilated_heavy.h clang-format -i include/verilated_imp.h clang-format -i include/verilated_unordered_set_map.h clang-format -i include/verilatedos.h diff --git a/include/verilated_dpi.h b/include/verilated_dpi.h index 26ff6f02b..bad33e130 100644 --- a/include/verilated_dpi.h +++ b/include/verilated_dpi.h @@ -35,22 +35,28 @@ /// Return WData from svBitVecVal static inline void VL_SET_W_SVBV(int obits, WDataOutP owp, const svBitVecVal* lwp) VL_MT_SAFE { int words = VL_WORDS_I(obits); - for (int i=0; i class VlWide { WData m_storage[T_Words]; + public: // Default constructor/destructor/copy are fine const WData& at(size_t index) const { return m_storage[index]; } @@ -95,13 +96,11 @@ public: // Convert a C array to std::array reference by pointer magic, without copy. // Data type (second argument) is so the function template can automatically generate. -template -VlWide& VL_CVT_W_A(WDataInP inp, const VlWide&) { +template VlWide& VL_CVT_W_A(WDataInP inp, const VlWide&) { return *((VlWide*)inp); } -template -std::string VL_TO_STRING(const VlWide& obj) { +template std::string VL_TO_STRING(const VlWide& obj) { return VL_TO_STRING_W(T_Words, obj.data()); } @@ -114,6 +113,7 @@ template class VlAssocArray { private: // TYPES typedef std::map Map; + public: typedef typename Map::const_iterator const_iterator; @@ -187,8 +187,11 @@ public: // Accessing. Verilog: v = assoc[index] const T_Value& at(const T_Key& index) const { typename Map::iterator it = m_map.find(index); - if (it == m_map.end()) return m_defaultValue; - else return it->second; + if (it == m_map.end()) { + return m_defaultValue; + } else { + return it->second; + } } // For save/restore const_iterator begin() const { return m_map.begin(); } @@ -251,6 +254,7 @@ template class VlQueue { private: // TYPES typedef std::deque Deque; + public: typedef typename Deque::const_iterator const_iterator; @@ -274,7 +278,9 @@ public: int size() const { return m_deque.size(); } // Clear array. Verilog: function void delete([input index]) void clear() { m_deque.clear(); } - void erase(size_t index) { if (VL_LIKELY(index < m_deque.size())) m_deque.erase(index); } + void erase(size_t index) { + if (VL_LIKELY(index < m_deque.size())) m_deque.erase(index); + } // Dynamic array new[] becomes a renew() void renew(size_t size) { @@ -282,7 +288,7 @@ public: m_deque.resize(size, atDefault()); } // Dynamic array new[]() becomes a renew_copy() - void renew_copy(size_t size, const VlQueue& rhs) { + void renew_copy(size_t size, const VlQueue& rhs) { if (size == 0) { clear(); } else { @@ -303,12 +309,16 @@ public: // function value_t q.pop_front(); T_Value pop_front() { if (m_deque.empty()) return m_defaultValue; - T_Value v = m_deque.front(); m_deque.pop_front(); return v; + T_Value v = m_deque.front(); + m_deque.pop_front(); + return v; } // function value_t q.pop_back(); T_Value pop_back() { if (m_deque.empty()) return m_defaultValue; - T_Value v = m_deque.back(); m_deque.pop_back(); return v; + T_Value v = m_deque.back(); + m_deque.pop_back(); + return v; } // Setting. Verilog: assoc[index] = v @@ -320,15 +330,19 @@ public: if (VL_UNLIKELY(index >= m_deque.size())) { s_throwAway = atDefault(); return s_throwAway; + } else { + return m_deque[index]; } - else return m_deque[index]; } // Accessing. Verilog: v = assoc[index] const T_Value& at(size_t index) const { static T_Value s_throwAway; // Needs to work for dynamic arrays, so does not use T_MaxSize - if (VL_UNLIKELY(index >= m_deque.size())) return atDefault(); - else return m_deque[index]; + if (VL_UNLIKELY(index >= m_deque.size())) { + return atDefault(); + } else { + return m_deque[index]; + } } // function void q.insert(index, value); void insert(size_t index, const T_Value& value) { @@ -352,8 +366,7 @@ public: } }; -template -std::string VL_TO_STRING(const VlQueue& obj) { +template std::string VL_TO_STRING(const VlQueue& obj) { return obj.to_string(); } @@ -362,26 +375,29 @@ std::string VL_TO_STRING(const VlQueue& obj) { extern std::string VL_CVT_PACK_STR_NW(int lwords, WDataInP lwp) VL_MT_SAFE; inline std::string VL_CVT_PACK_STR_NQ(QData lhs) VL_PURE { - WData lw[VL_WQ_WORDS_E]; VL_SET_WQ(lw, lhs); + WData lw[VL_WQ_WORDS_E]; + VL_SET_WQ(lw, lhs); return VL_CVT_PACK_STR_NW(VL_WQ_WORDS_E, lw); } -inline std::string VL_CVT_PACK_STR_NN(const std::string& lhs) VL_PURE { - return lhs; -} +inline std::string VL_CVT_PACK_STR_NN(const std::string& lhs) VL_PURE { return lhs; } inline std::string VL_CVT_PACK_STR_NI(IData lhs) VL_PURE { - WData lw[VL_WQ_WORDS_E]; VL_SET_WI(lw, lhs); + WData lw[VL_WQ_WORDS_E]; + VL_SET_WI(lw, lhs); return VL_CVT_PACK_STR_NW(1, lw); } inline std::string VL_CONCATN_NNN(const std::string& lhs, const std::string& rhs) VL_PURE { return lhs + rhs; } -inline std::string VL_REPLICATEN_NNQ(int,int,int, const std::string& lhs, IData rep) VL_PURE { - std::string out; out.reserve(lhs.length() * rep); - for (unsigned times=0; times