ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
ioWriteBaf.c
Go to the documentation of this file.
1
20
21#include "ioAbc.h"
22
24
25
29
30/*
31 Binary Aig Format
32
33 The motivation for this format is to have
34 - compact binary representation of large AIGs (~10x more compact than BLIF)
35 - consequently, fast reading/writing of large AIGs (~10x faster than BLIF)
36 - representation for all tech-ind info related to an AIG
37 - human-readable file header
38
39 The header:
40 (1) May contain several lines of human-readable comments.
41 Each comment line begins with symbol '#' and ends with symbol '\n'.
42 (2) Always contains the following data.
43 - benchmark name
44 - number of primary inputs
45 - number of primary outputs
46 - number of latches
47 - number of AIG nodes (excluding the constant 1 node)
48 Each entry is followed by 0-byte (character '\0'):
49 (3) Next follow the names of the PIs, POs, and latches in this order.
50 Each name is followed by 0-byte (character '\0').
51 Inside each set of names (PIs, POs, latches) there should be no
52 identical names but the PO names may coincide with PI/latch names.
53
54 The body:
55 (1) First part of the body contains binary information about the internal AIG nodes.
56 Each internal AIG node is represented using two edges (each edge is a 4-byte integer).
57 Each integer is the fanin ID followed by 1-bit representation of the complemented attribute.
58 (For example, complemented edge to node 10 will be represented as 2*10 + 1 = 21.)
59 The IDs of the nodes are created as follows: Constant 1 node has ID=0.
60 CIs (PIs and latch outputs) have 1-based IDs assigned in that order.
61 Each node in the array of the internal AIG nodes has the ID assigned in that order.
62 The constant 1 node is not written into the file.
63 (2) Second part of the body contains binary information about the edges connecting
64 the COs (POs and latch inputs) to the internal AIG nodes.
65 Each edge is a 4-byte integer the same way as a node fanin.
66 The latch initial value (2 bits) is stored in this integer.
67*/
68
72
84void Io_WriteBaf( Abc_Ntk_t * pNtk, char * pFileName )
85{
86 ProgressBar * pProgress;
87 FILE * pFile;
88 Abc_Obj_t * pObj;
89 int i, nNodes, nAnds, nBufferSize;
90 unsigned * pBufferNode;
91 assert( Abc_NtkIsStrash(pNtk) );
92 // start the output stream
93 pFile = fopen( pFileName, "wb" );
94 if ( pFile == NULL )
95 {
96 fprintf( stdout, "Io_WriteBaf(): Cannot open the output file \"%s\".\n", pFileName );
97 return;
98 }
99
100 // write the comment
101 fprintf( pFile, "# BAF (Binary Aig Format) for \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
102
103 // write the network name
104 fprintf( pFile, "%s%c", pNtk->pName, 0 );
105 // write the number of PIs
106 fprintf( pFile, "%d%c", Abc_NtkPiNum(pNtk), 0 );
107 // write the number of POs
108 fprintf( pFile, "%d%c", Abc_NtkPoNum(pNtk), 0 );
109 // write the number of latches
110 fprintf( pFile, "%d%c", Abc_NtkLatchNum(pNtk), 0 );
111 // write the number of internal nodes
112 fprintf( pFile, "%d%c", Abc_NtkNodeNum(pNtk), 0 );
113
114 // write PIs
115 Abc_NtkForEachPi( pNtk, pObj, i )
116 fprintf( pFile, "%s%c", Abc_ObjName(pObj), 0 );
117 // write POs
118 Abc_NtkForEachPo( pNtk, pObj, i )
119 fprintf( pFile, "%s%c", Abc_ObjName(pObj), 0 );
120 // write latches
121 Abc_NtkForEachLatch( pNtk, pObj, i )
122 {
123 fprintf( pFile, "%s%c", Abc_ObjName(pObj), 0 );
124 fprintf( pFile, "%s%c", Abc_ObjName(Abc_ObjFanin0(pObj)), 0 );
125 fprintf( pFile, "%s%c", Abc_ObjName(Abc_ObjFanout0(pObj)), 0 );
126 }
127
128 // set the node numbers to be used in the output file
129 Abc_NtkCleanCopy( pNtk );
130 nNodes = 1;
131 Abc_NtkForEachCi( pNtk, pObj, i )
132 pObj->pCopy = (Abc_Obj_t *)(ABC_PTRINT_T)nNodes++;
133 Abc_AigForEachAnd( pNtk, pObj, i )
134 pObj->pCopy = (Abc_Obj_t *)(ABC_PTRINT_T)nNodes++;
135
136 // write the nodes into the buffer
137 nAnds = 0;
138 nBufferSize = Abc_NtkNodeNum(pNtk) * 2 + Abc_NtkCoNum(pNtk);
139 pBufferNode = ABC_ALLOC( unsigned, nBufferSize );
140 pProgress = Extra_ProgressBarStart( stdout, nBufferSize );
141 Abc_AigForEachAnd( pNtk, pObj, i )
142 {
143 Extra_ProgressBarUpdate( pProgress, nAnds, NULL );
144 pBufferNode[nAnds++] = (((int)(ABC_PTRINT_T)Abc_ObjFanin0(pObj)->pCopy) << 1) | (int)Abc_ObjFaninC0(pObj);
145 pBufferNode[nAnds++] = (((int)(ABC_PTRINT_T)Abc_ObjFanin1(pObj)->pCopy) << 1) | (int)Abc_ObjFaninC1(pObj);
146 }
147
148 // write the COs into the buffer
149 Abc_NtkForEachCo( pNtk, pObj, i )
150 {
151 Extra_ProgressBarUpdate( pProgress, nAnds, NULL );
152 pBufferNode[nAnds] = (((int)(ABC_PTRINT_T)Abc_ObjFanin0(pObj)->pCopy) << 1) | (int)Abc_ObjFaninC0(pObj);
153 if ( Abc_ObjFanoutNum(pObj) > 0 && Abc_ObjIsLatch(Abc_ObjFanout0(pObj)) )
154 pBufferNode[nAnds] = (pBufferNode[nAnds] << 2) | ((int)(ABC_PTRINT_T)Abc_ObjData(Abc_ObjFanout0(pObj)) & 3);
155 nAnds++;
156 }
157 Extra_ProgressBarStop( pProgress );
158 assert( nBufferSize == nAnds );
159
160 // write the buffer
161 fwrite( pBufferNode, 1, sizeof(int) * nBufferSize, pFile );
162 fclose( pFile );
163 ABC_FREE( pBufferNode );
164}
165
166
170
171
173
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition abc.h:522
#define Abc_AigForEachAnd(pNtk, pNode, i)
Definition abc.h:488
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition abc.h:520
#define Abc_NtkForEachLatch(pNtk, pObj, i)
Definition abc.h:500
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition abcNames.c:49
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition abc.h:516
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition abc.h:518
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
Definition abcUtil.c:540
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
Definition bbrNtbdd.c:27
void Extra_ProgressBarStop(ProgressBar *p)
char * Extra_TimeStamp()
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
ABC_NAMESPACE_IMPL_START void Io_WriteBaf(Abc_Ntk_t *pNtk, char *pFileName)
DECLARATIONS ///.
Definition ioWriteBaf.c:84
char * pName
Definition abc.h:158
Abc_Obj_t * pCopy
Definition abc.h:148
#define assert(ex)
Definition util_old.h:213