OpenASIP  2.0
Static Public Member Functions | List of all members
ProGe::NetlistTools Class Reference

#include <NetlistTools.hh>

Collaboration diagram for ProGe::NetlistTools:
Collaboration graph

Static Public Member Functions

static std::pair< const BaseNetlistBlock *, size_t > commonParent (const BaseNetlistBlock &b1, const BaseNetlistBlock &b2)
 
static void addPrefixToPortNames (NetlistPortGroup &portGroup, const std::string &prefix)
 
static void addPrefixToPortName (NetlistPort &port, const std::string &prefix)
 
static size_t renamePorts (NetlistPortGroup &portGroup, std::map< SignalType, const std::string > &&renameRules)
 
static std::string getUniqueInstanceName (const BaseNetlistBlock &within, const std::string &basename)
 
static const BaseNetlistBlockparent (const BaseNetlistBlock &block)
 
static const BaseNetlistBlockparent (const BaseNetlistBlock *block)
 
static Direction mirror (Direction direction)
 
static NetlistPortmirror (NetlistPort *port)
 

Detailed Description

Definition at line 52 of file NetlistTools.hh.

Member Function Documentation

◆ addPrefixToPortName()

void ProGe::NetlistTools::addPrefixToPortName ( NetlistPort port,
const std::string &  prefix 
)
static

Renames port by adding prefix into it.

Definition at line 117 of file NetlistTools.cc.

118  {
119  port.rename(prefix + port.name());
120 }

References ProGe::NetlistPort::name(), and ProGe::NetlistPort::rename().

Referenced by addPrefixToPortNames().

Here is the call graph for this function:

◆ addPrefixToPortNames()

void ProGe::NetlistTools::addPrefixToPortNames ( NetlistPortGroup portGroup,
const std::string &  prefix 
)
static

Renames ports by adding prefix into them.

Definition at line 106 of file NetlistTools.cc.

107  {
108  for (NetlistPort* port : portGroup) {
109  addPrefixToPortName(*port, prefix);
110  }
111 }

References addPrefixToPortName().

Here is the call graph for this function:

◆ commonParent()

std::pair< const BaseNetlistBlock *, size_t > ProGe::NetlistTools::commonParent ( const BaseNetlistBlock b1,
const BaseNetlistBlock b2 
)
static

Finds common parent block of given netlist blocks and maximum distance to the common parent.

Distance is calculated how many times parent block pointer is needed to followed to get to the common parent block.

Returns
Returns found common parent and maximum distance to the parent as pair. The first member is the common parent and the second is the distance. If common parent has not found return (NULL, 0).

Definition at line 59 of file NetlistTools.cc.

60  {
61  // Todo check trivial cases: b1 id parent of b2 or vice versa.
62 
63  std::set<const BaseNetlistBlock*> parentChain;
64 
65  const BaseNetlistBlock* block = &b1;
66  do {
67  parentChain.insert(block);
68  } while ((block = parent(block)));
69 
70  const BaseNetlistBlock* found = NULL;
71  block = &b2;
72  do {
73  if (parentChain.count(block)) {
74  found = block;
75  break;
76  }
77  } while ((block = parent(block)));
78 
79  if (found == NULL) {
80  return std::make_pair(found, 0);
81  }
82 
83  size_t distance = 0;
84  block = &b1;
85  size_t hops = 0;
86  while (block != found) {
87  hops++;
88  block = parent(block);
89  }
90  distance = hops;
91  block = &b2;
92  hops = 0;
93  while (block != found) {
94  hops++;
95  block = parent(block);
96  }
97  distance = std::max(distance, hops);
98 
99  return std::make_pair(found, distance);
100 }

References parent().

Here is the call graph for this function:

◆ getUniqueInstanceName()

std::string ProGe::NetlistTools::getUniqueInstanceName ( const BaseNetlistBlock within,
const std::string &  basename 
)
static

Returns a string that is unique within the given netlist block.

That is, the string as instance name does not clash with any of the immediate sub block of the given netlist block.

Parameters
withinThe netlist block.
basenameThe string used as base for the instance name.
Returns
The unique instance name. May be the given base name if it itself is unique within the block. Otherwise the the returned string is base name postfixed with a running number.

Definition at line 155 of file NetlistTools.cc.

