1 /**CFile**********************************************************************
2 
3   FileName     [dddmpDbg.c]
4 
5   PackageName  [dddmp]
6 
7   Synopsis     [Functions to display BDD files]
8 
9   Description  [Functions to display BDD files in binary format
10     ]
11 
12   Author       [Gianpiero Cabodi and Stefano Quer]
13 
14   Copyright   [
15     Copyright (c) 2004 by Politecnico di Torino.
16     All Rights Reserved. This software is for educational purposes only.
17     Permission is given to academic institutions to use, copy, and modify
18     this software and its documentation provided that this introductory
19     message is not removed, that this software and its documentation is
20     used for the institutions' internal research and educational purposes,
21     and that no monies are exchanged. No guarantee is expressed or implied
22     by the distribution of this code.
23     Send bug-reports and/or questions to:
24     {gianpiero.cabodi,stefano.quer}@polito.it.
25     ]
26 
27 ******************************************************************************/
28 
29 #include "dddmpInt.h"
30 
31 /*---------------------------------------------------------------------------*/
32 /* Stucture declarations                                                     */
33 /*---------------------------------------------------------------------------*/
34 
35 /*---------------------------------------------------------------------------*/
36 /* Type declarations                                                         */
37 /*---------------------------------------------------------------------------*/
38 
39 /*---------------------------------------------------------------------------*/
40 /* Variable declarations                                                     */
41 /*---------------------------------------------------------------------------*/
42 
43 /*---------------------------------------------------------------------------*/
44 /* Macro declarations                                                        */
45 /*---------------------------------------------------------------------------*/
46 
47 
48 /**AutomaticStart*************************************************************/
49 
50 /*---------------------------------------------------------------------------*/
51 /* Static function prototypes                                                */
52 /*---------------------------------------------------------------------------*/
53 
54 
55 /**AutomaticEnd***************************************************************/
56 
57 
58 /*---------------------------------------------------------------------------*/
59 /* Definition of exported functions                                          */
60 /*---------------------------------------------------------------------------*/
61 
62 
63 /**Function********************************************************************
64 
65   Synopsis     [Display a binary dump file in a text file]
66 
67   Description  [Display a binary dump file in a text file]
68 
69   SideEffects  [None]
70 
71   SeeAlso      [Dddmp_cuddBddStore , Dddmp_cuddBddLoad ]
72 
73 ******************************************************************************/
74 
75 int
Dddmp_cuddBddDisplayBinary(char * fileIn,char * fileOut)76 Dddmp_cuddBddDisplayBinary(
77   char *fileIn  /* IN: name of binary file */,
78   char *fileOut /* IN: name of text file */
79   )
80 {
81   FILE *fp, *fpo;
82   int id, size;
83   struct binary_dd_code code;
84   char buf[1000];
85   int nnodes, i;
86   char *retval;
87 
88   fp = fopen (fileIn, "rb");
89   if (fp == 0) {
90     return (0);
91   }
92 
93   fpo = fopen (fileOut, "w");
94   if (fpo == 0) {
95     return (0);
96   }
97 
98   while (fgets(buf, 999,fp)!=NULL) {
99     fprintf (fpo, "%s", buf);
100     if (strncmp(buf, ".nnodes", 7) == 0) {
101       sscanf (buf, "%*s %d", &nnodes);
102     }
103     if (strncmp(buf, ".rootids", 8) == 0) {
104       break;
105     }
106   }
107 
108   for (i=1; i<=nnodes; i++) {
109     if (feof(fp)) {
110       return (0);
111     }
112     if (DddmpReadCode(fp,&code) == 0) {
113       return (0);
114     }
115     fprintf (fpo, "c  : v %d | T %d | E %d\n",
116       (int)code.V, (int)code.T,
117       (code.Ecompl ? -(int)(code.E) : (int)(code.E)));
118     if (code.V == DDDMP_TERMINAL) {
119       continue;
120     }
121     if (code.V <= DDDMP_RELATIVE_ID) {
122       size = DddmpReadInt(fp,&id);
123       if (size == 0) {
124         return (0);
125       }
126       fprintf(fpo, "v(%d): %d\n", size, id);
127     }
128     if (code.T <= DDDMP_RELATIVE_ID) {
129       size = DddmpReadInt(fp,&id);
130       if (size == 0) {
131         return (0);
132       }
133       fprintf(fpo, "T(%d): %d\n", size, id);
134     }
135     if (code.E <= DDDMP_RELATIVE_ID) {
136       size = DddmpReadInt(fp,&id);
137       if (size == 0) {
138         return (0);
139       }
140       fprintf(fpo, "E(%d): %d\n", size, id);
141     }
142 
143   }
144 
145   retval = fgets(buf, 999,fp);
146   if (!retval || strncmp(buf, ".end", 4) != 0) {
147     return (0);
148   }
149 
150   fprintf(fpo, ".end");
151 
152   fclose(fp);
153   fclose(fpo);
154 
155   return (1);
156 }
157 
158 
159 /*---------------------------------------------------------------------------*/
160 /* Definition of internal functions                                          */
161 /*---------------------------------------------------------------------------*/
162 
163 /*---------------------------------------------------------------------------*/
164 /* Definition of static functions                                            */
165 /*---------------------------------------------------------------------------*/
166 
167 
168