From df86e39845220b6d64cb448f0307d44e9756e32c Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Mon, 17 Apr 2023 09:57:29 +0000 Subject: [PATCH] Fix systemc namespace issues (#4126) (#4127) * replaces use of "systemc.h" with to avoid default namespace import --- docs/CONTRIBUTORS | 1 + examples/make_hello_sc/sc_main.cpp | 4 +++- examples/make_tracing_sc/sc_main.cpp | 4 +++- include/verilated.h | 14 +++++++------- include/verilated_fst_sc.h | 22 +++++++++++----------- include/verilated_funcs.h | 2 +- include/verilated_sc.h | 6 +++--- include/verilated_vcd_sc.h | 18 +++++++++--------- 8 files changed, 38 insertions(+), 33 deletions(-) diff --git a/docs/CONTRIBUTORS b/docs/CONTRIBUTORS index 404584aba..40c782fb0 100644 --- a/docs/CONTRIBUTORS +++ b/docs/CONTRIBUTORS @@ -29,6 +29,7 @@ Drew Taussig Driss Hafdi Edgar E. Iglesias Eric Rippey +Eyck Jentzsch Fan Shupei Felix Neumärker Felix Yan diff --git a/examples/make_hello_sc/sc_main.cpp b/examples/make_hello_sc/sc_main.cpp index 91fe02220..5f9ab2429 100644 --- a/examples/make_hello_sc/sc_main.cpp +++ b/examples/make_hello_sc/sc_main.cpp @@ -7,7 +7,7 @@ //====================================================================== // SystemC global header -#include +#include // Include common routines #include @@ -15,6 +15,8 @@ // Include model header, generated from Verilating "top.v" #include "Vtop.h" +using namespace sc_core; + int sc_main(int argc, char* argv[]) { // See a similar example walkthrough in the verilator manpage. diff --git a/examples/make_tracing_sc/sc_main.cpp b/examples/make_tracing_sc/sc_main.cpp index 223cce885..44e69c7f0 100644 --- a/examples/make_tracing_sc/sc_main.cpp +++ b/examples/make_tracing_sc/sc_main.cpp @@ -10,7 +10,7 @@ #include // SystemC global header -#include +#include // Include common routines #include @@ -23,6 +23,8 @@ // Include model header, generated from Verilating "top.v" #include "Vtop.h" +using namespace sc_core; + int sc_main(int argc, char* argv[]) { // This is a more complicated example, please also see the simpler examples/make_hello_c. diff --git a/include/verilated.h b/include/verilated.h index 02de0ea12..a1bad1d49 100644 --- a/include/verilated.h +++ b/include/verilated.h @@ -953,18 +953,18 @@ void VerilatedContext::timeprecision(int value) VL_MT_SAFE { const VerilatedLockGuard lock{m_mutex}; m_s.m_timeprecision = value; #if VM_SC - const sc_time sc_res = sc_get_time_resolution(); - if (sc_res == sc_time(1, SC_SEC)) { + const sc_core::sc_time sc_res = sc_core::sc_get_time_resolution(); + if (sc_res == sc_core::sc_time(1, sc_core::SC_SEC)) { sc_prec = 0; - } else if (sc_res == sc_time(1, SC_MS)) { + } else if (sc_res == sc_core::sc_time(1, sc_core::SC_MS)) { sc_prec = 3; - } else if (sc_res == sc_time(1, SC_US)) { + } else if (sc_res == sc_core::sc_time(1, sc_core::SC_US)) { sc_prec = 6; - } else if (sc_res == sc_time(1, SC_NS)) { + } else if (sc_res == sc_core::sc_time(1, sc_core::SC_NS)) { sc_prec = 9; - } else if (sc_res == sc_time(1, SC_PS)) { + } else if (sc_res == sc_core::sc_time(1, sc_core::SC_PS)) { sc_prec = 12; - } else if (sc_res == sc_time(1, SC_FS)) { + } else if (sc_res == sc_core::sc_time(1, sc_core::SC_FS)) { sc_prec = 15; } #endif diff --git a/include/verilated_fst_sc.h b/include/verilated_fst_sc.h index 0f0cc9e2d..af288f11b 100644 --- a/include/verilated_fst_sc.h +++ b/include/verilated_fst_sc.h @@ -19,8 +19,8 @@ /// //============================================================================= -#ifndef VERILATOR_VERILATED_VCD_SC_H_ -#define VERILATOR_VERILATED_VCD_SC_H_ +#ifndef VERILATOR_VERILATED_FST_SC_H_ +#define VERILATOR_VERILATED_FST_SC_H_ #include "verilatedos.h" @@ -36,23 +36,23 @@ /// with the SystemC simulation kernel, just like a SystemC-documented /// trace format. -class VerilatedFstSc final : sc_trace_file, public VerilatedFstC { +class VerilatedFstSc final : sc_core::sc_trace_file, public VerilatedFstC { // CONSTRUCTORS VL_UNCOPYABLE(VerilatedFstSc); public: /// Construct a SC trace object, and register with the SystemC kernel VerilatedFstSc() { - sc_get_curr_simcontext()->add_trace_file(this); + sc_core::sc_get_curr_simcontext()->add_trace_file(this); // We want to avoid a depreciated warning, but still be back compatible. // Turning off the message just for this still results in an // annoying "to turn off" message. - const sc_time t1sec{1, SC_SEC}; + const sc_core::sc_time t1sec{1, sc_core::SC_SEC}; if (t1sec.to_default_time_units() != 0) { - const sc_time tunits{1.0 / t1sec.to_default_time_units(), SC_SEC}; + const sc_core::sc_time tunits{1.0 / t1sec.to_default_time_units(), sc_core::SC_SEC}; spTrace()->set_time_unit(tunits.to_string()); } - spTrace()->set_time_resolution(sc_get_time_resolution().to_string()); + spTrace()->set_time_resolution(sc_core::sc_get_time_resolution().to_string()); } /// Destruct, flush, and close the dump ~VerilatedFstSc() override { close(); } @@ -60,7 +60,7 @@ public: // METHODS - for SC kernel // Called by SystemC simulate() void cycle(bool delta_cycle) override { - if (!delta_cycle) this->dump(sc_time_stamp().to_double()); + if (!delta_cycle) this->dump(sc_core::sc_time_stamp().to_double()); } // Override VerilatedFstC. Must be called after starting simulation. @@ -79,7 +79,7 @@ private: // Cadence Incisive has these as abstract functions so we must create them void set_time_unit(int exponent10_seconds) override {} // deprecated #endif - void set_time_unit(double v, sc_time_unit tu) override {} // LCOV_EXCL_LINE + void set_time_unit(double v, sc_core::sc_time_unit tu) override {} // LCOV_EXCL_LINE //-------------------------------------------------- // SystemC 2.1.v1 @@ -96,8 +96,8 @@ private: // Formatting matches that of sc_trace.h // LCOV_EXCL_START #if (SYSTEMC_VERSION >= 20171012) - DECL_TRACE_METHOD_A( sc_event ) - DECL_TRACE_METHOD_A( sc_time ) + DECL_TRACE_METHOD_A( sc_core::sc_event ) + DECL_TRACE_METHOD_A( sc_core::sc_time ) #endif DECL_TRACE_METHOD_A( bool ) diff --git a/include/verilated_funcs.h b/include/verilated_funcs.h index 6a1696e6f..983f19b4c 100644 --- a/include/verilated_funcs.h +++ b/include/verilated_funcs.h @@ -260,7 +260,7 @@ extern void _vl_debug_print_w(int lbits, WDataInP const iwp) VL_MT_SAFE; #if defined(SYSTEMC_VERSION) /// Return current simulation time // Already defined: extern sc_time sc_time_stamp(); -inline uint64_t vl_time_stamp64() VL_MT_SAFE { return sc_time_stamp().value(); } +inline uint64_t vl_time_stamp64() VL_MT_SAFE { return sc_core::sc_time_stamp().value(); } #else // Non-SystemC # if !defined(VL_TIME_CONTEXT) && !defined(VL_NO_LEGACY) # ifdef VL_TIME_STAMP64 diff --git a/include/verilated_sc.h b/include/verilated_sc.h index da6c479ba..81777c3c9 100644 --- a/include/verilated_sc.h +++ b/include/verilated_sc.h @@ -29,7 +29,7 @@ #include "verilatedos.h" -#include "systemc.h" +#include //============================================================================= // For \internal use, get a pointer to m_data in the sc_bv_base class, @@ -37,9 +37,9 @@ // use cast magic to get at it. Saves patching get_datap in SystemC. #define VL_SC_BV_DATAP(bv) (VlScBvExposer::sp_datap(bv)) // This class is thread safe (though most of SystemC is not). -class VlScBvExposer final : public sc_bv_base { +class VlScBvExposer final : public sc_dt::sc_bv_base { public: - static const uint32_t* sp_datap(const sc_bv_base& base) VL_MT_SAFE { + static const uint32_t* sp_datap(const sc_dt::sc_bv_base& base) VL_MT_SAFE { return static_cast(&base)->sp_datatp(); } const uint32_t* sp_datatp() const { return reinterpret_cast(m_data); } diff --git a/include/verilated_vcd_sc.h b/include/verilated_vcd_sc.h index 4ef558fb4..53d5efe43 100644 --- a/include/verilated_vcd_sc.h +++ b/include/verilated_vcd_sc.h @@ -36,23 +36,23 @@ /// with the SystemC simulation kernel, just like a SystemC-documented /// trace format. -class VerilatedVcdSc final : sc_trace_file, public VerilatedVcdC { +class VerilatedVcdSc final : sc_core::sc_trace_file, public VerilatedVcdC { // CONSTRUCTORS VL_UNCOPYABLE(VerilatedVcdSc); public: /// Construct a SC trace object, and register with the SystemC kernel VerilatedVcdSc() { - sc_get_curr_simcontext()->add_trace_file(this); + sc_core::sc_get_curr_simcontext()->add_trace_file(this); // We want to avoid a depreciated warning, but still be back compatible. // Turning off the message just for this still results in an // annoying "to turn off" message. - const sc_time t1sec{1, SC_SEC}; + const sc_core::sc_time t1sec{1, sc_core::SC_SEC}; if (t1sec.to_default_time_units() != 0) { - const sc_time tunits{1.0 / t1sec.to_default_time_units(), SC_SEC}; + const sc_core::sc_time tunits{1.0 / t1sec.to_default_time_units(), sc_core::SC_SEC}; spTrace()->set_time_unit(tunits.to_string()); } - spTrace()->set_time_resolution(sc_get_time_resolution().to_string()); + spTrace()->set_time_resolution(sc_core::sc_get_time_resolution().to_string()); } /// Destruct, flush, and close the dump ~VerilatedVcdSc() override { close(); } @@ -60,7 +60,7 @@ public: // METHODS - for SC kernel // Called by SystemC simulate() void cycle(bool delta_cycle) override { - if (!delta_cycle) this->dump(sc_time_stamp().to_double()); + if (!delta_cycle) this->dump(sc_core::sc_time_stamp().to_double()); } // Override VerilatedVcdC. Must be called after starting simulation. @@ -78,7 +78,7 @@ private: // Cadence Incisive has these as abstract functions so we must create them void set_time_unit(int exponent10_seconds) override {} // deprecated #endif - void set_time_unit(double v, sc_time_unit tu) override {} // LCOV_EXCL_LINE + void set_time_unit(double v, sc_core::sc_time_unit tu) override {} // LCOV_EXCL_LINE //-------------------------------------------------- // SystemC 2.1.v1 @@ -95,8 +95,8 @@ private: // Formatting matches that of sc_trace.h // LCOV_EXCL_START #if (SYSTEMC_VERSION >= 20171012) - DECL_TRACE_METHOD_A( sc_event ) - DECL_TRACE_METHOD_A( sc_time ) + DECL_TRACE_METHOD_A( sc_core::sc_event ) + DECL_TRACE_METHOD_A( sc_core::sc_time ) #endif DECL_TRACE_METHOD_A( bool )