|
degate 0.1.1
|
Implements a container to build up higher level entities. More...
#include <Module.h>

Public Types | |
| typedef std::set< Module_shptr > | module_collection |
| typedef std::set< Gate_shptr > | gate_collection |
| typedef std::map< std::string, GatePort_shptr > | port_collection |
| This map defines module ports. | |
Public Member Functions | |
| Module (std::string const &module_name="", std::string const &_entity_name="", bool is_root=false) | |
| Construct a new module. | |
| virtual | ~Module () |
| Destroy the module. | |
| bool | is_main_module () const |
| Check if module is the main module. | |
| void | set_main_module () |
| Set a module as main module. | |
| void | set_entity_name (std::string const &name) |
| Set an identifier for the module type. | |
| std::string | get_entity_name () const |
| Get name of the entity type. | |
| void | add_gate (Gate_shptr gate, bool detect_ports=true) |
| Add a gate to a module. | |
| bool | remove_gate (Gate_shptr gate) |
| Remove a gate from a module. | |
| void | add_module (Module_shptr module) |
| Add a sub-module to a module. | |
| bool | remove_module (Module_shptr module) |
| Remove a submodule. | |
| module_collection::iterator | modules_begin () |
| module_collection::iterator | modules_end () |
| gate_collection::iterator | gates_begin () |
| gate_collection::iterator | gates_end () |
| port_collection::iterator | ports_begin () |
| port_collection::iterator | ports_end () |
| module_collection::const_iterator | modules_begin () const |
| module_collection::const_iterator | modules_end () const |
| gate_collection::const_iterator | gates_begin () const |
| gate_collection::const_iterator | gates_end () const |
| port_collection::const_iterator | ports_begin () const |
| port_collection::const_iterator | ports_end () const |
| void | determine_module_ports () |
| Determine ports of a module. | |
| Module_shptr | lookup_module (std::string const &module_path) const |
| Lookup a sub-module. | |
| void | set_module_port_name (std::string const &module_port_name, GatePort_shptr adjacent_gate_port) |
| Set module port name. | |
| bool | exists_module_port_name (std::string const &module_port_name) const |
| Check if a module port name exists. | |
| boost::optional< std::string > | lookup_module_port_name (GatePort_shptr gate_port) |
| Lookup the module port name. | |
Private Member Functions | |
| void | move_gates_recursive (Module *dst_mod) |
| void | automove_gates () |
| bool | exists_gate_port_recursive (object_id_t oid) const |
Check if there is a gate is the current module or any child module that has a gate port with the object ID oid . | |
| GatePort_shptr | lookup_gate_port_recursive (object_id_t oid) const |
| void | add_module_port (std::string const &module_port_name, GatePort_shptr adjacent_gate_port) |
| bool | net_feeded_internally (Net_shptr net) const |
| bool | net_completely_internal (Net_shptr net) const |
| Module_shptr | lookup_module (std::list< std::string > &path_elements) const |
| Internal implementation of lookup_module(). | |
Private Attributes | |
| module_collection | modules |
| gate_collection | gates |
| port_collection | ports |
| std::string | entity_name |
| bool | is_root |
Friends | |
| class | LogicModelImporter |
| void | determine_module_ports_for_root (LogicModel_shptr lmodel) |
| Determine ports of a root module. | |
| typedef std::set<Gate_shptr> degate::Module::gate_collection |
| typedef std::set<Module_shptr> degate::Module::module_collection |
| typedef std::map<std::string, GatePort_shptr> degate::Module::port_collection |
| Module::Module | ( | std::string const & | module_name = "", |
| std::string const & | _entity_name = "", |
||
| bool | is_root = false |
||
| ) |
Construct a new module.
Definition at line 30 of file Module.cc.
References degate::LogicModelObjectBase::set_name().
: entity_name(_entity_name), is_root(_is_root) { set_name(module_name); }

| void Module::add_gate | ( | Gate_shptr | gate, |
| bool | detect_ports = true |
||
| ) |
Add a gate to a module.
| gate | The gate to add. |
| detect_ports | Switch for enabling or disabling automatic module port detection. |
| InvalidPointerException | This exception is thrown, if gate is a NULL pointer. |
Definition at line 59 of file Module.cc.
References determine_module_ports(), gates, and is_root.
Referenced by move_gates_recursive().
{
if(gate == NULL)
throw InvalidPointerException("Invalid pointer passed to add_gate().");
gates.insert(gate);
if(!is_root && detect_ports) determine_module_ports();
}


