degate  0.1.2
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | Friends
degate::GateTemplate Class Reference

A gate template is a container for common properties, that physically placed gates of that type share. More...

#include <GateTemplate.h>

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

List of all members.

Public Types

enum  IMPLEMENTATION_TYPE {
  UNDEFINED = 0,
  TEXT = 1,
  VHDL = 2,
  VHDL_TESTBENCH = 3,
  VERILOG = 4,
  VERILOG_TESTBENCH = 5
}
 Implementation types for a template. More...
typedef std::map
< IMPLEMENTATION_TYPE,
std::string > 
implementation_collection
typedef
implementation_collection::iterator 
implementation_iter
typedef std::map
< Layer::LAYER_TYPE,
GateTemplateImage_shptr
image_collection
typedef image_collection::iterator image_iterator
typedef std::set
< GateTemplatePort_shptr >
::iterator 
port_iterator

Public Member Functions

 GateTemplate (unsigned int width, unsigned int height)
 The constructor to set up a new gate template.
 GateTemplate (int _min_x, int _max_x, int _min_y, int _max_y)
 The constructor to set up a new gate template.
 GateTemplate ()
 Default constructor.
virtual ~GateTemplate ()
 The destructor.
virtual unsigned int get_width () const
 Get the width of a gate template.
virtual unsigned int get_height () const
 Get the height of a gate template.
virtual void set_width (unsigned int width)
 Set the width of a gate template.
virtual void set_height (unsigned int)
 Set the height of a gate template.
virtual BoundingBox const & get_bounding_box () const
 Get the bounding box of the template.
virtual void set_image (Layer::LAYER_TYPE layer_type, GateTemplateImage_shptr img)
 Set a reference image for the template.
virtual GateTemplateImage_shptr get_image (Layer::LAYER_TYPE layer_type)
 Get a reference image for the template.
virtual bool has_image (Layer::LAYER_TYPE layer_type) const
 Check if there is a reference image for a layer type.
virtual void add_template_port (GateTemplatePort_shptr template_port)
 Add a template port to a gate template.
virtual bool remove_template_port (GateTemplatePort_shptr template_port)
 Remove a port from a gate template.
virtual bool remove_template_port (object_id_t object_id)
 Remove a port from a gate template.
virtual GateTemplatePort_shptr get_template_port (object_id_t object_id)
 Get a template port.
virtual bool has_template_port (object_id_t object_id) const
 Check if a template has a specific template port.
virtual port_iterator ports_begin ()
 Get an iterator.
virtual port_iterator ports_end ()
 Get end marker for the iteration over ports.
virtual image_iterator images_begin ()
 Get an iterator to iterate over images.
virtual image_iterator images_end ()
 Get end marker for the iteration over images.
virtual unsigned int get_reference_counter () const
 Get the reference counter.
virtual implementation_iter implementations_begin ()
 Get an iterator to iterate over implementations.
virtual implementation_iter implementations_end ()
 Get an end marker for the iteration.
virtual void set_implementation (IMPLEMENTATION_TYPE impl_type, std::string const &code)
 Set VHDL/Verilog implementation for the gate template.
std::string get_implementation (IMPLEMENTATION_TYPE impl_type) const
 Get code for an implementation type.
virtual void print (std::ostream &os)
 Print gate template's meta information to an output stream.
virtual unsigned int get_number_of_ports () const
 Get number of defined ports.
virtual void set_logic_class (std::string const &logic_class)
 Set logic class for a standard cell.
virtual std::string get_logic_class () const
 Get logic class for a standard cell.
DeepCopyable_shptr cloneShallow () const
 Return a copy of this object, but with all references to other DeepCopyables cleared (e.g.
void cloneDeepInto (DeepCopyable_shptr destination, oldnew_t *oldnew) const

Static Public Member Functions

static std::string get_impl_type_as_string (IMPLEMENTATION_TYPE impl_type)
 Convert an implementation-type constant to a printable string.
static IMPLEMENTATION_TYPE get_impl_type_from_string (std::string const &impl_type_str)
 Convert an implementation type string to a correspondig constant.

Protected Member Functions

virtual void increment_reference_counter ()
 Increment the reference counter.
virtual void decrement_reference_counter ()
 Decrement the reference counter.

Private Attributes

BoundingBox bounding_box
unsigned int reference_counter
std::set
< GateTemplatePort_shptr,
LMOCompare
ports
implementation_collection implementations
image_collection images
std::string logic_class

Friends

class Gate

Detailed Description

A gate template is a container for common properties, that physically placed gates of that type share.

Definition at line 42 of file GateTemplate.h.


Member Typedef Documentation

Definition at line 63 of file GateTemplate.h.

typedef image_collection::iterator degate::GateTemplate::image_iterator

Definition at line 64 of file GateTemplate.h.

Definition at line 60 of file GateTemplate.h.

typedef implementation_collection::iterator degate::GateTemplate::implementation_iter

Definition at line 61 of file GateTemplate.h.

Definition at line 95 of file GateTemplate.h.


Member Enumeration Documentation

Implementation types for a template.

Enumerator:
UNDEFINED 
TEXT 
VHDL 
VHDL_TESTBENCH 
VERILOG 
VERILOG_TESTBENCH 

Definition at line 51 of file GateTemplate.h.

                             {
      UNDEFINED = 0,
      TEXT = 1,
      VHDL = 2,
      VHDL_TESTBENCH = 3,
      VERILOG = 4,
      VERILOG_TESTBENCH = 5
    };

Constructor & Destructor Documentation

GateTemplate::GateTemplate ( unsigned int  width,
unsigned int  height 
)

The constructor to set up a new gate template.

Deprecated:
A gate template should not rely on positions. Instead it should have a the region as a copy.

Definition at line 41 of file GateTemplate.cc.

                                                                  :
  bounding_box(0, width, 0, height), reference_counter(0) {
}
GateTemplate::GateTemplate ( int  _min_x,
int  _max_x,
int  _min_y,
int  _max_y 
)

The constructor to set up a new gate template.

Deprecated:
A gate template should not rely on positions. Instead it should have a the region as a copy.

Definition at line 37 of file GateTemplate.cc.

                                                                         :
  bounding_box(_min_x, _max_x, _min_y, _max_y), reference_counter(0) {
}

Default constructor.

Definition at line 45 of file GateTemplate.cc.

                           :
  bounding_box(0, 0, 0, 0), reference_counter(0) {
}

The destructor.

Definition at line 50 of file GateTemplate.cc.

                            {
}

Member Function Documentation

void GateTemplate::add_template_port ( GateTemplatePort_shptr  template_port) [virtual]

Add a template port to a gate template.

This is an isolated function. The port is just added to the gate template. Nothing else. Adding a port to a template requires some updates in the logic model. Therefore you should prefer the corresponding method from the LogicModel class.

Exceptions:
InvalidObjectIDExceptionThis exception is thrown if the template port has no valid object ID.
Todo:
In order to make the API hard to misuse, this method might be made private.
See also:
LogicModel::add_template_port

Definition at line 119 of file GateTemplate.cc.

References ports.

                                                                         {
  if(!template_port->has_valid_object_id())
    throw InvalidObjectIDException("Error in GateTemplate::add_template_port(). "
                                   "The object ID is invalid.");
  ports.insert(template_port);
}
void GateTemplate::cloneDeepInto ( DeepCopyable_shptr  dest,
oldnew_t oldnew 
) const [virtual]
Todo:
Determine whether 'images' must be deep-cloned.

(For now, it is not deep-cloned.)

Reimplemented from degate::ColoredObject.

Definition at line 65 of file GateTemplate.cc.

References images, and ports.

                                                                                {
  auto clone = std::dynamic_pointer_cast<GateTemplate>(dest);
  
  // ports
  std::transform(ports.begin(), ports.end(), std::inserter(clone->ports, clone->ports.begin()), [&](const GateTemplatePort_shptr &v) {
    return std::dynamic_pointer_cast<GateTemplatePort>(v->cloneDeep(oldnew));
  });
  
  // images
  clone->images = images;
  
  ColoredObject::cloneDeepInto(dest, oldnew);
  LogicModelObjectBase::cloneDeepInto(dest, oldnew);
}

Return a copy of this object, but with all references to other DeepCopyables cleared (e.g.

set to 0-pointer).

Implements degate::DeepCopyable.

Definition at line 53 of file GateTemplate.cc.

References bounding_box, implementations, logic_class, and reference_counter.

                                                    {
  auto clone = std::make_shared<GateTemplate>();
  clone->bounding_box = bounding_box;
  clone->reference_counter = reference_counter;
  clone->implementations = implementations;
  clone->logic_class = logic_class;
  return clone;
}
void GateTemplate::decrement_reference_counter ( ) [protected, virtual]

Decrement the reference counter.

Definition at line 32 of file GateTemplate.cc.

References reference_counter.

BoundingBox const & GateTemplate::get_bounding_box ( ) const [virtual]

Get the bounding box of the template.

Deprecated:

Definition at line 96 of file GateTemplate.cc.

References bounding_box.

                                                         {
  return bounding_box;
}
unsigned int GateTemplate::get_height ( ) const [virtual]

Get the height of a gate template.

Definition at line 84 of file GateTemplate.cc.

References bounding_box, and degate::BoundingBox::get_height().

                                            {
  return bounding_box.get_height();
}

Here is the call graph for this function:

Get a reference image for the template.

See also:
set_image()
Exceptions:
CollectionLookupExceptionThrows this exception, if there is no image.

Definition at line 108 of file GateTemplate.cc.

References images.

                                                                          {
  image_collection::iterator found = images.find(layer_type);
  if(found == images.end())
    throw CollectionLookupException("Can't find reference image.");
  else return (*found).second;
}
std::string GateTemplate::get_impl_type_as_string ( IMPLEMENTATION_TYPE  impl_type) [static]

Convert an implementation-type constant to a printable string.

Definition at line 248 of file GateTemplate.cc.

References TEXT, VERILOG, VERILOG_TESTBENCH, VHDL, and VHDL_TESTBENCH.

                                                                             {
  switch(impl_type) {
  case TEXT:
    return std::string("text");
  case VHDL:
    return std::string("vhdl");
  case VHDL_TESTBENCH:
    return std::string("vhdl-testbench");
  case VERILOG:
    return std::string("verilog");
  case VERILOG_TESTBENCH:
    return std::string("verilog-testbench");
  default:
    return std::string("undefined");
  }
}
GateTemplate::IMPLEMENTATION_TYPE GateTemplate::get_impl_type_from_string ( std::string const &  impl_type_str) [static]

Convert an implementation type string to a correspondig constant.

Exceptions:
DegateRuntimeExceptionThrows this exception, if the string cannot be parsed.

Definition at line 265 of file GateTemplate.cc.

References TEXT, UNDEFINED, VERILOG, VERILOG_TESTBENCH, VHDL, and VHDL_TESTBENCH.

                                                                                                      {

  if(impl_type_str == "text") return TEXT;
  else if(impl_type_str == "vhdl") return VHDL;
  else if(impl_type_str == "vhdl-testbench") return VHDL_TESTBENCH;
  else if(impl_type_str == "verilog") return VERILOG;
  else if(impl_type_str == "verilog-testbench") return VERILOG_TESTBENCH;
  else if(impl_type_str == "undefined" ||
          impl_type_str == "") return UNDEFINED;
  else {
    boost::format f("Can't parse implementation type '%1%'.");
    f % impl_type_str;
    throw DegateRuntimeException(f.str());
  }
}
std::string GateTemplate::get_implementation ( IMPLEMENTATION_TYPE  impl_type) const

Get code for an implementation type.

Exceptions:
CollectionLookupExceptionThrows an exception, if there is no code for the requested type.

Definition at line 204 of file GateTemplate.cc.

References implementations.

                                                                              {

  implementation_collection::const_iterator found = implementations.find(impl_type);
  if(found == implementations.end()) {
    throw CollectionLookupException("There is no implementation for the requested type");
  }
  else
    return found->second;
}
std::string GateTemplate::get_logic_class ( ) const [virtual]

Get logic class for a standard cell.

Definition at line 286 of file GateTemplate.cc.

References logic_class.

                                              {
  return logic_class;
}
unsigned int GateTemplate::get_number_of_ports ( ) const [virtual]

Get number of defined ports.

Definition at line 242 of file GateTemplate.cc.

References ports.

                                                     {
  return ports.size();
}
unsigned int GateTemplate::get_reference_counter ( ) const [virtual]

Get the reference counter.

Returns:
Returns how many gates reference this gate template.

Definition at line 195 of file GateTemplate.cc.

References reference_counter.

                                                       {
  return reference_counter;
}

Get a template port.

Exceptions:
InvalidObjectIDExceptionThis exception is thrown if the object ID is invalid.
CollectionLookupExceptionThis exception is thrown if a template port with object ID object_id was not found.

Definition at line 150 of file GateTemplate.cc.

References degate::LogicModelObjectBase::object_id, and ports.

                                                                            {

  if(object_id == 0)
    throw InvalidObjectIDException("Error in GateTemplate::get_template_port(). "
                                   "The object ID is invalid.");

  for(port_iterator iter = ports.begin(); iter != ports.end(); ++iter) {
    if((*iter)->get_object_id() == object_id) {
      return *iter;
    }
  }
  throw CollectionLookupException("The gate template has no template port with that ID.");
}
unsigned int GateTemplate::get_width ( ) const [virtual]

Get the width of a gate template.

Definition at line 80 of file GateTemplate.cc.

References bounding_box, and degate::BoundingBox::get_width().

                                           {
  return bounding_box.get_width();
}

Here is the call graph for this function:

bool GateTemplate::has_image ( Layer::LAYER_TYPE  layer_type) const [virtual]

Check if there is a reference image for a layer type.

Definition at line 115 of file GateTemplate.cc.

References images.

                                                             {
  return images.find(layer_type) != images.end();
}
bool GateTemplate::has_template_port ( object_id_t  object_id) const [virtual]

Check if a template has a specific template port.

Exceptions:
InvalidObjectIDExceptionThis exception is thrown if the object ID is invalid.

Definition at line 164 of file GateTemplate.cc.

References degate::LogicModelObjectBase::object_id, and ports.

                                                                {
  if(object_id == 0)
    throw InvalidObjectIDException("Error in GateTemplate::get_template_port(). "
                                   "The object ID is invalid.");

  for(port_iterator iter = ports.begin(); iter != ports.end(); ++iter) {
    if((*iter)->get_object_id() == object_id) {
      return true;
    }
  }
  return false;
}

Get an iterator to iterate over images.

Definition at line 185 of file GateTemplate.cc.

References images.

Referenced by print().

                                                      {
  return images.begin();
}

Here is the caller graph for this function:

Get end marker for the iteration over images.

Definition at line 189 of file GateTemplate.cc.

References images.

Referenced by print().

                                                    {
  return images.end();
}

Here is the caller graph for this function:

Get an iterator to iterate over implementations.

Definition at line 214 of file GateTemplate.cc.

References implementations.

                                                                    {
  return implementations.begin();
}

Get an end marker for the iteration.

Definition at line 218 of file GateTemplate.cc.

References implementations.

                                                                  {
  return implementations.end();
}
void GateTemplate::increment_reference_counter ( ) [protected, virtual]

Increment the reference counter.

Definition at line 28 of file GateTemplate.cc.

References reference_counter.

Get an iterator.

Definition at line 177 of file GateTemplate.cc.

References ports.

                                                    {
  return ports.begin();
}

Get end marker for the iteration over ports.

Definition at line 181 of file GateTemplate.cc.

References ports.

                                                  {
  return ports.end();
}
void GateTemplate::print ( std::ostream &  os) [virtual]

Print gate template's meta information to an output stream.

Definition at line 222 of file GateTemplate.cc.

References degate::LogicModelObjectBase::get_description(), degate::Layer::get_layer_type_as_string(), degate::LogicModelObjectBase::get_name(), degate::LogicModelObjectBase::get_object_id(), images_begin(), and images_end().

                                        {
  os
    << "Gate template name    : " << get_name() << std::endl
    << "Gate template descr.  : " << get_description() << std::endl
    << "Gate object ID        : " << get_object_id() << std::endl
    << std::endl
    ;

  for(image_iterator img_i = images_begin(); img_i != images_end(); ++img_i) {
    Layer::LAYER_TYPE layer_type = (*img_i).first;

    os
      << "Image for layer of type  : " << Layer::get_layer_type_as_string(layer_type) << std::endl
      << std::endl
      ;
  }

}

Here is the call graph for this function:

Remove a port from a gate template.

This is an isolated function. The port is just removed from the gate template. Nothing else. Removing a port from a template requires some updates in the logic model. Therefore you should prefer the corresponding method from the LogicModel class.

Todo:
In order to make the API hard to misuse, this method might be made private.
See also:
LogicModel::remove_template_port

Definition at line 127 of file GateTemplate.cc.

References ports.

                                                                            {
  assert(template_port->has_valid_object_id());
  return ports.erase(template_port) > 0;
}
bool GateTemplate::remove_template_port ( object_id_t  object_id) [virtual]

Remove a port from a gate template.

Exceptions:
InvalidObjectIDExceptionThis exception is thrown if the template port has no valid object ID.
See also:
remove_template_port(GateTemplatePort_shptr template_port)

Definition at line 133 of file GateTemplate.cc.

References degate::LogicModelObjectBase::object_id, and ports.

                                                             {
  if(object_id == 0)
    throw InvalidObjectIDException("Error in GateTemplate::remove_template_port(). "
                                   "The object ID is invalid.");

  for(port_iterator iter = ports.begin(); iter != ports.end(); ++iter) {
    if((*iter)->get_object_id() == object_id) {
      ports.erase(iter);
      return true;
    }
  }
  assert(1 == 0); // should not reach this line
  return false;
}
void GateTemplate::set_height ( unsigned int  height) [virtual]

Set the height of a gate template.

It does not adjust dimensions of gates that reference this template.

Definition at line 92 of file GateTemplate.cc.

References bounding_box, degate::BoundingBox::get_min_y(), and degate::BoundingBox::set_max_y().

Here is the call graph for this function:

void GateTemplate::set_image ( Layer::LAYER_TYPE  layer_type,
GateTemplateImage_shptr  img 
) [virtual]

Set a reference image for the template.

You can store reference images for different layers, that is for the transistor layer, for the logic layer and for a metal layer. The images must have equal image dimensions. It is not checked here.

Todo:
: Here we might need a hook for storing different image types, e.g. a template image that is an average image or sth. like that.
Exceptions:
InvalidPointerExceptionThrows this excpetion, if img is NULL.

Definition at line 101 of file GateTemplate.cc.

References debug(), images, and TM.

                                                                                    {
  if(img == NULL) throw InvalidPointerException("Invalid pointer for image.");
  debug(TM, "set image for template.");
  images[layer_type] = img;
}

Here is the call graph for this function:

void GateTemplate::set_implementation ( IMPLEMENTATION_TYPE  impl_type,
std::string const &  code 
) [virtual]

Set VHDL/Verilog implementation for the gate template.

Parameters:
impl_typeSet VHDL or Verilog.
codeThe implementation.

Definition at line 200 of file GateTemplate.cc.

References implementations.

                                                                                          {
  implementations[impl_type] = code;
}
void GateTemplate::set_logic_class ( std::string const &  logic_class) [virtual]

Set logic class for a standard cell.

There are two reasons for having this kind of tagging. First we want to render dedicated electronic symbols for standard gates, e.g. nands, xors and flipflops, independed of the standard cells name. Second we want to search for common building blocks, e.g. linear feedback shift registers, that we basically describe as a set of connected flipflops with some xor gates between them, independend of the gate's naming.

Definition at line 281 of file GateTemplate.cc.

References logic_class.

                                                               {
  this->logic_class = logic_class;
}
void GateTemplate::set_width ( unsigned int  width) [virtual]

Set the width of a gate template.

It does not adjust dimensions of gates that reference this template.

Definition at line 88 of file GateTemplate.cc.

References bounding_box, degate::BoundingBox::get_min_x(), and degate::BoundingBox::set_max_x().

Here is the call graph for this function:


Friends And Related Function Documentation

friend class Gate [friend]

Definition at line 44 of file GateTemplate.h.


Member Data Documentation

Definition at line 74 of file GateTemplate.h.

Referenced by cloneDeepInto(), get_image(), has_image(), images_begin(), images_end(), and set_image().

std::string degate::GateTemplate::logic_class [private]

Definition at line 76 of file GateTemplate.h.

Referenced by cloneShallow(), get_logic_class(), and set_logic_class().


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