156  {
157  std::string name(basename);
158  while (within.hasSubBlock(name)) {
159  int postFixNumber = -1;
160  std::string::iterator it;
161  std::string::reverse_iterator rit;
162  for (rit = name.rbegin(); rit != name.rend(); rit++) {
163  std::locale loc;
164  if (!std::isdigit(*rit, loc)) {
165  it = rit.base(); // Points to first number digit or end().
166  break;
167  }
168  }
169  if (it != name.end()) {
170  postFixNumber = Conversion::toInt(std::string(it, name.end()));
171  }
172  postFixNumber++;
173  name.replace(it, name.end(), Conversion::toString(postFixNumber));
174  }
175  return name;
176 }

References ProGe::BaseNetlistBlock::hasSubBlock(), Conversion::toInt(), and Conversion::toString().

Referenced by ProGe::BaseNetlistBlock::addSubBlock().

Here is the call graph for this function:

◆ mirror() [1/2]

Direction ProGe::NetlistTools::mirror ( Direction  direction)
static

Returns given direction mirrored.

Definition at line 202 of file NetlistTools.cc.

202  {
203  switch (direction) {
204  case IN:
205  return OUT;
206  break;
207  case OUT:
208  return IN;
209  break;
210  case BIDIR:
211  return BIDIR;
212  break;
213  default:
214  assert(false && "Unregocnized direction.");
215  return IN;
216  }
217 }

References assert, ProGe::BIDIR, ProGe::IN, and ProGe::OUT.

Referenced by ProGe::PortFactory::createPort(), mirror(), and ProGe::NetlistPort::NetlistPort().

◆ mirror() [2/2]

NetlistPort * ProGe::NetlistTools::mirror ( NetlistPort port)
static

Mirrors ports direction.

Definition at line 223 of file NetlistTools.cc.

223  {
224  port->setDirection(mirror(port->direction()));
225  return port;
226 }

References ProGe::NetlistPort::direction(), mirror(), and ProGe::NetlistPort::setDirection().

Here is the call graph for this function:

◆ parent() [1/2]

const BaseNetlistBlock * ProGe::NetlistTools::parent ( const BaseNetlistBlock block)
static

Returns parent of the given block or NULL if the block does not have one.

Definition at line 182 of file NetlistTools.cc.

182  {
183  return parent(&block);
184 }

Referenced by commonParent().

◆ parent() [2/2]

const BaseNetlistBlock * ProGe::NetlistTools::parent ( const BaseNetlistBlock block)
static

Returns parent of the given block or NULL if the block does not have one.

Definition at line 190 of file NetlistTools.cc.

190  {
191  if (!block->hasParentBlock()) {
192  return NULL;
193  } else {
194  return &block->parentBlock();
195  }
196 }

References ProGe::BaseNetlistBlock::hasParentBlock(), and ProGe::BaseNetlistBlock::parentBlock().

Here is the call graph for this function:

◆ renamePorts()

size_t ProGe::NetlistTools::renamePorts ( NetlistPortGroup portGroup,
std::map< SignalType, const std::string > &&  renameRules 
)
static

Renames ports in netlist port group by given rules.

returns number of ports left renamed.

Definition at line 128 of file NetlistTools.cc.

130  {
131  size_t renamedCount = 0;
132  for (NetlistPort* port : portGroup) {
133  SignalType type = port->assignedSignal().type();
134  if (renameRules.count(type)) {
135  port->rename(renameRules.at(type));
136  renamedCount++;
137  }
138  }
139  return portGroup.portCount() - renamedCount;
140 }

The documentation for this class was generated from the following files:
ProGe::BIDIR
@ BIDIR
Bidirectional port.
Definition: ProGeTypes.hh:55
ProGe::NetlistTools::parent
static const BaseNetlistBlock * parent(const BaseNetlistBlock &block)
Definition: NetlistTools.cc:182
Conversion::toString
static std::string toString(const T &source)
assert
#define assert(condition)
Definition: Application.hh:86
ProGe::NetlistTools::addPrefixToPortName
static void addPrefixToPortName(NetlistPort &port, const std::string &prefix)
Definition: NetlistTools.cc:117
ProGe::OUT
@ OUT
Output port.
Definition: ProGeTypes.hh:54
ProGe::SignalType
SignalType
Definition: SignalTypes.hh:42
ProGe::NetlistTools::mirror
static Direction mirror(Direction direction)
Definition: NetlistTools.cc:202
Conversion::toInt
static int toInt(const T &source)
ProGe::IN
@ IN
Input port.
Definition: ProGeTypes.hh:53