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 4313323Sgabeblack@google.comPythonReadyFunc *& 4413323Sgabeblack@google.comfirstReadyFunc() 4513323Sgabeblack@google.com{ 4613323Sgabeblack@google.com static PythonReadyFunc *first = nullptr; 4713323Sgabeblack@google.com return first; 4813323Sgabeblack@google.com} 4913323Sgabeblack@google.com 5013323Sgabeblack@google.comPythonInitFunc *& 5113323Sgabeblack@google.comfirstInitFunc() 5213323Sgabeblack@google.com{ 5313323Sgabeblack@google.com static PythonInitFunc *first = nullptr; 5413323Sgabeblack@google.com return first; 5513323Sgabeblack@google.com} 5613038Sgabeblack@google.com 5713038Sgabeblack@google.comvoid 5813038Sgabeblack@google.compython_ready(pybind11::args args) 5913038Sgabeblack@google.com{ 6013323Sgabeblack@google.com for (auto ptr = firstReadyFunc(); ptr; ptr = ptr->next) 6113323Sgabeblack@google.com ptr->run(); 6213038Sgabeblack@google.com} 6313038Sgabeblack@google.com 6413038Sgabeblack@google.comvoid 6513038Sgabeblack@google.comsystemc_pybind(pybind11::module &m_internal) 6613038Sgabeblack@google.com{ 6713038Sgabeblack@google.com pybind11::module m = m_internal.def_submodule("systemc"); 6813038Sgabeblack@google.com m.def("python_ready", &python_ready); 6913323Sgabeblack@google.com for (auto ptr = firstInitFunc(); ptr; ptr = ptr->next) 7013323Sgabeblack@google.com ptr->run(m); 7113038Sgabeblack@google.com} 7213038Sgabeblack@google.comEmbeddedPyBind embed_("systemc", &systemc_pybind); 7313038Sgabeblack@google.com 7413038Sgabeblack@google.com} // anonymous namespace 7513038Sgabeblack@google.com 7613323Sgabeblack@google.comPythonReadyFunc::PythonReadyFunc() : next(firstReadyFunc()) 7713038Sgabeblack@google.com{ 7813323Sgabeblack@google.com firstReadyFunc() = this; 7913038Sgabeblack@google.com} 8013038Sgabeblack@google.com 8113323Sgabeblack@google.comPythonInitFunc::PythonInitFunc() : next(firstInitFunc()) 8213038Sgabeblack@google.com{ 8313323Sgabeblack@google.com firstInitFunc() = this; 8413038Sgabeblack@google.com} 8513038Sgabeblack@google.com 8613038Sgabeblack@google.com} // namespace sc_gem5 87