Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/12041

Change subject: systemc: Make some functions of the kernel static.
......................................................................

systemc: Make some functions of the kernel static.

This makes it possible to call them without having to have a kernel
instance available. The kernel is a singleton anyway, so there should
only ever be a single instance of any of these values.

Change-Id: I3610d60cc72e9f3114997fe63db94b96ccaac3cd
---
M src/systemc/core/kernel.cc
M src/systemc/core/kernel.hh
M src/systemc/core/sc_main.cc
3 files changed, 39 insertions(+), 30 deletions(-)



diff --git a/src/systemc/core/kernel.cc b/src/systemc/core/kernel.cc
index dac2229..9eed325 100644
--- a/src/systemc/core/kernel.cc
+++ b/src/systemc/core/kernel.cc
@@ -36,44 +36,58 @@
 namespace sc_gem5
 {

+namespace
+{
+
+bool stopAfterCallbacks = false;
+bool startComplete = false;
+bool endComplete = false;
+
+sc_core::sc_status _status = sc_core::SC_ELABORATION;
+
+} // anonymous namespace
+
+bool Kernel::startOfSimulationComplete() { return startComplete; }
+bool Kernel::endOfSimulationComplete() { return endComplete; }
+
+sc_core::sc_status Kernel::status() { return _status; }
+void Kernel::status(sc_core::sc_status s) { _status = s; }
+
 Kernel::Kernel(Params *params) :
-    SimObject(params), _stopAfterCallbacks(false),
-    _startComplete(false), _endComplete(false),
-    _status(sc_core::SC_ELABORATION),
-    t0Event(this, false, EventBase::Default_Pri - 1) {}
+    SimObject(params), t0Event(this, false, EventBase::Default_Pri - 1) {}

 void
 Kernel::init()
 {
-    kernel->status(::sc_core::SC_BEFORE_END_OF_ELABORATION);
+    status(::sc_core::SC_BEFORE_END_OF_ELABORATION);
     for (auto m: sc_gem5::allModules)
         m->sc_mod()->before_end_of_elaboration();

-    if (_stopAfterCallbacks)
+    if (stopAfterCallbacks)
         stopWork();
 }

 void
 Kernel::regStats()
 {
-    kernel->status(::sc_core::SC_END_OF_ELABORATION);
+    status(::sc_core::SC_END_OF_ELABORATION);
     for (auto m: sc_gem5::allModules)
         m->sc_mod()->end_of_elaboration();

-    if (_stopAfterCallbacks)
+    if (stopAfterCallbacks)
         stopWork();
 }

 void
 Kernel::startup()
 {
-    kernel->status(::sc_core::SC_START_OF_SIMULATION);
+    status(::sc_core::SC_START_OF_SIMULATION);
     for (auto m: sc_gem5::allModules)
         m->sc_mod()->start_of_simulation();

-    _startComplete = true;
+    startComplete = true;

-    if (_stopAfterCallbacks)
+    if (stopAfterCallbacks)
         stopWork();

     kernel->status(::sc_core::SC_RUNNING);
@@ -89,7 +103,7 @@
 Kernel::stop()
 {
     if (status() < ::sc_core::SC_RUNNING)
-        _stopAfterCallbacks = true;
+        stopAfterCallbacks = true;
     else
         stopWork();
 }
@@ -97,15 +111,15 @@
 void
 Kernel::stopWork()
 {
-    kernel->status(::sc_core::SC_END_OF_SIMULATION);
+    status(::sc_core::SC_END_OF_SIMULATION);
     for (auto m: sc_gem5::allModules)
         m->sc_mod()->end_of_simulation();

-    _endComplete = true;
+    endComplete = true;

-    kernel->status(::sc_core::SC_STOPPED);
+    status(::sc_core::SC_STOPPED);

-    if (_stopAfterCallbacks)
+    if (stopAfterCallbacks)
         fatal("Simulation called sc_stop during elaboration.\n");
 }

diff --git a/src/systemc/core/kernel.hh b/src/systemc/core/kernel.hh
index 15641c5..b9a37d0 100644
--- a/src/systemc/core/kernel.hh
+++ b/src/systemc/core/kernel.hh
@@ -56,21 +56,16 @@

     void t0Handler();

-    sc_core::sc_status status() { return _status; }
-    void status(sc_core::sc_status s) { _status = s; }
+    static sc_core::sc_status status();
+    static void status(sc_core::sc_status s);

-    void stop();
+    static void stop();

-    bool startOfSimulationComplete() { return _startComplete; }
-    bool endOfSimulationComplete() { return _endComplete; }
+    static bool startOfSimulationComplete();
+    static bool endOfSimulationComplete();

   private:
-    bool _stopAfterCallbacks;
-    void stopWork();
-
-    bool _startComplete;
-    bool _endComplete;
-    sc_core::sc_status _status;
+    static void stopWork();

     EventWrapper<Kernel, &Kernel::t0Handler> t0Event;
 };
diff --git a/src/systemc/core/sc_main.cc b/src/systemc/core/sc_main.cc
index 8e92c94..45ca728 100644
--- a/src/systemc/core/sc_main.cc
+++ b/src/systemc/core/sc_main.cc
@@ -147,7 +147,7 @@
 void
 sc_pause()
 {
-    if (::sc_gem5::kernel->status() == SC_RUNNING)
+    if (::sc_gem5::Kernel::status() == SC_RUNNING)
         ::sc_gem5::scheduler.schedulePause();
 }

@@ -178,14 +178,14 @@
 void
 sc_stop()
 {
-    if (::sc_gem5::kernel->status() == SC_STOPPED)
+    if (::sc_gem5::Kernel::status() == SC_STOPPED)
         return;

     if (sc_is_running()) {
         bool finish_delta = (_stop_mode == SC_STOP_FINISH_DELTA);
         ::sc_gem5::scheduler.scheduleStop(finish_delta);
     } else {
-        ::sc_gem5::kernel->stop();
+        ::sc_gem5::Kernel::stop();
     }
 }


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/12041
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I3610d60cc72e9f3114997fe63db94b96ccaac3cd
Gerrit-Change-Number: 12041
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to