summaryrefslogtreecommitdiff
path: root/src/systemc
diff options
context:
space:
mode:
Diffstat (limited to 'src/systemc')
-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;