VIS
|
00001 00018 #include "maig.h" 00019 #include "ntk.h" 00020 #include "cmd.h" 00021 #include "baig.h" 00022 #include "baigInt.h" 00023 #include "ctlsp.h" 00024 00025 static char rcsid[] UNUSED = "$Id: baigCmd.c,v 1.32 2009/04/12 00:14:03 fabio Exp $"; 00026 00027 /*---------------------------------------------------------------------------*/ 00028 /* Constant declarations */ 00029 /*---------------------------------------------------------------------------*/ 00030 00031 00032 /*---------------------------------------------------------------------------*/ 00033 /* Stucture declarations */ 00034 /*---------------------------------------------------------------------------*/ 00035 00036 00037 /*---------------------------------------------------------------------------*/ 00038 /* Type declarations */ 00039 /*---------------------------------------------------------------------------*/ 00040 00041 00042 /*---------------------------------------------------------------------------*/ 00043 /* Variable declarations */ 00044 /*---------------------------------------------------------------------------*/ 00045 static jmp_buf timeOutEnv; 00046 static int bmcTimeOut; /* timeout value */ 00047 static long alarmLapTime; /* starting CPU time for timeout */ 00048 00049 00050 /*---------------------------------------------------------------------------*/ 00051 /* Macro declarations */ 00052 /*---------------------------------------------------------------------------*/ 00053 00054 00057 /*---------------------------------------------------------------------------*/ 00058 /* Static function prototypes */ 00059 /*---------------------------------------------------------------------------*/ 00060 00061 static int CommandPrintPartitionAig(Hrc_Manager_t ** hmgr, int argc, char ** argv); 00062 static int CommandPrintAigStats(Hrc_Manager_t ** hmgr, int argc, char ** argv); 00063 static int CommandCheckInvariantSat(Hrc_Manager_t ** hmgr, int argc, char ** argv); 00064 static void TimeOutHandle(void); 00065 00069 /*---------------------------------------------------------------------------*/ 00070 /* Definition of exported functions */ 00071 /*---------------------------------------------------------------------------*/ 00072 00082 void 00083 bAig_Init(void) 00084 { 00085 Cmd_CommandAdd("print_partition_aig_dot", CommandPrintPartitionAig, 0); 00086 Cmd_CommandAdd("print_aig_stats", CommandPrintAigStats, 0); 00087 Cmd_CommandAdd("check_invariant_sat", CommandCheckInvariantSat, 0); 00088 } 00089 00090 00100 void 00101 bAig_End(void) 00102 { 00103 } 00104 00118 bAig_Manager_t * 00119 bAig_initAig( 00120 int maxSize /* maximum number of nodes in the AIG graph */ 00121 ) 00122 { 00123 int i; 00124 00125 bAig_Manager_t *manager = ALLOC(bAig_Manager_t,1); 00126 if (manager == NIL( bAig_Manager_t)){ 00127 return NIL( bAig_Manager_t); 00128 } 00129 /*Bing:*/ 00130 memset(manager,0,sizeof(bAig_Manager_t )); 00131 00132 maxSize = maxSize * bAigNodeSize; /* each node is a size of bAigNodeSize */ 00133 00134 /* ??? */ 00135 /* maxSize = (maxSize/bAigNodeSize)*bAigNodeSize; 00136 if (maxSize > bAigArrayMaxSize ) { 00137 }*/ 00138 manager->NodesArray = ALLOC(bAigEdge_t, maxSize); 00139 manager->maxNodesArraySize = maxSize; 00140 manager->nodesArraySize = bAigFirstNodeIndex; 00141 00142 fanout(0) = 0; 00143 canonical(0) = 0; 00144 flags(0) = 0; 00145 aig_value(0) = 2; 00146 next(0) = bAig_NULL; 00147 /*Bing:*/ 00148 memset(manager->NodesArray,0,maxSize*sizeof(bAigEdge_t)); 00149 00150 manager->SymbolTable = st_init_table(strcmp,st_strhash); 00151 manager->nameList = ALLOC(char *, manager->maxNodesArraySize/bAigNodeSize); 00152 manager->bddIdArray = ALLOC(int, manager->maxNodesArraySize/bAigNodeSize); 00153 manager->bddArray = ALLOC(bdd_t *, manager->maxNodesArraySize/bAigNodeSize); 00154 00155 manager->HashTable = ALLOC(bAigEdge_t, bAig_HashTableSize); 00156 for (i=0; i<bAig_HashTableSize; i++) 00157 manager->HashTable[i]= bAig_NULL; 00158 00159 manager->mVarList = array_alloc(mAigMvar_t, 0); 00160 manager->bVarList = array_alloc(mAigBvar_t, 0); 00161 manager->timeframe = 0; 00162 manager->timeframeWOI = 0; 00163 manager->literals = 0; 00164 00165 /* Bing: for MultiCut */ 00166 manager->SymbolTableArray = ALLOC(st_table *,100); 00167 manager->HashTableArray = ALLOC(bAigEdge_t *,100); 00168 manager->NumOfTable = 100; 00169 00170 /* Bing: for interpolation */ 00171 manager->class_ = 1; 00172 manager->InitState = bAig_One; 00173 manager->assertArray = (satArray_t *)0; 00174 00175 return(manager); 00176 00177 } /* end of bAig_Init */ 00178 00179 00189 void 00190 bAig_quit( 00191 bAig_Manager_t *manager) 00192 { 00193 char *name; 00194 st_generator *stGen; 00195 bAigEdge_t varIndex; 00196 00197 if (manager->mVarList != NIL(array_t)){ 00198 array_free(manager->mVarList); 00199 } 00200 if (manager->bVarList != NIL(array_t)){ 00201 array_free(manager->bVarList); 00202 } 00203 FREE(manager->HashTable); 00204 st_foreach_item(manager->SymbolTable, stGen, &name, &varIndex) { 00205 FREE(name); 00206 } 00207 st_free_table(manager->SymbolTable); 00208 /* i is too small to represent 80000 00209 for (i=0; i< manager->maxNodesArraySize/bAigNodeSize ; i++){ 00210 FREE(manager->nameList[i]); 00211 } 00212 */ 00213 FREE(manager->nameList); 00214 FREE(manager->NodesArray); 00215 bAig_FreeTimeFrame(manager->timeframe); 00216 bAig_FreeTimeFrame(manager->timeframeWOI); 00217 FREE(manager); 00218 00219 /* Free SymbolTableArray and HashTableArray? */ 00220 } 00221 00233 void 00234 bAig_NodePrint( 00235 bAig_Manager_t *manager, 00236 bAigEdge_t node) 00237 { 00238 if (node == bAig_Zero) { 00239 printf("0"); 00240 return; 00241 } 00242 if (node == bAig_One) { 00243 printf("1"); 00244 return; 00245 } 00246 if (bAig_IsInverted(node)){ 00247 printf(" NOT("); 00248 } 00249 if (bAigIsVar(manager,node)) { 00250 printf("Var Node"); 00251 } else { 00252 printf("("); 00253 bAig_NodePrint(manager, leftChild(node)); 00254 printf("AND"); 00255 bAig_NodePrint(manager, rightChild(node)); 00256 printf(")"); 00257 } 00258 if (bAig_IsInverted(node)){ 00259 printf(")"); 00260 } 00261 00262 } /* bAig_NodePrint */ 00263 00264 00265 /*---------------------------------------------------------------------------*/ 00266 /* Definition of internal functions */ 00267 /*---------------------------------------------------------------------------*/ 00268 00269 00270 /*---------------------------------------------------------------------------*/ 00271 /* Definition of static functions */ 00272 /*---------------------------------------------------------------------------*/ 00273 00308 static int 00309 CommandPrintPartitionAig( 00310 Hrc_Manager_t ** hmgr, 00311 int argc, 00312 char ** argv) 00313 { 00314 FILE *fp; 00315 int c, i, mvfSize; 00316 Ntk_Network_t *network = Ntk_HrcManagerReadCurrentNetwork(*hmgr); 00317 mAig_Manager_t *manager; 00318 MvfAig_Function_t *mvfAig; 00319 bAigEdge_t v; 00320 Ntk_Node_t *node, *latch; 00321 st_table *node2MvfAigTable; 00322 lsGen gen; 00323 00324 util_getopt_reset(); 00325 while ((c = util_getopt(argc,argv,"h")) != EOF){ 00326 switch(c){ 00327 case 'h': 00328 goto usage; 00329 default: 00330 goto usage; 00331 } 00332 } 00333 /* Check if the network has been read in */ 00334 if (network == NIL(Ntk_Network_t)) { 00335 return 1; 00336 } 00337 00338 if (argc == 1) { 00339 fp = stdout; 00340 } 00341 else if (argc == 2) { 00342 fp = Cmd_FileOpen(*(++argv), "w", NIL(char *), /* silent */ 1); 00343 if (fp == NIL(FILE)) { 00344 (void) fprintf(vis_stderr, "Cannot write to %s\n", *argv); 00345 return 1; 00346 } 00347 } 00348 else { 00349 goto usage; 00350 } 00351 00352 manager = Ntk_NetworkReadMAigManager(network); 00353 00354 if (manager == NIL(mAig_Manager_t)) { 00355 return 1; 00356 } 00357 node2MvfAigTable = 00358 (st_table *)Ntk_NetworkReadApplInfo(network, MVFAIG_NETWORK_APPL_KEY); 00359 00360 Ntk_NetworkForEachLatch(network, gen, latch) { 00361 node = Ntk_LatchReadDataInput(latch); 00362 st_lookup(node2MvfAigTable, node, &mvfAig); 00363 mvfSize = array_n(mvfAig); 00364 for(i=0; i< mvfSize; i++){ 00365 v = bAig_GetCanonical(manager, MvfAig_FunctionReadComponent(mvfAig, i)); 00366 bAig_SetMaskTransitiveFanin(manager, v, VisitedMask); 00367 } 00368 } 00369 Ntk_NetworkForEachPrimaryOutput(network, gen, node) { 00370 st_lookup(node2MvfAigTable, node, &mvfAig); 00371 mvfSize = array_n(mvfAig); 00372 for(i=0; i< mvfSize; i++){ 00373 v = bAig_GetCanonical(manager, MvfAig_FunctionReadComponent(mvfAig, i)); 00374 bAig_SetMaskTransitiveFanin(manager, v, VisitedMask); 00375 } 00376 } 00377 00378 Ntk_NetworkForEachNode(network, gen, node) { 00379 st_lookup(node2MvfAigTable, node, &mvfAig); 00380 mvfSize = array_n(mvfAig); 00381 for(i=0; i< mvfSize; i++){ 00382 v = bAig_GetCanonical(manager, MvfAig_FunctionReadComponent(mvfAig, i)); 00383 bAig_SetMaskTransitiveFanin(manager, v, VisitedMask); 00384 } 00385 } 00386 00387 bAig_PrintDot(fp, manager); 00388 Ntk_NetworkForEachLatch(network, gen, latch) { 00389 node = Ntk_LatchReadInitialInput(latch); 00390 st_lookup(node2MvfAigTable, node, &mvfAig); 00391 mvfSize = array_n(mvfAig); 00392 for(i=0; i< mvfSize; i++){ 00393 v = bAig_GetCanonical(manager, MvfAig_FunctionReadComponent(mvfAig, i)); 00394 bAig_ResetMaskTransitiveFanin(manager, v, VisitedMask, ResetVisitedMask); 00395 } 00396 } 00397 Ntk_NetworkForEachPrimaryOutput(network, gen, node) { 00398 st_lookup(node2MvfAigTable, node, &mvfAig); 00399 mvfSize = array_n(mvfAig); 00400 for(i=0; i< mvfSize; i++){ 00401 v = bAig_GetCanonical(manager, MvfAig_FunctionReadComponent(mvfAig, i)); 00402 bAig_ResetMaskTransitiveFanin(manager, v, VisitedMask, ResetVisitedMask); 00403 } 00404 } 00405 Ntk_NetworkForEachNode(network, gen, node) { 00406 st_lookup(node2MvfAigTable, node, &mvfAig); 00407 mvfSize = array_n(mvfAig); 00408 for(i=0; i< mvfSize; i++){ 00409 v = bAig_GetCanonical(manager, MvfAig_FunctionReadComponent(mvfAig, i)); 00410 bAig_ResetMaskTransitiveFanin(manager, v, VisitedMask, ResetVisitedMask); 00411 } 00412 } 00413 00414 return 0; 00415 usage: 00416 (void) fprintf(vis_stderr, "usage: print_partition_aig_dot [-h] [file]\n"); 00417 (void) fprintf(vis_stderr, " -h\t\tprint the command usage\n"); 00418 return 1; 00419 } 00420 00459 static int 00460 CommandPrintAigStats( 00461 Hrc_Manager_t ** hmgr, 00462 int argc, 00463 char ** argv) 00464 { 00465 Ntk_Network_t *network = Ntk_HrcManagerReadCurrentNetwork(*hmgr); 00466 mAig_Manager_t *manager; 00467 int i; 00468 int printVar = 0; 00469 int c; 00470 00471 /* 00472 * Parse command line options. 00473 */ 00474 util_getopt_reset(); 00475 while ((c = util_getopt(argc, argv, "hn")) != EOF) { 00476 switch(c) { 00477 case 'h': 00478 goto usage; 00479 case 'n': 00480 printVar = 1; 00481 break; 00482 default: 00483 goto usage; 00484 } 00485 } 00486 if (network == NIL(Ntk_Network_t)) { 00487 return 1; 00488 } 00489 00490 manager = Ntk_NetworkReadMAigManager(network); 00491 00492 if (manager == NIL(mAig_Manager_t)) { 00493 return 1; 00494 } 00495 (void) fprintf(vis_stdout,"And/Inverter graph Static Report\n"); 00496 (void) fprintf(vis_stdout,"Maximum number of nodes: %ld\n", manager->maxNodesArraySize/bAigNodeSize); 00497 (void) fprintf(vis_stdout,"Current number of nodes: %ld\n\n", manager->nodesArraySize/bAigNodeSize); 00498 if (printVar == 1){ 00499 (void) fprintf(vis_stdout,"Nodes name\n"); 00500 for(i=1; i< manager->nodesArraySize/bAigNodeSize; i++){ 00501 if (manager->nameList[i][0] != 'N'){ 00502 (void) fprintf(vis_stdout,"%s\n", manager->nameList[i]); 00503 } 00504 } 00505 } 00506 return 0; 00507 usage: 00508 (void) fprintf(vis_stderr, "usage: print_aig_stats [-h] [-n] \n"); 00509 (void) fprintf(vis_stderr, " -h print the command usage\n"); 00510 (void) fprintf(vis_stderr, " -n list of variables\n"); 00511 return 1; /* error exit */ 00512 } 00513 00562 static int 00563 CommandCheckInvariantSat( 00564 Hrc_Manager_t ** hmgr, 00565 int argc, 00566 char ** argv) 00567 { 00568 char *filename; 00569 FILE *fin; 00570 array_t *invarArray; 00571 Ntk_Network_t *network; 00572 bAig_Manager_t *manager; 00573 bAigTransition_t *t; 00574 Ctlsp_Formula_t *formula; 00575 char c;int i, property; 00576 int timeOutPeriod; 00577 int passFlag, method; 00578 int interface, verbose; 00579 int inclusion_test; 00580 int constrain; 00581 int reductionUsingUnsat; 00582 int disableLifting; 00583 00584 timeOutPeriod = -1; 00585 method = 1; 00586 interface = 0; 00587 inclusion_test = 1; 00588 verbose = 0; 00589 constrain = 1; 00590 reductionUsingUnsat = 0; 00591 disableLifting = 0; 00592 util_getopt_reset(); 00593 while ((c = util_getopt(argc, argv, "hicdt:m:v:ul")) != EOF) { 00594 switch(c) { 00595 case 'h': 00596 goto usage; 00597 case 'i' : 00598 interface = 1; 00599 break; 00600 case 'd' : 00601 inclusion_test = 0; 00602 break; 00603 case 'c' : 00604 constrain = 0; 00605 break; 00606 case 'u' : 00607 reductionUsingUnsat = 1; 00608 break; 00609 case 'l' : 00610 disableLifting = 1; 00611 break; 00612 case 't' : 00613 timeOutPeriod = atoi(util_optarg); 00614 break; 00615 case 'v' : 00616 verbose = atoi(util_optarg); 00617 break; 00618 case 'm' : 00619 method = atoi(util_optarg); 00620 break; 00621 } 00622 } 00623 if (argc - util_optind == 0) { 00624 (void) fprintf(vis_stderr, "** ERROR : file containing property file not provided\n"); 00625 goto usage; 00626 } 00627 else if (argc - util_optind > 1) { 00628 (void) fprintf(vis_stderr, "** ERROR : too many arguments\n"); 00629 goto usage; 00630 } 00631 filename = util_strsav(argv[util_optind]); 00632 00633 if(!(fin = fopen(filename, "r"))) { 00634 fprintf(vis_stdout, "Error : can't open invariant file %s\n", filename); 00635 return(1); 00636 } 00637 invarArray = Ctlsp_FileParseFormulaArray(fin); 00638 fclose(fin); 00639 00640 if (timeOutPeriod > 0) { 00641 (void) signal(SIGALRM, (void(*)(int))TimeOutHandle); 00642 (void) alarm(timeOutPeriod); 00643 if (setjmp(timeOutEnv) > 0) { 00644 (void) fprintf(vis_stderr, 00645 "** ERROR : timeout occurred after %d seconds.\n", timeOutPeriod); 00646 alarm(0); 00647 return 1; 00648 } 00649 } 00650 00651 network = Ntk_HrcManagerReadCurrentNetwork(*hmgr); 00652 manager = Ntk_NetworkReadMAigManager(network); 00653 00654 t = bAigCreateTransitionRelation(network, manager); 00655 t->method = method; 00656 t->interface = interface; 00657 t->inclusionInitial = inclusion_test; 00658 t->verbose = verbose; 00659 t->constrain = constrain; 00660 t->disableLifting = disableLifting; 00661 t->reductionUsingUnsat = reductionUsingUnsat; 00662 00663 if(t->verbose > 1) 00664 bAigPrintTransitionInfo(t); 00665 00666 00667 fprintf(vis_stdout, "# INV: Summary of invariant pass/fail\n"); 00668 for(i=0; i<array_n(invarArray); i++) { 00669 formula = array_fetch(Ctlsp_Formula_t *, invarArray, i); 00670 Ctlsp_FormulaPrint(vis_stdout, formula); 00671 fprintf(vis_stdout, "\n"); 00672 00673 property = bAig_CreatebAigForInvariant(network, manager, formula); 00674 00675 passFlag = bAigCheckInvariantWithAG(t, property); 00676 00677 if(passFlag == 1) { 00678 fprintf(vis_stdout, "# INV: formula passed --- "); 00679 Ctlsp_FormulaPrint(vis_stdout, Ctlsp_FormulaReadOriginalFormula(formula)); 00680 fprintf(vis_stdout, "\n"); 00681 } 00682 else { 00683 fprintf(vis_stdout, "# INV: formula failed --- "); 00684 Ctlsp_FormulaPrint(vis_stdout, Ctlsp_FormulaReadOriginalFormula(formula)); 00685 fprintf(vis_stdout, "\n"); 00686 } 00687 } 00688 00689 return(0); 00690 00691 usage: 00692 (void) fprintf(vis_stderr, "usage: check_invariant_sat [-h] <inv_file>\n"); 00693 (void) fprintf(vis_stderr, " -h \tprint the command usage\n"); 00694 (void) fprintf(vis_stderr, " -d \tdisable inclusion test on initial states\n"); 00695 (void) fprintf(vis_stderr, " -m : 0 disable lifting\n"); 00696 (void) fprintf(vis_stderr, " 1 enable lifting (default)\n"); 00697 (void) fprintf(vis_stderr, " <inv_file> Invariant file to be checked.\n"); 00698 00699 return(1); 00700 } 00701 00702 00715 static void 00716 TimeOutHandle(void) 00717 { 00718 int seconds = (int) ((util_cpu_ctime() - alarmLapTime) / 1000); 00719 00720 if (seconds < bmcTimeOut) { 00721 unsigned slack = (unsigned) (bmcTimeOut - seconds); 00722 (void) signal(SIGALRM, (void(*)(int)) TimeOutHandle); 00723 (void) alarm(slack); 00724 } else { 00725 longjmp(timeOutEnv, 1); 00726 } 00727 } /* TimeOutHandle */ 00728