mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-10-31 11:42:30 +00:00 
			
		
		
		
	Introduced namespace and removed class-prefixes to increase readability
This commit is contained in:
		
							parent
							
								
									ccb4dcd013
								
							
						
					
					
						commit
						7911379d4a
					
				
					 1 changed files with 175 additions and 173 deletions
				
			
		|  | @ -3,36 +3,38 @@ | ||||||
| #include "yosys.h" | #include "yosys.h" | ||||||
| #include <boost/python.hpp> | #include <boost/python.hpp> | ||||||
| 
 | 
 | ||||||
| struct YosysDesign; | namespace YOSYS_PYTHON { | ||||||
| struct YosysModule; |  | ||||||
| struct YosysCell; |  | ||||||
| struct YosysWire; |  | ||||||
| 
 | 
 | ||||||
| void yosys_setup() | 	struct Design; | ||||||
| { | 	struct Module; | ||||||
|  | 	struct Cell; | ||||||
|  | 	struct Wire; | ||||||
|  | 
 | ||||||
|  | 	void yosys_setup() | ||||||
|  | 	{ | ||||||
| 		Yosys::log_streams.push_back(&std::cout); | 		Yosys::log_streams.push_back(&std::cout); | ||||||
| 		Yosys::log_error_stderr = true; | 		Yosys::log_error_stderr = true; | ||||||
| 
 | 
 | ||||||
| 		Yosys::yosys_setup(); | 		Yosys::yosys_setup(); | ||||||
| 		Yosys::yosys_banner(); | 		Yosys::yosys_banner(); | ||||||
| } | 	} | ||||||
| 
 | 
 | ||||||
| void run(std::string command) | 	void run(std::string command) | ||||||
| { | 	{ | ||||||
| 		Yosys::run_pass(command); | 		Yosys::run_pass(command); | ||||||
| } | 	} | ||||||
| 
 | 
 | ||||||
| void yosys_shutdown() | 	void yosys_shutdown() | ||||||
| { | 	{ | ||||||
| 		Yosys::yosys_shutdown(); | 		Yosys::yosys_shutdown(); | ||||||
| } | 	} | ||||||
| 
 | 
 | ||||||
| struct YosysCell | 	struct Cell | ||||||
| { | 	{ | ||||||
| 		Yosys::RTLIL::IdString name; | 		Yosys::RTLIL::IdString name; | ||||||
| 		Yosys::RTLIL::IdString parent_name; | 		Yosys::RTLIL::IdString parent_name; | ||||||
| 
 | 
 | ||||||
| 	YosysCell(Yosys::RTLIL::Cell* ref) | 		Cell(Yosys::RTLIL::Cell* ref) | ||||||
| 		{ | 		{ | ||||||
| 			this->name = ref->name; | 			this->name = ref->name; | ||||||
| 			this->parent_name = ref->module->name; | 			this->parent_name = ref->module->name; | ||||||
|  | @ -47,20 +49,20 @@ struct YosysCell | ||||||
| 				return NULL; | 				return NULL; | ||||||
| 			return active_design->modules_[this->parent_name]->cells_[this->name]; | 			return active_design->modules_[this->parent_name]->cells_[this->name]; | ||||||
| 		} | 		} | ||||||
| }; | 	}; | ||||||
| 
 | 
 | ||||||
| std::ostream &operator<<(std::ostream &ostr, const YosysCell &cell) | 	std::ostream &operator<<(std::ostream &ostr, const Cell &cell) | ||||||
| { | 	{ | ||||||
| 		ostr << "Cell with name " << cell.name.c_str(); | 		ostr << "Cell with name " << cell.name.c_str(); | ||||||
| 		return ostr; | 		return ostr; | ||||||
| } | 	} | ||||||
| 
 | 
 | ||||||
| struct YosysWire | 	struct Wire | ||||||
| { | 	{ | ||||||
| 		Yosys::RTLIL::IdString name; | 		Yosys::RTLIL::IdString name; | ||||||
| 		Yosys::RTLIL::IdString parent_name; | 		Yosys::RTLIL::IdString parent_name; | ||||||
| 
 | 
 | ||||||
| 	YosysWire(Yosys::RTLIL::Wire* ref) | 		Wire(Yosys::RTLIL::Wire* ref) | ||||||
| 		{ | 		{ | ||||||
| 			this->name = ref->name; | 			this->name = ref->name; | ||||||
| 			this->parent_name = ref->module->name; | 			this->parent_name = ref->module->name; | ||||||
|  | @ -75,20 +77,20 @@ struct YosysWire | ||||||
| 				return NULL; | 				return NULL; | ||||||
| 			return active_design->modules_[this->parent_name]->wires_[this->name]; | 			return active_design->modules_[this->parent_name]->wires_[this->name]; | ||||||
| 		} | 		} | ||||||
| }; | 	}; | ||||||
| 
 | 
 | ||||||
| std::ostream &operator<<(std::ostream &ostr, const YosysWire &wire) | 	std::ostream &operator<<(std::ostream &ostr, const Wire &wire) | ||||||
| { | 	{ | ||||||
| 		ostr << "Wire with name " << wire.name.c_str(); | 		ostr << "Wire with name " << wire.name.c_str(); | ||||||
| 		return ostr; | 		return ostr; | ||||||
| } | 	} | ||||||
| 
 | 
 | ||||||
| struct YosysModule | 	struct Module | ||||||
| { | 	{ | ||||||
| 		Yosys::RTLIL::IdString name; | 		Yosys::RTLIL::IdString name; | ||||||
| 		unsigned int parent_hashid; | 		unsigned int parent_hashid; | ||||||
| 
 | 
 | ||||||
| 	YosysModule(Yosys::RTLIL::Module* ref) | 		Module(Yosys::RTLIL::Module* ref) | ||||||
| 		{ | 		{ | ||||||
| 			this->name = ref->name; | 			this->name = ref->name; | ||||||
| 			this->parent_hashid = ref->design->hashidx_; | 			this->parent_hashid = ref->design->hashidx_; | ||||||
|  | @ -112,7 +114,7 @@ struct YosysModule | ||||||
| 				return result; | 				return result; | ||||||
| 			for(auto &cell_it : cpp_mod->cells_) | 			for(auto &cell_it : cpp_mod->cells_) | ||||||
| 			{ | 			{ | ||||||
| 			result.append(new YosysCell(cell_it.second)); | 				result.append(new Cell(cell_it.second)); | ||||||
| 			} | 			} | ||||||
| 			return result; | 			return result; | ||||||
| 		} | 		} | ||||||
|  | @ -125,28 +127,28 @@ struct YosysModule | ||||||
| 				return result; | 				return result; | ||||||
| 			for(auto &wire_it : cpp_mod->wires_) | 			for(auto &wire_it : cpp_mod->wires_) | ||||||
| 			{ | 			{ | ||||||
| 			result.append(new YosysWire(wire_it.second)); | 				result.append(new Wire(wire_it.second)); | ||||||
| 			} | 			} | ||||||
| 			return result; | 			return result; | ||||||
| 		} | 		} | ||||||
| }; | 	}; | ||||||
| 
 | 
 | ||||||
