VIS
|
00001 00038 #include "ordInt.h" 00039 00040 static char rcsid[] UNUSED = "$Id: ordRoots.c,v 1.7 2002/08/27 08:43:16 fabio Exp $"; 00041 00042 /*---------------------------------------------------------------------------*/ 00043 /* Constant declarations */ 00044 /*---------------------------------------------------------------------------*/ 00045 00046 00047 /*---------------------------------------------------------------------------*/ 00048 /* Type declarations */ 00049 /*---------------------------------------------------------------------------*/ 00050 00051 00052 /*---------------------------------------------------------------------------*/ 00053 /* Structure declarations */ 00054 /*---------------------------------------------------------------------------*/ 00055 00056 00057 /*---------------------------------------------------------------------------*/ 00058 /* Variable declarations */ 00059 /*---------------------------------------------------------------------------*/ 00060 00061 00062 /*---------------------------------------------------------------------------*/ 00063 /* Macro declarations */ 00064 /*---------------------------------------------------------------------------*/ 00065 00066 00069 /*---------------------------------------------------------------------------*/ 00070 /* Static function prototypes */ 00071 /*---------------------------------------------------------------------------*/ 00072 00073 00077 /*---------------------------------------------------------------------------*/ 00078 /* Definition of exported functions */ 00079 /*---------------------------------------------------------------------------*/ 00080 00106 lsList 00107 Ord_NetworkOrderRoots( 00108 Ntk_Network_t *network, 00109 Ord_RootMethod rootMethod, 00110 lsList partialOrder, 00111 boolean verbose) 00112 { 00113 lsList rootOrderList; 00114 00115 switch (rootMethod) { 00116 case Ord_RootsByDepth_c: 00117 rootOrderList = OrdNetworkOrderRootsByDepth(network, verbose); 00118 break; 00119 case Ord_RootsByPerm_c: 00120 rootOrderList = OrdNetworkOrderRootsByPerm(network, verbose); 00121 break; 00122 case Ord_RootsByDefault_c: 00123 /* 00124 * RootByPerm method is cubic in the number of latches, so use it by 00125 * default only if the number of latches is not too large (30 is somewhat 00126 * arbitrary). 00127 */ 00128 if (Ntk_NetworkReadNumLatches(network) < 30) { 00129 rootOrderList = OrdNetworkOrderRootsByPerm(network, verbose); 00130 } 00131 else { 00132 rootOrderList = OrdNetworkOrderRootsByDepth(network, verbose); 00133 } 00134 break; 00135 default: 00136 fail("unrecognized root order method"); 00137 } 00138 00139 /* 00140 * If a partial order is supplied, merge (left, arbitrarily) the computed 00141 * order into the supplied order, to get a total ordering on all of the 00142 * roots. 00143 */ 00144 if (partialOrder != (lsList) NULL) { 00145 lsList partialOrderCopy = lsCopy(partialOrder, 00146 (lsGeneric (*) (lsGeneric)) NULL); 00147 00148 Ord_ListMergeList(partialOrderCopy, rootOrderList, Ord_ListMergeLeft_c); 00149 (void) lsDestroy(rootOrderList, (void (*) (lsGeneric)) NULL); 00150 return partialOrderCopy; 00151 } 00152 else { 00153 return rootOrderList; 00154 } 00155 } 00156 00157 00158 /*---------------------------------------------------------------------------*/ 00159 /* Definition of internal functions */ 00160 /*---------------------------------------------------------------------------*/ 00161 00180 lsList 00181 OrdNetworkOrderRootsByDepth( 00182 Ntk_Network_t *network, 00183 boolean verbose) 00184 { 00185 lsGen gen; 00186 Ntk_Node_t *node; 00187 st_table *processedTable = st_init_table(st_ptrcmp, st_ptrhash); 00188 lsList dataInputs = lsCreate(); 00189 lsList otherCombOuts = lsCreate(); 00190 lsList combOutputs = Ntk_NetworkReadCombOutputs(network); 00191 00192 /* 00193 * A node can drive more than one latch data input, latch initial input, 00194 * or primary output. Use a hash table to ensure that no node appears twice 00195 * across the two lists. 00196 */ 00197 Ntk_NetworkForEachCombOutput(network, gen, node) { 00198 if (Ntk_NodeTestIsLatchDataInput(node)) { 00199 OrdNodeAddToList(dataInputs, processedTable, node); 00200 } 00201 else { 00202 OrdNodeAddToList(otherCombOuts, processedTable, node); 00203 } 00204 } 00205 st_free_table(processedTable); 00206 00207 /* Compute depth of all combinational outputs. */ 00208 OrdNetworkComputeNodeDepths(network, combOutputs); 00209 00210 /* Sort each list independently. */ 00211 lsSort(dataInputs, OrdNodesFromListCompareDepth); 00212 lsSort(otherCombOuts, OrdNodesFromListCompareDepth); 00213 00214 Ord_ListAppendList(dataInputs, otherCombOuts); 00215 (void) lsDestroy(otherCombOuts, (void (*) (lsGeneric)) NULL); 00216 00217 return dataInputs; 00218 } 00219 00227 void 00228 OrdNodeAddToList( 00229 lsList nodeList, 00230 st_table *nodeTable, 00231 Ntk_Node_t *node) 00232 { 00233 if (!st_is_member(nodeTable, (char *) node)) { 00234 st_insert(nodeTable, (char *) node, NIL(char)); 00235 (void) lsNewEnd(nodeList, (lsGeneric) node, LS_NH); 00236 } 00237 } 00238 00239 00240 00241 /*---------------------------------------------------------------------------*/ 00242 /* Definition of static functions */ 00243 /*---------------------------------------------------------------------------*/ 00244