namespace
{
-std::vector<PythonReadyFunc *> pythonReadyFuncs;
-std::vector<PythonInitFunc *> pythonInitFuncs;
+PythonReadyFunc *&
+firstReadyFunc()
+{
+ static PythonReadyFunc *first = nullptr;
+ return first;
+}
+
+PythonInitFunc *&
+firstInitFunc()
+{
+ static PythonInitFunc *first = nullptr;
+ return first;
+}
void
python_ready(pybind11::args args)
{
- for (auto &func: pythonReadyFuncs)
- func->run();
+ for (auto ptr = firstReadyFunc(); ptr; ptr = ptr->next)
+ ptr->run();
}
void
{
pybind11::module m = m_internal.def_submodule("systemc");
m.def("python_ready", &python_ready);
- for (auto &func: pythonInitFuncs)
- func->run(m);
+ for (auto ptr = firstInitFunc(); ptr; ptr = ptr->next)
+ ptr->run(m);
}
EmbeddedPyBind embed_("systemc", &systemc_pybind);
} // anonymous namespace
-PythonReadyFunc::PythonReadyFunc()
+PythonReadyFunc::PythonReadyFunc() : next(firstReadyFunc())
{
- pythonReadyFuncs.push_back(this);
+ firstReadyFunc() = this;
}
-PythonInitFunc::PythonInitFunc()
+PythonInitFunc::PythonInitFunc() : next(firstInitFunc())
{
- pythonInitFuncs.push_back(this);
+ firstInitFunc() = this;
}
} // namespace sc_gem5
struct PythonReadyFunc
{
+ PythonReadyFunc *next;
+
PythonReadyFunc();
~PythonReadyFunc() {}
virtual void run() = 0;
struct PythonInitFunc
{
+ PythonInitFunc *next;
+
PythonInitFunc();
~PythonInitFunc() {}
virtual void run(pybind11::module &systemc) = 0;
#include "systemc/utils/report.hh"
+#include "systemc/core/python.hh"
+
namespace sc_gem5
{
bool reportWarningsAsErrors = false;
-DefaultReportMessages::DefaultReportMessages(
- std::initializer_list<std::pair<int, const char *>> msgs)
+DefaultReportMessages *&
+DefaultReportMessages::top()
+{
+ static DefaultReportMessages *top_ptr = nullptr;
+ return top_ptr;
+}
+
+void
+DefaultReportMessages::install()
{
for (auto &p: msgs)
sc_core::sc_report::register_id(p.first, p.second);
}
+DefaultReportMessages::DefaultReportMessages(
+ std::initializer_list<std::pair<int, const char *>> msgs) :
+ next(top()), msgs(msgs)
+{
+ top() = this;
+}
+
+void
+DefaultReportMessages::installAll()
+{
+ for (DefaultReportMessages *ptr = top(); ptr; ptr = ptr->next)
+ ptr->install();
+}
+
+namespace
+{
+
+struct InstallDefaultReportMessages : public PythonReadyFunc
+{
+ void run() override { DefaultReportMessages::installAll(); }
+} messageInstaller;
+
+} // anonymous namespace
+
} // namespace sc_gem5
struct DefaultReportMessages
{
+ protected:
+ static DefaultReportMessages *&top();
+ DefaultReportMessages *next;
+
+ std::initializer_list<std::pair<int, const char *>> msgs;
+ void install();
+
public:
DefaultReportMessages(std::initializer_list<std::pair<int, const char *>>);
+
+ static void installAll();
};
} // namespace sc_gem5