| std::ostream &operator<<(std::ostream &ostr, const YosysModule &module) | 	std::ostream &operator<<(std::ostream &ostr, const Module &module) | ||||||
| { | 	{ | ||||||
| 		ostr << "Module with name " << module.name.c_str(); | 		ostr << "Module with name " << module.name.c_str(); | ||||||
| 		return ostr; | 		return ostr; | ||||||
| } | 	} | ||||||
| 
 | 
 | ||||||
| struct YosysDesign | 	struct Design | ||||||
| { | 	{ | ||||||
| 		unsigned int hashid; | 		unsigned int hashid; | ||||||
| 
 | 
 | ||||||
| 	YosysDesign(unsigned int hashid) | 		Design(unsigned int hashid) | ||||||
| 		{ | 		{ | ||||||
| 			this->hashid = hashid; | 			this->hashid = hashid; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 	YosysDesign() | 		Design() | ||||||
| 		{ | 		{ | ||||||
| 			Yosys::RTLIL::Design* active_design = Yosys::yosys_get_design(); | 			Yosys::RTLIL::Design* active_design = Yosys::yosys_get_design(); | ||||||
| 			if(active_design != NULL) | 			if(active_design != NULL) | ||||||
|  | @ -164,40 +166,40 @@ struct YosysDesign | ||||||
| 				return result; | 				return result; | ||||||
| 			for(auto &mod_it : active_design->modules_) | 			for(auto &mod_it : active_design->modules_) | ||||||
| 			{ | 			{ | ||||||
| 			result.append(new YosysModule(mod_it.second)); | 				result.append(new Module(mod_it.second)); | ||||||
| 			} | 			} | ||||||
| 			return result; | 			return result; | ||||||
| 		} | 		} | ||||||
| }; | 	}; | ||||||
| 
 | 
 | ||||||
| std::ostream &operator<<(std::ostream &ostr, const YosysDesign &design) | 	std::ostream &operator<<(std::ostream &ostr, const Design &design) | ||||||
| { | 	{ | ||||||
| 		ostr << "Design with id " << design.hashid; | 		ostr << "Design with id " << design.hashid; | ||||||
| 		return ostr; | 		return ostr; | ||||||
| } | 	} | ||||||
| 
 | 
 | ||||||
| BOOST_PYTHON_MODULE(libyosys) | 	BOOST_PYTHON_MODULE(libyosys) | ||||||
| { | 	{ | ||||||
| 		using namespace boost::python; | 		using namespace boost::python; | ||||||
| 
 | 
 | ||||||
| 	class_<YosysDesign>("YosysDesign", init<unsigned int>()) | 		class_<Design>("Design", init<unsigned int>()) | ||||||
| 			.def(init<>()) | 			.def(init<>()) | ||||||
| 		.def("get_modules", &YosysDesign::get_modules) | 			.def("get_modules", &Design::get_modules) | ||||||
| 			; | 			; | ||||||
| 
 | 
 | ||||||
| 	class_<YosysModule>("YosysModule", no_init) | 		class_<Module>("Module", no_init) | ||||||
| 			.def(boost::python::self_ns::str(boost::python::self_ns::self)) | 			.def(boost::python::self_ns::str(boost::python::self_ns::self)) | ||||||
| 			.def(boost::python::self_ns::repr(boost::python::self_ns::self)) | 			.def(boost::python::self_ns::repr(boost::python::self_ns::self)) | ||||||
| 		.def("get_cells", &YosysModule::get_cells) | 			.def("get_cells", &Module::get_cells) | ||||||
| 		.def("get_wires", &YosysModule::get_wires) | 			.def("get_wires", &Module::get_wires) | ||||||
| 			; | 			; | ||||||
| 
 | 
 | ||||||
| 	class_<YosysCell>("YosysCell", no_init) | 		class_<Cell>("Cell", no_init) | ||||||
| 			.def(boost::python::self_ns::str(boost::python::self_ns::self)) | 			.def(boost::python::self_ns::str(boost::python::self_ns::self)) | ||||||
| 			.def(boost::python::self_ns::repr(boost::python::self_ns::self)) | 			.def(boost::python::self_ns::repr(boost::python::self_ns::self)) | ||||||
| 			; | 			; | ||||||
| 
 | 
 | ||||||
| 	class_<YosysWire>("YosysWire", no_init) | 		class_<Wire>("Wire", no_init) | ||||||
| 			.def(boost::python::self_ns::str(boost::python::self_ns::self)) | 			.def(boost::python::self_ns::str(boost::python::self_ns::self)) | ||||||
| 			.def(boost::python::self_ns::repr(boost::python::self_ns::self)) | 			.def(boost::python::self_ns::repr(boost::python::self_ns::self)) | ||||||
| 			; | 			; | ||||||
|  | @ -206,7 +208,7 @@ BOOST_PYTHON_MODULE(libyosys) | ||||||
| 		def("yosys_setup",yosys_setup); | 		def("yosys_setup",yosys_setup); | ||||||
| 		def("run",run); | 		def("run",run); | ||||||
| 		def("yosys_shutdown",yosys_shutdown); | 		def("yosys_shutdown",yosys_shutdown); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| } | } | ||||||
| 
 |  | ||||||
| #endif | #endif | ||||||
| 
 |  | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue