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.
*/
#include <cstring>
+#include <string>
#include "base/fiber.hh"
#include "base/logging.hh"
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 {
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.
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;