summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2018-08-22 20:31:27 -0700
committerGabe Black <gabeblack@google.com>2018-09-25 23:57:52 +0000
commitf0e36029ffd8acb482823e89a033a6fe175bb833 (patch)
treeeced4f93708febfd5ee58c279c8a0147e53ffb26
parent3d33eecfe8e38acb5fa6ac26cc2b7b371bdcda49 (diff)
downloadgem5-f0e36029ffd8acb482823e89a033a6fe175bb833.tar.xz
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 Reviewed-on: https://gem5-review.googlesource.com/12253 Reviewed-by: Gabe Black <gabeblack@google.com> Maintainer: Gabe Black <gabeblack@google.com>
-rw-r--r--src/systemc/core/SystemC.py11
-rw-r--r--src/systemc/core/sc_main.cc36
2 files changed, 44 insertions, 3 deletions
diff --git a/src/systemc/core/SystemC.py b/src/systemc/core/SystemC.py
index 13ef4eb98..49b569b0c 100644
--- a/src/systemc/core/SystemC.py
+++ b/src/systemc/core/SystemC.py
@@ -36,11 +36,22 @@ class SystemC_Kernel(SimObject):
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 bacde2e0f..47ca2e354 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 @@ char **_argv = NULL;
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 @@ sc_main(pybind11::args args)
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 @@ struct InstallScMain : public ::sc_gem5::PythonInitFunc
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;