degate 0.1.1
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends
degate::Module Class Reference

Implements a container to build up higher level entities. More...

#include <Module.h>

Inheritance diagram for degate::Module:
Inheritance graph
[legend]

List of all members.

Public Types

typedef std::set< Module_shptrmodule_collection
typedef std::set< Gate_shptrgate_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.

Detailed Description

Implements a container to build up higher level entities.

Definition at line 39 of file Module.h.


Member Typedef Documentation

Definition at line 47 of file Module.h.

Definition at line 46 of file Module.h.

typedef std::map<std::string, GatePort_shptr> degate::Module::port_collection

This map defines module ports.

A port is identified by a name. A module port is 'connected' to a list of gate ports.

Definition at line 55 of file Module.h.


Constructor & Destructor Documentation

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);
}

Here is the call graph for this function:

Module::~Module ( ) [virtual]

Destroy the module.

Definition at line 39 of file Module.cc.

{}

Member Function Documentation

void Module::add_gate ( Gate_shptr  gate,
bool  detect_ports = true 
)

Add a gate to a module.

Parameters:
gateThe gate to add.
detect_portsSwitch for enabling or disabling automatic module port detection.
Exceptions:
InvalidPointerExceptionThis 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();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Module::add_module ( Module_shptr  module)

Add a sub-module to a module.

Exceptions:
InvalidPointerExceptionThis 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]

Definition at line 335 of file Module.cc.

References ports.

                                                                                                 {
  ports[module_port_name] = adjacent_gate_port;
}
void Module::automove_gates ( ) [private]

Definition at line 189 of file Module.cc.

                            {
  /*
    from top to down in the module hierarchy:

    for each module: iterate over gates:

      iterate over gate ports:
      - port unconnected - ignore
      - port connected - check all related

   */
}
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;

}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool Module::exists_module_port_name ( std::string const &  module_port_name) const

Check if a module port name exists.

Definition at line 499 of file Module.cc.

References ports.

                                                                            {
  return ports.find(module_port_name) != ports.end();
}
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();
}

Here is the caller graph for this function:

Module::gate_collection::const_iterator Module::gates_begin ( ) const

Definition at line 172 of file Module.cc.

References gates.

                                                              {
  return gates.begin();
}
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();
}

Here is the caller graph for this function:

Module::gate_collection::const_iterator Module::gates_end ( ) const

Definition at line 176 of file Module.cc.

References gates.

                                                            {
  return gates.end();
}
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;
}

Here is the caller graph for this function:

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();
}

Here is the caller graph for this function:

Module_shptr Module::lookup_module ( std::list< std::string > &  path_elements) const [private]

Internal implementation of lookup_module().

Parameters:
path_elementsReference to a list of path elements. List is modified.
Returns:
Returns a valid pointer on success. Else a null pointer is returned.

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.

Parameters:
module_pathPath to the module, e.g. : an absolute path "main_module/crypto/lfsr_a" an relative path "crypto/lfsr_a"
Returns:
Returns the module. In case of lookup failure a NULL pointer is returned.

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
  }

}

Here is the call graph for this function:

boost::optional< std::string > Module::lookup_module_port_name ( GatePort_shptr  gate_port)

Lookup the module port name.

Returns:
Returns the module port name.

Definition at line 488 of file Module.cc.

References ports.

                                                                                 {
  
  for(Module::port_collection::const_iterator iter = ports.begin(); iter != ports.end(); ++iter) {
    if(iter->second == gate_port) {
      return boost::optional<std::string>(iter->first);
    }
  }
  return boost::optional<std::string>();
}
Module::module_collection::const_iterator Module::modules_begin ( ) const

Definition at line 164 of file Module.cc.

References modules.

                                                                  {
  return modules.begin();
}
Module::module_collection::iterator Module::modules_begin ( )

Definition at line 140 of file Module.cc.

References modules.

                                                      {
  return modules.begin();
}
Module::module_collection::const_iterator Module::modules_end ( ) const

Definition at line 168 of file Module.cc.

References modules.

                                                                {
  return modules.end();
}
Module::module_collection::iterator Module::modules_end ( )

Definition at line 144 of file Module.cc.

References modules.

                                                    {
  return modules.end();
}
void Module::move_gates_recursive ( Module dst_mod) [private]
Exceptions:
InvalidPointerExceptionThis 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);
}

Here is the call graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Module::port_collection::iterator Module::ports_begin ( )

Definition at line 156 of file Module.cc.

References ports.

                                                  {
  return ports.begin();
}
Module::port_collection::const_iterator Module::ports_begin ( ) const

Definition at line 180 of file Module.cc.

References ports.

                                                              {
  return ports.begin();
}
Module::port_collection::iterator Module::ports_end ( )

Definition at line 160 of file Module.cc.

References ports.

                                                {
  return ports.end();
}
Module::port_collection::const_iterator Module::ports_end ( ) const

Definition at line 184 of file Module.cc.

References ports.

                                                            {
  return ports.end();
}
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.

Returns:
Returns true if a module was removed, else false.
See also:
add_gate()
Exceptions:
InvalidPointerExceptionThis 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;
}

Here is the call graph for this function:

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.

Returns:
Returns true if a module was removed, else false.
Exceptions:
InvalidPointerExceptionThis 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 ( )

Set a module as main module.

This will set the new state only in the current module and will not disable the root-node-state of any other module.

Definition at line 45 of file Module.cc.

References is_root.

                             {
  is_root = true;
}
void Module::set_module_port_name ( std::string const &  module_port_name,
GatePort_shptr  adjacent_gate_port 
)

Set module port name.

Definition at line 475 of file Module.cc.

References ports.

                                                                                                      {

  for(Module::port_collection::const_iterator iter = ports.begin(); iter != ports.end(); ++iter) {
    if(iter->second == adjacent_gate_port) {
      ports.erase(iter->first);
      ports[module_port_name] = adjacent_gate_port;
      return;
    }
  }
  
}

Friends And Related Function Documentation

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]

Definition at line 42 of file Module.h.


Member Data Documentation

std::string degate::Module::entity_name [private]

Definition at line 63 of file Module.h.

Referenced by get_entity_name(), and set_entity_name().

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().


The documentation for this class was generated from the following files: