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

Change subject: systemc: Keep track of how sc_main completes and expose that to python.
......................................................................

systemc: Keep track of how sc_main completes and expose that to python.

That makes it possible for the config script to retrieve the result of
running sc_main. sc_main (or at least the python front end for it)
can't return results directly since it usually doesn't run to
completion when it's first called.

Change-Id: I9740e9688571e2ca824a684be70480f1eadddcdb
---
M src/systemc/core/SystemC.py
M src/systemc/core/sc_main.cc
2 files changed, 44 insertions(+), 3 deletions(-)



diff --git a/src/systemc/core/SystemC.py b/src/systemc/core/SystemC.py
index 13ef4eb..49b569b 100644
--- a/src/systemc/core/SystemC.py
+++ b/src/systemc/core/SystemC.py
@@ -36,11 +36,22 @@
     cxx_class = 'sc_gem5::Kernel'
     cxx_header = 'systemc/core/kernel.hh'

+    class ScMainResult(object):
+        def __init__(self, code, message):
+            self.code = code
+            self.message = message
+
     def sc_main(self, *args):
         '''Call the systemc sc_main function with the given string args'''
         from _m5.systemc import sc_main
         sc_main(*args)

+    def sc_main_result(self):
+        '''Retrieve and return the results of running sc_main'''
+        from _m5.systemc import sc_main_result_code, sc_main_result_str
+        return SystemC_Kernel.ScMainResult(
+                sc_main_result_code(), sc_main_result_str());
+
# This class represents systemc sc_object instances in python config files. It # inherits from SimObject in python, but the c++ version, sc_core::sc_object,
 # doesn't inherit from gem5's c++ SimObject class.
diff --git a/src/systemc/core/sc_main.cc b/src/systemc/core/sc_main.cc
index bacde2e..47ca2e3 100644
--- a/src/systemc/core/sc_main.cc
+++ b/src/systemc/core/sc_main.cc
@@ -28,6 +28,7 @@
  */

 #include <cstring>
+#include <string>

 #include "base/fiber.hh"
 #include "base/logging.hh"
@@ -57,13 +58,28 @@

 class ScMainFiber : public Fiber
 {
+  public:
+    std::string resultStr;
+    int resultInt;
+
+    ScMainFiber() : resultInt(1) {}
+
     void
     main()
     {
         if (::sc_main) {
-            ::sc_main(_argc, _argv);
-            // Make sure no systemc events/notifications are scheduled
-            // after sc_main returns.
+            try {
+                resultInt = ::sc_main(_argc, _argv);
+                if (resultInt)
+                    resultStr = "sc_main returned non-zero";
+                else
+                    resultStr = "sc_main finished";
+                // Make sure no systemc events/notifications are scheduled
+                // after sc_main returns.
+            } catch (const sc_report &r) {
+                // There was an exception nobody caught.
+                resultStr = r.what();
+            }
             ::sc_gem5::Kernel::scMainFinished(true);
             ::sc_gem5::scheduler.clear();
         } else {
@@ -115,6 +131,18 @@
     scMainFiber.run();
 }

+int
+sc_main_result_code()
+{
+    return scMainFiber.resultInt;
+}
+
+std::string
+sc_main_result_str()
+{
+    return scMainFiber.resultStr;
+}
+
// Make our sc_main wrapper available in the internal _m5 python module under
 // the systemc submodule.

@@ -124,6 +152,8 @@
     run(pybind11::module &systemc) override
     {
         systemc.def("sc_main", &sc_main);
+        systemc.def("sc_main_result_code", &sc_main_result_code);
+        systemc.def("sc_main_result_str", &sc_main_result_str);
     }
 } installScMain;


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/12253
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: I9740e9688571e2ca824a684be70480f1eadddcdb
Gerrit-Change-Number: 12253
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