ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
decPrint.c
Go to the documentation of this file.
1
18
19#include "base/abc/abc.h"
20#include "dec.h"
21
23
24
28
29static void Dec_GraphPrint_rec( FILE * pFile, Dec_Graph_t * pGraph, Dec_Node_t * pNode, int fCompl, char * pNamesIn[], int * pPos, int LitSizeMax );
30static int Dec_GraphPrintGetLeafName( FILE * pFile, int iLeaf, int fCompl, char * pNamesIn[] );
31static void Dec_GraphPrintUpdatePos( FILE * pFile, int * pPos, int LitSizeMax );
32static int Dec_GraphPrintOutputName( FILE * pFile, char * pNameOut );
33
37
49void Dec_GraphPrint( FILE * pFile, Dec_Graph_t * pGraph, char * pNamesIn[], char * pNameOut )
50{
51 Vec_Ptr_t * vNamesIn = NULL;
52 int LitSizeMax, LitSizeCur, Pos, i;
53
54 // create the names if not given by the user
55 if ( pNamesIn == NULL )
56 {
57 vNamesIn = Abc_NodeGetFakeNames( Dec_GraphLeaveNum(pGraph) );
58 pNamesIn = (char **)vNamesIn->pArray;
59 }
60 if ( pNameOut == NULL )
61 pNameOut = "F";
62
63 // get the size of the longest literal
64 LitSizeMax = 0;
65 for ( i = 0; i < Dec_GraphLeaveNum(pGraph); i++ )
66 {
67 LitSizeCur = strlen(pNamesIn[i]);
68 if ( LitSizeMax < LitSizeCur )
69 LitSizeMax = LitSizeCur;
70 }
71 if ( LitSizeMax > 50 )
72 LitSizeMax = 20;
73
74 // write the decomposition graph (factored form)
75 if ( Dec_GraphIsConst(pGraph) ) // constant
76 {
77 Pos = Dec_GraphPrintOutputName( pFile, pNameOut );
78 fprintf( pFile, "Constant %d", !Dec_GraphIsComplement(pGraph) );
79 }
80 else if ( Dec_GraphIsVar(pGraph) ) // literal
81 {
82 Pos = Dec_GraphPrintOutputName( pFile, pNameOut );
83 Dec_GraphPrintGetLeafName( pFile, Dec_GraphVarInt(pGraph), Dec_GraphIsComplement(pGraph), pNamesIn );
84 }
85 else
86 {
87 Pos = Dec_GraphPrintOutputName( pFile, pNameOut );
88 Dec_GraphPrint_rec( pFile, pGraph, Dec_GraphNodeLast(pGraph), Dec_GraphIsComplement(pGraph), pNamesIn, &Pos, LitSizeMax );
89 }
90 fprintf( pFile, "\n" );
91
92 if ( vNamesIn )
93 Abc_NodeFreeNames( vNamesIn );
94}
95
107void Dec_GraphPrint2_rec( FILE * pFile, Dec_Graph_t * pGraph, Dec_Node_t * pNode, int fCompl, char * pNamesIn[], int * pPos, int LitSizeMax )
108{
109 Dec_Node_t * pNode0, * pNode1;
110 pNode0 = Dec_GraphNode(pGraph, pNode->eEdge0.Node);
111 pNode1 = Dec_GraphNode(pGraph, pNode->eEdge1.Node);
112 if ( Dec_GraphNodeIsVar(pGraph, pNode) ) // FT_NODE_LEAF )
113 {
114 (*pPos) += Dec_GraphPrintGetLeafName( pFile, Dec_GraphNodeInt(pGraph,pNode), fCompl, pNamesIn );
115 return;
116 }
117 if ( !pNode->fNodeOr ) // FT_NODE_AND )
118 {
119 if ( !pNode0->fNodeOr ) // != FT_NODE_OR )
120 Dec_GraphPrint_rec( pFile, pGraph, pNode0, pNode->fCompl0, pNamesIn, pPos, LitSizeMax );
121 else
122 {
123 fprintf( pFile, "(" );
124 (*pPos)++;
125 Dec_GraphPrint_rec( pFile, pGraph, pNode0, pNode->fCompl0, pNamesIn, pPos, LitSizeMax );
126 fprintf( pFile, ")" );
127 (*pPos)++;
128 }
129 fprintf( pFile, " " );
130 (*pPos)++;
131
132 Dec_GraphPrintUpdatePos( pFile, pPos, LitSizeMax );
133
134 if ( !pNode1->fNodeOr ) // != FT_NODE_OR )
135 Dec_GraphPrint_rec( pFile, pGraph, pNode1, pNode->fCompl1, pNamesIn, pPos, LitSizeMax );
136 else
137 {
138 fprintf( pFile, "(" );
139 (*pPos)++;
140 Dec_GraphPrint_rec( pFile, pGraph, pNode1, pNode->fCompl1, pNamesIn, pPos, LitSizeMax );
141 fprintf( pFile, ")" );
142 (*pPos)++;
143 }
144 return;
145 }
146 if ( pNode->fNodeOr ) // FT_NODE_OR )
147 {
148 Dec_GraphPrint_rec( pFile, pGraph, pNode0, pNode->fCompl0, pNamesIn, pPos, LitSizeMax );
149 fprintf( pFile, " + " );
150 (*pPos) += 3;
151
152 Dec_GraphPrintUpdatePos( pFile, pPos, LitSizeMax );
153
154 Dec_GraphPrint_rec( pFile, pGraph, pNode1, pNode->fCompl1, pNamesIn, pPos, LitSizeMax );
155 return;
156 }
157 assert( 0 );
158}
159
171void Dec_GraphPrint_rec( FILE * pFile, Dec_Graph_t * pGraph, Dec_Node_t * pNode, int fCompl, char * pNamesIn[], int * pPos, int LitSizeMax )
172{
173 Dec_Node_t * pNode0, * pNode1;
174 Dec_Node_t * pNode00, * pNode01, * pNode10, * pNode11;
175 pNode0 = Dec_GraphNode(pGraph, pNode->eEdge0.Node);
176 pNode1 = Dec_GraphNode(pGraph, pNode->eEdge1.Node);
177 if ( Dec_GraphNodeIsVar(pGraph, pNode) ) // FT_NODE_LEAF )
178 {
179 (*pPos) += Dec_GraphPrintGetLeafName( pFile, Dec_GraphNodeInt(pGraph,pNode), fCompl, pNamesIn );
180 return;
181 }
182 if ( !Dec_GraphNodeIsVar(pGraph, pNode0) && !Dec_GraphNodeIsVar(pGraph, pNode1) )
183 {
184 pNode00 = Dec_GraphNode(pGraph, pNode0->eEdge0.Node);
185 pNode01 = Dec_GraphNode(pGraph, pNode0->eEdge1.Node);
186 pNode10 = Dec_GraphNode(pGraph, pNode1->eEdge0.Node);
187 pNode11 = Dec_GraphNode(pGraph, pNode1->eEdge1.Node);
188 if ( (pNode00 == pNode10 || pNode00 == pNode11) && (pNode01 == pNode10 || pNode01 == pNode11) )
189 {
190 fprintf( pFile, "(" );
191 (*pPos)++;
192 Dec_GraphPrint_rec( pFile, pGraph, pNode00, pNode00->fCompl0, pNamesIn, pPos, LitSizeMax );
193 fprintf( pFile, " # " );
194 (*pPos) += 3;
195 Dec_GraphPrint_rec( pFile, pGraph, pNode01, pNode01->fCompl1, pNamesIn, pPos, LitSizeMax );
196 fprintf( pFile, ")" );
197 (*pPos)++;
198 return;
199 }
200 }
201 if ( fCompl )
202 {
203 fprintf( pFile, "(" );
204 (*pPos)++;
205 Dec_GraphPrint_rec( pFile, pGraph, pNode0, !pNode->eEdge0.fCompl, pNamesIn, pPos, LitSizeMax );
206 fprintf( pFile, " + " );
207 (*pPos) += 3;
208 Dec_GraphPrint_rec( pFile, pGraph, pNode1, !pNode->eEdge1.fCompl, pNamesIn, pPos, LitSizeMax );
209 fprintf( pFile, ")" );
210 (*pPos)++;
211 }
212 else
213 {
214 fprintf( pFile, "(" );
215 (*pPos)++;
216 Dec_GraphPrint_rec( pFile, pGraph, pNode0, pNode->eEdge0.fCompl, pNamesIn, pPos, LitSizeMax );
217 Dec_GraphPrint_rec( pFile, pGraph, pNode1, pNode->eEdge1.fCompl, pNamesIn, pPos, LitSizeMax );
218 fprintf( pFile, ")" );
219 (*pPos)++;
220 }
221}
222
234int Dec_GraphPrintGetLeafName( FILE * pFile, int iLeaf, int fCompl, char * pNamesIn[] )
235{
236 static char Buffer[100];
237 sprintf( Buffer, "%s%s", fCompl? "!" : "", pNamesIn[iLeaf] );
238 fprintf( pFile, "%s", Buffer );
239 return strlen( Buffer );
240}
241
253void Dec_GraphPrintUpdatePos( FILE * pFile, int * pPos, int LitSizeMax )
254{
255 int i;
256 if ( *pPos + LitSizeMax < 77 )
257 return;
258 fprintf( pFile, "\n" );
259 for ( i = 0; i < 10; i++ )
260 fprintf( pFile, " " );
261 *pPos = 10;
262}
263
275int Dec_GraphPrintOutputName( FILE * pFile, char * pNameOut )
276{
277 if ( pNameOut == NULL )
278 return 0;
279 fprintf( pFile, "%6s = ", pNameOut );
280 return 10;
281}
282
286
287
289
ABC_DLL void Abc_NodeFreeNames(Vec_Ptr_t *vNames)
Definition abcNames.c:264
ABC_DLL Vec_Ptr_t * Abc_NodeGetFakeNames(int nNames)
Definition abcNames.c:228
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void Dec_GraphPrint2_rec(FILE *pFile, Dec_Graph_t *pGraph, Dec_Node_t *pNode, int fCompl, char *pNamesIn[], int *pPos, int LitSizeMax)
Definition decPrint.c:107
void Dec_GraphPrint(FILE *pFile, Dec_Graph_t *pGraph, char *pNamesIn[], char *pNameOut)
FUNCTION DEFINITIONS ///.
Definition decPrint.c:49
struct Dec_Node_t_ Dec_Node_t
Definition dec.h:49
struct Dec_Graph_t_ Dec_Graph_t
Definition dec.h:68
ush Pos
Definition deflate.h:88
unsigned fCompl1
Definition dec.h:61
Dec_Edge_t eEdge1
Definition dec.h:53
unsigned fNodeOr
Definition dec.h:59
Dec_Edge_t eEdge0
Definition dec.h:52
unsigned fCompl0
Definition dec.h:60
#define assert(ex)
Definition util_old.h:213
int strlen()
char * sprintf()
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42