mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-10-31 03:32:29 +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 <boost/python.hpp> | ||||
| 
 | ||||
| struct YosysDesign; | ||||
| struct YosysModule; | ||||
| struct YosysCell; | ||||
| struct YosysWire; | ||||
| namespace YOSYS_PYTHON { | ||||
| 
 | ||||
| void yosys_setup() | ||||
| { | ||||
| 	struct Design; | ||||
| 	struct Module; | ||||
| 	struct Cell; | ||||
| 	struct Wire; | ||||
| 
 | ||||
| 	void yosys_setup() | ||||
| 	{ | ||||
| 		Yosys::log_streams.push_back(&std::cout); | ||||
| 		Yosys::log_error_stderr = true; | ||||
| 
 | ||||
| 		Yosys::yosys_setup(); | ||||
| 		Yosys::yosys_banner(); | ||||
| } | ||||
| 	} | ||||
| 
 | ||||
| void run(std::string command) | ||||
| { | ||||
| 	void run(std::string command) | ||||
| 	{ | ||||
| 		Yosys::run_pass(command); | ||||
| } | ||||
| 	} | ||||
| 
 | ||||
| void yosys_shutdown() | ||||
| { | ||||
| 	void yosys_shutdown() | ||||
| 	{ | ||||
| 		Yosys::yosys_shutdown(); | ||||
| } | ||||
| 	} | ||||
| 
 | ||||
| struct YosysCell | ||||
| { | ||||
| 	struct Cell | ||||
| 	{ | ||||
| 		Yosys::RTLIL::IdString name; | ||||
| 		Yosys::RTLIL::IdString parent_name; | ||||
| 
 | ||||
| 	YosysCell(Yosys::RTLIL::Cell* ref) | ||||
| 		Cell(Yosys::RTLIL::Cell* ref) | ||||
| 		{ | ||||
| 			this->name = ref->name; | ||||
| 			this->parent_name = ref->module->name; | ||||
|  | @ -47,20 +49,20 @@ struct YosysCell | |||
| 				return NULL; | ||||
| 			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(); | ||||
| 		return ostr; | ||||
| } | ||||
| 	} | ||||
| 
 | ||||
| struct YosysWire | ||||
| { | ||||
| 	struct Wire | ||||
| 	{ | ||||
| 		Yosys::RTLIL::IdString name; | ||||
| 		Yosys::RTLIL::IdString parent_name; | ||||
| 
 | ||||
| 	YosysWire(Yosys::RTLIL::Wire* ref) | ||||
| 		Wire(Yosys::RTLIL::Wire* ref) | ||||
| 		{ | ||||
| 			this->name = ref->name; | ||||
| 			this->parent_name = ref->module->name; | ||||
|  | @ -75,20 +77,20 @@ struct YosysWire | |||
| 				return NULL; | ||||
| 			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(); | ||||
| 		return ostr; | ||||
| } | ||||
| 	} | ||||
| 
 | ||||
| struct YosysModule | ||||
| { | ||||
| 	struct Module | ||||
| 	{ | ||||
| 		Yosys::RTLIL::IdString name; | ||||
| 		unsigned int parent_hashid; | ||||
| 
 | ||||
| 	YosysModule(Yosys::RTLIL::Module* ref) | ||||
| 		Module(Yosys::RTLIL::Module* ref) | ||||
| 		{ | ||||
| 			this->name = ref->name; | ||||
| 			this->parent_hashid = ref->design->hashidx_; | ||||
|  | @ -112,7 +114,7 @@ struct YosysModule | |||
| 				return result; | ||||
| 			for(auto &cell_it : cpp_mod->cells_) | ||||
| 			{ | ||||
| 			result.append(new YosysCell(cell_it.second)); | ||||
| 				result.append(new Cell(cell_it.second)); | ||||
| 			} | ||||
| 			return result; | ||||
| 		} | ||||
|  | @ -125,28 +127,28 @@ struct YosysModule | |||
| 				return result; | ||||
| 			for(auto &wire_it : cpp_mod->wires_) | ||||
| 			{ | ||||
| 			result.append(new YosysWire(wire_it.second)); | ||||
| 				result.append(new Wire(wire_it.second)); | ||||
| 			} | ||||
| 			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(); | ||||
| 		return ostr; | ||||
| } | ||||
| 	} | ||||
| 
 | ||||
| struct YosysDesign | ||||
| { | ||||
| 	struct Design | ||||
| 	{ | ||||
| 		unsigned int hashid; | ||||
| 
 | ||||
| 	YosysDesign(unsigned int hashid) | ||||
| 		Design(unsigned int hashid) | ||||
| 		{ | ||||
| 			this->hashid = hashid; | ||||
| 		} | ||||
| 
 | ||||
| 	YosysDesign() | ||||
| 		Design() | ||||
| 		{ | ||||
| 			Yosys::RTLIL::Design* active_design = Yosys::yosys_get_design(); | ||||
| 			if(active_design != NULL) | ||||
|  | @ -164,40 +166,40 @@ struct YosysDesign | |||
| 				return result; | ||||
| 			for(auto &mod_it : active_design->modules_) | ||||
| 			{ | ||||
| 			result.append(new YosysModule(mod_it.second)); | ||||
| 				result.append(new Module(mod_it.second)); | ||||
| 			} | ||||
| 			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; | ||||
| 		return ostr; | ||||
| } | ||||
| 	} | ||||
| 
 | ||||
| BOOST_PYTHON_MODULE(libyosys) | ||||
| { | ||||
| 	BOOST_PYTHON_MODULE(libyosys) | ||||
| 	{ | ||||
| 		using namespace boost::python; | ||||
| 
 | ||||
| 	class_<YosysDesign>("YosysDesign", init<unsigned int>()) | ||||
| 		class_<Design>("Design", init<unsigned int>()) | ||||
| 			.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::repr(boost::python::self_ns::self)) | ||||
| 		.def("get_cells", &YosysModule::get_cells) | ||||
| 		.def("get_wires", &YosysModule::get_wires) | ||||
| 			.def("get_cells", &Module::get_cells) | ||||
| 			.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::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::repr(boost::python::self_ns::self)) | ||||
| 			; | ||||
|  | @ -206,7 +208,7 @@ BOOST_PYTHON_MODULE(libyosys) | |||
| 		def("yosys_setup",yosys_setup); | ||||
| 		def("run",run); | ||||
| 		def("yosys_shutdown",yosys_shutdown); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| #endif | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue