torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
torc::packer::Unpacker Class Reference

#include <Unpacker.hpp>

+ Collaboration diagram for torc::packer::Unpacker:

Public Member Functions

 Unpacker (DesignSharedPtr &inDesignPtr)
 
virtual ~Unpacker (void)
 Virtual destructor. More...
 

Protected Types

typedef std::string string
 Imported type name. More...
 
typedef
torc::physical::DesignSharedPtr 
DesignSharedPtr
 Imported type name. More...
 
typedef
torc::physical::InstanceSharedPtrVector 
InstanceSharedPtrVector
 
typedef
torc::physical::Circuit::InstanceSharedPtrConstIterator 
InstanceSharedPtrConstIterator
 
typedef torc::architecture::DDB DDB
 
typedef torc::physical::ConfigMap ConfigMap
 
typedef std::map< std::string,
PrimitiveStructureSharedPtr
PrimitiveStructuresSharedPtrMap
 Map of PrimitiveStructure Shared Pointers. More...
 
typedef std::vector< const
torc::architecture::PrimitiveElementPin * > 
PrimitiveElementPinPtrVector
 Vector of Primitive Element Pin Pointers. More...
 
typedef std::map< const
torc::architecture::PrimitiveElementPin
*, PrimitiveElementPinPtrVector
CandidateNet
 Map of Candidate Nets. More...
 
typedef std::map< std::string,
const
PrimitiveStructure::PrimitiveElement * > 
NameToElementPtrMap
 Map of Primitive Element Name to Primitive Element. More...
 
typedef std::map< const
torc::architecture::PrimitiveElement
*, torc::physical::InstanceSharedPtr
ElementPtrToInstancePtrMap
 Map of Primitive Element Pointer to Instance Shared Pointer. More...
 

Protected Member Functions

virtual void initialize (void)
 Initialize this object based on the PrimitiveDef information. More...
 
void unpack (void)
 Default unpack function. More...
 
void unpack (InstanceSharedPtrConstIterator inBegin, InstanceSharedPtrConstIterator inEnd)
 Unpack function that takes Instance iterators as input. More...
 
bool findNextElement (const PrimitiveStructure &inPrimitiveStructure, const torc::architecture::PrimitiveElement &element, torc::physical::InstanceSharedPtr &inInstancePtr, NameToElementPtrMap &inUsedElements, std::vector< std::string > inInstanceInputPins, CandidateNet &inElementPinsForNet, const torc::architecture::PrimitiveElementPin *&outNetSourcePin, std::vector< torc::physical::InstanceSharedPtr > &outNewInstances, ElementPtrToInstancePtrMap &elementToInstanceMap)
 Function to find the next element. More...
 

Protected Attributes

PrimitiveStructuresSharedPtrMap mPrimitiveStructures
 
InstanceSharedPtrVector mInstances
 
DesignSharedPtr mDesignPtr
 
DDBmDDBPtr
 

Friends

class torc::packer::packer::UnpackerUnitTest
 Our unit test class has access to our internals. More...
 

Detailed Description

Definition at line 34 of file Unpacker.hpp.

Member Typedef Documentation

Map of Candidate Nets.

Definition at line 58 of file Unpacker.hpp.

Definition at line 49 of file Unpacker.hpp.

Definition at line 48 of file Unpacker.hpp.

Imported type name.

Definition at line 44 of file Unpacker.hpp.

Map of Primitive Element Pointer to Instance Shared Pointer.

Definition at line 64 of file Unpacker.hpp.

Map of Primitive Element Name to Primitive Element.

Definition at line 61 of file Unpacker.hpp.

Vector of Primitive Element Pin Pointers.

Definition at line 55 of file Unpacker.hpp.

Map of PrimitiveStructure Shared Pointers.

Definition at line 52 of file Unpacker.hpp.

typedef std::string torc::packer::Unpacker::string
protected

Imported type name.

Definition at line 42 of file Unpacker.hpp.

Constructor & Destructor Documentation

torc::packer::Unpacker::Unpacker ( DesignSharedPtr inDesignPtr)
inline

Definition at line 93 of file Unpacker.hpp.

93  : mDesignPtr(inDesignPtr), mDDBPtr(0) {
94  initialize();
95  }
virtual void initialize(void)
Initialize this object based on the PrimitiveDef information.
Definition: Unpacker.cpp:41
DesignSharedPtr mDesignPtr
Definition: Unpacker.hpp:69

+ Here is the call graph for this function:

virtual torc::packer::Unpacker::~Unpacker ( void  )
inlinevirtual

Virtual destructor.

Definition at line 98 of file Unpacker.hpp.

98 {}

Member Function Documentation

