3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-06-13 09:26:16 +00:00

Introduced namespace and removed class-prefixes to increase readability

This commit is contained in:
Benedikt Tutzer 2018-06-28 15:07:21 +02:00
parent ccb4dcd013
commit 7911379d4a

View file

@ -3,10 +3,12 @@
#include "yosys.h" #include "yosys.h"
#include <boost/python.hpp> #include <boost/python.hpp>
struct YosysDesign; namespace YOSYS_PYTHON {
struct YosysModule;
struct YosysCell; struct Design;
struct YosysWire; struct Module;
struct Cell;
struct Wire;
void yosys_setup() void yosys_setup()
{ {
@ -27,12 +29,12 @@ 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;
@ -49,18 +51,18 @@ struct YosysCell
} }
}; };
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;
@ -77,18 +79,18 @@ struct YosysWire
} }
}; };
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,13 +166,13 @@ 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;
@ -180,24 +182,24 @@ 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))
; ;
@ -208,5 +210,5 @@ BOOST_PYTHON_MODULE(libyosys)
def("yosys_shutdown",yosys_shutdown); def("yosys_shutdown",yosys_shutdown);
} }
}
#endif #endif