gem5
v19.0.0.0
Main Page
Related Pages
Modules
+
Namespaces
Namespace List
+
Namespace Members
+
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
+
Functions
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
+
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
+
Typedefs
a
b
c
d
e
f
g
h
i
m
n
o
p
r
s
t
u
v
w
x
+
Enumerations
a
b
c
d
e
f
i
l
m
o
p
r
s
t
v
x
+
Enumerator
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
+
Classes
Class List
Class Index
Class Hierarchy
+
Class Members
+
All
:
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
+
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
+
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
+
Typedefs
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
y
+
Enumerations
a
b
c
d
e
f
g
h
i
l
m
o
p
r
s
t
u
w
+
Enumerator
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
+
Related Functions
:
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
+
Files
File List
+
File Members
+
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
+
Functions
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
z
+
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
z
+
Typedefs
a
b
c
d
e
f
g
h
i
l
m
n
o
p
r
s
t
u
v
w
+
Enumerations
a
b
c
d
e
f
g
i
l
m
o
p
r
s
t
v
w
+
Enumerator
a
b
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
t
u
v
w
x
+
Macros
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
Pages
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
* Authors: Gabe Black
28
*/
29
30
// This should be on top since it is including python headers
31
#include "
systemc/core/python.hh
"
32
33
#include <cstring>
34
#include <string>
35
36
#include "
base/fiber.hh
"
37
#include "
base/logging.hh
"
38
#include "
systemc/core/sc_main_fiber.hh
"
39
40
namespace
41
{
42
43
// This wrapper adapts the python version of sc_main to the c++ version.
44
void
45
sc_main
(pybind11::args args)
46
{
47
panic_if
(::
sc_gem5::scMainFiber
.called(),
48
"sc_main called more than once."
);
49
50
int
argc = args.size();
51
char
**argv =
new
char
*[argc];
52
53
// Initialize all the argvs to NULL so we can delete [] them
54
// unconditionally.
55
for
(
int
idx = 0; idx < argc; idx++)
56
argv[idx] = NULL;
57
58
// Attempt to convert all the arguments to strings. If that fails, clean
59
// up after ourselves. Also don't count this as a call to sc_main since
60
// we never got to the c++ version of that function.
61
try
{
62
for
(
int
idx = 0; idx < argc; idx++) {
63
std::string arg = args[idx].cast<std::string>();
64
argv[idx] =
new
char
[arg.length() + 1];
65
strcpy(argv[idx], arg.c_str());
66
}
67
}
catch
(...) {
68
// If that didn't work for some reason (probably a conversion error)
69
// blow away argv and argc and pass on the exception.
70
for
(
int
idx = 0; idx < argc; idx++)
71
delete
[] argv[idx];
72
delete
[] argv;
73
argc = 0;
74
throw
;
75
}
76
77
::sc_gem5::scMainFiber
.
setArgs
(argc, argv);
78
::sc_gem5::scMainFiber
.
run
();
79
}
80
81
int
82
sc_main_result_code()
83
{
84
return ::sc_gem5::scMainFiber
.
resultInt
();
85
}
86
87
std::string
88
sc_main_result_str()
89
{
90
return ::sc_gem5::scMainFiber
.
resultStr
();
91
}
92
93
// Make our sc_main wrapper available in the internal _m5 python module under
94
// the systemc submodule.
95
96
struct
InstallScMain :
public
::sc_gem5::PythonInitFunc
97
{
98
void
99
run
(pybind11::module &systemc)
override
100
{
101
systemc.def(
"sc_main"
, &
sc_main
);
102
systemc.def(
"sc_main_result_code"
, &sc_main_result_code);
103
systemc.def(
"sc_main_result_str"
, &sc_main_result_str);
104
}
105
} installScMain;
106
107
}
// anonymous namespace
logging.hh
Fiber::run
void run()
Start executing the fiber represented by this object.
Definition:
fiber.cc:165
sc_gem5::ScMainFiber::resultStr
std::string resultStr()
Definition:
sc_main_fiber.hh:54
sc_gem5::PythonInitFunc
Definition:
python.hh:47
sc_gem5::ScMainFiber::resultInt
int resultInt()
Definition:
sc_main_fiber.hh:55
python.hh
fiber.hh
sc_gem5::ScMainFiber::setArgs
void setArgs(int new_argc, char **new_argv)
Definition:
sc_main_fiber.hh:59
sc_gem5::PythonInitFunc::run
virtual void run(pybind11::module &systemc)=0
sc_main
int sc_main(int argc, char *argv[])
sc_gem5::scMainFiber
ScMainFiber scMainFiber
Definition:
sc_main_fiber.cc:80
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:185
sc_main_fiber.hh
Generated on Fri Feb 28 2020 16:27:03 for gem5 by
doxygen
1.8.13