bool torc::packer::Unpacker::findNextElement ( const PrimitiveStructure inPrimitiveStructure,
const torc::architecture::PrimitiveElement element,
torc::physical::InstanceSharedPtr inInstancePtr,
NameToElementPtrMap inUsedElements,
std::vector< std::string >  inInstanceInputPins,
CandidateNet inElementPinsForNet,
const torc::architecture::PrimitiveElementPin *&  outNetSourcePin,
std::vector< torc::physical::InstanceSharedPtr > &  outNewInstances,
ElementPtrToInstancePtrMap elementToInstanceMap 
)
protected

Function to find the next element.

Definition at line 70 of file Unpacker.cpp.

80  {
81 
82  // if we have already seen and marked this element as used, return true immediately
83  if(inUsedElements.find(element.getName()) != inUsedElements.end()) return true;
84 
85  const PrimitiveElement* elementPtr = &element;
86  std::string elementName = element.getName();
87 //std::cout << "Current element -- >" << elementName << std::endl;
88  const PrimitiveElementPinArray& fetchNextElementPins = element.getPins();
89  PrimitiveElementPinArray::const_iterator fpp = fetchNextElementPins.begin();
90  PrimitiveElementPinArray::const_iterator fpe = fetchNextElementPins.end();
91  std::vector<std::string>::const_iterator instanceInputit;
92  bool result = false;
93  bool found = false;
94  bool isInverter = false;
95  bool isInputTerminal = false;
96  bool isOutputTerminal = false;
97  // Check if the current element is a terminal and check if it is input/output
98  if(inPrimitiveStructure.mTerminals.find(elementName)
99  != inPrimitiveStructure.mTerminals.end()) {
100  const PrimitivePinArray& primitivePins
101  = inPrimitiveStructure.mPrimitiveDefPtr->getPins();
102  int primitivePinIndex
103  = inPrimitiveStructure.mPrimitiveDefPtr->findPinIndexByName
104  (elementName);
105  const PrimitivePin& primitivePin = primitivePins[primitivePinIndex];
106  //look up pin
107  isInputTerminal = (!primitivePin.isOutput());
108  isOutputTerminal = (primitivePin.isOutput());
109  }
110  // if it is a used input terminal, return true
111  if(isInputTerminal){
112  instanceInputit = find(inInstanceInputPins.begin(),
113  inInstanceInputPins.end(), elementName);
114  if(instanceInputit != inInstanceInputPins.end()) {
115  inUsedElements[elementName]
116  = inPrimitiveStructure.mElements.find(elementName)->second;
117  return true;
118  } else {
119  return false;
120  }
121  }
122  // look up config settings for the current element
123  std::string cfgName;
124  std::string cfgSetting;
125  bool hasConfig = inInstancePtr->getConfig(elementName, cfgName, cfgSetting);
126  //std::cout << "Config Name: " << elementName << " " << cfgName << " "
127  //<< cfgSetting << std::endl;
128 
129  int pinIndex;
130  const PrimitiveElementPin* invPtr;
131  // Check is the current element is a MUX
132  if(inPrimitiveStructure.mMuxes.find(elementName)
133  != inPrimitiveStructure.mMuxes.end()){
134  // If the current element is a MUX and it has a config, then it *is* used
135  if(hasConfig){
136 //std::cout << "Next element *is* a MUX.. Recurse!" << std::endl;
137  pinIndex = element.findPinIndexByName(cfgSetting);
138  const PrimitiveElementPin* muxPtr
139  = fetchNextElementPins[pinIndex].getPrimitiveConn()
140  ->getSourcePtr();
141  invPtr = &fetchNextElementPins[pinIndex];
142 //std::cout << "Is this the Pin?: " << invPtr->getName() << std::endl;
143  // Check if it is an inverter
144  std::set<const PrimitiveElementPin*>::const_iterator it
145  = inPrimitiveStructure.mInvertedInputs.find(invPtr);
146  if(it != inPrimitiveStructure.mInvertedInputs.end()) {
147  outNetSourcePin = invPtr;
148  isInverter = true;
149  } else {
150  outNetSourcePin = muxPtr;
151  const PrimitiveElement* nextElementPtr2
152  = fetchNextElementPins[pinIndex].getPrimitiveConn()
153  ->getSourcePtr()->getElementPtr();
154  const PrimitiveElement& nextElement2 = *nextElementPtr2;
155  return findNextElement(inPrimitiveStructure, nextElement2,
156  inInstancePtr, inUsedElements,
157  inInstanceInputPins,
158  inElementPinsForNet,
159  outNetSourcePin, outNewInstances,
160  elementToInstanceMap);
161  }
162  // If the current element is a MUX and it does *NOT* have a config,
163  // then we discard the trace and move on
164  } else {
165  return false;
166  }
167  }
168  // Check if the *current* element is a power/ground element
169  if(inPrimitiveStructure.mPower.find(elementName)
170  != inPrimitiveStructure.mPower.end()){
171  result = true;
172  } else if(inPrimitiveStructure.mGround.find(elementName)
173  != inPrimitiveStructure.mGround.end()){
174  result = true;
175  }
176  // If the current element is a non-MUX and has a config,
177  // we add a new instance for that element
178  if(hasConfig) result = true;
179 //std::cout << "Next element is a NON-MUX element.. Get its Inputs!" << std::endl;
180 //std::cout << "Element Name: " << elementName << std::endl;
181  const PrimitiveElementPin* newNetSourcePin;
182  //Iterate through Element PINS
183  while(fpp < fpe) {
184 
185  const PrimitiveElementPin& fetchNextElementPin = *fpp++;
186  const PrimitiveElementPin* fetchNextElementPinPtr = &fetchNextElementPin;
187  if(!fetchNextElementPin.isInput()) continue;
188 //std::cout << "Element Pin Name: " << fetchNextElementPin.getName() << std::endl;
189  if(isInverter && (invPtr != fetchNextElementPinPtr)) continue;
190  // Tracing back using primitive Conn
191  const PrimitiveElement* nextElementPtr
192  = fetchNextElementPin.getPrimitiveConn()->getSourcePtr()
193  ->getElementPtr();
194  const PrimitiveElementPin* sourcePtr
195  = fetchNextElementPin.getPrimitiveConn()->getSourcePtr();
196  const PrimitiveElement& nextElement = *nextElementPtr;
197  std::string nextElementName = fetchNextElementPin.getPrimitiveConn()
198  ->getSourcePtr()->getElementPtr()->getName();
199 //std::cout << "Next Element: " << nextElementName << std::endl;
200 //std::cout << "Next Element Pin: " << sourcePtr->getName() << std::endl;
201 //std::cout << "Current Element Pin: " << fetchNextElementPin.getName() << std::endl;
202  // Check if the *next* element is a power/ground element
203  bool isPower = false;
204  if(inPrimitiveStructure.mPower.find(nextElementName)
205  != inPrimitiveStructure.mPower.end()){
206  isPower = true;
207  } else if(inPrimitiveStructure.mGround.find(nextElementName)
208  != inPrimitiveStructure.mGround.end()){
209  isPower = true;
210  }
211  newNetSourcePin = sourcePtr;
212  found = findNextElement(inPrimitiveStructure, nextElement, inInstancePtr,
213  inUsedElements, inInstanceInputPins,
214  inElementPinsForNet, newNetSourcePin,
215  outNewInstances, elementToInstanceMap);
216 
217  if(found) {
218 //std::cout << "Adding to the Candidate Net: " << newNetSourcePin->getName()
219 //<< "...." << fetchNextElementPinPtr->getName() << std::endl;
220  inElementPinsForNet[newNetSourcePin]
221  .push_back(fetchNextElementPinPtr);
222  }
223  result |= found && !isPower;
224  }
225  // If result is true (and the element is not an output terminal) add a new Instance
226  if (result && !isOutputTerminal){
227  //std::cout << "Adding a Used Element: " << elementName << std::endl;
228  inUsedElements[elementName] = inPrimitiveStructure.mElements.find
229  (elementName)->second;
230  string newName = inInstancePtr->getName();
231  newName = newName + ":" + elementName + ":" + cfgName;
232  // We don't have definitive types yet so giving it the element name.
233  string typeName = isInverter ? "INV" : elementName;
234  torc::physical::InstanceSharedPtr newInstancePtr
235  = torc::physical::Factory::newInstancePtr(newName, typeName,
236  "", "");
237  // Keeping the new instances in a vector to add them to the design later
238  outNewInstances.push_back(newInstancePtr);
239 //std::cout << "THIS IS A NEW INSTANCE: " << newInstancePtr->getName() << std::endl;
240  // Set the config for a new instance
241  newInstancePtr->setConfig(elementName, cfgName, cfgSetting);
242  std::map<std::string,
243  std::vector<const PrimitiveElement*> >::const_iterator it;
244  // For non-MUX elements, copy over the configs of the
245  // orphans into the unpacked design
246  if(inPrimitiveStructure.mFlops.find(elementName)
247  != inPrimitiveStructure.mFlops.end()
248  || inPrimitiveStructure.mLUTs.find(elementName)
249  != inPrimitiveStructure.mLUTs.end()){
250 
251  for(it = inPrimitiveStructure.mPrincipalsToOrphans.begin();
252  it != inPrimitiveStructure.mPrincipalsToOrphans.end(); it++){
253  if(it->first != elementName) continue;
254  for(std::vector<const PrimitiveElement*>
255  ::const_iterator iter = it->second.begin();
256  iter != it->second.end(); iter++){
257  const PrimitiveElement* orphanPtr = *iter;
258  const PrimitiveElement& orphan
259  = *orphanPtr;
260  std::string orphanName = orphan.getName();
261  std::string orphanCfgName,
262  orphanCfgSetting;
263  bool configForOrphan = inInstancePtr
264  ->getConfig(orphanName,
265  orphanCfgName,
266  orphanCfgSetting);
267  if(configForOrphan)
268  newInstancePtr->setConfig(
269  orphanName, orphanCfgName,
270  orphanCfgSetting);
271  }
272  }
273  }
274  elementToInstanceMap[elementPtr] = newInstancePtr;
275  return true;
276  }
277  return false;
278  }
bool isOutput(void) const
Returns true if this pin is a primitive output.
const const PrimitiveElementPin * const_iterator
Constant T iterator type.
Definition: Array.hpp:83
bool findNextElement(const PrimitiveStructure &inPrimitiveStructure, const torc::architecture::PrimitiveElement &element, torc::physical::InstanceSharedPtr &inInstancePtr, NameToElementPtrMap &inUsedElements, std::vector< std::string > inInstanceInputPins, CandidateNet &inElementPinsForNet, const torc::architecture::PrimitiveElementPin *&outNetSourcePin, std::vector< torc::physical::InstanceSharedPtr > &outNewInstances, ElementPtrToInstancePtrMap &elementToInstanceMap)
Function to find the next element.
Definition: Unpacker.cpp:70
PinIndex findPinIndexByName(const string &inName) const
Returns the pin index corresponding to the given pin name, or PinIndex::undefined() if the pin name d...
const PrimitiveConnSharedPtr getPrimitiveConn(void) const
Returns the primitive connection that includes this pin.
T * end(void)
Returns the non-constant end iterator.
Definition: Array.hpp:97
std::string string
const string & getName(void) const
Returns the name of the element.
PrimitiveElementPinArray & getPins(void)
Returns a non-constant array of element pins. This function should only be used by the Sites class d...
bool isInput(void) const
Returns true if this pin is a primitive input.
static InstanceSharedPtr newInstancePtr(const string &inName, const string &inType, const string &inTile, const string &inSite, EInstanceBonding inBonding=eInstanceBondingUnknown, InstanceReferenceSharedPtr inInstanceReferencePtr=InstanceReferenceSharedPtr())
Construct and return a new Instance shared pointer.
boost::shared_ptr< Instance > InstanceSharedPtr
Shared pointer encapsulation of an Instance.
Encapsulation of a primitive pin's name and flags. Primitive pins are logic site inputs or outputs...
Encapsulation of a primitive site element. Primitive elements are subcomponents of logic primitive s...
Encapsulation of a primitive element pin's name, flags, and element pointer. Primitive element pins ...
T * begin(void)
Returns the non-constant begin iterator.
Definition: Array.hpp:95

+ Here is the call graph for this function:

void torc::packer::Unpacker::initialize ( void  )
protectedvirtual

Initialize this object based on the PrimitiveDef information.

Definition at line 41 of file Unpacker.cpp.

41  {
42 
43 
44  torc::common::DeviceDesignator deviceDesignator(mDesignPtr->getDevice() +
45  mDesignPtr->getPackage()
46  + mDesignPtr->getSpeedGrade());
47  mDDBPtr = new DDB(deviceDesignator);
48  const Sites& sites = mDDBPtr->getSites();
49 
50  // look up the primitive def types
51  typedef const Array<const PrimitiveDef> PrimitiveDefArray;
52  PrimitiveDefArray& primitiveDefs = sites.getSiteTypes();
53  PrimitiveDefArray::const_iterator p = primitiveDefs.begin();
54  PrimitiveDefArray::const_iterator e = primitiveDefs.end();
55  while(p < e) {
56  // create a PrimitiveStructure object for this PrimitiveDef
57  PrimitiveStructureSharedPtr primitiveStructurePtr
58  (new Virtex5PrimitiveStructure(&*p++));
59  const torc::architecture::PrimitiveDef* primitiveDefPtr
60  = primitiveStructurePtr->getPrimitiveDefPtr();
61  const std::string& primitiveDefName = primitiveDefPtr->getName();
62  // insert the PrimitiveStructure into the map
63  if(primitiveDefName != "IOB" && primitiveDefName != "IOBM"
64  && primitiveDefName != "IOBS")
65  mPrimitiveStructures[primitiveDefName] = primitiveStructurePtr;
66  }
67  }
torc::architecture::DDB DDB
Definition: Unpacker.hpp:48
Encapsulation of a device designator and its constituent elements.
Encapsulation of primitive site definition, with associated connections, elements, and pins.
std::string string
const Array< const PrimitiveDef > & getSiteTypes(void) const
Returns the site types for this family.
Definition: Sites.hpp:125
Site type and population data for the family and the device.
Definition: Sites.hpp:45
const Array< const Site > & getSites(void) const
Returns the sites for this family.
Definition: Sites.hpp:127
PrimitiveStructuresSharedPtrMap mPrimitiveStructures
Definition: Unpacker.hpp:67
DesignSharedPtr mDesignPtr
Definition: Unpacker.hpp:69
boost::shared_ptr< PrimitiveStructure > PrimitiveStructureSharedPtr
Shared pointer encapsulation of a PrimitiveStructure.
Encapsulation of a static array.
Definition: Array.hpp:39
const string & getName(void) const
Returns the name of the primitive.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void torc::packer::Unpacker::unpack ( void  )
protected