| void Module::add_module | ( | Module_shptr | module | ) |
Add a sub-module to a module.
| InvalidPointerException | This exception is thrown, if gate is a NULL pointer. |
Definition at line 92 of file Module.cc.
References modules.
{
if(module == NULL)
throw InvalidPointerException("Invalid pointer passed to add_modue().");
modules.insert(module);
}
| void Module::add_module_port | ( | std::string const & | module_port_name, |
| GatePort_shptr | adjacent_gate_port | ||
| ) | [private] |
| void Module::automove_gates | ( | ) | [private] |
| void Module::determine_module_ports | ( | ) |
Determine ports of a module.
Definition at line 238 of file Module.cc.
References exists_gate_port_recursive(), gate_port_already_named(), gates_begin(), gates_end(), modules, net_completely_internal(), net_feeded_internally(), and ports.
Referenced by add_gate(), and remove_gate().
{
int pnum = 0;
port_collection new_ports;
std::set<Net_shptr> known_net;
for(gate_collection::iterator g_iter = gates_begin(); g_iter != gates_end(); ++g_iter) {
Gate_shptr gate = *g_iter;
assert(gate != NULL);
for(Gate::port_const_iterator p_iter = gate->ports_begin(); p_iter != gate->ports_end(); ++p_iter) {
GatePort_shptr gate_port = *p_iter;
assert(gate_port != NULL);
Net_shptr net = gate_port->get_net();
std::cout << "Check net for object gate port " << gate_port->get_descriptive_identifier() << "?\n";
bool net_already_processed = known_net.find(net) != known_net.end();
if((net != NULL) && !net_already_processed && !net_completely_internal(net)) {
bool is_a_port = false;
for(Net::connection_iterator c_iter = net->begin(); c_iter != net->end() && !is_a_port; ++c_iter) {
object_id_t oid = *c_iter;
if(!exists_gate_port_recursive(oid)) { // outbound connection
// Now we check, wheather the connection is feeded by an ouside entity or feeded
// from this module.
// Problem: We can't see the object outside this module, because we only have an
// object ID and no logic model object to look up the object ID. Therefore we have
// to derive the state of feeding from the objects we have in this or any sub-module.
// If we see only in-ports in the net, the module port must be driven by an outside
// port.
GateTemplatePort_shptr tmpl_port = gate_port->get_template_port();
assert(tmpl_port != NULL); // if a gate has no standard cell type, the gate cannot have a port
if(net_feeded_internally(net) && tmpl_port->is_inport()) {
std::cout << " Net feeded internally, but port is inport. Will check where the net is driven.\n";
}
else {
std::string mod_port_name = gate_port_already_named(ports, gate_port);
if(mod_port_name == "") {
// generate a new port name and check if the port name is already in use
do {
pnum++;
boost::format f("p%1%");
f % pnum;
mod_port_name = f.str();
}while(ports.find(mod_port_name) != ports.end());
}
std::cout << " New module port: " << gate_port->get_descriptive_identifier() << " == "
<< mod_port_name << "\n";
new_ports[mod_port_name] = gate_port;
is_a_port = true;
std::cout << " Set net as known net: " << net->get_descriptive_identifier() << "\n";
known_net.insert(net);
}
}
}
}
else if(net == NULL) {
std::cout << " Will not check net -- no net.\n";
}
else if(net_already_processed) {
std::cout << " Will not check net -- already processed " << net->get_descriptive_identifier() << ".\n";
}
}
}
// check sub-modules
BOOST_FOREACH(Module_shptr sub, modules) {
BOOST_FOREACH(port_collection::value_type const& p, sub->ports) {
std::string mod_port_name = p.first;
GatePort_shptr gate_port = p.second;
Net_shptr net = gate_port->get_net();
bool net_already_processed = known_net.find(net) != known_net.end();
if(net != NULL && !net_already_processed && !net_completely_internal(net)) { // outbound connection
new_ports[mod_port_name] = gate_port;
}
}
}
ports = new_ports;
}


| bool Module::exists_gate_port_recursive | ( | object_id_t | oid | ) | const [private] |
Check if there is a gate is the current module or any child module that has a gate port with the object ID oid .
Definition at line 339 of file Module.cc.
References lookup_gate_port_recursive().
Referenced by determine_module_ports().
{
return lookup_gate_port_recursive(oid) != NULL;
}


| bool Module::exists_module_port_name | ( | std::string const & | module_port_name | ) | const |
| Module::gate_collection::iterator Module::gates_begin | ( | ) |
Definition at line 148 of file Module.cc.
References gates.
Referenced by determine_module_ports(), and move_gates_recursive().
{
return gates.begin();
}

| Module::gate_collection::const_iterator Module::gates_begin | ( | ) | const |
| Module::gate_collection::iterator Module::gates_end | ( | ) |
Definition at line 152 of file Module.cc.
References gates.
Referenced by determine_module_ports(), and move_gates_recursive().
{
return gates.end();
}

