19 #ifndef TORC_PHYSICAL_MODULETRANSFORMER_HPP
20 #define TORC_PHYSICAL_MODULETRANSFORMER_HPP
24 #include <boost/lexical_cast.hpp>
27 using namespace torc::architecture;
28 using namespace torc::architecture::xilinx;
69 eNetConnectivityNotConnected = 0, eNetConnectivityInternal, eNetConnectivityExternal
148 const string& inModuleDefinitionName,
const string& inModuleInstanceName,
149 bool inKeepPlacement =
false,
bool inKeepRouting =
false) {
157 if(inInstanceSharedPtrConstIter == inInstanceSharedPtrConstEnd) {
160 std::clog <<
"WARNING: There were no instances specified to be modularized. "
171 ModuleSharedPtr moduleDefinition = Factory::newModulePtr(inModuleDefinitionName,
172 moduleReferenceInst->getName());
175 inModuleDefinitionName, moduleReferenceInst->getTile(),
176 moduleReferenceInst->getSite());
179 if(!inKeepPlacement) moduleInst->unplace();
183 while(inInstanceSharedPtrConstIter != inInstanceSharedPtrConstEnd) {
190 = mDesignPtr->findInstance(instPtr->getName());
193 if(instPtrIter == mDesignPtr->instancesEnd()) {
196 std::clog <<
"WARNING: Instance " << instPtr->getName()
197 <<
"was not found in design " << mDesignPtr->getName() << std::endl;
207 if(!inKeepPlacement) designInstPtr->unplace();
210 moduleDefinition->addInstance(designInstPtr);
212 mDesignPtr->removeInstance(designInstPtr);
215 inInstanceSharedPtrConstIter++;
227 = moduleDefinition->instancesBegin();
230 = moduleDefinition->instancesEnd();
237 while(designNetsIter != designNetsEnd) {
243 modHostedInstPtrConstEnd, designNetPtr);
246 if(eNet == eNetConnectivityInternal) {
249 if(!inKeepRouting) designNetPtr->unroute();
252 moduleDefinition->addNet(designNetPtr);
254 mDesignPtr->removeNet(designNetPtr);
256 designNetsEnd = mDesignPtr->netsEnd();
261 if(eNet == eNetConnectivityNotConnected) {
271 if(!inKeepRouting) designNetPtr->unroute();
275 = designNetPtr->sourcesBegin();
279 u_int32_t portIndex = 0;
282 while(designNetSourcesIter != designNetSourcesEnd) {
290 if((std::find(modHostedInstPtrConstBegin, modHostedInstPtrConstEnd,
291 pinInstPtr)) != modHostedInstPtrConstEnd) {
294 string portName = sanitizePinName(designNetPtr->getName())
295 + sPortIndexSeparator
296 + boost::lexical_cast<std::string>(portIndex++);
298 PortSharedPtr portPtr = Factory::newPortPtr(portName, *(std::find(
299 modHostedInstPtrConstBegin, modHostedInstPtrConstEnd,
300 pinInstPtr)), instPinPtr->getPinName());
302 moduleDefinition->addPort(portPtr);
304 modInstSourcePinPtrVector.push_back(
305 Factory::newInstancePinPtr(moduleInst, portName));
307 designNetPtr->removeSource(instPinPtr);
309 designNetSourcesEnd = designNetPtr->sourcesEnd();
314 designNetSourcesIter++;
321 modInstSourcePinPtrVector.begin();
324 modInstSourcePinPtrVector.end();
327 while(modInstSourcesIter != modInstSourcesEnd) {
330 designNetPtr->addSource(*modInstSourcesIter);
332 modInstSourcesIter++;
337 modInstSourcePinPtrVector.clear();
344 while(designNetSinksIter != designNetSinksEnd) {
352 if((std::find(modHostedInstPtrConstBegin, modHostedInstPtrConstEnd,
353 pinInstPtr)) != modHostedInstPtrConstEnd) {
356 string portName = sanitizePinName(designNetPtr->getName())
357 + sPortIndexSeparator + boost::lexical_cast<std::string>(
360 PortSharedPtr portPtr = Factory::newPortPtr(portName, *(std::find(
361 modHostedInstPtrConstBegin, modHostedInstPtrConstEnd,
362 pinInstPtr)), instPinPtr->getPinName());
364 moduleDefinition->addPort(portPtr);
366 modInstSinkPinPtrVector.push_back(Factory::newInstancePinPtr(
367 moduleInst, portName));
369 designNetPtr->removeSink(instPinPtr);
371 designNetSinksEnd = designNetPtr->sinksEnd();
376 designNetSinksIter++;
383 modInstSinkPinPtrVector.begin();
386 modInstSinkPinPtrVector.end();
389 while(modInstSinksIter != modInstSinksEnd) {
392 designNetPtr->addSink(*modInstSinksIter);
399 modInstSinkPinPtrVector.clear();
409 mDesignPtr->addModule(moduleDefinition);
411 mDesignPtr->addInstance(moduleInst);
481 bool flatten(
const string& inModuleInstanceName,
bool inKeepPlacement =
false,
482 bool inKeepRouting =
false) {
490 = mDesignPtr->findInstance(inModuleInstanceName);
493 if(designModInstPtrConstIter == mDesignPtr->instancesEnd()) {
496 std::clog <<
"WARNING: Module instance of name " << inModuleInstanceName
497 <<
" was not found in design " << mDesignPtr->getName() <<
"." << std::endl;
508 = mDesignPtr->findModule(instPtr->getType());
511 if(designModPtrConstIter == mDesignPtr->modulesEnd()) {
514 std::clog <<
"WARNING: Module of name " << instPtr->getType()
515 <<
" was not found in design " << mDesignPtr->getName() <<
"." << std::endl;
529 = module->findInstance(module->getAnchor());
538 while(moduleInstancesIter != moduleInstancesEnd) {
546 modInstPtrClone->setInstanceReferencePtr(Factory::newInstanceReferencePtr(
547 inModuleInstanceName, module, modInstPtr));
550 if(!inKeepPlacement) modInstPtrClone->unplace();
553 mDesignPtr->addInstance(modInstPtrClone);
556 moduleInstancesIter++;
568 while(moduleNetsIter != moduleNetsEnd) {
573 NetSharedPtr moduleNetPtrClone = cloneNet(moduleNetPtr, inModuleInstanceName
577 if(!inKeepRouting) moduleNetPtrClone->unroute();
580 mDesignPtr->addNet(moduleNetPtrClone);
593 while(designNetsIter != designNetsEnd) {
604 while(designNetSourcesIter != designNetSourcesEnd) {
612 if(pinInstPtr == instPtr) {
615 if(!inKeepRouting) designNetPtr->unroute();
619 = module->findPort(instPinPtr->getPinName());
622 if(modulePortConstIter != module->portsEnd()) {
630 = mDesignPtr->findInstance(inModuleInstanceName
633 flattenedModuleSourcePinPtrVector.push_back(
634 Factory::newInstancePinPtr(*pinInstPtrCloneItr,
635 modPortPtr->getPinName()));
637 designNetPtr->removeSource(instPinPtr);
639 designNetSourcesEnd = designNetPtr->sourcesEnd();
646 designNetSourcesIter++;
653 = flattenedModuleSourcePinPtrVector.begin();
656 = flattenedModuleSourcePinPtrVector.end();
659 while(flattenedModuleSourcesIter != flattenedModuleSourcesEnd) {
662 designNetPtr->addSource(*flattenedModuleSourcesIter);
664 flattenedModuleSourcesIter++;
668 flattenedModuleSourcePinPtrVector.clear();
675 while(designNetSinksIter != designNetSinksEnd) {
683 if(pinInstPtr == instPtr) {
686 if(!inKeepRouting) designNetPtr->unroute();
690 = module->findPort(instPinPtr->getPinName());
693 if(modulePortConstIter != module->portsEnd()) {
701 = mDesignPtr->findInstance(inModuleInstanceName
704 flattenedModuleSinkPinPtrVector.push_back(
705 Factory::newInstancePinPtr(*pinInstPtrCloneItr,
706 modPortPtr->getPinName()));
708 designNetPtr->removeSink(instPinPtr);
710 designNetSinksEnd = designNetPtr->sinksEnd();
716 designNetSinksIter++;
723 = flattenedModuleSinkPinPtrVector.begin();
726 = flattenedModuleSinkPinPtrVector.end();
729 while(flattenedModuleSinksBegin != flattenedModuleSinksEnd) {
732 designNetPtr->addSink(*flattenedModuleSinksBegin);
734 flattenedModuleSinksBegin++;
739 flattenedModuleSinkPinPtrVector.clear();
748 mDesignPtr->removeInstance(instPtr);
767 bool isNetConnectedToModule =
false;
769 bool isNetInterToModule =
false;
776 while(sourcesBegin != sourcesEnd) {
784 if((std::find(inInstanceSharedPtrConstBegin, inInstanceSharedPtrConstEnd, pinInst))
785 != inInstanceSharedPtrConstEnd) {
788 isNetConnectedToModule =
true;
793 isNetInterToModule =
true;
807 while(sinksBegin != sinksEnd) {
814 if((std::find(inInstanceSharedPtrConstBegin, inInstanceSharedPtrConstEnd, pinInst))
815 != inInstanceSharedPtrConstEnd) {
817 isNetConnectedToModule =
true;
820 isNetInterToModule =
true;
826 if(isNetConnectedToModule) {
827 if(isNetInterToModule) {
828 netConnectivity = eNetConnectivityExternal;
830 netConnectivity = eNetConnectivityInternal;
835 return netConnectivity;
843 string sanitizedPinName;
846 for(u_int32_t i = 0; i < inPinName.length(); i++) {
849 if(boost::regex_match(inPinName.substr(i, 1), sValidPinNameCharactersRegEx)) {
850 sanitizedPinName += inPinName.substr(i, 1);
855 while(sanitizedPinName.size() > 0 && boost::regex_match(sanitizedPinName.substr(0, 1),
856 sInvalidPinNameFirstCharactersRegEx)) {
859 sanitizedPinName = sanitizedPinName.substr(1, sanitizedPinName.size() - 1);
864 return sanitizedPinName;
873 const string& inCloneInstanceName) {
876 InstanceSharedPtr inInstanceClonePtr = Factory::newInstancePtr(inCloneInstanceName,
877 inIntancePtr->getType(), inIntancePtr->getTile(), inIntancePtr->getSite(),
878 inIntancePtr->getBonding());
889 while(instanceConfigBegin != instanceConfigEnd) {
892 const string setting = instanceConfigBegin->first;
894 const Config config = instanceConfigBegin->second;
898 instanceConfigBegin++;
903 inInstanceClonePtr->addConfigs(configMap);
907 return inInstanceClonePtr;
917 const string& inModuleInstanceName) {
920 NetSharedPtr inNetClonePtr = Factory::newNetPtr(inNetCloneName, inNetPtr->getNetType());
931 while(netConfigBegin != netConfigEnd) {
934 const string setting = netConfigBegin->first;
936 const Config config = netConfigBegin->second;
945 inNetClonePtr->addConfigs(configMap);
955 while(inNetSourcesBegin != inNetSourcesEnd) {
966 = Factory::newInstancePinPtr(*pinInstPtrCloneItr, instPinPtr->getPinName());
968 inNetClonePtr->addSource(instPinPtrClone);
982 while(inNetSinksBegin != inNetSinksEnd) {
993 = Factory::newInstancePinPtr(*pinInstPtrCloneItr, instPinPtr->getPinName());
995 inNetClonePtr->addSink(instPinPtrClone);
1009 while(inNetPipsBegin != inNetPipsEnd) {
1012 Pip pipPtr = *inNetPipsBegin;
1018 inNetClonePtr->addPip(pipClone);
1026 return inNetClonePtr;
1033 #endif // TORC_PHYSICAL_MODULETRANSFORMER_HPP
void setConfig(const string &inSetting, const Config &inConfig)
Sets the configuration for the given setting.
std::vector< InstanceSharedPtr > InstanceSharedPtrVector
Vector of Instance shared pointers.
Main torc::architecture namespace header.
PortSharedPtrVector::const_iterator PortSharedPtrConstIterator
Constant iterator to Port shared pointers.
PipVector::const_iterator PipConstIterator
Constant iterator to Pip objects.
boost::shared_ptr< Port > PortSharedPtr
Shared pointer encapsulation of a Port.
InstancePinSharedPtrVector::iterator InstancePinSharedPtrIterator
Non-constant iterator to InstancePin shared pointer objects.
InstanceSharedPtrVector::const_iterator InstanceSharedPtrConstIterator
Constant iterator to Instance shared pointers.
std::vector< InstancePinSharedPtr > InstancePinSharedPtrVector
Vector of InstancePin shared pointers.
boost::shared_ptr< class InstancePin > InstancePinSharedPtr
Shared pointer encapsulation of an InstancePin.
const_iterator const_iterator
Constant iterator to {setting,Config} pairs.
boost::shared_ptr< Module > ModuleSharedPtr
Shared pointer encapsulation of a Module.
const WireName & getSinkWireName(void) const
Returns the pip sink wire.
Configuration. A {name:value} pair.
boost::shared_ptr< Net > NetSharedPtr
Shared pointer encapsulation of a Net.
boost::shared_ptr< Instance > InstanceSharedPtr
Shared pointer encapsulation of an Instance.
boost::shared_ptr< Design > DesignSharedPtr
Shared pointer encapsulation of a Design.
InstancePinSharedPtrVector::const_iterator InstancePinSharedPtrConstIterator
Constant iterator to InstancePin shared pointer objects.
NetSharedPtrVector::iterator NetSharedPtrIterator
Non-constant iterator to Net shared pointers.
const TileName & getTileName(void) const
Returns the pip tile.
EPipDirection getDirection(void) const
Returns the pip directionality.
Physical design programmable interconnect point.
const WireName & getSourceWireName(void) const
Returns the pip source wire.
Configuration setting map.
ModuleSharedPtrVector::iterator ModuleSharedPtrIterator
Non-constant iterator for Module shared pointers.
Header for the Factory class.
InstanceSharedPtrVector::iterator InstanceSharedPtrIterator
Non-constant iterator to Instance shared pointers.
static const string sHierarchySeparator