Default unpack function.

Definition at line 281 of file Unpacker.cpp.

281  {
283  = mDesignPtr->instancesBegin();
285  = mDesignPtr->instancesEnd();
286  unpack(ip, ie);
287  }
InstanceSharedPtrVector::const_iterator InstanceSharedPtrConstIterator
Constant iterator to Instance shared pointers.
Definition: Circuit.hpp:72
void unpack(void)
Default unpack function.
Definition: Unpacker.cpp:281
DesignSharedPtr mDesignPtr
Definition: Unpacker.hpp:69
void torc::packer::Unpacker::unpack ( InstanceSharedPtrConstIterator  inBegin,
InstanceSharedPtrConstIterator  inEnd 
)
protected

Unpack function that takes Instance iterators as input.

Definition at line 290 of file Unpacker.cpp.

291  {
292  std::vector<torc::physical::InstanceSharedPtr> oldInstances;
293  std::vector<torc::physical::InstanceSharedPtr> newInstances;
294  std::vector<torc::physical::InstanceSharedPtr>::iterator instIt;
295  // Iterating through all the instances
296  while(ip < ie){
297 //std::cout << ">>>> ip: " << &ip << std::endl;
298  torc::physical::InstanceSharedPtr instancePtr = *ip++;
299  torc::physical::Instance& instance = *instancePtr;
300  std::string instanceType = instance.getType();
301  std::string instanceName = instance.getName();
302  CandidateNet elementPinsForNet;
303  CandidateNet::const_iterator it1;
304  // Maintining a list of used elements
305  NameToElementPtrMap usedElements;
306  NameToElementPtrMap::const_iterator it;
307  ElementPtrToInstancePtrMap elementToInstanceMap;
308  ElementPtrToInstancePtrMap::const_iterator elementToInstanceMapit;
309  std::vector<std::string> instanceInputPins;
310  std::vector<std::string> instanceOutputPins;
311  std::vector<std::string> usedPower;
312  std::vector<std::string> usedGround;
313  const PrimitiveElementPin* outNetSourcePin = 0;
314 
315 //std::cout << instanceName << std::endl;
316  PrimitiveStructuresSharedPtrMap::const_iterator pos;
317  // Finding the primitive structure that matches the instance type
318  pos = mPrimitiveStructures.find(instanceType);
319  if(pos != mPrimitiveStructures.end()){
320  // we need to retain this primitive structure!
321  const PrimitiveStructure& primitiveStructure = *(pos->second);
322  const PrimitiveDef* primitiveDefPtr
323  = primitiveStructure.getPrimitiveDefPtr();
324  // this should not happen for valid instances
325  if(primitiveDefPtr == 0) return;
326  const PrimitivePinArray& primitivePins
327  = primitiveDefPtr->getPins();
328 
334 
335  // iterate over the instance pins
336  InstancePinSharedPtrVector inputPins;
337  InstancePinSharedPtrVector outputPins;
338  Instance::InstancePinSharedPtrConstIterator ipp
339  = instancePtr->pinsBegin();
340  Instance::InstancePinSharedPtrConstIterator ipe
341  = instancePtr->pinsEnd();
342  InstancePinSharedPtr instancePinPtr;
343  NetSharedPtr netPtr;
344  while(ipp != ipe) {
345  // look up the instance pin
346  InstancePinSharedPtr instancePinPtr = ipp++->second;
347  const std::string& pinName = instancePinPtr->getPinName();
348  netPtr = instancePinPtr->getParentWeakPtr().lock();
349 //std::cout << " found " << pinName << " connected to net " << netPtr->getName() << ": ";
350  // determine whether the pin is an output or input
351  PinIndex pinIndex
352  = primitiveDefPtr->findPinIndexByName(pinName);
353  // this shouldn't happen
354  if(static_cast<boost::int32_t>(pinIndex) < 0) continue;
355  const PrimitivePin& primitivePin = primitivePins[pinIndex];
356  if(primitivePin.isInput())
357  inputPins.push_back(instancePinPtr);
358  if(primitivePin.isOutput())
359  outputPins.push_back(instancePinPtr);
360 //std::cout << (primitivePin.isInput() ? "INPUT" : (primitivePin.isOutput() ? "OUTPUT" : ""))
361 //<< std::endl;
362  }
363  // // iterate over the input pins
364  InstancePinSharedPtrVector::const_iterator ipp2;
365  InstancePinSharedPtrVector::const_iterator ipe2;
366  //InstancePinSharedPtr instancePinPtr;
367  ipp2 = inputPins.begin();
368  ipe2 = inputPins.end();
369  while(ipp2 != ipe2) {
370  InstancePinSharedPtr instancePinPtr = *ipp2++;
371  instanceInputPins.push_back(instancePinPtr->getPinName());
372 //std::cout << " found INPUT " << instancePinPtr->getPinName() << std::endl;
373  }
374  // iterate over the output pins
375  ipp2 = outputPins.begin();
376  ipe2 = outputPins.end();
377  while(ipp2 != ipe2) {
378  InstancePinSharedPtr instancePinPtr = *ipp2++;
379  instanceOutputPins.push_back(instancePinPtr->getPinName());
380  std::cout << " found OUTPUT " << instancePinPtr
381  ->getPinName() << std::endl;
382  std::string outPinName = instancePinPtr->getPinName();
383 //std::cout << "Used output terminal found:" << outPinName << std::endl;
384  const PrimitiveElement* elementPtr
385  = primitiveStructure.mTerminals.find(outPinName)
386  ->second;
387  const PrimitiveElement& element = *elementPtr;
388  findNextElement(primitiveStructure, element, instancePtr,
389  usedElements, instanceInputPins,
390  elementPinsForNet, outNetSourcePin,
391  newInstances, elementToInstanceMap);
392  }
393  // Iterating over the candidate nets
394  for(it1 = elementPinsForNet.begin();
395  it1 != elementPinsForNet.end(); it1++){
398  const PrimitiveElementPin* sourcePinPtr = it1->first;
399  std::string drivingElementName = sourcePinPtr
400  ->getElementPtr()->getName();
401  std::string sourcePinName = sourcePinPtr->getName();
402 //std::cout << drivingElementName << "." << sourcePinName << " ---->" << std::endl;
403  // Checking if the candidate net source is a terminal
404  if(primitiveStructure.mTerminals
405  .find(sourcePinPtr->getElementPtr()->getName())
406  != primitiveStructure.mTerminals.end()) {
407 //std::cout << "Source (terminal) Pin Name: " << sourcePinName << std::endl;
408  terminals.push_back(sourcePinPtr);
409  }
410  // Iterating over the candidate net sinks
411  for(PrimitiveElementPinPtrVector::const_iterator iter
412  = it1->second.begin(); iter
413  != it1->second.end(); iter++){
414  const PrimitiveElementPin* sinkPinPtr
415  = *iter;
416 //std::cout << "Sink Pin Element: " << sinkPinPtr->getElementPtr()->getName() << std::endl;
417  // Checking if the candidate net sinks
418  //are terminals
419  if(primitiveStructure.mTerminals.find(sinkPinPtr
420  ->getElementPtr()->getName())
421  != primitiveStructure.mTerminals.end()){
422  terminals.push_back(sinkPinPtr);
423  std::string sinkPinName
424  = sinkPinPtr->getName();
425 //std::cout << sinkPinPtr->getElementPtr()->getName() << "." << sinkPinName << std::endl;
426 //std::cout << "Terminal Pin Name: " << sinkPinName << std::endl;
427  }
428  }
429  // Number of terminals in the candidate net is
430  // more than one.. create a new net and collapse
431  // the old one
432  if(terminals.size() > 1){
433  std::string netName = instancePtr->getName()
434  + ":" + drivingElementName + ":"
435  + sourcePinName;
436  net = torc::physical::Factory::newNetPtr(netName);
437  for(std::vector<const PrimitiveElementPin*>
438  ::const_iterator iter
439  = terminals.begin();
440  iter != terminals.end(); iter++){
441  Instance::InstancePinSharedPtrConstIterator
442  pin = instancePtr
443  ->findPin(torc::physical
444  ::PinName(sourcePinPtr
445  ->getName()));
446  InstancePinSharedPtr pinPtr = pin->second;
448  = pinPtr
449  ->getParentWeakPtr().lock();
451  ::InstancePinSharedPtrIterator
452  netSourceIter = net2
453  ->sourcesBegin();
454  netSourceIter != net2->sourcesEnd();
455  netSourceIter++ ){
456  net->addSource(*netSourceIter);
457  }
459  ::InstancePinSharedPtrIterator
460  netSinkIter = net2
461  ->sourcesBegin();
462  netSinkIter != net2->sourcesEnd();
463  netSinkIter++ ){
464  net->addSink(*netSinkIter);
465  }
466  mDesignPtr->removeNet(net2);
467  }
468  // Number of terminals is one..
469  // get the net it is a part of..
470  // this is the net we *modify*
471  } else if(terminals.size() == 1){
472  Instance::InstancePinSharedPtrConstIterator pin
473  = instancePtr
474  ->findPin(torc::physical::PinName
475  (terminals.front()->getName()));
476  InstancePinSharedPtr pinPtr = pin->second;
477  net = pinPtr->getParentWeakPtr().lock();
478  net->unroute();
479  // No terminals in the candidate net..
480  // create a new net and add source and sink to it
481  } else {
482  //define a new net
483  std::cout << "Adding a new net" << std::endl;
484  std::string netName = instancePtr->getName()
485  + ":" + drivingElementName + ":"
486  + sourcePinName;
487  net = torc::physical::Factory::newNetPtr(netName);
488  mDesignPtr->addNet(net);
489  }
490  // For the source pin
491 //std::cout << "Adjusting net " << net->getName() << std::endl;
492  if(primitiveStructure.mTerminals.find(sourcePinPtr
493  ->getElementPtr()
494  ->getName())
495  != primitiveStructure.mTerminals.end()) {
496  Instance::InstancePinSharedPtrConstIterator pin1
497  = instancePtr
498  ->findPin(torc::physical::PinName
499  (sourcePinPtr->getName()));
500  InstancePinSharedPtr pin1Ptr = pin1->second;
501 //std::cout << "removing a terminal (sink) pin from the net: " << pin1Ptr->getPinName()
502 //<< std::endl;
503  net->removeSink(pin1Ptr);
504  }else{
505  torc::physical::InstanceSharedPtr instanceSourcePtr
506  = elementToInstanceMap.find(sourcePinPtr
507  ->getElementPtr())->second;
508  InstancePinSharedPtr instanceSourcePin
510  ::newInstancePinPtr(instanceSourcePtr,
511  sourcePinName);
512 //std::cout << "Adding source pin: " << instanceSourcePin->getPinName() << std::endl << std::endl;
513  net->addSource(instanceSourcePin);
514  }
515  const PrimitiveElementPinPtrVector& sinkVector
516  = it1->second;
517  //Iterate over the sink pins
519  ::const_iterator iter = sinkVector.begin();
520  iter != sinkVector.end(); iter++){
521  if(primitiveStructure.mTerminals.find((*iter)
522  ->getElementPtr()->getName())
523  != primitiveStructure.mTerminals.end()) {
524  Instance::InstancePinSharedPtrConstIterator
525  pin2 = instancePtr
526  ->findPin(torc::physical::PinName
527  ((*iter)->getName()));
528  InstancePinSharedPtr pin2Ptr
529  = pin2->second;
530  net->removeSource(pin2Ptr);
531 //std::cout << "removing a terminal (source) pin from the net: " << pin2Ptr->getPinName()
532 //<< std::endl;
533  }else{
535  instanceSinkPtr
536  = elementToInstanceMap.find((*iter)
537  ->getElementPtr())->second;
538  InstancePinSharedPtr instanceSinkPin
541  (instanceSinkPtr,
542  (*iter)->getName());
543 //std::cout << "INSTANCE SINK PIN: " << instanceSinkPin->getPinName() << std::endl << std::endl;
544  net->addSink(instanceSinkPin);
545  }
546  }
547  terminals.clear();
548  }
549  // remember to remove the original instance from the design
550  oldInstances.push_back(instancePtr);
551  }
552  // std::cout << "----------- USED ELEMENTS ------------" << std::endl;
553  // for(it = usedElements.begin(); it != usedElements.end(); it++){
554  // std::cout << " " << it->first << std::endl;
555  // }
556  }
557  std::cout << "-------------------- NEW INSTANCES -------------------" << std::endl;
558  for(instIt = newInstances.begin(); instIt != newInstances.end(); instIt++){
559  torc::physical::InstanceSharedPtr newInstancePtr = *instIt;
560  torc::physical::Instance newInstance = *newInstancePtr;
561  std::cout << " " << newInstance.getName() << std::endl;
562  mDesignPtr->addInstance(newInstancePtr);
563  }
564  std::cout << "-------------------- OLD INSTANCES -------------------" << std::endl;
565  for(instIt = oldInstances.begin(); instIt != oldInstances.end(); instIt++){
566  torc::physical::InstanceSharedPtr oldInstancePtr = *instIt;
567  torc::physical::Instance oldInstance = *oldInstancePtr;
568  std::cout << " " << oldInstance.getName() << std::endl;
569  mDesignPtr->removeInstance(oldInstancePtr);
570  }
571 
572  }
bool isOutput(void) const
Returns true if this pin is a primitive output.
InstancePinSharedPtrConstIterator sourcesEnd(void) const
Returns the end constant iterator for source instance pins.
bool findNextElement(const PrimitiveStructure &inPrimitiveStructure, const torc::architecture::PrimitiveElement &element, torc::physical::InstanceSharedPtr &inInstancePtr, NameToElementPtrMap &inUsedElements, std::vector< std::string > inInstanceInputPins, CandidateNet &inElementPinsForNet, const torc::architecture::PrimitiveElementPin *&outNetSourcePin, std::vector< torc::physical::InstanceSharedPtr > &outNewInstances, ElementPtrToInstancePtrMap &elementToInstanceMap)
Function to find the next element.
Definition: Unpacker.cpp:70
const string & getType(void) const
Returns the logic type for this instance.
Encapsulation of a site pin name.
Encapsulation of primitive site definition, with associated connections, elements, and pins.
static NetSharedPtr newNetPtr(const string &inName, ENetType inNetType=eNetTypeNormal)
Create and return a new Net share pointer.
std::vector< InstancePinSharedPtr > InstancePinSharedPtrVector
Vector of InstancePin shared pointers.
std::map< const torc::architecture::PrimitiveElement *, torc::physical::InstanceSharedPtr > ElementPtrToInstancePtrMap
Map of Primitive Element Pointer to Instance Shared Pointer.
Definition: Unpacker.hpp:64
bool isInput(void) const
Returns true if this pin is a primitive input.
Encapsulation of a pin index in an unsigned 32-bit integer.
PinIndex findPinIndexByName(const std::string &inName) const
Returns the pin index corresponding to the given pin name, or PinIndex::undefined() if the pin name d...
boost::shared_ptr< class InstancePin > InstancePinSharedPtr
Shared pointer encapsulation of an InstancePin.
const string & getName(void) const
Returns the pin name.
std::string string
const string & getName(void) const
Returns the name of the element.
std::map< const torc::architecture::PrimitiveElementPin *, PrimitiveElementPinPtrVector > CandidateNet
Map of Candidate Nets.
Definition: Unpacker.hpp:58
std::vector< InstancePinSharedPtr > InstancePinSharedPtrVector
Vector of InstancePin shared pointers.
Physical design instance.
boost::shared_ptr< Net > NetSharedPtr
const PrimitiveElement * getElementPtr(void) const
Returns a pointer to the primitive element that owns this pin.
Physical design net.
std::map< std::string, const PrimitiveStructure::PrimitiveElement * > NameToElementPtrMap
Map of Primitive Element Name to Primitive Element.
Definition: Unpacker.hpp:61
const string & getName(void) const
Returns the object name.
Definition: Named.hpp:51
boost::shared_ptr< Net > NetSharedPtr
Shared pointer encapsulation of a Net.
PrimitivePinArray & getPins(void)
Returns a non-constant array of element pins. This function should only be used by the Sites class d...
boost::shared_ptr< Instance > InstanceSharedPtr
Shared pointer encapsulation of an Instance.
Encapsulation of a primitive pin's name and flags. Primitive pins are logic site inputs or outputs...
Encapsulation of a primitive site element. Primitive elements are subcomponents of logic primitive s...
Encapsulation of a primitive element pin's name, flags, and element pointer. Primitive element pins ...
PrimitiveStructuresSharedPtrMap mPrimitiveStructures
Definition: Unpacker.hpp:67
T * begin(void)
Returns the non-constant begin iterator.
Definition: Array.hpp:95
DesignSharedPtr mDesignPtr
Definition: Unpacker.hpp:69
static InstancePinSharedPtr newInstancePinPtr(InstanceSharedPtr inInstancePtr, const string &inPinName)
Construct and return a new InstancePin shared pointer.
std::vector< const PrimitiveElementPin * > PrimitiveElementPinPtrVector
Vector of constant PrimitiveElementPin pointers.
boost::shared_ptr< InstancePin > InstancePinSharedPtr
Shared pointer encapsulation of an InstancePin.

+ Here is the call graph for this function:

Friends And Related Function Documentation

friend class torc::packer::packer::UnpackerUnitTest
friend

Our unit test class has access to our internals.

Definition at line 38 of file Unpacker.hpp.

Field Documentation

DDB* torc::packer::Unpacker::mDDBPtr
protected

Definition at line 70 of file Unpacker.hpp.

DesignSharedPtr torc::packer::Unpacker::mDesignPtr
protected

Definition at line 69 of file Unpacker.hpp.

InstanceSharedPtrVector torc::packer::Unpacker::mInstances
protected

Definition at line 68 of file Unpacker.hpp.

PrimitiveStructuresSharedPtrMap torc::packer::Unpacker::mPrimitiveStructures
protected

Definition at line 67 of file Unpacker.hpp.


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