Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyosys: support ObjRange #4703

Merged
merged 1 commit into from
Nov 11, 2024
Merged

Conversation

georgerennie
Copy link
Collaborator

This adds support for cells(), modules() and wires() that all return ObjRanges, converting them into lists for python.

The C++ diff is slightly messy as this causes a load of generated variable indices to be shifted, but ignoring those changes you get the following

2572a2573,2578
> 		// WRAPPED from "RTLIL::ObjRange<RTLIL::Wire*> wires() { return RTLIL::ObjRange<RTLIL::Wire*>(&wires_, &refcount_wires_); }" in kernel/rtlil
> 		boost::python::list wires();
>
> 		// WRAPPED from "RTLIL::ObjRange<RTLIL::Cell*> cells() { return RTLIL::ObjRange<RTLIL::Cell*>(&cells_, &refcount_cells_); }" in kernel/rtlil
> 		boost::python::list cells();
>
4082a4089,4091
> 		// WRAPPED from "RTLIL::ObjRange<RTLIL::Module*> modules();" in kernel/rtlil
> 		boost::python::list modules();
>
8760a8770,8793
> 	// WRAPPED from "RTLIL::ObjRange<RTLIL::Wire*> wires() { return RTLIL::ObjRange<RTLIL::Wire*>(&wires_, &refcount_wires_); }" in kernel/rtlil
> 	boost::python::list Module::wires()
> 	{
> 		RTLIL::ObjRange<YOSYS_NAMESPACE::RTLIL::Wire*> ret_ = this->get_cpp_obj()->wires();
> 		boost::python::list ret____tmp;
> 		for(auto tmp_205 : ret_)
> 		{
> 			ret____tmp.append(Wire::get_py_obj(tmp_205));
> 		}
> 		return ret____tmp;
> 	}
>
> 	// WRAPPED from "RTLIL::ObjRange<RTLIL::Cell*> cells() { return RTLIL::ObjRange<RTLIL::Cell*>(&cells_, &refcount_cells_); }" in kernel/rtlil
> 	boost::python::list Module::cells()
> 	{
> 		RTLIL::ObjRange<YOSYS_NAMESPACE::RTLIL::Cell*> ret_ = this->get_cpp_obj()->cells();
> 		boost::python::list ret____tmp;
> 		for(auto tmp_206 : ret_)
> 		{
> 			ret____tmp.append(Cell::get_py_obj(tmp_206));
> 		}
> 		return ret____tmp;
> 	}
>
12284a12318,12329
> 	// WRAPPED from "RTLIL::ObjRange<RTLIL::Module*> modules();" in kernel/rtlil
> 	boost::python::list Design::modules()
> 	{
> 		RTLIL::ObjRange<YOSYS_NAMESPACE::RTLIL::Module*> ret_ = this->get_cpp_obj()->modules();
> 		boost::python::list ret____tmp;
> 		for(auto tmp_230 : ret_)
> 		{
> 			ret____tmp.append(Module::get_py_obj(tmp_230));
> 		}
> 		return ret____tmp;
> 	}
>
14722a14768,14769
> 			.def<boost::python::list (Module::*)(void)>("wires", &Module::wires)
> 			.def<boost::python::list (Module::*)(void)>("cells", &Module::cells)
15216a15264
> 			.def<boost::python::list (Design::*)(void)>("modules", &Design::modules)

apologies for the number of pyosys PRs in one afternoon - I'm trying to get it working and fixing up little issues I have along the way

* this adds support for cells(), modules() and wires() that all return
  ObjRanges, converting them into lists for python
@povik
Copy link
Member

povik commented Nov 4, 2024

What did one do to get lists of the objects when these methods weren't available?

@georgerennie
Copy link
Collaborator Author

I'm guessing either directly accessing wires_ or selected_wires() (which returns std::vector). I suspect the fact that pyosys has been not used too much is a factor.

https://github.com/YosysHQ/yosys/blob/main/examples/python-api/pass.py uses selected_* methods.

@povik
Copy link
Member

povik commented Nov 4, 2024

Thanks, I wanted to look into the sample plugin but couldn't find it quickly

@povik povik merged commit 7cfc497 into YosysHQ:main Nov 11, 2024
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants