Setup is called automatically when the module is loaded, shutdown when python exits
authorBenedikt Tutzer <e1225461@student.tuwien.ac.at>
Wed, 1 Aug 2018 08:08:23 +0000 (10:08 +0200)
committerBenedikt Tutzer <benedikt_tutzer@yahoo.de>
Wed, 1 Aug 2018 08:57:46 +0000 (10:57 +0200)
kernel/python_wrappers.cc

index ba7be91060410498f2e2ceb19daffa7480180e06..718e3f5c1bbe26874cfcad8c5e99a3f631934a60 100644 (file)
@@ -15,25 +15,11 @@ namespace YOSYS_PYTHON {
        struct Wire;
        struct Monitor;
 
-       void yosys_setup()
-       {
-               Yosys::log_streams.push_back(&std::cout);
-               Yosys::log_error_stderr = true;
-
-               Yosys::yosys_setup();
-               Yosys::yosys_banner();
-       }
-
        void run(std::string command)
        {
                Yosys::run_pass(command);
        }
 
-       void yosys_shutdown()
-       {
-               Yosys::yosys_shutdown();
-       }
-
        struct Cell
        {
                unsigned int id;
@@ -292,10 +278,29 @@ namespace YOSYS_PYTHON {
                return 0;
        }
 
+       struct Initializer
+       {
+               Initializer() {
+                       Yosys::log_streams.push_back(&std::cout);
+                       Yosys::log_error_stderr = true;
+                       Yosys::yosys_setup();
+                       Yosys::yosys_banner();
+               }
+
+               Initializer(Initializer const &) {}
+
+               ~Initializer() {
+                       Yosys::yosys_shutdown();
+               }
+       };
+
        BOOST_PYTHON_MODULE(libyosys)
        {
                using namespace boost::python;
 
+               class_<Initializer>("Initializer");
+               scope().attr("_hidden") = new Initializer();
+
                class_<Design>("Design", init<unsigned int>())
                        .def(boost::python::self_ns::str(boost::python::self_ns::self))
                        .def(boost::python::self_ns::repr(boost::python::self_ns::self))
@@ -329,10 +334,8 @@ namespace YOSYS_PYTHON {
                        .def("py_notify_blackout", &Monitor::py_notify_blackout, &MonitorWrap::default_py_notify_blackout)
                        ;
 
-               def("yosys_setup",yosys_setup);
                def("run",run);
                def("get_active_design_id",get_active_design_id);
-               def("yosys_shutdown",yosys_shutdown);
        }
 
 }