| Module::gate_collection::const_iterator Module::gates_end | ( | ) | const |
| std::string Module::get_entity_name | ( | ) | const |
Get name of the entity type.
Definition at line 54 of file Module.cc.
References entity_name.
{
return entity_name;
}
| bool Module::is_main_module | ( | ) | const |
Check if module is the main module.
Definition at line 41 of file Module.cc.
References is_root.
Referenced by lookup_module().
{
return is_root;
}

| GatePort_shptr Module::lookup_gate_port_recursive | ( | object_id_t | oid | ) | const [private] |
Definition at line 343 of file Module.cc.
References gates, and modules.
Referenced by exists_gate_port_recursive(), net_completely_internal(), and net_feeded_internally().
{
assert(oid != 0);
for(gate_collection::const_iterator g_iter = gates.begin();
g_iter != gates.end(); ++g_iter) {
Gate_shptr gate = *g_iter;
for(Gate::port_const_iterator p_iter = gate->ports_begin();
p_iter != gate->ports_end(); ++p_iter)
if((*p_iter)->get_object_id() == oid) return *p_iter;
}
for(module_collection::const_iterator iter = modules.begin();
iter != modules.end(); ++iter)
if(GatePort_shptr gport = (*iter)->lookup_gate_port_recursive(oid)) return gport;
return GatePort_shptr();
}

| Module_shptr Module::lookup_module | ( | std::list< std::string > & | path_elements | ) | const [private] |
Internal implementation of lookup_module().
| path_elements | Reference to a list of path elements. List is modified. |
Definition at line 453 of file Module.cc.
References modules.
{
if(path_elements.size() > 0) {
BOOST_FOREACH(Module_shptr m, modules) {
if(m->get_name() == path_elements.front()) {
if(path_elements.size() == 1)
return m;
else {
path_elements.pop_front();
return m->lookup_module(path_elements);
}
}
}
}
return Module_shptr();
}
| Module_shptr Module::lookup_module | ( | std::string const & | module_path | ) | const |
Lookup a sub-module.
| module_path | Path to the module, e.g. : an absolute path "main_module/crypto/lfsr_a" an relative path "crypto/lfsr_a" |
Definition at line 424 of file Module.cc.
References degate::LogicModelObjectBase::get_name(), and is_main_module().
{
std::list<std::string> path_elements;
boost::split(path_elements, module_path, boost::is_any_of("/"));
if(is_main_module()) {
// handle absolut path
while(path_elements.size() > 0 &&
get_name() != path_elements.front()) {
path_elements.pop_front();
}
}
if(path_elements.size() == 0)
return Module_shptr();
// leading path element should equals current module name
if(get_name() != path_elements.front())
return Module_shptr();
else {
path_elements.pop_front();
return lookup_module(path_elements); // first real name is name of the main module, skipped
}
}

| boost::optional< std::string > Module::lookup_module_port_name | ( | GatePort_shptr | gate_port | ) |
| Module::module_collection::const_iterator Module::modules_begin | ( | ) | const |
| Module::module_collection::iterator Module::modules_begin | ( | ) |
| Module::module_collection::const_iterator Module::modules_end | ( | ) | const |
| Module::module_collection::iterator Module::modules_end | ( | ) |
| void Module::move_gates_recursive | ( | Module * | dst_mod | ) | [private] |
| InvalidPointerException | This exception is thrown if the parameter is a NULL pointer. |
Definition at line 123 of file Module.cc.
References add_gate(), gates_begin(), gates_end(), degate::LogicModelObjectBase::get_name(), and modules.
{
if(dst_mod == NULL)
throw InvalidPointerException("Invalid pointer passed to move_all_child_gates_into_current_module().");
for(gate_collection::iterator g_iter = gates_begin();
g_iter != gates_end(); ++g_iter) {
std::cout << "Add gate " << (*g_iter)->get_name() << " to module " << dst_mod->get_name() << std::endl;
dst_mod->add_gate(*g_iter);
}
for(module_collection::iterator iter = modules.begin();
iter != modules.end(); ++iter)
(*iter)->move_gates_recursive(dst_mod);
}

| bool Module::net_completely_internal | ( | Net_shptr | net | ) | const [private] |
Definition at line 203 of file Module.cc.
References lookup_gate_port_recursive().
Referenced by determine_module_ports().
{
for(Net::connection_iterator c_iter = net->begin(); c_iter != net->end(); ++c_iter) {
object_id_t oid = *c_iter;
GatePort_shptr gport = lookup_gate_port_recursive(oid);
if(gport == NULL) { // external entity
return false;
}
}
return true;
}


