degate  0.1.2
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
degate::CodeTemplateGenerator Class Reference

Base class for code generators. More...

#include <CodeTemplateGenerator.h>

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

List of all members.

Public Types

enum  PORT_FUNCTION_TYPE {
  CLOCK,
  RESET,
  ENABLE,
  Q,
  NOT_Q,
  D,
  SELECT
}
typedef std::map< std::string,
bool > 
port_direction_type

Public Member Functions

 CodeTemplateGenerator (std::string const &_entity_name, std::string const &_description, std::string const &_logic_class)
virtual ~CodeTemplateGenerator ()
virtual void add_port (std::string const &port_name, bool is_inport)
virtual std::string generate () const =0

Protected Member Functions

virtual std::vector< std::string > get_inports () const
 Get a list of input ports.
virtual std::vector< std::string > get_outports () const
 Get a list of output ports.
virtual std::vector< std::string > get_ports () const
 Get a list of ports.
std::string get_port_name_by_type (PORT_FUNCTION_TYPE t) const
 Get the name of the port, that is most likely of the type t.
std::string get_first_port_name_not_in (std::vector< std::string > const &ports, std::vector< std::string > const &blacklist) const
 Get the first port name from ports that is not contained in blacklist.
std::string get_first_port_name_not_in (std::vector< std::string > const &ports, std::string const &blacklist_item) const
 Get the first port name from ports that is not equal to blacklist_item.
virtual std::string generate_identifier (std::string const &name, std::string const &prefix="") const =0
template<typename Container >
Container generate_identifier (Container const &c, std::string const &prefix="") const

Protected Attributes

std::string entity_name
std::string description
std::string logic_class
port_direction_type port_direction

Detailed Description

Base class for code generators.

Definition at line 37 of file CodeTemplateGenerator.h.


Member Typedef Documentation

typedef std::map<std::string, bool> degate::CodeTemplateGenerator::port_direction_type

Definition at line 39 of file CodeTemplateGenerator.h.


Member Enumeration Documentation

Enumerator:
CLOCK 
RESET 
ENABLE 
Q 
NOT_Q 
D 
SELECT 

Definition at line 44 of file CodeTemplateGenerator.h.


Constructor & Destructor Documentation

CodeTemplateGenerator::CodeTemplateGenerator ( std::string const &  _entity_name,
std::string const &  _description,
std::string const &  _logic_class 
)

Definition at line 30 of file CodeTemplateGenerator.cc.

                                                                            :
  entity_name(_entity_name),
  description(_description),
  logic_class(_logic_class) {
}

Definition at line 38 of file CodeTemplateGenerator.cc.

                                              {
}

Member Function Documentation

void CodeTemplateGenerator::add_port ( std::string const &  port_name,
bool  is_inport 
) [virtual]

Definition at line 42 of file CodeTemplateGenerator.cc.

References port_direction.

Referenced by degate::VerilogModuleGenerator::VerilogModuleGenerator().

                                                                               {
  std::string lc = port_name;
  std::transform(lc.begin(), lc.end(), lc.begin(), ::tolower);
  port_direction[lc] = is_inport;
}

Here is the caller graph for this function:

virtual std::string degate::CodeTemplateGenerator::generate ( ) const [pure virtual]
virtual std::string degate::CodeTemplateGenerator::generate_identifier ( std::string const &  name,
std::string const &  prefix = "" 
) const [protected, pure virtual]
template<typename Container >
Container degate::CodeTemplateGenerator::generate_identifier ( Container const &  c,
std::string const &  prefix = "" 
) const [inline, protected]

Definition at line 100 of file CodeTemplateGenerator.h.

References generate_identifier().

                                                                                          {
      Container new_c;
      BOOST_FOREACH(typename Container::value_type const& s, c) {
        new_c.push_back(generate_identifier(s, prefix));
      }
      return new_c;
    }

Here is the call graph for this function:

std::string CodeTemplateGenerator::get_first_port_name_not_in ( std::vector< std::string > const &  ports,
std::vector< std::string > const &  blacklist 
) const [protected]

Get the first port name from ports that is not contained in blacklist.

Returns:
Returns an empty string, if no port name matches.

Definition at line 100 of file CodeTemplateGenerator.cc.

Referenced by degate::VerilogCodeTemplateGenerator::generate_impl(), and get_first_port_name_not_in().

                                                                                                           {
  
  typedef std::vector<std::string>::const_iterator iter;

  BOOST_FOREACH(std::string const& p_name, ports) {
    iter i = std::find(blacklist.begin(), blacklist.end(), p_name);
    if(i == blacklist.end()) return p_name;    
  }

  return "";
}

Here is the caller graph for this function:

std::string CodeTemplateGenerator::get_first_port_name_not_in ( std::vector< std::string > const &  ports,
std::string const &  blacklist_item 
) const [protected]

Get the first port name from ports that is not equal to blacklist_item.

Returns:
Returns an empty string, if no port name matches.

Definition at line 113 of file CodeTemplateGenerator.cc.

References get_first_port_name_not_in().

                                                                                                     {
  std::vector<std::string> v(1);
  v[0] = blacklist_item;
  return get_first_port_name_not_in(ports, v);
}

Here is the call graph for this function:

std::vector< std::string > CodeTemplateGenerator::get_inports ( ) const [protected, virtual]
std::vector< std::string > CodeTemplateGenerator::get_outports ( ) const [protected, virtual]

Get the name of the port, that is most likely of the type t.

Returns:
Returns an empty string, if no port name matches.

Definition at line 49 of file CodeTemplateGenerator.cc.

References CLOCK, D, ENABLE, NOT_Q, port_direction, Q, RESET, and SELECT.

Referenced by degate::VHDLTBCodeTemplateGenerator::generate(), degate::VerilogCodeTemplateGenerator::generate_impl(), and degate::VHDLCodeTemplateGenerator::generate_impl().

                                                                                                      {
  port_direction_type::const_iterator found;
  
  if(t == CLOCK) {
    if((port_direction.end() != (found = port_direction.find("clock"))) ||
       (port_direction.end() != (found = port_direction.find("clk"))))
      return found->first;
  }
  else if(t == RESET) {
    if((port_direction.end() != (found = port_direction.find("/reset"))) ||
       (port_direction.end() != (found = port_direction.find("!reset"))) ||
       (port_direction.end() != (found = port_direction.find("reset"))) ||
       (port_direction.end() != (found = port_direction.find("/rst"))) ||
       (port_direction.end() != (found = port_direction.find("!rst"))) ||
       (port_direction.end() != (found = port_direction.find("rst"))))
      return found->first;
  }
  else if(t == ENABLE) {
    if((port_direction.end() != (found = port_direction.find("en"))) ||
       (port_direction.end() != (found = port_direction.find("enable"))) ||
       (port_direction.end() != (found = port_direction.find("/en"))) ||
       (port_direction.end() != (found = port_direction.find("!en"))) ||
       (port_direction.end() != (found = port_direction.find("/enable"))) ||
       (port_direction.end() != (found = port_direction.find("!enable"))))
      return found->first;
  }
  else if(t == SELECT) {
    if((port_direction.end() != (found = port_direction.find("select"))) ||
       (port_direction.end() != (found = port_direction.find("sel"))) ||
       (port_direction.end() != (found = port_direction.find("s"))))
      return found->first;
  }
  else if(t == Q) {
    if((port_direction.end() != (found = port_direction.find("q"))) )
      return found->first;
  }
  else if(t == NOT_Q) {
    if((port_direction.end() != (found = port_direction.find("!q"))) ||
       (port_direction.end() != (found = port_direction.find("/q"))))
      return found->first;
  }
  else if(t == D) {
    if((port_direction.end() != (found = port_direction.find("d"))) )
      return found->first;
  }

  return "";
}

Here is the caller graph for this function:

std::vector< std::string > CodeTemplateGenerator::get_ports ( ) const [protected, virtual]

Get a list of ports.

Definition at line 140 of file CodeTemplateGenerator.cc.

References port_direction.

Referenced by degate::VerilogTBCodeTemplateGenerator::generate_module().

                                                            {
  std::vector<std::string> ports;

  BOOST_FOREACH(port_direction_type::value_type const& p, port_direction)
    ports.push_back(p.first);

  std::sort(ports.begin(), ports.end());
  return ports;
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 55 of file CodeTemplateGenerator.h.


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