40a41
> #include "systemc/core/sc_main_fiber.hh"
47,49d47
< // A weak symbol to detect if sc_main has been defined, and if so where it is.
< [[gnu::weak]] int sc_main(int argc, char *argv[]);
<
56,103d53
< bool scMainCalled = false;
<
< int _argc = 0;
< char **_argv = NULL;
<
< class ScMainFiber : public Fiber
< {
< public:
< std::string resultStr;
< int resultInt;
<
< ScMainFiber() : resultInt(1) {}
<
< void
< main()
< {
< if (::sc_main) {
< 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 = "uncaught sc_report";
< sc_gem5::reportHandlerProc(
< r, sc_report_handler::get_catch_actions());
< } catch (...) {
< // There was some other type of exception we need to wrap.
< resultStr = "uncaught exception";
< sc_gem5::reportHandlerProc(
< ::sc_gem5::reportifyException(),
< sc_report_handler::get_catch_actions());
< }
< ::sc_gem5::Kernel::scMainFinished(true);
< ::sc_gem5::scheduler.clear();
< } else {
< // If python tries to call sc_main but no sc_main was defined...
< fatal("sc_main called but not defined.\n");
< }
< }
< };
<
< ScMainFiber scMainFiber;
<
108c58,59
< panic_if(scMainCalled, "sc_main called more than once.");
---
> panic_if(::sc_gem5::scMainFiber.called(),
> "sc_main called more than once.");
110,111c61,62
< _argc = args.size();
< _argv = new char *[_argc];
---
> int argc = args.size();
> char **argv = new char *[argc];
113c64
< // Initialize all the _argvs to NULL so we can delete [] them
---
> // Initialize all the argvs to NULL so we can delete [] them
115,116c66,67
< for (int idx = 0; idx < _argc; idx++)
< _argv[idx] = NULL;
---
> for (int idx = 0; idx < argc; idx++)
> argv[idx] = NULL;
122c73
< for (int idx = 0; idx < _argc; idx++) {
---
> for (int idx = 0; idx < argc; idx++) {
124,125c75,76
< _argv[idx] = new char[arg.length() + 1];
< strcpy(_argv[idx], arg.c_str());
---
> argv[idx] = new char[arg.length() + 1];
> strcpy(argv[idx], arg.c_str());
129,133c80,84
< // blow away _argv and _argc and pass on the exception.
< for (int idx = 0; idx < _argc; idx++)
< delete [] _argv[idx];
< delete [] _argv;
< _argc = 0;
---
> // blow away argv and argc and pass on the exception.
> for (int idx = 0; idx < argc; idx++)
> delete [] argv[idx];
> delete [] argv;
> argc = 0;
137,141c88,89
< // At this point we're going to call the c++ sc_main, so we can't try
< // again later.
< scMainCalled = true;
<
< scMainFiber.run();
---
> ::sc_gem5::scMainFiber.setArgs(argc, argv);
> ::sc_gem5::scMainFiber.run();
147c95
< return scMainFiber.resultInt;
---
> return ::sc_gem5::scMainFiber.resultInt();
153c101
< return scMainFiber.resultStr;
---
> return ::sc_gem5::scMainFiber.resultStr();
177c125
< return _argc;
---
> return ::sc_gem5::scMainFiber.argc();
183c131
< return _argv;
---
> return ::sc_gem5::scMainFiber.argv();