| bool Module::net_feeded_internally | ( | Net_shptr | net | ) | const [private] |
Definition at line 215 of file Module.cc.
References lookup_gate_port_recursive().
Referenced by determine_module_ports().
{
for(Net::connection_iterator c_iter = net->begin(); c_iter != net->end(); ++c_iter) {
object_id_t oid = *c_iter;
GatePort_shptr gport = lookup_gate_port_recursive(oid);
if(gport != NULL) { // internal entity
GateTemplatePort_shptr tmpl_port = gport->get_template_port();
if(tmpl_port->is_outport()) return true;
}
}
return false;
}


| Module::port_collection::iterator Module::ports_begin | ( | ) |
| Module::port_collection::const_iterator Module::ports_begin | ( | ) | const |
| Module::port_collection::iterator Module::ports_end | ( | ) |
| Module::port_collection::const_iterator Module::ports_end | ( | ) | const |
| bool Module::remove_gate | ( | Gate_shptr | gate | ) |
Remove a gate from a module.
This method even works if the gate is not a direct child. Afterwards the gate is completely removed from the module hierarchy (if you run this method for the "right" root node). In most cases you want to add the gate to the module hierarchy again. Therefore you have to call method add_gate() on your own.
| InvalidPointerException | This exception is thrown, if gate is a NULL pointer. |
Definition at line 67 of file Module.cc.
References determine_module_ports(), gates, is_root, and modules.
{
if(gate == NULL)
throw InvalidPointerException("Invalid pointer passed to remove_gate().");
gate_collection::const_iterator g_iter = gates.find(gate);
if(g_iter != gates.end()) {
gates.erase(g_iter);
if(!is_root) determine_module_ports();
return true;
}
else {
for(module_collection::iterator iter = modules.begin();
iter != modules.end(); ++iter) {
Module_shptr child = *iter;
if((*iter)->remove_gate(gate) == true) return true;
}
}
return false;
}

| bool Module::remove_module | ( | Module_shptr | module | ) |
Remove a submodule.
This method even works if the submodule is not a direct child. If you remove a child module that contains gates, the gates are moved one layer above.
| InvalidPointerException | This exception is thrown, if gate is a NULL pointer. |
Definition at line 101 of file Module.cc.
References modules.
{
if(module == NULL)
throw InvalidPointerException("Invalid pointer passed to remove_module().");
for(module_collection::iterator iter = modules.begin();
iter != modules.end(); ++iter) {
Module_shptr child = *iter;
if(child == module) {
child->move_gates_recursive(this);
modules.erase(iter);
return true;
}
else if((*iter)->remove_module(module) == true)
return true;
}
return false;
}
| void Module::set_entity_name | ( | std::string const & | name | ) |
Set an identifier for the module type.
Definition at line 50 of file Module.cc.
References entity_name, and degate::LogicModelObjectBase::name.
{
entity_name = name;
}
| void Module::set_main_module | ( | ) |
| void Module::set_module_port_name | ( | std::string const & | module_port_name, |
| GatePort_shptr | adjacent_gate_port | ||
| ) |
| void determine_module_ports_for_root | ( | LogicModel_shptr | lmodel | ) | [friend] |
Determine ports of a root module.
Note: It would b more nice to have this function as a member function of class Module. But this would intorduce a dependency of LogicModel. The lmodel is neccessary for looking up objects, because main module's ports are modelled by having a special emarker in the net. I have no idea how the main module's ports could be identified else. (Using all ports is obviously not an option.)
friend class LogicModelImporter [friend] |
std::string degate::Module::entity_name [private] |
Definition at line 63 of file Module.h.
Referenced by get_entity_name(), and set_entity_name().
gate_collection degate::Module::gates [private] |
Definition at line 60 of file Module.h.
Referenced by add_gate(), gates_begin(), gates_end(), lookup_gate_port_recursive(), and remove_gate().
bool degate::Module::is_root [private] |
Definition at line 64 of file Module.h.
Referenced by add_gate(), is_main_module(), remove_gate(), and set_main_module().
module_collection degate::Module::modules [private] |
Definition at line 59 of file Module.h.
Referenced by add_module(), determine_module_ports(), lookup_gate_port_recursive(), lookup_module(), modules_begin(), modules_end(), move_gates_recursive(), remove_gate(), and remove_module().
port_collection degate::Module::ports [private] |
Definition at line 61 of file Module.h.
Referenced by add_module_port(), determine_module_ports(), exists_module_port_name(), lookup_module_port_name(), ports_begin(), ports_end(), and set_module_port_name().
1.7.4