python.cc revision 13038
113038Sgabeblack@google.com/*
213038Sgabeblack@google.com * Copyright 2018 Google, Inc.
313038Sgabeblack@google.com *
413038Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
513038Sgabeblack@google.com * modification, are permitted provided that the following conditions are
613038Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
713038Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
813038Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
913038Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1013038Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1113038Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1213038Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1313038Sgabeblack@google.com * this software without specific prior written permission.
1413038Sgabeblack@google.com *
1513038Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1613038Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1713038Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1813038Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1913038Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2013038Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2113038Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2213038Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2313038Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2413038Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2513038Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2613038Sgabeblack@google.com *
2713038Sgabeblack@google.com * Authors: Gabe Black
2813038Sgabeblack@google.com */
2913038Sgabeblack@google.com
3013038Sgabeblack@google.com#include "systemc/core/python.hh"
3113038Sgabeblack@google.com
3213038Sgabeblack@google.com#include <vector>
3313038Sgabeblack@google.com
3413038Sgabeblack@google.com#include "python/pybind11/pybind.hh"
3513038Sgabeblack@google.com#include "sim/init.hh"
3613038Sgabeblack@google.com
3713038Sgabeblack@google.comnamespace sc_gem5
3813038Sgabeblack@google.com{
3913038Sgabeblack@google.com
4013038Sgabeblack@google.comnamespace
4113038Sgabeblack@google.com{
4213038Sgabeblack@google.com
4313038Sgabeblack@google.comstd::vector<PythonReadyFunc *> pythonReadyFuncs;
4413038Sgabeblack@google.comstd::vector<PythonInitFunc *> pythonInitFuncs;
4513038Sgabeblack@google.com
4613038Sgabeblack@google.comvoid
4713038Sgabeblack@google.compython_ready(pybind11::args args)
4813038Sgabeblack@google.com{
4913038Sgabeblack@google.com    for (auto &func: pythonReadyFuncs)
5013038Sgabeblack@google.com        func->run();
5113038Sgabeblack@google.com}
5213038Sgabeblack@google.com
5313038Sgabeblack@google.comvoid
5413038Sgabeblack@google.comsystemc_pybind(pybind11::module &m_internal)
5513038Sgabeblack@google.com{
5613038Sgabeblack@google.com    pybind11::module m = m_internal.def_submodule("systemc");
5713038Sgabeblack@google.com    m.def("python_ready", &python_ready);
5813038Sgabeblack@google.com    for (auto &func: pythonInitFuncs)
5913038Sgabeblack@google.com        func->run(m);
6013038Sgabeblack@google.com}
6113038Sgabeblack@google.comEmbeddedPyBind embed_("systemc", &systemc_pybind);
6213038Sgabeblack@google.com
6313038Sgabeblack@google.com} // anonymous namespace
6413038Sgabeblack@google.com
6513038Sgabeblack@google.comPythonReadyFunc::PythonReadyFunc()
6613038Sgabeblack@google.com{
6713038Sgabeblack@google.com    pythonReadyFuncs.push_back(this);
6813038Sgabeblack@google.com}
6913038Sgabeblack@google.com
7013038Sgabeblack@google.comPythonInitFunc::PythonInitFunc()
7113038Sgabeblack@google.com{
7213038Sgabeblack@google.com    pythonInitFuncs.push_back(this);
7313038Sgabeblack@google.com}
7413038Sgabeblack@google.com
7513038Sgabeblack@google.com} // namespace sc_gem5
76