mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-10-31 03:32:29 +00:00 
			
		
		
		
	pyosys: rewrite wrapper generator
[skip ci]
This commit is contained in:
		
							parent
							
								
									88be728353
								
							
						
					
					
						commit
						384f7431fd
					
				
					 7 changed files with 738 additions and 2011 deletions
				
			
		
							
								
								
									
										1
									
								
								pyosys/.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								pyosys/.gitignore
									
										
									
									
										vendored
									
									
								
							|  | @ -1 +1,2 @@ | |||
| wrappers.cc | ||||
| wrappers.inc.cc | ||||
|  |  | |||
|  | @ -1,4 +1,3 @@ | |||
| 
 | ||||
| import os | ||||
| import sys | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										2695
									
								
								pyosys/generator.py
									
										
									
									
									
								
							
							
						
						
									
										2695
									
								
								pyosys/generator.py
									
										
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							|  | @ -48,6 +48,7 @@ | |||
| #include "kernel/hashlib.h" | ||||
| 
 | ||||
| namespace pybind11 { | ||||
| namespace hashlib { | ||||
| 
 | ||||
| template<typename T> | ||||
| struct is_pointer { static const bool value = false; }; | ||||
|  | @ -59,6 +60,11 @@ bool is_mapping(object obj) { | |||
| 	return isinstance(obj, mapping); | ||||
| } | ||||
| 
 | ||||
| // shim
 | ||||
| template <typename C, typename V> | ||||
| void bind_vector(module &m, const char *name_cstr) { | ||||
| 	pybind11::bind_vector<C>(m, name_cstr); | ||||
| } | ||||
| 
 | ||||
| // also used for std::set because the semantics are close enough
 | ||||
| template <typename C, typename T> | ||||
|  | @ -106,6 +112,13 @@ void bind_pool(module &m, const char *name_cstr) { | |||
| 		}); | ||||
| } | ||||
| 
 | ||||
| // shim
 | ||||
| template <typename C, typename T> | ||||
| void bind_set(module &m, const char *name_cstr) { | ||||
| 	bind_pool<C, T>(m, name_cstr); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| template <typename C, typename K, typename V> | ||||
| void update_dict(C *target, iterable &iterable_or_mapping) { | ||||
| 	if (is_mapping(iterable_or_mapping)) { | ||||
|  | @ -272,4 +285,5 @@ void bind_idict(module &m, const char *name_cstr) { | |||
| 		}); | ||||
| 	} | ||||
| } | ||||
| }; // namespace hashlib
 | ||||
| }; // namespace pybind11
 | ||||
|  |  | |||
|  | @ -26,7 +26,12 @@ | |||
| 
 | ||||
| USING_YOSYS_NAMESPACE | ||||
| 
 | ||||
| // <!-- generated top-level code -->
 | ||||
| using std::set; | ||||
| using std::regex; | ||||
| using std::ostream; | ||||
| using namespace RTLIL; | ||||
| 
 | ||||
| #include "wrappers.inc.cc" | ||||
| 
 | ||||
| namespace YOSYS_PYTHON { | ||||
| 
 | ||||
|  | @ -37,8 +42,6 @@ namespace YOSYS_PYTHON { | |||
| 
 | ||||
| 	struct YosysStatics{}; | ||||
| 
 | ||||
| 	// <!-- generated YOSYS_PYTHON namespace-level code -->
 | ||||
| 
 | ||||
| 	// Trampolines for Classes with Python-Overridable Virtual Methods
 | ||||
| 	// https://pybind11.readthedocs.io/en/stable/advanced/classes.html#overriding-virtual-functions-in-python
 | ||||
| 	class PassTrampoline : public Pass { | ||||
|  | @ -182,7 +185,18 @@ namespace YOSYS_PYTHON { | |||
| 			})); | ||||
| 		} | ||||
| 
 | ||||
| 		m.def("log_to_stream", &log_to_stream, "pipes yosys logs to a Python stream"); | ||||
| 		// Logging Methods
 | ||||
| 		m.def("log_header", [](Design *d, std::string s) { log_formatted_header(d, "%s", s); }); | ||||
| 		m.def("log", [](std::string s) { log_formatted_string("%s", s); }); | ||||
| 		m.def("log_file_info", [](std::string_view file, int line, std::string s) { log_formatted_file_info(file, line, s); }); | ||||
| 		m.def("log_warning", [](std::string s) { log_formatted_warning("Warning: ", s); }); | ||||
| 		m.def("log_warning_noprefix", [](std::string s) { log_formatted_warning("", s); }); | ||||
| 		m.def("log_file_warning", [](std::string_view file, int line, std::string s) { log_formatted_file_warning(file, line, s); }); | ||||
| 		m.def("log_error", [](std::string s) { log_formatted_error(s); }); | ||||
| 		m.def("log_file_error", [](std::string_view file, int line, std::string s) { log_formatted_file_error(file, line, s); }); | ||||
| 
 | ||||
| 		// Namespace to host global objects
 | ||||
| 		auto global_variables = py::class_<YosysStatics>(m, "Yosys"); | ||||
| 
 | ||||
| 		// Trampoline Classes
 | ||||
| 		py::class_<Pass, YOSYS_PYTHON::PassTrampoline, std::unique_ptr<Pass, py::nodelete>>(m, "Pass") | ||||
|  | @ -241,6 +255,9 @@ namespace YOSYS_PYTHON { | |||
| 			.def("notify_blackout", &RTLIL::Monitor::notify_blackout) | ||||
| 		; | ||||
| 
 | ||||
| 		// Bind Opaque Containers
 | ||||
| 		bind_autogenerated_opaque_containers(m); | ||||
| 
 | ||||
| 		// <!-- generated pymod-level code -->
 | ||||
| 	}; | ||||
| }; | ||||
|  |  | |||
|  | @ -1,6 +1,7 @@ | |||
| [build-system] | ||||
| requires = [ | ||||
|     "setuptools>=42", | ||||
|     "pybind11>=3,<4", | ||||
| 	"setuptools>=42", | ||||
| 	"pybind11>=3,<4", | ||||
| 	"cxxheaderparser", | ||||
| ] | ||||
| build-backend = "setuptools.build_meta" | ||||
|  |  | |||
							
								
								
									
										8
									
								
								tests/pyosys/test_logs.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								tests/pyosys/test_logs.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,8 @@ | |||
| from pyosys import libyosys as ys | ||||
| 
 | ||||
| d = ys.Design(); ys.log_header(d, "foo\n") | ||||
| ys.log("foo\n") | ||||
| ys.log_warning("foo\n") | ||||
| ys.log_warning_noprefix("foo\n") | ||||
| ys.log_file_info("foo.ys", 1, "foo\n") | ||||
| ys.log_file_warning("foo.ys", 1, "foo\n") | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue