58 #include "config/have_protobuf.hh"
64 #include <google/protobuf/stubs/common.h>
69 namespace py = pybind11;
73 #define PyCC(x) (const_cast<char *>(x))
78 const char *modpath,
const unsigned char *code,
int zlen,
int len)
79 : filename(filename), abspath(abspath), modpath(modpath), code(code),
84 if (
string(modpath) ==
string(
"importer"))
104 Bytef marshalled[
len];
106 int ret = uncompress(marshalled, &unzlen, (
const Bytef *)
code,
zlen);
108 panic(
"Could not uncompress code: %s\n", zError(ret));
109 assert(unzlen == (uLongf)
len);
111 return PyMarshal_ReadObjectFromString((
char *)marshalled, len);
147 for (; i != end; ++
i)
148 if (!(*i)->addModule())
155 void (*init_func)(py::module &),
157 : initFunc(init_func), registered(false),
name(_name),
base(_base)
159 getMap()[_name] =
this;
163 void (*init_func)(py::module &))
164 : initFunc(init_func), registered(false),
name(_name),
base(
"")
166 getMap()[_name] =
this;
176 cprintf(
"Warning: %s already registered.\n",
name);
186 std::map<std::string, EmbeddedPyBind *> &
189 static std::map<std::string, EmbeddedPyBind *> objs;
198 py::module m_m5 = py::module(
"_m5");
199 m_m5.attr(
"__package__") = py::cast(
"_m5");
208 for (
auto &kv :
getMap()) {
209 auto &obj = kv.second;
210 if (obj->base.empty()) {
213 pending.push_back(obj);
217 while (!pending.empty()) {
218 for (
auto it = pending.begin(); it != pending.end(); ) {
222 it = pending.erase(it);
258 GOOGLE_PROTOBUF_VERIFY_VERSION;
261 PySys_SetArgv(argc, argv);
264 PyObject *module = PyImport_AddModule(
PyCC(
"__main__"));
266 panic(
"Could not import __main__");
267 PyObject *dict = PyModule_GetDict(module);
276 result = PyRun_String(*command, Py_file_input, dict, dict);
287 google::protobuf::ShutdownProtobufLibrary();
297 PyImport_ImportModule(
PyCC(
"m5"));
int m5Main(int argc, char **argv)
void pybind_init_core(py::module &m_native)
static std::list< EmbeddedPython * > & getList()
void pybind_init_stats(pybind11::module &m_native)
const std::string & name()
This file defines flags used to handle asynchronous simulator events.
const char * __attribute__((weak)) m5MainCommands[]
static EmbeddedPython * importer
void(* initFunc)(pybind11::module &)
static std::map< std::string, EmbeddedPyBind * > & getMap()
void init(pybind11::module &m)
void pybind_init_pyobject(pybind11::module &m_native)
const char * m5MainCommands[]
PyObject * getCode() const
static PyObject * importerModule
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
void pybind_init_debug(py::module &m_native)
EmbeddedPython(const char *filename, const char *abspath, const char *modpath, const uint8_t *code, int zlen, int len)
void pybind_init_event(py::module &m_native)
PyMODINIT_FUNC initm5(void)
void cprintf(const char *format, const Args &...args)
EmbeddedPyBind(const char *_name, void(*init_func)(pybind11::module &), const char *_base)