00001
00038 #include "util_hack.h"
00039 #include "cuddInt.h"
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #ifndef lint
00058 static char rcsid[] DD_UNUSED = "$Id: cuddExport.c,v 1.1.1.1 2003/02/24 22:23:52 wjiang Exp $";
00059 #endif
00060
00061
00062
00063
00064
00067
00068
00069
00070
00071 static int ddDoDumpBlif ARGS((DdManager *dd, DdNode *f, FILE *fp, st_table *visited, char **names));
00072 static int ddDoDumpDaVinci ARGS((DdManager *dd, DdNode *f, FILE *fp, st_table *visited, char **names, long mask));
00073 static int ddDoDumpDDcal ARGS((DdManager *dd, DdNode *f, FILE *fp, st_table *visited, char **names, long mask));
00074 static int ddDoDumpFactoredForm ARGS((DdManager *dd, DdNode *f, FILE *fp, char **names));
00075
00079
00080
00081
00082
00083
00104 int
00105 Cudd_DumpBlif(
00106 DdManager * dd ,
00107 int n ,
00108 DdNode ** f ,
00109 char ** inames ,
00110 char ** onames ,
00111 char * mname ,
00112 FILE * fp )
00113 {
00114 DdNode *support = NULL;
00115 DdNode *scan;
00116 int *sorted = NULL;
00117 int nvars = dd->size;
00118 int retval;
00119 int i;
00120
00121
00122 sorted = ALLOC(int,nvars);
00123 if (sorted == NULL) {
00124 dd->errorCode = CUDD_MEMORY_OUT;
00125 goto failure;
00126 }
00127 for (i = 0; i < nvars; i++) sorted[i] = 0;
00128
00129
00130 support = Cudd_VectorSupport(dd,f,n);
00131 if (support == NULL) goto failure;
00132 cuddRef(support);
00133 scan = support;
00134 while (!cuddIsConstant(scan)) {
00135 sorted[scan->index] = 1;
00136 scan = cuddT(scan);
00137 }
00138 Cudd_RecursiveDeref(dd,support);
00139 support = NULL;
00140
00141
00142 if (mname == NULL) {
00143 retval = fprintf(fp,".model DD\n.inputs");
00144 } else {
00145 retval = fprintf(fp,".model %s\n.inputs",mname);
00146 }
00147 if (retval == EOF) return(0);
00148
00149
00150 for (i = 0; i < nvars; i++) {
00151 if (sorted[i]) {
00152 if (inames == NULL) {
00153 retval = fprintf(fp," %d", i);
00154 } else {
00155 retval = fprintf(fp," %s", inames[i]);
00156 }
00157 if (retval == EOF) goto failure;
00158 }
00159 }
00160 FREE(sorted);
00161 sorted = NULL;
00162
00163
00164 retval = fprintf(fp,"\n.outputs");
00165 if (retval == EOF) goto failure;
00166 for (i = 0; i < n; i++) {
00167 if (onames == NULL) {
00168 retval = fprintf(fp," f%d", i);
00169 } else {
00170 retval = fprintf(fp," %s", onames[i]);
00171 }
00172 if (retval == EOF) goto failure;
00173 }
00174 retval = fprintf(fp,"\n");
00175 if (retval == EOF) goto failure;
00176
00177 retval = Cudd_DumpBlifBody(dd, n, f, inames, onames, fp);
00178 if (retval == 0) goto failure;
00179
00180
00181 retval = fprintf(fp,".end\n");
00182 if (retval == EOF) goto failure;
00183
00184 return(1);
00185
00186 failure:
00187 if (sorted != NULL) FREE(sorted);
00188 if (support != NULL) Cudd_RecursiveDeref(dd,support);
00189 return(0);
00190
00191 }
00192
00193
00215 int
00216 Cudd_DumpBlifBody(
00217 DdManager * dd ,
00218 int n ,
00219 DdNode ** f ,
00220 char ** inames ,
00221 char ** onames ,
00222 FILE * fp )
00223 {
00224 st_table *visited = NULL;
00225 int retval;
00226 int i;
00227
00228
00229 visited = st_init_table(st_ptrcmp, st_ptrhash);
00230 if (visited == NULL) goto failure;
00231
00232
00233 for (i = 0; i < n; i++) {
00234 retval = ddDoDumpBlif(dd,Cudd_Regular(f[i]),fp,visited,inames);
00235 if (retval == 0) goto failure;
00236 }
00237
00238
00239
00240
00241
00242 for (i = 0; i < n; i++) {
00243 if (onames == NULL) {
00244 retval = fprintf(fp,
00245 #if SIZEOF_VOID_P == 8
00246 ".names %lx f%d\n", (unsigned long) f[i] / (unsigned long) sizeof(DdNode), i);
00247 #else
00248 ".names %x f%d\n", (unsigned) f[i] / (unsigned) sizeof(DdNode), i);
00249 #endif
00250 } else {
00251 retval = fprintf(fp,
00252 #if SIZEOF_VOID_P == 8
00253 ".names %lx %s\n", (unsigned long) f[i] / (unsigned long) sizeof(DdNode), onames[i]);
00254 #else
00255 ".names %x %s\n", (unsigned) f[i] / (unsigned) sizeof(DdNode), onames[i]);
00256 #endif
00257 }
00258 if (retval == EOF) goto failure;
00259 if (Cudd_IsComplement(f[i])) {
00260 retval = fprintf(fp,"0 1\n");
00261 } else {
00262 retval = fprintf(fp,"1 1\n");
00263 }
00264 if (retval == EOF) goto failure;
00265 }
00266
00267 st_free_table(visited);
00268 return(1);
00269
00270 failure:
00271 if (visited != NULL) st_free_table(visited);
00272 return(0);
00273
00274 }
00275
00276
00306 int
00307 Cudd_DumpDot(
00308 DdManager * dd ,
00309 int n ,
00310 DdNode ** f ,
00311 char ** inames ,
00312 char ** onames ,
00313 FILE * fp )
00314 {
00315 DdNode *support = NULL;
00316 DdNode *scan;
00317 int *sorted = NULL;
00318 int nvars = dd->size;
00319 st_table *visited = NULL;
00320 st_generator *gen = NULL;
00321 int retval;
00322 int i, j;
00323 int slots;
00324 DdNodePtr *nodelist;
00325 long refAddr, diff, mask;
00326
00327
00328 sorted = ALLOC(int,nvars);
00329 if (sorted == NULL) {
00330 dd->errorCode = CUDD_MEMORY_OUT;
00331 goto failure;
00332 }
00333 for (i = 0; i < nvars; i++) sorted[i] = 0;
00334
00335
00336 support = Cudd_VectorSupport(dd,f,n);
00337 if (support == NULL) goto failure;
00338 cuddRef(support);
00339 scan = support;
00340 while (!cuddIsConstant(scan)) {
00341 sorted[scan->index] = 1;
00342 scan = cuddT(scan);
00343 }
00344 Cudd_RecursiveDeref(dd,support);
00345 support = NULL;
00346
00347
00348 visited = st_init_table(st_ptrcmp, st_ptrhash);
00349 if (visited == NULL) goto failure;
00350
00351
00352 for (i = 0; i < n; i++) {
00353 retval = cuddCollectNodes(Cudd_Regular(f[i]),visited);
00354 if (retval == 0) goto failure;
00355 }
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369 refAddr = (long) Cudd_Regular(f[0]);
00370 diff = 0;
00371 gen = st_init_gen(visited);
00372 if (gen == NULL) goto failure;
00373 while (st_gen(gen, (char **) &scan, NULL)) {
00374 diff |= refAddr ^ (long) scan;
00375 }
00376 st_free_gen(gen); gen = NULL;
00377
00378
00379 for (i = 0; (unsigned) i < 8 * sizeof(long); i += 4) {
00380 mask = (1 << i) - 1;
00381 if (diff <= mask) break;
00382 }
00383
00384
00385 retval = fprintf(fp,"digraph \"DD\" {\n");
00386 if (retval == EOF) return(0);
00387 retval = fprintf(fp,
00388 "size = \"7.5,10\"\ncenter = true;\nedge [dir = none];\n");
00389 if (retval == EOF) return(0);
00390
00391
00392 retval = fprintf(fp,"{ node [shape = plaintext];\n");
00393 if (retval == EOF) goto failure;
00394 retval = fprintf(fp," edge [style = invis];\n");
00395 if (retval == EOF) goto failure;
00396
00397
00398
00399 retval = fprintf(fp," \"CONST NODES\" [style = invis];\n");
00400 if (retval == EOF) goto failure;
00401 for (i = 0; i < nvars; i++) {
00402 if (sorted[dd->invperm[i]]) {
00403 if (inames == NULL || inames[dd->invperm[i]] == NULL) {
00404 retval = fprintf(fp,"\" %d \" -> ", dd->invperm[i]);
00405 } else {
00406 retval = fprintf(fp,"\" %s \" -> ", inames[dd->invperm[i]]);
00407 }
00408 if (retval == EOF) goto failure;
00409 }
00410 }
00411 retval = fprintf(fp,"\"CONST NODES\"; \n}\n");
00412 if (retval == EOF) goto failure;
00413
00414
00415 retval = fprintf(fp,"{ rank = same; node [shape = box]; edge [style = invis];\n");
00416 if (retval == EOF) goto failure;
00417 for (i = 0; i < n; i++) {
00418 if (onames == NULL) {
00419 retval = fprintf(fp,"\"F%d\"", i);
00420 } else {
00421 retval = fprintf(fp,"\" %s \"", onames[i]);
00422 }
00423 if (retval == EOF) goto failure;
00424 if (i == n - 1) {
00425 retval = fprintf(fp,"; }\n");
00426 } else {
00427 retval = fprintf(fp," -> ");
00428 }
00429 if (retval == EOF) goto failure;
00430 }
00431
00432
00433 for (i = 0; i < nvars; i++) {
00434 if (sorted[dd->invperm[i]]) {
00435 retval = fprintf(fp,"{ rank = same; ");
00436 if (retval == EOF) goto failure;
00437 if (inames == NULL || inames[dd->invperm[i]] == NULL) {
00438 retval = fprintf(fp,"\" %d \";\n", dd->invperm[i]);
00439 } else {
00440 retval = fprintf(fp,"\" %s \";\n", inames[dd->invperm[i]]);
00441 }
00442 if (retval == EOF) goto failure;
00443 nodelist = dd->subtables[i].nodelist;
00444 slots = dd->subtables[i].slots;
00445 for (j = 0; j < slots; j++) {
00446 scan = nodelist[j];
00447 while (scan != NULL) {
00448 if (st_is_member(visited,(char *) scan)) {
00449 retval = fprintf(fp,"\"%lx\";\n", (mask & (long) scan) / sizeof(DdNode));
00450 if (retval == EOF) goto failure;
00451 }
00452 scan = scan->next;
00453 }
00454 }
00455 retval = fprintf(fp,"}\n");
00456 if (retval == EOF) goto failure;
00457 }
00458 }
00459
00460
00461 retval = fprintf(fp,
00462 "{ rank = same; \"CONST NODES\";\n{ node [shape = box]; ");
00463 if (retval == EOF) goto failure;
00464 nodelist = dd->constants.nodelist;
00465 slots = dd->constants.slots;
00466 for (j = 0; j < slots; j++) {
00467 scan = nodelist[j];
00468 while (scan != NULL) {
00469 if (st_is_member(visited,(char *) scan)) {
00470 retval = fprintf(fp,"\"%lx\";\n", (mask & (long) scan) / sizeof(DdNode));
00471 if (retval == EOF) goto failure;
00472 }
00473 scan = scan->next;
00474 }
00475 }
00476 retval = fprintf(fp,"}\n}\n");
00477 if (retval == EOF) goto failure;
00478
00479
00480
00481 for (i = 0; i < n; i++) {
00482 if (onames == NULL) {
00483 retval = fprintf(fp,"\"F%d\"", i);
00484 } else {
00485 retval = fprintf(fp,"\" %s \"", onames[i]);
00486 }
00487 if (retval == EOF) goto failure;
00488
00489 if (Cudd_IsComplement(f[i])) {
00490 retval = fprintf(fp," -> \"%lx\" [style = dotted];\n",
00491 (mask & (long) f[i]) / sizeof(DdNode));
00492 } else {
00493 retval = fprintf(fp," -> \"%lx\" [style = solid];\n",
00494 (mask & (long) f[i]) / sizeof(DdNode));
00495 }
00496 if (retval == EOF) goto failure;
00497 }
00498
00499
00500 for (i = 0; i < nvars; i++) {
00501 if (sorted[dd->invperm[i]]) {
00502 nodelist = dd->subtables[i].nodelist;
00503 slots = dd->subtables[i].slots;
00504 for (j = 0; j < slots; j++) {
00505 scan = nodelist[j];
00506 while (scan != NULL) {
00507 if (st_is_member(visited,(char *) scan)) {
00508 retval = fprintf(fp,
00509 "\"%lx\" -> \"%lx\";\n",
00510 (mask & (long) scan) / sizeof(DdNode),
00511 (mask & (long) cuddT(scan)) / sizeof(DdNode));
00512 if (retval == EOF) goto failure;
00513 if (Cudd_IsComplement(cuddE(scan))) {
00514 retval = fprintf(fp,
00515 "\"%lx\" -> \"%lx\" [style = dotted];\n",
00516 (mask & (long) scan) / sizeof(DdNode),
00517 (mask & (long) cuddE(scan)) / sizeof(DdNode));
00518 } else {
00519 retval = fprintf(fp,
00520 "\"%lx\" -> \"%lx\" [style = dashed];\n",
00521 (mask & (long) scan) / sizeof(DdNode),
00522 (mask & (long) cuddE(scan)) / sizeof(DdNode));
00523 }
00524 if (retval == EOF) goto failure;
00525 }
00526 scan = scan->next;
00527 }
00528 }
00529 }
00530 }
00531
00532
00533 nodelist = dd->constants.nodelist;
00534 slots = dd->constants.slots;
00535 for (j = 0; j < slots; j++) {
00536 scan = nodelist[j];
00537 while (scan != NULL) {
00538 if (st_is_member(visited,(char *) scan)) {
00539 retval = fprintf(fp,"\"%lx\" [label = \"%g\"];\n",
00540 (mask & (long) scan) / sizeof(DdNode), cuddV(scan));
00541 if (retval == EOF) goto failure;
00542 }
00543 scan = scan->next;
00544 }
00545 }
00546
00547
00548 retval = fprintf(fp,"}\n");
00549 if (retval == EOF) goto failure;
00550
00551 st_free_table(visited);
00552 FREE(sorted);
00553 return(1);
00554
00555 failure:
00556 if (sorted != NULL) FREE(sorted);
00557 if (support != NULL) Cudd_RecursiveDeref(dd,support);
00558 if (visited != NULL) st_free_table(visited);
00559 return(0);
00560
00561 }
00562
00563
00582 int
00583 Cudd_DumpDaVinci(
00584 DdManager * dd ,
00585 int n ,
00586 DdNode ** f ,
00587 char ** inames ,
00588 char ** onames ,
00589 FILE * fp )
00590 {
00591 DdNode *support = NULL;
00592 DdNode *scan;
00593 st_table *visited = NULL;
00594 int retval;
00595 int i;
00596 st_generator *gen;
00597 long refAddr, diff, mask;
00598
00599
00600 visited = st_init_table(st_ptrcmp, st_ptrhash);
00601 if (visited == NULL) goto failure;
00602
00603
00604 for (i = 0; i < n; i++) {
00605 retval = cuddCollectNodes(Cudd_Regular(f[i]),visited);
00606 if (retval == 0) goto failure;
00607 }
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621 refAddr = (long) Cudd_Regular(f[0]);
00622 diff = 0;
00623 gen = st_init_gen(visited);
00624 while (st_gen(gen, (char **) &scan, NULL)) {
00625 diff |= refAddr ^ (long) scan;
00626 }
00627 st_free_gen(gen);
00628
00629
00630 for (i = 0; (unsigned) i < 8 * sizeof(long); i += 4) {
00631 mask = (1 << i) - 1;
00632 if (diff <= mask) break;
00633 }
00634 st_free_table(visited);
00635
00636
00637 visited = st_init_table(st_ptrcmp, st_ptrhash);
00638 if (visited == NULL) goto failure;
00639
00640 retval = fprintf(fp, "[");
00641 if (retval == EOF) goto failure;
00642
00643 for (i = 0; i < n; i++) {
00644 if (onames == NULL) {
00645 retval = fprintf(fp,
00646 "l(\"f%d\",n(\"root\",[a(\"OBJECT\",\"f%d\")],",
00647 i,i);
00648 } else {
00649 retval = fprintf(fp,
00650 "l(\"%s\",n(\"root\",[a(\"OBJECT\",\"%s\")],",
00651 onames[i], onames[i]);
00652 }
00653 if (retval == EOF) goto failure;
00654 retval = fprintf(fp, "[e(\"edge\",[a(\"EDGECOLOR\",\"%s\"),a(\"_DIR\",\"none\")],",
00655 Cudd_IsComplement(f[i]) ? "red" : "blue");
00656 if (retval == EOF) goto failure;
00657 retval = ddDoDumpDaVinci(dd,Cudd_Regular(f[i]),fp,visited,inames,mask);
00658 if (retval == 0) goto failure;
00659 retval = fprintf(fp, ")]))%s", i == n-1 ? "" : ",");
00660 if (retval == EOF) goto failure;
00661 }
00662
00663
00664 retval = fprintf(fp, "]\n");
00665 if (retval == EOF) goto failure;
00666
00667 st_free_table(visited);
00668 return(1);
00669
00670 failure:
00671 if (support != NULL) Cudd_RecursiveDeref(dd,support);
00672 if (visited != NULL) st_free_table(visited);
00673 return(0);
00674
00675 }
00676
00677
00696 int
00697 Cudd_DumpDDcal(
00698 DdManager * dd ,
00699 int n ,
00700 DdNode ** f ,
00701 char ** inames ,
00702 char ** onames ,
00703 FILE * fp )
00704 {
00705 DdNode *support = NULL;
00706 DdNode *scan;
00707 int *sorted = NULL;
00708 int nvars = dd->size;
00709 st_table *visited = NULL;
00710 int retval;
00711 int i;
00712 st_generator *gen;
00713 long refAddr, diff, mask;
00714
00715
00716 visited = st_init_table(st_ptrcmp, st_ptrhash);
00717 if (visited == NULL) goto failure;
00718
00719
00720 for (i = 0; i < n; i++) {
00721 retval = cuddCollectNodes(Cudd_Regular(f[i]),visited);
00722 if (retval == 0) goto failure;
00723 }
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737 refAddr = (long) Cudd_Regular(f[0]);
00738 diff = 0;
00739 gen = st_init_gen(visited);
00740 while (st_gen(gen, (char **) &scan, NULL)) {
00741 diff |= refAddr ^ (long) scan;
00742 }
00743 st_free_gen(gen);
00744
00745
00746 for (i = 0; (unsigned) i < 8 * sizeof(long); i += 4) {
00747 mask = (1 << i) - 1;
00748 if (diff <= mask) break;
00749 }
00750 st_free_table(visited);
00751
00752
00753 sorted = ALLOC(int,nvars);
00754 if (sorted == NULL) {
00755 dd->errorCode = CUDD_MEMORY_OUT;
00756 goto failure;
00757 }
00758 for (i = 0; i < nvars; i++) sorted[i] = 0;
00759
00760
00761 support = Cudd_VectorSupport(dd,f,n);
00762 if (support == NULL) goto failure;
00763 cuddRef(support);
00764 scan = support;
00765 while (!cuddIsConstant(scan)) {
00766 sorted[scan->index] = 1;
00767 scan = cuddT(scan);
00768 }
00769 Cudd_RecursiveDeref(dd,support);
00770 support = NULL;
00771 for (i = 0; i < nvars; i++) {
00772 if (sorted[dd->invperm[i]]) {
00773 if (inames == NULL || inames[dd->invperm[i]] == NULL) {
00774 retval = fprintf(fp,"v%d", dd->invperm[i]);
00775 } else {
00776 retval = fprintf(fp,"%s", inames[dd->invperm[i]]);
00777 }
00778 if (retval == EOF) goto failure;
00779 }
00780 retval = fprintf(fp,"%s", i == nvars - 1 ? "\n" : " * ");
00781 if (retval == EOF) goto failure;
00782 }
00783 FREE(sorted);
00784 sorted = NULL;
00785
00786
00787 visited = st_init_table(st_ptrcmp, st_ptrhash);
00788 if (visited == NULL) goto failure;
00789
00790
00791 for (i = 0; i < n; i++) {
00792 retval = ddDoDumpDDcal(dd,Cudd_Regular(f[i]),fp,visited,inames,mask);
00793 if (retval == 0) goto failure;
00794 if (onames == NULL) {
00795 retval = fprintf(fp, "f%d = ", i);
00796 } else {
00797 retval = fprintf(fp, "%s = ", onames[i]);
00798 }
00799 if (retval == EOF) goto failure;
00800 retval = fprintf(fp, "n%lx%s\n",
00801 ((long) f[i] & mask) / sizeof(DdNode),
00802 Cudd_IsComplement(f[i]) ? "'" : "");
00803 if (retval == EOF) goto failure;
00804 }
00805
00806
00807 retval = fprintf(fp, "[");
00808 if (retval == EOF) goto failure;
00809 for (i = 0; i < n; i++) {
00810 if (onames == NULL) {
00811 retval = fprintf(fp, "f%d", i);
00812 } else {
00813 retval = fprintf(fp, "%s", onames[i]);
00814 }
00815 retval = fprintf(fp, "%s", i == n-1 ? "" : " ");
00816 if (retval == EOF) goto failure;
00817 }
00818 retval = fprintf(fp, "]\n");
00819 if (retval == EOF) goto failure;
00820
00821 st_free_table(visited);
00822 return(1);
00823
00824 failure:
00825 if (sorted != NULL) FREE(sorted);
00826 if (support != NULL) Cudd_RecursiveDeref(dd,support);
00827 if (visited != NULL) st_free_table(visited);
00828 return(0);
00829
00830 }
00831
00832
00853 int
00854 Cudd_DumpFactoredForm(
00855 DdManager * dd ,
00856 int n ,
00857 DdNode ** f ,
00858 char ** inames ,
00859 char ** onames ,
00860 FILE * fp )
00861 {
00862 int retval;
00863 int i;
00864
00865
00866 for (i = 0; i < n; i++) {
00867 if (onames == NULL) {
00868 retval = fprintf(fp, "f%d = ", i);
00869 } else {
00870 retval = fprintf(fp, "%s = ", onames[i]);
00871 }
00872 if (retval == EOF) return(0);
00873 if (f[i] == DD_ONE(dd)) {
00874 retval = fprintf(fp, "CONST1");
00875 if (retval == EOF) return(0);
00876 } else if (f[i] == Cudd_Not(DD_ONE(dd)) || f[i] == DD_ZERO(dd)) {
00877 retval = fprintf(fp, "CONST0");
00878 if (retval == EOF) return(0);
00879 } else {
00880 retval = fprintf(fp, "%s", Cudd_IsComplement(f[i]) ? "!(" : "");
00881 if (retval == EOF) return(0);
00882 retval = ddDoDumpFactoredForm(dd,Cudd_Regular(f[i]),fp,inames);
00883 if (retval == 0) return(0);
00884 retval = fprintf(fp, "%s", Cudd_IsComplement(f[i]) ? ")" : "");
00885 if (retval == EOF) return(0);
00886 }
00887 retval = fprintf(fp, "%s", i == n-1 ? "" : "\n");
00888 if (retval == EOF) return(0);
00889 }
00890
00891 return(1);
00892
00893 }
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00920 static int
00921 ddDoDumpBlif(
00922 DdManager * dd,
00923 DdNode * f,
00924 FILE * fp,
00925 st_table * visited,
00926 char ** names)
00927 {
00928 DdNode *T, *E;
00929 int retval;
00930
00931 #ifdef DD_DEBUG
00932 assert(!Cudd_IsComplement(f));
00933 #endif
00934
00935
00936 if (st_is_member(visited, (char *) f) == 1)
00937 return(1);
00938
00939
00940 if (f == NULL)
00941 return(0);
00942
00943
00944 if (st_insert(visited, (char *) f, NULL) == ST_OUT_OF_MEM)
00945 return(0);
00946
00947
00948 if (f == DD_ONE(dd)) {
00949 #if SIZEOF_VOID_P == 8
00950 retval = fprintf(fp, ".names %lx\n1\n",(unsigned long) f / (unsigned long) sizeof(DdNode));
00951 #else
00952 retval = fprintf(fp, ".names %x\n1\n",(unsigned) f / (unsigned) sizeof(DdNode));
00953 #endif
00954 if (retval == EOF) {
00955 return(0);
00956 } else {
00957 return(1);
00958 }
00959 }
00960
00961
00962
00963
00964 if (f == DD_ZERO(dd)) {
00965 #if SIZEOF_VOID_P == 8
00966 retval = fprintf(fp, ".names %lx\n",(unsigned long) f / (unsigned long) sizeof(DdNode));
00967 #else
00968 retval = fprintf(fp, ".names %x\n",(unsigned) f / (unsigned) sizeof(DdNode));
00969 #endif
00970 if (retval == EOF) {
00971 return(0);
00972 } else {
00973 return(1);
00974 }
00975 }
00976 if (cuddIsConstant(f))
00977 return(0);
00978
00979
00980 T = cuddT(f);
00981 retval = ddDoDumpBlif(dd,T,fp,visited,names);
00982 if (retval != 1) return(retval);
00983 E = Cudd_Regular(cuddE(f));
00984 retval = ddDoDumpBlif(dd,E,fp,visited,names);
00985 if (retval != 1) return(retval);
00986
00987
00988 if (names != NULL) {
00989 retval = fprintf(fp,".names %s", names[f->index]);
00990 } else {
00991 retval = fprintf(fp,".names %d", f->index);
00992 }
00993 if (retval == EOF)
00994 return(0);
00995
00996 #if SIZEOF_VOID_P == 8
00997 if (Cudd_IsComplement(cuddE(f))) {
00998 retval = fprintf(fp," %lx %lx %lx\n11- 1\n0-0 1\n",
00999 (unsigned long) T / (unsigned long) sizeof(DdNode),
01000 (unsigned long) E / (unsigned long) sizeof(DdNode),
01001 (unsigned long) f / (unsigned long) sizeof(DdNode));
01002 } else {
01003 retval = fprintf(fp," %lx %lx %lx\n11- 1\n0-1 1\n",
01004 (unsigned long) T / (unsigned long) sizeof(DdNode),
01005 (unsigned long) E / (unsigned long) sizeof(DdNode),
01006 (unsigned long) f / (unsigned long) sizeof(DdNode));
01007 }
01008 #else
01009 if (Cudd_IsComplement(cuddE(f))) {
01010 retval = fprintf(fp," %x %x %x\n11- 1\n0-0 1\n",
01011 (unsigned) T / (unsigned) sizeof(DdNode),
01012 (unsigned) E / (unsigned) sizeof(DdNode),
01013 (unsigned) f / (unsigned) sizeof(DdNode));
01014 } else {
01015 retval = fprintf(fp," %x %x %x\n11- 1\n0-1 1\n",
01016 (unsigned) T / (unsigned) sizeof(DdNode),
01017 (unsigned) E / (unsigned) sizeof(DdNode),
01018 (unsigned) f / (unsigned) sizeof(DdNode));
01019 }
01020 #endif
01021 if (retval == EOF) {
01022 return(0);
01023 } else {
01024 return(1);
01025 }
01026
01027 }
01028
01029
01044 static int
01045 ddDoDumpDaVinci(
01046 DdManager * dd,
01047 DdNode * f,
01048 FILE * fp,
01049 st_table * visited,
01050 char ** names,
01051 long mask)
01052 {
01053 DdNode *T, *E;
01054 int retval;
01055 long id;
01056
01057 #ifdef DD_DEBUG
01058 assert(!Cudd_IsComplement(f));
01059 #endif
01060
01061 id = ((long) f & mask) / sizeof(DdNode);
01062
01063
01064 if (st_is_member(visited, (char *) f) == 1) {
01065 retval = fprintf(fp,"r(\"%lx\")", id);
01066 if (retval == EOF) {
01067 return(0);
01068 } else {
01069 return(1);
01070 }
01071 }
01072
01073
01074 if (f == NULL)
01075 return(0);
01076
01077
01078 if (st_insert(visited, (char *) f, NULL) == ST_OUT_OF_MEM)
01079 return(0);
01080
01081
01082 if (Cudd_IsConstant(f)) {
01083 retval = fprintf(fp, "l(\"%lx\",n(\"constant\",[a(\"OBJECT\",\"%g\")],[]))", id, cuddV(f));
01084 if (retval == EOF) {
01085 return(0);
01086 } else {
01087 return(1);
01088 }
01089 }
01090
01091
01092 if (names != NULL) {
01093 retval = fprintf(fp,
01094 "l(\"%lx\",n(\"internal\",[a(\"OBJECT\",\"%s\"),",
01095 id, names[f->index]);
01096 } else {
01097 retval = fprintf(fp,
01098 "l(\"%lx\",n(\"internal\",[a(\"OBJECT\",\"%d\"),",
01099 id, f->index);
01100 }
01101 retval = fprintf(fp, "a(\"_GO\",\"ellipse\")],[e(\"then\",[a(\"EDGECOLOR\",\"blue\"),a(\"_DIR\",\"none\")],");
01102 if (retval == EOF) return(0);
01103 T = cuddT(f);
01104 retval = ddDoDumpDaVinci(dd,T,fp,visited,names,mask);
01105 if (retval != 1) return(retval);
01106 retval = fprintf(fp, "),e(\"else\",[a(\"EDGECOLOR\",\"%s\"),a(\"_DIR\",\"none\")],",
01107 Cudd_IsComplement(cuddE(f)) ? "red" : "green");
01108 if (retval == EOF) return(0);
01109 E = Cudd_Regular(cuddE(f));
01110 retval = ddDoDumpDaVinci(dd,E,fp,visited,names,mask);
01111 if (retval != 1) return(retval);
01112
01113 retval = fprintf(fp,")]))");
01114 if (retval == EOF) {
01115 return(0);
01116 } else {
01117 return(1);
01118 }
01119
01120 }
01121
01122
01137 static int
01138 ddDoDumpDDcal(
01139 DdManager * dd,
01140 DdNode * f,
01141 FILE * fp,
01142 st_table * visited,
01143 char ** names,
01144 long mask)
01145 {
01146 DdNode *T, *E;
01147 int retval;
01148 long id, idT, idE;
01149
01150 #ifdef DD_DEBUG
01151 assert(!Cudd_IsComplement(f));
01152 #endif
01153
01154 id = ((long) f & mask) / sizeof(DdNode);
01155
01156
01157 if (st_is_member(visited, (char *) f) == 1) {
01158 return(1);
01159 }
01160
01161
01162 if (f == NULL)
01163 return(0);
01164
01165
01166 if (st_insert(visited, (char *) f, NULL) == ST_OUT_OF_MEM)
01167 return(0);
01168
01169
01170 if (Cudd_IsConstant(f)) {
01171 if (f != DD_ONE(dd) && f != DD_ZERO(dd))
01172 return(0);
01173 retval = fprintf(fp, "n%lx = %g\n", id, cuddV(f));
01174 if (retval == EOF) {
01175 return(0);
01176 } else {
01177 return(1);
01178 }
01179 }
01180
01181
01182 T = cuddT(f);
01183 retval = ddDoDumpDDcal(dd,T,fp,visited,names,mask);
01184 if (retval != 1) return(retval);
01185 E = Cudd_Regular(cuddE(f));
01186 retval = ddDoDumpDDcal(dd,E,fp,visited,names,mask);
01187 if (retval != 1) return(retval);
01188 idT = ((long) T & mask) / sizeof(DdNode);
01189 idE = ((long) E & mask) / sizeof(DdNode);
01190 if (names != NULL) {
01191 retval = fprintf(fp, "n%lx = %s * n%lx + %s' * n%lx%s\n",
01192 id, names[f->index], idT, names[f->index],
01193 idE, Cudd_IsComplement(cuddE(f)) ? "'" : "");
01194 } else {
01195 retval = fprintf(fp, "n%lx = v%d * n%lx + v%d' * n%lx%s\n",
01196 id, f->index, idT, f->index,
01197 idE, Cudd_IsComplement(cuddE(f)) ? "'" : "");
01198 }
01199 if (retval == EOF) {
01200 return(0);
01201 } else {
01202 return(1);
01203 }
01204
01205 }
01206
01207
01225 static int
01226 ddDoDumpFactoredForm(
01227 DdManager * dd,
01228 DdNode * f,
01229 FILE * fp,
01230 char ** names)
01231 {
01232 DdNode *T, *E;
01233 int retval;
01234
01235 #ifdef DD_DEBUG
01236 assert(!Cudd_IsComplement(f));
01237 assert(!Cudd_IsConstant(f));
01238 #endif
01239
01240
01241 if (f == NULL)
01242 return(0);
01243
01244
01245 T = cuddT(f);
01246 E = cuddE(f);
01247 if (T != DD_ZERO(dd)) {
01248 if (E != DD_ONE(dd)) {
01249 if (names != NULL) {
01250 retval = fprintf(fp, "%s", names[f->index]);
01251 } else {
01252 retval = fprintf(fp, "x%d", f->index);
01253 }
01254 if (retval == EOF) return(0);
01255 }
01256 if (T != DD_ONE(dd)) {
01257 retval = fprintf(fp, "%s(", E != DD_ONE(dd) ? " * " : "");
01258 if (retval == EOF) return(0);
01259 retval = ddDoDumpFactoredForm(dd,T,fp,names);
01260 if (retval != 1) return(retval);
01261 retval = fprintf(fp, ")");
01262 if (retval == EOF) return(0);
01263 }
01264 if (E == Cudd_Not(DD_ONE(dd)) || E == DD_ZERO(dd)) return(1);
01265 retval = fprintf(fp, " + ");
01266 if (retval == EOF) return(0);
01267 }
01268 E = Cudd_Regular(E);
01269 if (T != DD_ONE(dd)) {
01270 if (names != NULL) {
01271 retval = fprintf(fp, "!%s", names[f->index]);
01272 } else {
01273 retval = fprintf(fp, "!x%d", f->index);
01274 }
01275 if (retval == EOF) return(0);
01276 }
01277 if (E != DD_ONE(dd)) {
01278 retval = fprintf(fp, "%s%s(", T != DD_ONE(dd) ? " * " : "",
01279 E != cuddE(f) ? "!" : "");
01280 if (retval == EOF) return(0);
01281 retval = ddDoDumpFactoredForm(dd,E,fp,names);
01282 if (retval != 1) return(retval);
01283 retval = fprintf(fp, ")");
01284 if (retval == EOF) return(0);
01285 }
01286 return(1);
01287
01288 }
01289