aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/python_wrappers.cc
diff options
context:
space:
mode:
authorBenedikt Tutzer <e1225461@student.tuwien.ac.at>2018-08-16 16:00:11 +0200
committerBenedikt Tutzer <e1225461@student.tuwien.ac.at>2018-08-16 16:00:11 +0200
commitd79a2808cf2446fa21d91a6141f6fbe2318c03ec (patch)
treee0c630f1dd8ccab3c5d04ddf8a6fa06376d1f5e7 /kernel/python_wrappers.cc
parentbf7b73acfc2b5e46206e5688b8a6e8d9b0d60d8f (diff)
downloadyosys-d79a2808cf2446fa21d91a6141f6fbe2318c03ec.tar.gz
yosys-d79a2808cf2446fa21d91a6141f6fbe2318c03ec.tar.bz2
yosys-d79a2808cf2446fa21d91a6141f6fbe2318c03ec.zip
Python Passes can now be added with the -m option or with the plugin command. There are still issues when run in shell mode, but they can be used just fine in a python script
Diffstat (limited to 'kernel/python_wrappers.cc')
-rw-r--r--kernel/python_wrappers.cc66
1 files changed, 65 insertions, 1 deletions
diff --git a/kernel/python_wrappers.cc b/kernel/python_wrappers.cc
index 18b0010ae..197be0853 100644
--- a/kernel/python_wrappers.cc
+++ b/kernel/python_wrappers.cc
@@ -34,6 +34,11 @@ namespace YOSYS_PYTHON {
Yosys::run_pass(command);
}
+ void log(std::string text)
+ {
+ Yosys::log(text.c_str());
+ }
+
struct IdString
{
Yosys::RTLIL::IdString* ref_obj;
@@ -1388,7 +1393,7 @@ namespace YOSYS_PYTHON {
virtual void py_notify_connect_tuple(Module *module, boost::python::tuple sigsig){};
virtual void py_notify_connect_list(Module* module, boost::python::list sigsig_list){};
virtual void py_notify_blackout(Module*){};
- };
+ };
struct MonitorWrap : Monitor, boost::python::wrapper<Monitor>
{
@@ -1471,6 +1476,59 @@ namespace YOSYS_PYTHON {
}
};
+ struct PyPass : public Yosys::Pass
+ {
+ PyPass(std::string name, std::string short_help) : Yosys::Pass(name, short_help) { }
+
+ virtual void execute(vector<string> args, Yosys::RTLIL::Design* d) YS_OVERRIDE
+ {
+ boost::python::list py_args;
+ for(auto arg : args)
+ py_args.append(arg);
+ py_execute(py_args, new Design(d));
+ }
+
+ virtual void help() YS_OVERRIDE
+ {
+ py_help();
+ }
+
+ virtual void py_execute(boost::python::list args, Design* d){}
+ virtual void py_help(){}
+ };
+
+ struct PassWrap : PyPass, boost::python::wrapper<PyPass>
+ {
+
+ PassWrap(std::string name, std::string short_help) : PyPass(name, short_help) { }
+
+ void py_execute(boost::python::list args, Design* d)
+ {
+ if(boost::python::override py_execute = this->get_override("py_execute"))
+ py_execute(args, d);
+ else
+ PyPass::py_execute(args, d);
+ }
+
+ void default_py_execute(boost::python::list args, Design* d)
+ {
+ this->PyPass::py_execute(args, d);
+ }
+
+ void py_help()
+ {
+ if(boost::python::override py_help = this->get_override("py_help"))
+ py_help();
+ else
+ PyPass::py_help();
+ }
+
+ void default_py_help()
+ {
+ this->PyPass::py_help();
+ }
+ };
+
void Module::register_monitor(Monitor* const m)
{
Yosys::RTLIL::Module* cpp_module = this->get_cpp_obj();
@@ -2778,6 +2836,11 @@ namespace YOSYS_PYTHON {
.def("py_notify_blackout", &Monitor::py_notify_blackout, &MonitorWrap::default_py_notify_blackout)
;
+ class_<PassWrap, boost::noncopyable>("Pass", init<std::string, std::string>())
+ .def("py_execute", &PyPass::py_execute, &PassWrap::default_py_execute)
+ .def("py_help", &PyPass::py_help, &PassWrap::default_py_help)
+ ;
+
class_<Initializer>("Initializer");
scope().attr("_hidden") = new Initializer();
@@ -3099,6 +3162,7 @@ namespace YOSYS_PYTHON {
def("const_neg", const_neg);
def("run",run);
+ def("log",log);
}