00001
00021 #include "aig.h"
00022
00026
00030
00043 void Aig_WriteDotAig( Aig_Man_t * pMan, char * pFileName, int fHaig, Vec_Ptr_t * vBold )
00044 {
00045 FILE * pFile;
00046 Aig_Obj_t * pNode;
00047 int LevelMax, Level, i;
00048
00049 if ( Aig_ManNodeNum(pMan) > 200 )
00050 {
00051 fprintf( stdout, "Cannot visualize AIG with more than 200 nodes.\n" );
00052 return;
00053 }
00054 if ( (pFile = fopen( pFileName, "w" )) == NULL )
00055 {
00056 fprintf( stdout, "Cannot open the intermediate file \"%s\".\n", pFileName );
00057 return;
00058 }
00059
00060
00061 if ( vBold )
00062 Vec_PtrForEachEntry( vBold, pNode, i )
00063 pNode->fMarkB = 1;
00064
00065
00066
00067 LevelMax = 1 + Aig_ManLevels( pMan );
00068 Aig_ManForEachPo( pMan, pNode, i )
00069 pNode->Level = LevelMax;
00070
00071
00072 fprintf( pFile, "# %s\n", "AIG structure generated by IVY package" );
00073 fprintf( pFile, "\n" );
00074 fprintf( pFile, "digraph AIG {\n" );
00075 fprintf( pFile, "size = \"7.5,10\";\n" );
00076
00077
00078 fprintf( pFile, "center = true;\n" );
00079
00080
00081
00082 fprintf( pFile, "edge [dir = back];\n" );
00083 fprintf( pFile, "\n" );
00084
00085
00086 fprintf( pFile, "{\n" );
00087 fprintf( pFile, " node [shape = plaintext];\n" );
00088 fprintf( pFile, " edge [style = invis];\n" );
00089 fprintf( pFile, " LevelTitle1 [label=\"\"];\n" );
00090 fprintf( pFile, " LevelTitle2 [label=\"\"];\n" );
00091
00092 for ( Level = LevelMax; Level >= 0; Level-- )
00093 {
00094
00095 fprintf( pFile, " Level%d", Level );
00096 fprintf( pFile, " [label = " );
00097
00098 fprintf( pFile, "\"" );
00099 fprintf( pFile, "\"" );
00100 fprintf( pFile, "];\n" );
00101 }
00102
00103
00104 fprintf( pFile, " LevelTitle1 -> LevelTitle2 ->" );
00105 for ( Level = LevelMax; Level >= 0; Level-- )
00106 {
00107
00108 fprintf( pFile, " Level%d", Level );
00109
00110 if ( Level != 0 )
00111 fprintf( pFile, " ->" );
00112 else
00113 fprintf( pFile, ";" );
00114 }
00115 fprintf( pFile, "\n" );
00116 fprintf( pFile, "}" );
00117 fprintf( pFile, "\n" );
00118 fprintf( pFile, "\n" );
00119
00120
00121 fprintf( pFile, "{\n" );
00122 fprintf( pFile, " rank = same;\n" );
00123 fprintf( pFile, " LevelTitle1;\n" );
00124 fprintf( pFile, " title1 [shape=plaintext,\n" );
00125 fprintf( pFile, " fontsize=20,\n" );
00126 fprintf( pFile, " fontname = \"Times-Roman\",\n" );
00127 fprintf( pFile, " label=\"" );
00128 fprintf( pFile, "%s", "AIG structure visualized by ABC" );
00129 fprintf( pFile, "\\n" );
00130 fprintf( pFile, "Benchmark \\\"%s\\\". ", "aig" );
00131
00132 fprintf( pFile, "\"\n" );
00133 fprintf( pFile, " ];\n" );
00134 fprintf( pFile, "}" );
00135 fprintf( pFile, "\n" );
00136 fprintf( pFile, "\n" );
00137
00138
00139 fprintf( pFile, "{\n" );
00140 fprintf( pFile, " rank = same;\n" );
00141 fprintf( pFile, " LevelTitle2;\n" );
00142 fprintf( pFile, " title2 [shape=plaintext,\n" );
00143 fprintf( pFile, " fontsize=18,\n" );
00144 fprintf( pFile, " fontname = \"Times-Roman\",\n" );
00145 fprintf( pFile, " label=\"" );
00146 fprintf( pFile, "The set contains %d logic nodes and spans %d levels.", Aig_ManNodeNum(pMan), LevelMax );
00147 fprintf( pFile, "\\n" );
00148 fprintf( pFile, "\"\n" );
00149 fprintf( pFile, " ];\n" );
00150 fprintf( pFile, "}" );
00151 fprintf( pFile, "\n" );
00152 fprintf( pFile, "\n" );
00153
00154
00155 fprintf( pFile, "{\n" );
00156 fprintf( pFile, " rank = same;\n" );
00157
00158 fprintf( pFile, " Level%d;\n", LevelMax );
00159
00160 Aig_ManForEachPo( pMan, pNode, i )
00161 {
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 fprintf( pFile, " Node%d [label = \"%d\"", pNode->Id, pNode->Id );
00172
00173 fprintf( pFile, ", shape = %s", (Aig_ObjIsLatch(pNode)? "box":"invtriangle") );
00174 fprintf( pFile, ", color = coral, fillcolor = coral" );
00175 fprintf( pFile, "];\n" );
00176 }
00177 fprintf( pFile, "}" );
00178 fprintf( pFile, "\n" );
00179 fprintf( pFile, "\n" );
00180
00181
00182 for ( Level = LevelMax - 1; Level > 0; Level-- )
00183 {
00184 fprintf( pFile, "{\n" );
00185 fprintf( pFile, " rank = same;\n" );
00186
00187 fprintf( pFile, " Level%d;\n", Level );
00188 Aig_ManForEachObj( pMan, pNode, i )
00189 {
00190 if ( (int)pNode->Level != Level )
00191 continue;
00192
00193
00194
00195
00196
00197
00198
00199 fprintf( pFile, " Node%d [label = \"%d\"", pNode->Id, pNode->Id );
00200
00201 fprintf( pFile, ", shape = ellipse" );
00202 if ( vBold && pNode->fMarkB )
00203 fprintf( pFile, ", style = filled" );
00204 fprintf( pFile, "];\n" );
00205 }
00206 fprintf( pFile, "}" );
00207 fprintf( pFile, "\n" );
00208 fprintf( pFile, "\n" );
00209 }
00210
00211
00212 fprintf( pFile, "{\n" );
00213 fprintf( pFile, " rank = same;\n" );
00214
00215 fprintf( pFile, " Level%d;\n", 0 );
00216
00217 if ( Aig_ObjRefs(Aig_ManConst1(pMan)) > 0 )
00218 {
00219 pNode = Aig_ManConst1(pMan);
00220
00221 fprintf( pFile, " Node%d [label = \"Const1\"", pNode->Id );
00222 fprintf( pFile, ", shape = ellipse" );
00223 fprintf( pFile, ", color = coral, fillcolor = coral" );
00224 fprintf( pFile, "];\n" );
00225 }
00226
00227 Aig_ManForEachPi( pMan, pNode, i )
00228 {
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238 fprintf( pFile, " Node%d [label = \"%d\"", pNode->Id, pNode->Id );
00239
00240 fprintf( pFile, ", shape = %s", (Aig_ObjIsLatch(pNode)? "box":"triangle") );
00241 fprintf( pFile, ", color = coral, fillcolor = coral" );
00242 fprintf( pFile, "];\n" );
00243 }
00244 fprintf( pFile, "}" );
00245 fprintf( pFile, "\n" );
00246 fprintf( pFile, "\n" );
00247
00248
00249 fprintf( pFile, "title1 -> title2 [style = invis];\n" );
00250 Aig_ManForEachPo( pMan, pNode, i )
00251 fprintf( pFile, "title2 -> Node%d%s [style = invis];\n", pNode->Id, (Aig_ObjIsLatch(pNode)? "_in":"") );
00252
00253
00254 Aig_ManForEachObj( pMan, pNode, i )
00255 {
00256 if ( !Aig_ObjIsNode(pNode) && !Aig_ObjIsPo(pNode) && !Aig_ObjIsBuf(pNode) )
00257 continue;
00258
00259 fprintf( pFile, "Node%d%s", pNode->Id, (Aig_ObjIsLatch(pNode)? "_in":"") );
00260 fprintf( pFile, " -> " );
00261 fprintf( pFile, "Node%d%s", Aig_ObjFaninId0(pNode), (Aig_ObjIsLatch(Aig_ObjFanin0(pNode))? "_out":"") );
00262 fprintf( pFile, " [" );
00263 fprintf( pFile, "style = %s", Aig_ObjFaninC0(pNode)? "dotted" : "bold" );
00264
00265
00266 fprintf( pFile, "]" );
00267 fprintf( pFile, ";\n" );
00268 if ( !Aig_ObjIsNode(pNode) )
00269 continue;
00270
00271 fprintf( pFile, "Node%d", pNode->Id );
00272 fprintf( pFile, " -> " );
00273 fprintf( pFile, "Node%d%s", Aig_ObjFaninId1(pNode), (Aig_ObjIsLatch(Aig_ObjFanin1(pNode))? "_out":"") );
00274 fprintf( pFile, " [" );
00275 fprintf( pFile, "style = %s", Aig_ObjFaninC1(pNode)? "dotted" : "bold" );
00276
00277
00278 fprintf( pFile, "]" );
00279 fprintf( pFile, ";\n" );
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302 }
00303
00304 fprintf( pFile, "}" );
00305 fprintf( pFile, "\n" );
00306 fprintf( pFile, "\n" );
00307 fclose( pFile );
00308
00309
00310 if ( vBold )
00311 Vec_PtrForEachEntry( vBold, pNode, i )
00312 pNode->fMarkB = 0;
00313
00314 Aig_ManForEachPo( pMan, pNode, i )
00315 pNode->Level = Aig_ObjFanin0(pNode)->Level;
00316 }
00317
00329 void Aig_ManShow( Aig_Man_t * pMan, int fHaig, Vec_Ptr_t * vBold )
00330 {
00331 extern void Abc_ShowFile( char * FileNameDot );
00332 static Counter = 0;
00333 char FileNameDot[200];
00334 FILE * pFile;
00335
00336
00337 sprintf( FileNameDot, "temp%02d.dot", Counter++ );
00338
00339 if ( (pFile = fopen( FileNameDot, "w" )) == NULL )
00340 {
00341 fprintf( stdout, "Cannot open the intermediate file \"%s\".\n", FileNameDot );
00342 return;
00343 }
00344 fclose( pFile );
00345
00346 Aig_WriteDotAig( pMan, FileNameDot, fHaig, vBold );
00347
00348 Abc_ShowFile( FileNameDot );
00349 }
00350
00351
00355
00356