Fixed issue when using a python plugin in the yosys shell
authorBenedikt Tutzer <e1225461@student.tuwien.ac.at>
Mon, 20 Aug 2018 12:44:03 +0000 (14:44 +0200)
committerBenedikt Tutzer <e1225461@student.tuwien.ac.at>
Mon, 20 Aug 2018 12:44:03 +0000 (14:44 +0200)
kernel/python_wrappers.cc
kernel/yosys.cc
kernel/yosys.h

index 197be08537998b6ef2abd7ad44bfcd3f1b765cf6..af1f80929c9e18d0bde6650a5ba3a9d037eeef30 100644 (file)
@@ -2783,10 +2783,13 @@ namespace YOSYS_PYTHON {
        struct Initializer
        {
                Initializer() {
-                       Yosys::log_streams.push_back(&std::cout);
-                       Yosys::log_error_stderr = true;
-                       Yosys::yosys_setup();
-                       Yosys::yosys_banner();
+                       if(!Yosys::yosys_already_setup())
+                       {
+                               Yosys::log_streams.push_back(&std::cout);
+                               Yosys::log_error_stderr = true;
+                               Yosys::yosys_setup();
+                               Yosys::yosys_banner();
+                       }
                }
 
                Initializer(Initializer const &) {}
index 8e16ba01df6c9275559a60e2e511d6e3723068de..8380fe75db17ee8a9b53e32b4ae5a67addeea7d9 100644 (file)
 #  include <sys/sysctl.h>
 #endif
 
+#ifdef WITH_PYTHON
+#if PY_MAJOR_VERSION >= 3
+#   define INIT_MODULE PyInit_libyosys
+    extern "C" PyObject* INIT_MODULE();
+#else
+#   define INIT_MODULE initlibyosys
+           extern "C" void INIT_MODULE();
+#endif
+#endif
+
 #include <limits.h>
 #include <errno.h>
 
@@ -482,6 +492,7 @@ void yosys_setup()
        IdString::get_reference(empty_id.index_);
 
        #ifdef WITH_PYTHON
+               PyImport_AppendInittab((char*)"libyosys", INIT_MODULE);
                Py_Initialize();
                PyRun_SimpleString("import sys");
                PyRun_SimpleString("sys.path.append(\"./\")");
@@ -496,6 +507,11 @@ void yosys_setup()
        log_push();
 }
 
+bool yosys_already_setup()
+{
+       return already_setup;
+}
+
 bool already_shutdown = false;
 
 void yosys_shutdown()
index 4380a5b6962822c9ec6a0f8bcbb3b9540d7ae158..6ed0f8b20b381305b68cec1e985101eee11cd442 100644 (file)
@@ -278,6 +278,11 @@ namespace hashlib {
 }
 
 void yosys_setup();
+
+#ifdef WITH_PYTHON
+bool yosys_already_setup();
+#endif
+
 void yosys_shutdown();
 
 #ifdef YOSYS_ENABLE_TCL