gem5
v24.0.0.0
Loading...
Searching...
No Matches
systemc
core
sc_main_python.cc
Go to the documentation of this file.
1
/*
2
* Copyright 2018 Google, Inc.
3
*
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are
6
* met: redistributions of source code must retain the above copyright
7
* notice, this list of conditions and the following disclaimer;
8
* redistributions in binary form must reproduce the above copyright
9
* notice, this list of conditions and the following disclaimer in the
10
* documentation and/or other materials provided with the distribution;
11
* neither the name of the copyright holders nor the names of its
12
* contributors may be used to endorse or promote products derived from
13
* this software without specific prior written permission.
14
*
15
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
*/
27
28
// This should be on top since it is including python headers
29
#include "
systemc/core/python.hh
"
30
31
#include <cstring>
32
#include <string>
33
34
#include "
base/fiber.hh
"
35
#include "
base/logging.hh
"
36
#include "
systemc/core/sc_main_fiber.hh
"
37
38
namespace
39
{
40
41
// This wrapper adapts the python version of sc_main to the c++ version.
42
void
43
sc_main
(pybind11::args args)
44
{
45
using namespace
gem5
;
46
panic_if
(
::sc_gem5::scMainFiber
.called(),
47
"sc_main called more than once."
);
48
49
int
argc = args.size();
50
char
**argv =
new
char
*[argc];
51
52
// Initialize all the argvs to NULL so we can delete [] them
53
// unconditionally.
54
for
(
int
idx = 0; idx < argc; idx++)
55
argv[idx] = NULL;
56
57
// Attempt to convert all the arguments to strings. If that fails, clean
58
// up after ourselves. Also don't count this as a call to sc_main since
59
// we never got to the c++ version of that function.
60
try
{
61
for
(
int
idx = 0; idx < argc; idx++) {
62
std::string arg = args[idx].cast<std::string>();
63
argv[idx] =
new
char
[arg.length() + 1];
64
strcpy(argv[idx], arg.c_str());
65
}
66
}
catch
(...) {
67
// If that didn't work for some reason (probably a conversion error)
68
// blow away argv and argc and pass on the exception.
69
for
(
int
idx = 0; idx < argc; idx++)
70
delete
[] argv[idx];
71
delete
[] argv;
72
argc = 0;
73
throw
;
74
}
75
76
::sc_gem5::scMainFiber
.
setArgs
(argc, argv);
77
::sc_gem5::scMainFiber
.
run
();
78
}
79
80
int
81
sc_main_result_code()
82
{
83
return ::sc_gem5::scMainFiber.resultInt();
84
}
85
86
std::string
87
sc_main_result_str()
88
{
89
return ::sc_gem5::scMainFiber.resultStr();
90
}
91
92
// Make our sc_main wrapper available in the internal _m5 python module under
93
// the systemc submodule.
94
95
::sc_gem5::PythonInitFunc
installScMain([](pybind11::module_ &systemc) {
96
systemc.def(
"sc_main"
, &
sc_main
);
97
systemc.def(
"sc_main_result_code"
, &sc_main_result_code);
98
systemc.def(
"sc_main_result_str"
, &sc_main_result_str);
99
});
100
101
}
// anonymous namespace
sc_gem5::ScMainFiber::setArgs
void setArgs(int new_argc, char **new_argv)
Definition
sc_main_fiber.hh:57
fiber.hh
gem5::Fiber::run
void run()
Start executing the fiber represented by this object.
Definition
fiber.cc:166
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition
logging.hh:214
logging.hh
gem5
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition
binary32.hh:36
sc_gem5::scMainFiber
ScMainFiber scMainFiber
Definition
sc_main_fiber.cc:81
python.hh
sc_main
GEM5_WEAK int sc_main(int argc, char *argv[])
sc_main_fiber.hh
sc_gem5::PythonInitFunc
Definition
python.hh:37
Generated on Tue Jun 18 2024 16:24:06 for gem5 by
doxygen
1.11.0