VIS

src/eqv/eqvMisc.c

Go to the documentation of this file.
00001 
00037 #include "eqvInt.h"
00038 
00039 static char rcsid[] UNUSED = "$Id: eqvMisc.c,v 1.10 2009/04/11 01:40:06 fabio Exp $";
00040 
00041 /*---------------------------------------------------------------------------*/
00042 /* Constant declarations                                                     */
00043 /*---------------------------------------------------------------------------*/
00044 
00045 
00046 /*---------------------------------------------------------------------------*/
00047 /* Type declarations                                                         */
00048 /*---------------------------------------------------------------------------*/
00049 
00050 
00051 /*---------------------------------------------------------------------------*/
00052 /* Structure declarations                                                    */
00053 /*---------------------------------------------------------------------------*/
00054 
00055 
00056 /*---------------------------------------------------------------------------*/
00057 /* Variable declarations                                                     */
00058 /*---------------------------------------------------------------------------*/
00059 
00060 
00061 /*---------------------------------------------------------------------------*/
00062 /* Macro declarations                                                        */
00063 /*---------------------------------------------------------------------------*/
00064 
00065 
00068 /*---------------------------------------------------------------------------*/
00069 /* Static function prototypes                                                */
00070 /*---------------------------------------------------------------------------*/
00071 
00072 static boolean NodesMatchUp(Ntk_Node_t *node1, Ntk_Node_t *node2);
00073 
00077 /*---------------------------------------------------------------------------*/
00078 /* Definition of exported functions                                          */
00079 /*---------------------------------------------------------------------------*/
00080 
00081 
00082 /*---------------------------------------------------------------------------*/
00083 /* Definition of internal functions                                          */
00084 /*---------------------------------------------------------------------------*/
00106 st_table *
00107 MapPrimaryInputsByName(
00108   Ntk_Network_t *network1,
00109   Ntk_Network_t *network2)
00110 {
00111   lsGen gen1, gen2;
00112   Ntk_Node_t *node1, *node2;
00113   Var_Variable_t *var1, *var2;
00114   char *name1, *name2;
00115   boolean flag = FALSE;
00116   boolean equivalent = TRUE;
00117   boolean causeOfError = TRUE;
00118   st_table *inputMap;
00119   int numValues;
00120   int i;
00121   
00122   if(Ntk_NetworkReadNumPrimaryInputs(network1) !=
00123            Ntk_NetworkReadNumPrimaryInputs(network2)) {
00124     error_append("Different number of primary inputs in the two networks\n");
00125     return NIL(st_table);
00126   }
00127   inputMap = st_init_table(st_ptrcmp, st_ptrhash);
00128   Ntk_NetworkForEachPrimaryInput(network1, gen1, node1) {
00129     name1 = Ntk_NodeReadName(node1);
00130     Ntk_NetworkForEachPrimaryInput(network2, gen2, node2) {
00131       name2 = Ntk_NodeReadName(node2);
00132       if (strcmp(name1, name2) == 0) {
00133         boolean a, b;
00134         
00135         var1 = Ntk_NodeReadVariable(node1);
00136         var2 = Ntk_NodeReadVariable(node2);
00137         a = Var_VariableTestIsEnumerative(var1);
00138         b = Var_VariableTestIsEnumerative(var2);
00139         if((a && !b) || (!a && b)) {
00140           error_append("Input ");
00141           error_append(name1);
00142           error_append(" and ");
00143           error_append(name2);
00144           error_append(" have different variable types\n");
00145           causeOfError = FALSE;
00146         }
00147         else {
00148           numValues = Var_VariableReadNumValues(var1);
00149           if(a && b) {
00150             if(numValues == Var_VariableReadNumValues(var2)) {
00151               st_insert(inputMap, (char *) node1, (char *) node2);
00152               flag = TRUE;
00153             }   
00154             else {
00155               error_append("Input ");
00156               error_append(name1);
00157               error_append(" and ");
00158               error_append(name2);
00159               error_append(" have different range of values\n");
00160               causeOfError = FALSE;
00161             }
00162           }
00163           else {/* both are symbolic */
00164             boolean flag2 = TRUE;
00165             for(i=0; i<numValues; i++) {
00166               if(strcmp(Var_VariableReadSymbolicValueFromIndex(var1, i),
00167                         Var_VariableReadSymbolicValueFromIndex(var2, i)))
00168                 {
00169                   flag2 = FALSE;
00170                   error_append("Input ");
00171                   error_append(name1);
00172                   error_append(" and ");
00173                   error_append(name2);
00174                   error_append(" have different symbolic values\n");
00175                   causeOfError = FALSE;
00176                 }
00177             }
00178             if(flag2) {
00179               st_insert(inputMap, (char *) node1, (char *) node2);
00180               flag = TRUE;
00181             }
00182           }
00183         }
00184       }
00185     }
00186 
00187     if(!flag) {
00188       equivalent = FALSE;    /* name1 did not find a match in network2 */
00189       if(causeOfError) {
00190         error_append("Input ");
00191         error_append(name1);
00192         error_append(" does not have a match\n");
00193       }
00194       else {
00195         causeOfError = TRUE;
00196       }
00197     }
00198     else {
00199       flag = FALSE;
00200     }   
00201   }
00202   
00203   
00204   if(!equivalent) {
00205     st_free_table(inputMap);
00206     return NIL(st_table);
00207   }
00208   else {
00209     return inputMap;
00210   }
00211 }
00212 
00235 st_table *
00236 MapCombInputsByName(
00237   Ntk_Network_t *network1,
00238   Ntk_Network_t *network2)
00239 {
00240   lsGen gen1, gen2;
00241   Ntk_Node_t *node1, *node2;
00242   Var_Variable_t *var1, *var2;
00243   char *name1, *name2;
00244   boolean flag = FALSE;
00245   boolean equivalent = TRUE;
00246   boolean causeOfError = TRUE;
00247   st_table *inputMap;
00248   int numValues;
00249   int i;
00250   
00251   if(Ntk_NetworkReadNumCombInputs(network1) !=
00252            Ntk_NetworkReadNumCombInputs(network2)) {
00253     error_append("Different number of combinational inputs in the two networks\n");
00254     return NIL(st_table);
00255   }
00256   inputMap = st_init_table(st_ptrcmp, st_ptrhash);
00257   Ntk_NetworkForEachCombInput(network1, gen1, node1) {
00258     name1 = Ntk_NodeReadName(node1);
00259     Ntk_NetworkForEachCombInput(network2, gen2, node2) {
00260       name2 = Ntk_NodeReadName(node2);
00261       if (strcmp(name1, name2) == 0) {
00262         boolean a, b;
00263         
00264         var1 = Ntk_NodeReadVariable(node1);
00265         var2 = Ntk_NodeReadVariable(node2);
00266         a = Var_VariableTestIsEnumerative(var1);
00267         b = Var_VariableTestIsEnumerative(var2);
00268         if((a && !b) || (!a && b)) {
00269           error_append("Input ");
00270           error_append(name1);
00271           error_append(" and ");
00272           error_append(name2);
00273           error_append(" have different variable types\n");
00274           causeOfError = FALSE;
00275         }
00276         else {
00277           numValues = Var_VariableReadNumValues(var1);
00278           if(a && b) {
00279             if(numValues == Var_VariableReadNumValues(var2)) {
00280               st_insert(inputMap, (char *) node1, (char *) node2);
00281               flag = TRUE;
00282             }   
00283             else {
00284               error_append("Input ");
00285               error_append(name1);
00286               error_append(" and ");
00287               error_append(name2);
00288               error_append(" have different range of values\n");
00289               causeOfError = FALSE;
00290             }
00291           }
00292           else {/* both are symbolic */
00293             boolean flag2 = TRUE;
00294             for(i=0; i<numValues; i++) {
00295               if(strcmp(Var_VariableReadSymbolicValueFromIndex(var1, i),
00296                         Var_VariableReadSymbolicValueFromIndex(var2, i)))
00297                 {
00298                   flag2 = FALSE;
00299                   error_append("Input ");
00300                   error_append(name1);
00301                   error_append(" and ");
00302                   error_append(name2);
00303                   error_append(" have different symbolic values\n");
00304                   causeOfError = FALSE;
00305                 }
00306             }
00307             if(flag2) {
00308               st_insert(inputMap, (char *) node1, (char *) node2);
00309               flag = TRUE;
00310             }
00311           }
00312         }
00313       }
00314     }
00315 
00316     if(!flag) {
00317       equivalent = FALSE;    /* name1 did not find a match in network2 */
00318       if(causeOfError) {
00319         error_append("Input ");
00320         error_append(name1);
00321         error_append(" does not have a match\n");
00322       }
00323       else {
00324         causeOfError = TRUE;
00325       }
00326     }
00327     else {
00328       flag = FALSE;
00329     }   
00330   }
00331   
00332   
00333   if(!equivalent) {
00334     st_free_table(inputMap);
00335     return NIL(st_table);
00336   }
00337   else {
00338     return inputMap;
00339   }
00340 }
00341   
00363 st_table *
00364 MapPrimaryOutputsByName(
00365   Ntk_Network_t *network1,
00366   Ntk_Network_t *network2)
00367 {
00368   lsGen gen1, gen2;
00369   Ntk_Node_t *node1, *node2;
00370   Var_Variable_t *var1, *var2;
00371   char *name1, *name2;
00372   boolean flag = FALSE;
00373   boolean equivalent = TRUE;
00374   boolean causeOfError = TRUE;
00375   st_table *outputMap;
00376   int numValues;
00377   int i;
00378   
00379   if(Ntk_NetworkReadNumPrimaryOutputs(network1) !=
00380            Ntk_NetworkReadNumPrimaryOutputs(network2)) {
00381     error_append("Different number of primary outputs in the two networks\n");
00382     return NIL(st_table);
00383   }
00384   outputMap = st_init_table(st_ptrcmp, st_ptrhash);
00385   Ntk_NetworkForEachPrimaryOutput(network1, gen1, node1) {
00386     name1 = Ntk_NodeReadName(node1);
00387     Ntk_NetworkForEachPrimaryOutput(network2, gen2, node2) {
00388       name2 = Ntk_NodeReadName(node2);
00389       if (strcmp(name1, name2) == 0) {
00390         boolean a, b;
00391         
00392         var1 = Ntk_NodeReadVariable(node1);
00393         var2 = Ntk_NodeReadVariable(node2);
00394         a = Var_VariableTestIsEnumerative(var1);
00395         b = Var_VariableTestIsEnumerative(var2);
00396         if((a && !b) || (!a && b)) {
00397           error_append("Output ");
00398           error_append(name1);
00399           error_append(" and ");
00400           error_append(name2);
00401           error_append(" have different variable types\n");
00402           causeOfError = FALSE;
00403         }
00404         else {
00405           numValues = Var_VariableReadNumValues(var1);
00406           if(a && b) {
00407             if(numValues == Var_VariableReadNumValues(var2)) {
00408               st_insert(outputMap, (char *) node1, (char *) node2);
00409               flag = TRUE;
00410             }   
00411             else {
00412               error_append("Output ");
00413               error_append(name1);
00414               error_append(" and ");
00415               error_append(name2);
00416               error_append(" have different range of values\n");
00417               causeOfError = FALSE;
00418             }
00419           }
00420           else {/* both are symbolic */
00421             boolean flag2 = TRUE;
00422             for(i=0; i<numValues; i++) {
00423               if(strcmp(Var_VariableReadSymbolicValueFromIndex(var1, i),
00424                         Var_VariableReadSymbolicValueFromIndex(var2, i)))
00425                 {
00426                   flag2 = FALSE;
00427                   error_append("Output ");
00428                   error_append(name1);
00429                   error_append(" and ");
00430                   error_append(name2);
00431                   error_append(" have different symbolic values\n");
00432                   causeOfError = FALSE;
00433                 }
00434             }
00435             if(flag2) {
00436               st_insert(outputMap, (char *) node1, (char *) node2);
00437               flag = TRUE;
00438             }
00439           }
00440         }
00441         
00442       }
00443     }
00444 
00445     if(!flag) {
00446       equivalent = FALSE;    /* name1 did not find a match in network2 */
00447       if(causeOfError) {
00448         error_append("Output ");
00449         error_append(name1);
00450         error_append(" does not have a match\n");
00451       }
00452       else {
00453         causeOfError = TRUE;
00454       }
00455     }
00456     else {
00457       flag = FALSE;
00458     }   
00459   }
00460   
00461   
00462   if(!equivalent) {
00463     st_free_table(outputMap);
00464     return NIL(st_table);
00465   }
00466   else {
00467     return outputMap;
00468   }
00469 }
00470 
00493 st_table *
00494 MapCombOutputsByName(
00495   Ntk_Network_t *network1,
00496   Ntk_Network_t *network2)
00497 {
00498   lsGen gen1, gen2;
00499   Ntk_Node_t *node1, *node2;
00500   Var_Variable_t *var1, *var2;
00501   char *name1, *name2;
00502   boolean flag = FALSE;
00503   boolean equivalent = TRUE;
00504   boolean causeOfError = TRUE;
00505   st_table *outputMap;
00506   int numValues;
00507   int i;
00508   
00509   if(Ntk_NetworkReadNumCombOutputs(network1) !=
00510      Ntk_NetworkReadNumCombOutputs(network2)) {
00511     error_append("Different number of combinational outputs in the two networks\n");
00512     return NIL(st_table);
00513   }
00514   outputMap = st_init_table(st_ptrcmp, st_ptrhash);
00515   Ntk_NetworkForEachCombOutput(network1, gen1, node1) {
00516     name1 = Ntk_NodeReadName(node1);
00517     Ntk_NetworkForEachCombOutput(network2, gen2, node2) {
00518       name2 = Ntk_NodeReadName(node2);
00519       if (NodesMatchUp(node1, node2)) {
00520         boolean a, b;
00521 
00522         var1 = Ntk_NodeReadVariable(node1);
00523         var2 = Ntk_NodeReadVariable(node2);
00524         a = Var_VariableTestIsEnumerative(var1);
00525         b = Var_VariableTestIsEnumerative(var2);
00526         if((a && !b) || (!a && b)) {
00527           error_append("Output ");
00528           error_append(name1);
00529           error_append(" and ");
00530           error_append(name2);
00531           error_append(" have different variable types\n");
00532           causeOfError = FALSE;
00533         }
00534         else {
00535           numValues = Var_VariableReadNumValues(var1);
00536           if(a && b) {
00537             if(numValues == Var_VariableReadNumValues(var2)) {
00538               st_insert(outputMap, (char *) node1, (char *) node2);
00539               flag = TRUE;
00540             }
00541             else {
00542               error_append("Output ");
00543               error_append(name1);
00544               error_append(" and ");
00545               error_append(name2);
00546               error_append(" have different range of values\n");
00547               causeOfError = FALSE;
00548             }
00549           }
00550           else {/* both are symbolic */
00551             boolean flag2 = TRUE;
00552             for(i=0; i<numValues; i++) {
00553               if(strcmp(Var_VariableReadSymbolicValueFromIndex(var1, i),
00554                         Var_VariableReadSymbolicValueFromIndex(var2, i)))
00555                 {
00556                   flag2 = FALSE;
00557                   error_append("Output ");
00558                   error_append(name1);
00559                   error_append(" and ");
00560                   error_append(name2);
00561                   error_append(" have different symbolic values\n");
00562                   causeOfError = FALSE;
00563                 }
00564             }
00565             if(flag2) {
00566               st_insert(outputMap, (char *) node1, (char *) node2);
00567               flag = TRUE;
00568               break;
00569             }
00570           }
00571         }
00572       }
00573     }
00574 
00575     if(!flag) {
00576       equivalent = FALSE;    /* name1 did not find a match in network2 */
00577       if(causeOfError) {
00578         error_append("Output ");
00579         error_append(name1);
00580         error_append(" does not have a match\n");
00581       }
00582       else {
00583         causeOfError = TRUE;
00584       }
00585     }
00586     else {
00587       flag = FALSE;
00588     }   
00589   }
00590   
00591   
00592   if(!equivalent) {
00593     st_free_table(outputMap);
00594     return NIL(st_table);
00595   }
00596   else {
00597     return outputMap;
00598   }
00599 }
00600 
00610 OFT
00611 FindOrderingMethod(void)
00612 {
00613   return (OFT) NULL;
00614 }
00615 
00632 boolean
00633 TestRootsAndLeavesAreValid(
00634   Ntk_Network_t *network1,
00635   Ntk_Network_t *network2,
00636   st_table *inputMap,
00637   st_table *outputMap)
00638 {
00639   
00640   st_generator *gen;
00641   array_t *roots1, *roots2;
00642   st_table *leaves1, *leaves2;
00643   Ntk_Node_t *node1, *node2;
00644   boolean test = TRUE;
00645   
00646   roots1 = array_alloc(Ntk_Node_t *, 0);
00647   roots2 = array_alloc(Ntk_Node_t *, 0);
00648   st_foreach_item(outputMap, gen, &node1, &node2) {
00649     array_insert_last(Ntk_Node_t *, roots1, node1);
00650     array_insert_last(Ntk_Node_t *, roots2, node2);
00651   }
00652   leaves1 = st_init_table(st_ptrcmp, st_ptrhash);
00653   leaves2 = st_init_table(st_ptrcmp, st_ptrhash);
00654   st_foreach_item(inputMap, gen, &node1, &node2) {
00655     st_insert(leaves1, node1, NULL);
00656     st_insert(leaves2, node2, NULL);
00657   }
00658   if(!Ntk_NetworkTestLeavesCoverSupportOfRoots(network1, roots1,
00659                                              leaves1)) {
00660     error_append("Leaves do not form a complete support for roots in network1.\n");
00661     test = FALSE;
00662   }
00663   if(!Ntk_NetworkTestLeavesCoverSupportOfRoots(network2, roots2,
00664                                              leaves2)) {
00665     error_append("Leaves do not form a complete support for roots in network2.\n");
00666     test = FALSE;
00667   }
00668   array_free(roots1);
00669   array_free(roots2);
00670   st_free_table(leaves1);
00671   st_free_table(leaves2);
00672   return test;
00673 }
00674 
00693 st_table *
00694 MapNamesToNodes(
00695   Ntk_Network_t *network1,
00696   Ntk_Network_t *network2,
00697   st_table *names)
00698 {
00699   st_table *nodes = st_init_table(st_ptrcmp, st_ptrhash);
00700   char *name1, *name2;
00701   Ntk_Node_t *node1, *node2;
00702   boolean error = FALSE;
00703   st_generator *gen;
00704   
00705   
00706   st_foreach_item(names, gen, &name1, &name2) {
00707     if((node1 = Ntk_NetworkFindNodeByName(network1, name1)) ==
00708        NIL(Ntk_Node_t)) {
00709       error = TRUE;
00710       error_append(name1);
00711       error_append(" not present in network1.\n");
00712     }
00713     
00714     if((node2 = Ntk_NetworkFindNodeByName(network2, name2)) ==
00715        NIL(Ntk_Node_t)) {
00716       error = TRUE;
00717       error_append(name2);
00718       error_append(" not present in network2.\n");
00719     }
00720     st_insert(nodes, (char *) node1, (char *) node2);
00721   }
00722   if(error) {
00723     st_free_table(nodes);
00724     return NIL(st_table);
00725   }
00726   else {
00727     return nodes;
00728   }
00729 }
00730 
00731     
00749 int
00750 ReadRootLeafMap(
00751   FILE *inputFile,
00752   st_table *rootsTable,
00753   st_table *leavesTable)
00754 {
00755   char *name;
00756   char *rootName1, *rootName2;
00757   char *leafName1, *leafName2;
00758   char c;
00759   boolean rootsFlag= 0;
00760   boolean leavesFlag = 0;
00761   st_generator *gen;
00762   
00763   while(((c = fgetc(inputFile)) == ' ') || (c == '\t') || (c== '\n' ));
00764   ungetc(c, inputFile);
00765   name = ALLOC(char, 20);
00766   
00767   if(fscanf(inputFile, "%s", name) == EOF) {
00768     FREE(name);
00769     return 0;
00770     /* both roots and leaves absent */
00771   }
00772   if(!strcmp(name, ".roots")) {
00773     rootsFlag = 1;
00774     while(((c = fgetc(inputFile)) == ' ') || (c == '\t') || (c== '\n' ));
00775     ungetc(c, inputFile);
00776     while((fscanf(inputFile, "%s", name) != EOF) && strcmp(name, ".leaves")) {
00777       rootName1 = ALLOC(char, strlen(name) + 1);
00778       strcpy(rootName1, name);
00779       while(((c = fgetc(inputFile)) == ' ') || (c == '\t') || (c== '\n' ));
00780       ungetc(c, inputFile);
00781       if((fscanf(inputFile, "%s", name) == EOF) || (!strcmp(name, ".leaves"))) {
00782         FREE(name);
00783         FREE(rootName1);
00784         st_foreach_item(rootsTable, gen, &rootName1, &rootName2) {
00785           FREE(rootName1);
00786           FREE(rootName2);
00787           return 0;
00788         }
00789       }
00790       rootName2 = ALLOC(char, strlen(name) + 1);
00791       strcpy(rootName2, name);
00792       st_insert(rootsTable, rootName1, rootName2);
00793       while(((c = fgetc(inputFile)) == ' ') || (c == '\t') || (c== '\n' ));
00794       ungetc(c, inputFile);
00795       name[0] = '\0'; /* this is to insure that whenever the while loop
00796                          is terminated, only one of the conditions is false */
00797     }
00798   }
00799   if(!strcmp(name, ".leaves")) {
00800     leavesFlag = 1;
00801     while(((c = fgetc(inputFile)) == ' ') || (c == '\t') || (c== '\n' ));
00802     ungetc(c, inputFile);
00803     while(fscanf(inputFile, "%s", name) != EOF) {
00804       leafName1 = ALLOC(char, strlen(name) + 1);
00805       strcpy(leafName1, name);
00806       while(((c = fgetc(inputFile)) == ' ') || (c == '\t') || (c== '\n' ));
00807       ungetc(c, inputFile);
00808       if(fscanf(inputFile, "%s", name) == EOF) {
00809         FREE(name);
00810         FREE(leafName1);
00811         st_foreach_item(leavesTable, gen, &leafName1, &leafName2) {
00812           FREE(leafName1);
00813           FREE(leafName2);
00814           return 0;
00815         }
00816       }
00817       leafName2 = ALLOC(char, strlen(name) + 1);
00818       strcpy(leafName2, name);
00819       st_insert(leavesTable, leafName1, leafName2);
00820       while(((c = fgetc(inputFile)) == ' ') || (c == '\t') || (c== '\n' ));
00821       ungetc(c, inputFile);
00822     }
00823   }
00824   FREE(name);
00825   if(rootsFlag == 1) {
00826     if(leavesFlag == 1) {
00827       return 3; /* both leaves and roots present */
00828     }
00829     else {
00830       return 2; /* roots present but leaves absent */
00831     }
00832   }
00833   else {
00834     if(leavesFlag == 1) {
00835       return 1; /* roots absent but leaves present */
00836     }
00837     else {
00838       return 0;
00839     }
00840   }
00841 }
00842   
00859 void
00860 DefaultCommonOrder(
00861   Ntk_Network_t *network1, 
00862   Ntk_Network_t *network2,
00863   st_table *inputMap)
00864 {
00865   st_generator *gen;
00866   Ntk_Node_t *node1, *node2;
00867   int id;
00868   lsList dummy = (lsList) 0;
00869   
00870   if(Ntk_NetworkReadApplInfo(network1, PART_NETWORK_APPL_KEY) == NIL(void)) {
00871     Ord_NetworkOrderVariables(network1, Ord_RootsByDefault_c,
00872                               Ord_NodesByDefault_c, FALSE, Ord_All_c,
00873                               Ord_Unassigned_c, dummy, 0);
00874   }
00875   
00876   st_foreach_item(inputMap, gen, &node1, &node2) {
00877     id = Ntk_NodeReadMddId(node1);
00878     Ntk_NodeSetMddId(node2, id);
00879   }
00880 }
00881   
00882       
00883 
00903 boolean
00904 TestLeavesAreValid(
00905   Ntk_Network_t *network1,
00906   Ntk_Network_t *network2,
00907   st_table *leavesTable)
00908 
00909 {
00910   st_generator *gen;
00911   Ntk_Node_t *node1, *node2;
00912   char *name1, *name2;
00913   boolean valid = TRUE;
00914   int count = 0;
00915   
00916   st_foreach_item(leavesTable, gen, &name1, &name2) {
00917     node1 = Ntk_NetworkFindNodeByName(network1, name1);
00918     node2 = Ntk_NetworkFindNodeByName(network2, name2);
00919     if(node1 == NIL(Ntk_Node_t)) {
00920       error_append(name1);
00921       error_append(" not found in network1.\n");
00922       valid = FALSE;
00923     }
00924     else {
00925       if(!Ntk_NodeTestIsPrimaryInput(node1)) {
00926         error_append(name1);
00927         error_append(" is not a primary input node\n");
00928         valid = FALSE;
00929       }
00930     }
00931     
00932     if(node2 == NIL(Ntk_Node_t)) {
00933       error_append(name2);
00934       error_append(" not found in network2.\n");
00935       valid = FALSE;
00936     }
00937     else {
00938       if(!Ntk_NodeTestIsPrimaryInput(node2)) {
00939         error_append(name2);
00940         error_append(" is not a primary input node\n");
00941         valid = FALSE;
00942       }
00943     }
00944     
00945     count ++;
00946   }
00947   if(valid) {
00948     if(!((Ntk_NetworkReadNumPrimaryInputs(network1) == count) && (Ntk_NetworkReadNumPrimaryInputs(network2) == count))) {
00949       error_append("All primary inputs not specified in the input file\n");
00950       valid = FALSE;
00951     }
00952   }
00953   return valid;
00954 }
00955 
00971 boolean
00972 TestRootsAreValid(
00973   Ntk_Network_t *network1,
00974   Ntk_Network_t *network2,
00975   st_table *rootsTable)
00976 
00977 {
00978   st_generator *gen;
00979   char *name1, *name2;
00980   boolean valid = TRUE;
00981   
00982   st_foreach_item(rootsTable, gen, &name1, &name2) {
00983     if(Ntk_NetworkFindNodeByName(network1, name1) == NIL(Ntk_Node_t)) {
00984       valid = FALSE;
00985       error_append(name1);
00986       error_append(" not present in network1.\n");
00987     }
00988     
00989     if(Ntk_NetworkFindNodeByName(network2, name2) == NIL(Ntk_Node_t)) {
00990       valid = FALSE;
00991       error_append(name2);
00992       error_append(" not present in network2.\n");
00993     }
00994   }
00995   return valid;
00996 }
00997 
01015 boolean
01016 TestPartitionIsValid(
01017   Ntk_Network_t *network,
01018   st_table *roots,
01019   st_table *leaves)
01020 {
01021   graph_t *partition = Part_NetworkReadPartition(network);
01022   st_generator *gen;
01023   char *name;
01024   Ntk_Node_t *node1, *node2;
01025   boolean flag = TRUE;
01026   
01027   st_foreach_item(roots, gen, &node1, &node2) {
01028     name = Ntk_NodeReadName(node1);
01029     if(Part_PartitionFindVertexByName(partition, name) == NIL(vertex_t)) {
01030       flag = FALSE;
01031     }
01032   }
01033   st_foreach_item(leaves, gen, &node1, &node2) {
01034     name = Ntk_NodeReadName(node1);
01035     if(Part_PartitionFindVertexByName(partition, name) == NIL(vertex_t)) {
01036       flag = FALSE;
01037     }
01038   }
01039   return flag;
01040 }
01041 
01042 /*---------------------------------------------------------------------------*/
01043 /* Definition of static functions                                            */
01044 /*---------------------------------------------------------------------------*/
01045 
01064 static boolean
01065 NodesMatchUp(
01066   Ntk_Node_t *node1 /* node from network1 */,
01067   Ntk_Node_t *node2 /* node from network2 */
01068   )
01069 {
01070   char *name1, *name2;
01071 
01072   name1 = Ntk_NodeReadName(node1);
01073   name2 = Ntk_NodeReadName(node2);
01074 
01075   if (strcmp(name1, name2) == 0)
01076     return TRUE;
01077 
01078   /* Try to match through the state variables. */
01079   if ((Ntk_NodeTestIsLatchDataInput(node1) &&
01080       Ntk_NodeTestIsLatchDataInput(node2)) ||
01081       (Ntk_NodeTestIsLatchInitialInput(node1) &&
01082        Ntk_NodeTestIsLatchInitialInput(node2))) {
01083     Ntk_Node_t *latch1, *latch2;
01084     char *nameLatch1, *nameLatch2;
01085     array_t *fanout1, *fanout2;
01086 
01087     fanout1 = Ntk_NodeReadFanouts(node1);
01088     if (array_n(fanout1) != 1) return FALSE;
01089     fanout2 = Ntk_NodeReadFanouts(node2);
01090     if (array_n(fanout2) != 1) return FALSE;
01091 
01092     latch1 = array_fetch(Ntk_Node_t *, fanout1, 0);
01093     assert(Ntk_NodeTestIsLatch(latch1));
01094     latch2 = array_fetch(Ntk_Node_t *, fanout2, 0);
01095     assert(Ntk_NodeTestIsLatch(latch2));
01096 
01097     nameLatch1 = Ntk_NodeReadName(latch1);
01098     nameLatch2 = Ntk_NodeReadName(latch2);
01099 
01100     return (strcmp(nameLatch1, nameLatch2) == 0);
01101   }
01102 
01103   return FALSE;
01104 
01105 } /* NodesMatchUp */