Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

oagFpgaModGraph.cpp

Go to the documentation of this file.
00001 
00002 #include "oagFpga.h"
00003 #include "oagFpgaModGraph.h"
00004 #include <set>
00005 
00006 #include "oagFpgaDebug.h"
00007 
00008 namespace oagFpga {
00009 
00010 // *****************************************************************************
00011 // failIfInDifferentModules()
00012 //
00017 //
00018 // *****************************************************************************
00019 inline void
00020 ModGraph::failIfInDifferentModules(oa::oaModule *x, oa::oaModule *y) {
00021     if (x != y) {
00022         cerr << "ERROR: Expected ModRefs that refer to nodes in the same module" << endl;    
00023         QUIT_ON_ERROR;
00024     }
00025 }     
00026 
00027 
00028 // *****************************************************************************
00029 // convertRefListToModRefList()
00030 //
00036 //
00037 // *****************************************************************************
00038 void
00039 ModGraph::convertRefListToModRefList(const list<BBRef> & source,
00040                                      oa::oaModule *module,
00041                                      list<ModRef> & result) {
00042     for(list<BBRef>::const_iterator it = source.begin(); it != source.end(); ++it) {
00043         result.push_back(ModRef(*it, module));
00044     }
00045 }
00046 
00047 // *****************************************************************************
00048 // convertModRefListToRefList()
00049 //
00054 //
00055 // *****************************************************************************
00056 oa::oaModule*
00057 ModGraph::convertModRefListToRefList(const list<ModRef> & source,
00058                                      list<BBRef> & result) {
00059     if (source.empty()) return NULL;
00060     oa::oaModule *module = source.front().module;
00061     for(list<ModRef>::const_iterator it = source.begin(); it != source.end(); ++it) {
00062       assert(it->module == module);
00063       result.push_back(it->ref);
00064     }
00065     return module;
00066 }
00067 
00068 // *****************************************************************************
00069 // convertRefVectorToModRefVector()
00070 //
00076 //
00077 // *****************************************************************************
00078 void
00079 ModGraph::convertRefVectorToModRefVector(const vector<BBRef> & source,
00080                                          oa::oaModule *module,
00081                                          vector<ModRef> & result) {
00082   result.reserve(source.size());
00083   for(vector<BBRef>::const_iterator it = source.begin(); it != source.end(); ++it) {
00084     result.push_back(ModRef(*it, module));
00085   }
00086 }
00087 
00088 /*
00089 // *****************************************************************************
00090 // newAnd()
00091 //
00100 //
00101 // *****************************************************************************
00102 ModRef
00103 ModGraph::newAnd(ModRef x, ModRef y) {
00104     failIfInDifferentModules(x,y);
00105     
00106     return ModRef(getGraph(x)->newAnd(x.ref, y.ref), x.module);
00107 }
00108 
00109 
00110 // *****************************************************************************
00111 // andOf()
00123 //
00124 // *****************************************************************************
00125 ModRef
00126 ModGraph::andOf(ModRef x, ModRef y) {
00127     failIfInDifferentModules(x,y);
00128     
00129     return ModRef(getGraph(x)->andOf(x.ref, y.ref), x.module);
00130 }
00131     
00132 */
00133 
00134 // *****************************************************************************
00135 // setTerminalDriver()
00144 //
00145 // *****************************************************************************
00146 void
00147 ModGraph::setTerminalDriver(ModRef terminal, ModRef driver) {
00148     failIfInDifferentModules(terminal, driver);
00149 
00150     getGraph(terminal)->setTerminalDriver(terminal.ref, driver.ref);
00151 }
00152 
00153 /*
00154 
00155 // *****************************************************************************
00156 // setAndLeft()
00157 //
00165 //
00166 // *****************************************************************************
00167 void
00168 ModGraph::setAndLeft(ModRef x, ModRef left) {
00169     failIfInDifferentModules(x,left);
00170 
00171     getGraph(x)->setAndLeft(x.ref, left.ref);
00172 }
00173 
00174 
00175 // *****************************************************************************
00176 // setAndRight()
00177 //
00185 //
00186 // *****************************************************************************
00187 void
00188 ModGraph::setAndRight(ModRef x, ModRef right) {
00189     failIfInDifferentModules(x,right);
00190 
00191     getGraph(x)->setAndRight(x.ref, right.ref);
00192 }
00193 
00194 
00195 // *****************************************************************************
00196 // setNextState()
00197 //
00205 //
00206 // *****************************************************************************
00207 void
00208 ModGraph::setNextState(ModRef sequential, ModRef nextState) {
00209     failIfInDifferentModules(sequential, nextState);
00210 
00211     getGraph(sequential)->setNextState(sequential.ref, nextState.ref);
00212 }
00213 
00214 
00215 // *****************************************************************************
00216 // resubsitute()
00217 //
00227 //
00228 // *****************************************************************************
00229 void
00230 ModGraph::resubstitute(ModRef original, ModRef replacement) {
00231     failIfInDifferentModules(original, replacement);
00232 
00233     getGraph(original)->resubstitute(original.ref, replacement.ref);
00234 }
00235 
00236 
00237 // *****************************************************************************
00238 // resubsitute()
00239 //
00250 //
00251 // *****************************************************************************
00252 void
00253 ModGraph::resubstitute(ModRef original, ModRef replacement, ModRef target) {
00254     failIfInDifferentModules(original, replacement);
00255     failIfInDifferentModules(original, target);
00256     
00257     getGraph(original)->resubstitute(original.ref, replacement.ref, target.ref);
00258 }
00259 
00260 
00261 // *****************************************************************************
00262 // detach()
00263 //
00270 //
00271 // *****************************************************************************
00272 void
00273 ModGraph::detach(ModRef x) {
00274 
00275     getGraph(x)->detach(x.ref);
00276 }
00277 */
00278 
00279 // *****************************************************************************
00280 //  hasCombinationalCycle()
00288 //
00289 // *****************************************************************************
00290 bool
00291 ModGraph::hasCombinationalCycle(oa::oaModule *module) {
00292     return getGraph(module)->hasCombinationalCycle();
00293 }
00294 
00295 /*
00296 // *****************************************************************************
00297 // enumerateKfeasibleCuts()
00312 //
00313 // *****************************************************************************
00314 ModGraph::CutSet
00315 ModGraph::enumerateKfeasibleCuts(ModRef x, unsigned int maxCutSize, 
00316                                  int maxCutCount, int maxCutDepth,
00317                                  bool includeConstantNode) {
00318   oagAi::Graph::CutSet *source = getGraph(x)->enumerateKfeasibleCuts(x.ref, 
00319                                                                      maxCutSize, maxCutCount, maxCutDepth,
00320                                                                      includeConstantNode);
00321 
00322     // convert cuts in Refs to cuts in ModRefs
00323     CutSet result;
00324     for(oagAi::Graph::CutSet::iterator setIter = source->begin(); setIter != source->end(); ++setIter) {
00325         Cut    resultCut;
00326         for(oagAi::Graph::Cut::iterator cutIter = setIter->begin(); cutIter != setIter->end(); ++cutIter) {
00327             resultCut.insert(ModRef(*cutIter, x.module));
00328         }
00329         result.push_back(resultCut);
00330     }
00331     return result;
00332 }
00333 
00334 
00335 // *****************************************************************************
00336 // clearKfeasibleCuts()
00337 //
00341 //
00342 // *****************************************************************************
00343 void
00344 ModGraph::clearKfeasibleCuts(oa::oaModule *module) {
00345     getGraph(module)->clearKfeasibleCuts();
00346 }
00347 
00348 */
00349 
00350 // *****************************************************************************
00351 // getFanin()
00352 //
00357 //
00358 // *****************************************************************************
00359 list<ModRef>
00360 ModGraph::getFanin(ModRef x) {
00361     list<ModRef> result;
00362     convertRefListToModRefList(getGraph(x)->getFanin(x.ref), x.module, result);
00363     return result;
00364 }
00365  
00366 // *****************************************************************************
00367 // getFanout()
00368 //
00373 //
00374 // *****************************************************************************
00375 list<ModRef>
00376 ModGraph::getFanout(ModRef x) {
00377     list<ModRef> result;
00378     convertRefListToModRefList(getGraph(x)->getFanout(x.ref), x.module, result);
00379     return result;
00380 }
00381     
00382     
00383 // *****************************************************************************
00384 // getFanout()
00385 //
00390 //
00391 // *****************************************************************************
00392 void
00393 ModGraph::getFanout(ModRef x, list<ModRef> &result) {
00394     convertRefListToModRefList(getGraph(x)->getFanout(x.ref), x.module, result);
00395 }
00396 
00397 // *****************************************************************************
00398 // getTransitiveFanin()
00399 //
00411 //
00412 // *****************************************************************************
00413 void
00414 ModGraph::getTransitiveFanin(ModRef x, list<ModRef> &transitiveFanin, 
00415                              bool includeRoots, bool crossSequential) {
00416     list<BBRef> flatResult;
00417     getGraph(x)->getTransitiveFanin(x.ref, flatResult, 
00418                                     includeRoots, crossSequential);
00419     convertRefListToModRefList(flatResult, x.module, transitiveFanin);
00420 }
00421 
00422 // *****************************************************************************
00423 // getTransitiveFanout()
00424 //
00437 //
00438 // *****************************************************************************
00439 void
00440 ModGraph::getTransitiveFanout(ModRef x, list<ModRef> &transitiveFanout,
00441                               bool includeRoots, bool crossSequential) {
00442     list<BBRef> flatResult;
00443     getGraph(x)->getTransitiveFanout(x.ref, flatResult, 
00444                                      includeRoots, crossSequential);
00445     convertRefListToModRefList(flatResult, x.module, transitiveFanout);
00446 }
00447 
00448 
00449 // *****************************************************************************
00450 // getTransitiveFanin()
00451 //
00464 //
00465 // *****************************************************************************
00466 void
00467 ModGraph::getTransitiveFanin(ModRef x, vector<ModRef> &transitiveFanin,
00468                              bool includeRoots, bool crossSequential) {
00469     vector<BBRef> flatResult;
00470     getGraph(x)->getTransitiveFanin(x.ref, flatResult, 
00471                                     includeRoots, crossSequential);
00472     convertRefVectorToModRefVector(flatResult, x.module, transitiveFanin);
00473 }
00474 
00475 
00476 // *****************************************************************************
00477 // getTransitiveFanout()
00478 //
00491 //
00492 // *****************************************************************************
00493 void
00494 ModGraph::getTransitiveFanout(ModRef x, vector<ModRef> &transitiveFanout,
00495                               bool includeRoots, bool crossSequential) {
00496     vector<BBRef> flatResult;
00497     getGraph(x)->getTransitiveFanout(x.ref, flatResult, 
00498                                      includeRoots, crossSequential);
00499     convertRefVectorToModRefVector(flatResult, x.module, transitiveFanout);
00500 }
00501 
00502 
00503 // *****************************************************************************
00504 // getTransitiveFanin()
00505 //
00518 //
00519 // *****************************************************************************
00520 void
00521 ModGraph::getTransitiveFanin(list<ModRef> x, list<ModRef> &transitiveFanin, 
00522                              bool includeRoots, bool crossSequential) {
00523     if (x.empty()) return;
00524     list<BBRef> flatInput;
00525     oa::oaModule *module = convertModRefListToRefList(x, flatInput);
00526     list<BBRef> flatResult;
00527     getGraph(module)->getTransitiveFanin(flatInput, flatResult, 
00528                                          includeRoots, crossSequential);
00529     convertRefListToModRefList(flatResult, module, transitiveFanin);
00530 }
00531 
00532 
00533 // *****************************************************************************
00534 // getTransitiveFanout()
00535 //
00548 //
00549 // *****************************************************************************
00550 void
00551 ModGraph::getTransitiveFanout(list<ModRef> x, list<ModRef> &transitiveFanout,
00552                               bool includeRoots, bool crossSequential) {
00553     if (x.empty()) return;
00554     list<BBRef> flatInput;
00555     oa::oaModule *module = convertModRefListToRefList(x, flatInput);
00556     list<BBRef> flatResult;
00557     getGraph(module)->getTransitiveFanout(flatInput, flatResult, 
00558                                           includeRoots, crossSequential);
00559     convertRefListToModRefList(flatResult, module, transitiveFanout);
00560 }
00561 
00562 
00563 // *****************************************************************************
00564 // getTransitiveFanin()
00565 //
00578 //
00579 // *****************************************************************************
00580 void
00581 ModGraph::getTransitiveFanin(list<ModRef> x, vector<ModRef> &transitiveFanin,
00582                              bool includeRoots, bool crossSequential) {
00583     if (x.empty()) return;
00584     list<BBRef> flatInput;
00585     oa::oaModule *module = convertModRefListToRefList(x, flatInput);
00586     vector<BBRef> flatResult;
00587     getGraph(module)->getTransitiveFanin(flatInput, flatResult, 
00588                                          includeRoots, crossSequential);
00589     convertRefVectorToModRefVector(flatResult, module, transitiveFanin);
00590 }
00591 
00592 
00593 // *****************************************************************************
00594 // getTransitiveFanout()
00595 //
00608 //
00609 // *****************************************************************************
00610 void
00611 ModGraph::getTransitiveFanout(list<ModRef> x, vector<ModRef> &transitiveFanout,
00612                               bool includeRoots, bool crossSequential) {
00613     if (x.empty()) return;
00614     list<BBRef> flatInput;
00615     oa::oaModule *module = convertModRefListToRefList(x, flatInput);
00616     vector<BBRef> flatResult;
00617     getGraph(module)->getTransitiveFanout(flatInput, flatResult, 
00618                                           includeRoots, crossSequential);
00619     convertRefVectorToModRefVector(flatResult, module, transitiveFanout);
00620 }
00621 
00622 
00623 /*
00624 
00625 // *****************************************************************************
00626 // getFaninRoots()
00627 //
00632 //
00633 // *****************************************************************************
00634 void
00635 ModGraph::getFaninRoots(ModRef x, list<ModRef> &faninRoots) {
00636     list<oagAi::Ref> flatResult;
00637     getGraph(x)->getFaninRoots(x.ref, flatResult);
00638     
00639     convertRefListToModRefList(flatResult, x.module, faninRoots);
00640 }
00641 
00642 
00643 // *****************************************************************************
00644 // getFanoutRoots()
00645 //
00650 //
00651 // *****************************************************************************
00652 void
00653 ModGraph::getFanoutRoots(ModRef x, list<ModRef> &fanoutRoots) {
00654     list<oagAi::Ref> flatResult;
00655     getGraph(x)->getFanoutRoots(x.ref, flatResult);
00656     
00657     convertRefListToModRefList(flatResult, x.module, fanoutRoots);
00658 }
00659 
00660 
00661 // *****************************************************************************
00662 // testEquivalence()
00663 //
00668 //
00669 // *****************************************************************************
00670 bool
00671 ModGraph::testEquivalence(ModRef x, ModRef y) {
00672     failIfInDifferentModules(x,y);
00673 
00674     return getGraph(x)->testEquivalence(x.ref, y.ref);
00675 }
00676 
00677 
00678 // *****************************************************************************
00679 // setEquivalent()
00680 //
00684 //
00685 // *****************************************************************************
00686 void
00687 ModGraph::setEquivalent(ModRef x, ModRef y) {
00688     failIfInDifferentModules(x,y);
00689 
00690     getGraph(x)->setEquivalent(x.ref, y.ref);
00691 }
00692 
00693 
00694 // *****************************************************************************
00695 // getEquivalents()
00696 //
00704 //
00705 // *****************************************************************************
00706 void
00707 ModGraph::getEquivalents(ModRef x, list<ModRef> & result) {
00708     list<oagAi::Ref> flatResult;
00709     getGraph(x)->getEquivalents(x.ref, flatResult);
00710     
00711     convertRefListToModRefList(flatResult, x.module, result);
00712 }
00713 
00714 
00715 // *****************************************************************************
00716 // getFanoutOfEquivalentNodes()
00717 //
00722 //
00723 // *****************************************************************************
00724 void
00725 ModGraph::getFanoutOfEquivalentNodes(ModRef x, list<ModRef> &result) {
00726     list<oagAi::Ref> flatResult;
00727     getGraph(x)->getFanoutOfEquivalentNodes(x.ref, flatResult);
00728     
00729     convertRefListToModRefList(flatResult, x.module, result);
00730 }
00731 
00732 */
00733 
00734 // *****************************************************************************
00735 // prepareNetToBBConnection()
00736 //
00746 //
00747 // *****************************************************************************
00748 ModRef   
00749 ModGraph::prepareNetToBBConnection(oa::oaModBitNet *net) {
00750     Manager *manager = Manager::get(net->getDesign());
00751     return ModRef(manager->prepareNetToBBConnection(net), net->getModule());
00752 }
00753 
00754 
00755 // *****************************************************************************
00756 // getNetToBBConnection()
00757 //
00762 //
00763 // *****************************************************************************
00764 oa::oaModBitNet *   
00765 ModGraph::getNetToBBConnection(ModRef x) {
00766     Manager *manager = Manager::get(x.module->getDesign());
00767     return manager->getNetToBBConnection(x.ref);
00768 }
00769 
00770 
00771 // *****************************************************************************
00772 // getNetToBBConnection()
00773 //
00778 //
00779 // *****************************************************************************
00780 ModRef
00781 ModGraph::getNetToBBConnection(oa::oaModBitNet *net) {
00782     Manager *manager = Manager::get(net->getDesign());
00783     return ModRef(manager->getNetToBBConnection(net), net->getModule());
00784 }
00785 
00786 
00787 // *****************************************************************************
00788 // setNetToBBConnection()
00789 //
00794 //
00795 // *****************************************************************************
00796 void
00797 ModGraph::setNetToBBConnection(oa::oaModBitNet *net, ModRef x) {
00798     failIfInDifferentModules(net->getModule(), x.module);
00799 
00800     Manager *manager = Manager::get(x.module->getDesign());
00801     manager->setNetToBBConnection(net, x.ref);
00802 }
00803 
00804 /*
00805 
00806 
00807 // *****************************************************************************
00808 // removeNetToBBConnection()
00809 //
00813 //
00814 // *****************************************************************************
00815 void
00816 ModGraph::removeNetToBBConnection(oa::oaModBitNet *net) {
00817     Manager *manager = Manager::get(net->getDesign());
00818     manager->removeNetToBBConnection(net);
00819 }
00820 
00821 */
00822 
00823 // *****************************************************************************
00824 // getOutputs()
00825 //
00835 //
00836 // *****************************************************************************
00837 void         
00838 ModGraph::getOutputs(oa::oaModule *module, list<ModRef> &result) {
00839     assert(module);
00840     oa::oaModTerm *term;
00841     oa::oaIter<oa::oaModTerm> termIter(module->getTerms(oacTermIterSingleBit));
00842     while((term = termIter.getNext())) {
00843         if(term->getTermType() == oa::oacOutputTermType) {
00844             result.push_back(prepareNetToBBConnection(toBitNet(term->getNet())));
00845         }
00846     }
00847 }
00848 
00849 /*
00850 
00851 // *****************************************************************************
00852 // getInputs()
00853 //
00863 //
00864 // *****************************************************************************
00865 void         
00866 ModGraph::getInputs(oa::oaModule *module, list<ModRef> &result) {
00867     assert(module);
00868     oa::oaModTerm *term;
00869     oa::oaIter<oa::oaModTerm> termIter(module->getTerms(oacTermIterSingleBit));
00870     while((term = termIter.getNext())) {
00871         if(term->getTermType() == oa::oacInputTermType) {
00872             result.push_back(prepareNetToAiConnection(toBitNet(term->getNet())));
00873         }
00874     }
00875 }
00876 
00877 
00878 // *****************************************************************************
00879 // getAllNodes()
00880 //
00885 //
00886 // *****************************************************************************
00887 void         
00888 ModGraph::getAllNodes(oa::oaModule *module, list<ModRef> &result) {
00889     assert(module);
00890 
00891     // add the state bits inside this object
00892     list<oagAi::Ref> flatResult;
00893     getGraph(module)->getAll(flatResult);
00894     convertRefListToModRefList(flatResult, module, result);
00895 
00896 }
00897 
00898 
00899 // *****************************************************************************
00900 // getLocalStates()
00901 //
00906 //
00907 // *****************************************************************************
00908 void         
00909 ModGraph::getLocalStates(oa::oaModule *module, list<ModRef> &result) {
00910     assert(module);
00911 
00912     // add the state bits inside this object
00913     list<oagAi::Ref> flatResult;
00914     getGraph(module)->getAllSequential(flatResult);
00915     convertRefListToModRefList(flatResult, module, result);
00916 }
00917 
00918 
00919 // *****************************************************************************
00920 // getAllConnections()
00921 //
00932 //
00933 // *****************************************************************************
00934 void
00935 ModGraph::getAllConnections(oa::oaModBitNet *net, 
00936                             set<oa::oaModBitNet*> &connectedNets,
00937                             set<ModRef> &connectedRefs,
00938                             bool searchForwardThroughGraph,
00939                             bool searchBackwardThroughGraph,
00940                             bool searchThroughEquivNets,
00941                             bool searchThroughEquivRefs,
00942                             bool includeSelf) {
00943     assert(net);
00944     
00945     // has this net been visited?
00946     if (connectedNets.find(net) == connectedNets.end()) {
00947         connectedNets.insert(net);
00948     } else {
00949         return;
00950     }
00951 
00952     // --- directly connected refs
00953     getAllConnections(getNetToAiConnection(net), connectedNets, connectedRefs,
00954                 searchForwardThroughGraph, searchBackwardThroughGraph,
00955                 searchThroughEquivNets, searchThroughEquivRefs, true);
00956     
00957     // --- equivalent nets (if searchThroughEquivNets)
00958     if (searchThroughEquivNets) {
00959         oa::oaModBitNet *equivNet;
00960         oa::oaIter<oa::oaModBitNet> equivIter(net->getEquivalentNets());
00961         while((equivNet = equivIter.getNext())) {
00962             getAllConnections(equivNet, connectedNets, connectedRefs,
00963                 searchForwardThroughGraph, searchBackwardThroughGraph,
00964                 searchThroughEquivNets, searchThroughEquivRefs, true);
00965         }
00966     }
00967     
00968     // -- exclude self
00969     if (!includeSelf) {
00970         connectedNets.erase(net);
00971     }
00972 }
00973 
00974 
00975 // *****************************************************************************
00976 // getAllConnections()
00977 //
00981 
00990 //
00991 // *****************************************************************************    
00992 void 
00993 ModGraph::getAllConnections(ModRef x, 
00994                             set<oa::oaModBitNet*> &connectedNets,
00995                             set<ModRef> &connectedRefs,
00996                             bool searchForwardThroughGraph,
00997                             bool searchBackwardThroughGraph,
00998                             bool searchThroughEquivNets,
00999                             bool searchThroughEquivRefs,
01000                             bool includeSelf) {
01001     if (isNull(x)) {
01002         return;
01003     }
01004 
01005     // has this ref been visited?
01006     if (connectedRefs.find(x) == connectedRefs.end()) {
01007         connectedRefs.insert(x);
01008     } else {
01009         return;
01010     }
01011     
01012     // --- directly connected nets
01013     if (isTerminal(x) && !isInverted(x)) {
01014         oa::oaModBitNet *net;
01015         if ((net = getNetToAiConnection(x))) {
01016             getAllConnections(net, connectedNets, connectedRefs,
01017                 searchForwardThroughGraph, searchBackwardThroughGraph,
01018                 searchThroughEquivNets, searchThroughEquivRefs, true);
01019         }
01020     }
01021 
01022     // --- connected backward through graph (if searchBackwardThroughGraph)
01023     if (searchBackwardThroughGraph) {
01024         // terminal drivers
01025         if (isTerminal(x)) {
01026             ModRef driver = getTerminalDriver(x);
01027             driver = isInverted(x) ? notOf(driver) : driver;
01028             getAllConnections(driver, connectedNets, connectedRefs,
01029                 searchForwardThroughGraph, searchBackwardThroughGraph,
01030                 searchThroughEquivNets, searchThroughEquivRefs, true);
01031         }
01032     }
01033 
01034     // --- connected forward through graph (if searchForwardThroughGraph)
01035     if (searchForwardThroughGraph) {
01036         // terminals in fanout
01037         list<ModRef> fanoutList;
01038         getFanout(x, fanoutList);
01039         while(!fanoutList.empty()) {
01040             ModRef fanout(fanoutList.front());
01041             fanoutList.pop_front();
01042             if(isTerminal(fanout)) {
01043                 fanout = isInverted(x) ? notOf(fanout) : fanout;
01044                 fanout = isInverted(getTerminalDriver(fanout)) ? notOf(fanout) : fanout;
01045                 getAllConnections(fanout, connectedNets, connectedRefs,
01046                     searchForwardThroughGraph, searchBackwardThroughGraph,
01047                     searchThroughEquivNets, searchThroughEquivRefs, true);
01048             }
01049         }
01050     }
01051 
01052     // --- equivalent nodes (if searchThroughEquivRefs)
01053     if (searchThroughEquivRefs) {
01054         list<ModRef> equivList;
01055         getEquivalents(x, equivList);
01056         while(!equivList.empty()) {
01057             ModRef equiv(equivList.front());
01058             equivList.pop_front();
01059             getAllConnections(equiv, connectedNets, connectedRefs,
01060                 searchForwardThroughGraph, searchBackwardThroughGraph,
01061                 searchThroughEquivNets, searchThroughEquivRefs, true);
01062         }
01063     }
01064     
01065     // -- exclude self
01066     if (!includeSelf) {
01067         connectedRefs.erase(x);
01068     }
01069 }
01070 */
01071 
01072 // *****************************************************************************
01073 // findDriverOfEquivalentNets()
01074 //
01086 //
01087 // *****************************************************************************
01088 oa::oaModBitNet *
01089 ModGraph::findDriverOfEquivalentNets(oa::oaModBitNet *net) {
01090     assert(net);
01091 
01092     // ignore if there are no equivalent nets
01093     if (net->getEquivalentNets().isEmpty()) {
01094       return NULL;
01095     }
01096 
01097     // ignore if there is already a driver in the graph
01098     ModRef termRef = getNetToBBConnection(net);
01099     if (!isNull(termRef) && !isNull(getTerminalDriver(termRef))) {    
01100       return NULL;
01101     }
01102 
01103     // iterate over equivalent nets to find driver
01104     oa::oaModBitNet *equivNet;
01105     oa::oaIter<oa::oaModBitNet> equivNetIter(net->getEquivalentNets());
01106 
01107     DEBUG_PRINT("Equivalent set : ");
01108     while ((equivNet = equivNetIter.getNext())) {
01109       assert(equivNet);
01110       
01111       oa::oaString netString;
01112       equivNet->getName(oa::oaVerilogNS(), netString);
01113       DEBUG_PRINTMORE(netString << " ");
01114 
01115       // is this driven in the graph?
01116       ModRef termRef = getNetToBBConnection(equivNet);
01117       if (!isNull(termRef) && !isNull(getTerminalDriver(termRef))) {
01118         // avoid combinational cycles
01119         ModRef driverRef = termRef;
01120         while(true) {
01121           oa::oaModBitNet *net2 = getNetToBBConnection(driverRef);
01122           if (net2 && net2 == net) {
01123             // net can't be in a cycle with itself
01124             return NULL;
01125           }
01126           driverRef = getTerminalDriver(driverRef);
01127           if (isNull(driverRef) || !isTerminal(driverRef)) {
01128             break;
01129           }
01130         }
01131         return equivNet;
01132       }
01133       
01134       // is an input terminal attached?
01135       oa::oaModTerm *term;
01136       oa::oaIter<oa::oaModTerm> termIter(equivNet->getTerms(oacTermIterSingleBit));
01137       while((term = termIter.getNext())) {
01138         assert(term);
01139         if(term->getTermType() == oa::oacInputTermType) {
01140           return equivNet;
01141         }
01142       }
01143     }
01144     DEBUG_PRINTMORE("\n");
01145     
01146 //    // is there a preferred equivalent?
01147 //    
01148 //    // NOTE: This appears to be broken.  A preferred net is sometimes
01149 //    // returned when none has been set.  Reason unknown.
01150 //
01151 //    if (net->getPreferredEquivalent() != net) {
01152 //      return net->getPreferredEquivalent();
01153 //    }
01154     
01155 
01156     return NULL;
01157 }
01158 
01159 
01160 // *****************************************************************************
01161 // connectEquivalentNetsInGraph()
01162 //
01193 // *****************************************************************************
01194 void
01195 ModGraph::connectEquivalentNetsInGraph(oa::oaModule *module) {
01196   assert(module);
01197 
01198   oa::oaModNet *net;
01199   oa::oaIter<oa::oaModNet> netIter(module->getNets(oacNetIterSingleBit));
01200   while((net = netIter.getNext())) {
01201     oa::oaModBitNet *bitNet = toBitNet(net);
01202     assert(bitNet);
01203     ModRef termNode = getNetToBBConnection(bitNet);
01204     assert(!isNull(termNode));
01205     if (!isNull(getTerminalDriver(termNode))) {
01206       continue;
01207     }
01208 
01209     oa::oaModBitNet *driverNet = findDriverOfEquivalentNets(bitNet);
01210 
01211     if (driverNet) {      
01212       ModRef driver = getNetToBBConnection(driverNet);
01213 #if defined(DEBUG)
01214       cout << "Moving equivalent nets to graph : node ";
01215       termNode.printName(false);
01216       cout << " was ";
01217       getTerminalDriver(termNode).printName();
01218       cout << " is now driven by ";
01219       driver.printName(true);
01220       cout << endl;
01221 #endif
01222       setTerminalDriver(termNode, driver);
01223     }
01224   }
01225 }
01226 
01227 /*
01228 // *****************************************************************************
01229 // print()
01230 //
01232 //
01233 // *****************************************************************************
01234 void                
01235 ModGraph::print(oa::oaModule *module) {
01236   assert(module);
01237 
01238   list<ModRef> all;
01239   getAllNodes(module, all);
01240   for(list<ModRef>::iterator it = all.begin(); it!=all.end(); it++) {
01241     it->print();
01242   }
01243 }
01244 
01245 
01246 // *****************************************************************************
01247 // print()
01248 //
01252 //
01253 // *****************************************************************************
01254 void                
01255 ModRef::print(bool lineFeed) {
01256     const int TYPE_COL_WIDTH = 4;
01257     const int MODULE_COL_WIDTH = 20;
01258     const int REF_COL_WIDTH = 5;
01259 
01260     oa::oaString modString;
01261     if (!module) {
01262         modString = "(null)";
01263     } else {
01264         module->getName(oa::oaVerilogNS(), modString);
01265     }
01266 
01267     if (ModGraph::getNodeType(*this) == oagAi::Node::AND) {
01268         cout.width(TYPE_COL_WIDTH);
01269         cout << "AND ";
01270         cout.width(MODULE_COL_WIDTH);
01271         cout << modString << ".";
01272         cout.width(REF_COL_WIDTH);
01273         cout << ref << " :\t";
01274         cout << ModGraph::getAndLeft(*this).ref << ", " << ModGraph::getAndRight(*this).ref;
01275     } else if (ModGraph::getNodeType(*this) == oagAi::Node::SEQUENTIAL) {
01276         cout.width(TYPE_COL_WIDTH);
01277         cout << "SEQ ";
01278         cout.width(MODULE_COL_WIDTH);
01279         cout << modString << ".";
01280         cout.width(REF_COL_WIDTH);
01281         cout << ref << " :\t";
01282         cout << ModGraph::getNextState(*this).ref;
01283     } else if (ModGraph::getNodeType(*this) == oagAi::Node::CONSTANT0) {
01284         cout.width(TYPE_COL_WIDTH);
01285         cout << "ZRO ";
01286         cout.width(MODULE_COL_WIDTH);
01287         cout << modString << ".";
01288         cout.width(REF_COL_WIDTH);
01289         cout << ref << " :\t";
01290     } else if (ModGraph::getNodeType(*this) == oagAi::Node::TERMINAL) {
01291         cout.width(TYPE_COL_WIDTH);
01292         cout << "TRM ";
01293         cout.width(MODULE_COL_WIDTH);
01294         cout << modString << ".";
01295         cout.width(REF_COL_WIDTH);
01296         cout << ref << " :\t";
01297         cout << ModGraph::getTerminalDriver(*this).ref;
01298         cout << " net= ";
01299         oa::oaModBitNet *net = ModGraph::getNetToAiConnection(*this);
01300         if (net) {
01301           oa::oaString netString;
01302           net->getName(oa::oaVerilogNS(), netString);
01303           cout << netString;
01304         } else {
01305           cout << "*none*";
01306         }
01307     } else if (ModGraph::getNodeType(*this) == oagAi::Node::NONE) {
01308         cout.width(TYPE_COL_WIDTH);
01309         cout << "NUL ";
01310         cout.width(MODULE_COL_WIDTH);
01311         cout << modString << ".";
01312         cout.width(REF_COL_WIDTH);
01313         cout << ref << " :\t";
01314     }
01315 
01316     if (ModGraph::isInverted(*this)) {
01317         cout << " (inverted)";
01318     }
01319     
01320     if (lineFeed) {
01321         cout << endl;
01322     }
01323 }
01324 
01325 */
01326 // *****************************************************************************
01327 // printName()
01328 //
01332 //
01333 // *****************************************************************************
01334 void                
01335 ModRef::printName(bool lineFeed) {
01336 
01337     oa::oaString modString;
01338     if (!module) {
01339         modString = "(null)";
01340     } else {
01341         module->getName(oa::oaVerilogNS(), modString);
01342     }
01343 
01344     cout << modString << "." << ref;
01345     
01346     if (lineFeed) {
01347         cout << endl;
01348     }
01349 }
01350 
01351 /*
01352 // *****************************************************************************
01353 // getFaninCone()
01354 //
01367 //
01368 // *****************************************************************************
01369 void
01370 ModGraph::getFaninCone(ModRef x, const list<ModRef> &coneRoots, 
01371                        list<ModRef> &transitiveFanin, bool includeRoots) {
01372 
01373   list<oagAi::Ref> flatCut;
01374   oa::oaModule *module = convertModRefListToRefList(coneRoots, flatCut);
01375   assert(coneRoots.empty() || module == x.module);
01376   list<oagAi::Ref> flatResult;
01377   getGraph(x.module)->getFaninCone(x.ref, flatCut, flatResult, includeRoots);
01378   convertRefListToModRefList(flatResult, x.module, transitiveFanin);
01379 }
01380 
01381 
01382 // *****************************************************************************
01383 // getFanoutCone()
01384 //
01397 //
01398 // *****************************************************************************
01399 void
01400 ModGraph::getFanoutCone(ModRef x, const list<ModRef> &coneRoots, 
01401                         list<ModRef> &transitiveFanout, bool includeRoots) {
01402   
01403   list<oagAi::Ref> flatCut;
01404   oa::oaModule *module = convertModRefListToRefList(coneRoots, flatCut);
01405   assert(module == x.module);
01406   list<oagAi::Ref> flatResult;
01407   getGraph(x.module)->getFanoutCone(x.ref, flatCut, flatResult, includeRoots);
01408   convertRefListToModRefList(flatResult, x.module, transitiveFanout);
01409 }
01410 */
01411 
01412 }

Generated on Mon Jul 9 14:17:19 2007 for OA Gear Fpga by  doxygen 1.3.9.1