abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ioWriteList.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [ioWriteList.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Command processing package.]
8 
9  Synopsis [Procedures to write the graph structure of sequential AIG.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: ioWriteList.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "ioAbc.h"
22 
24 
25 
26 /*
27 -------- Original Message --------
28 Subject: Re: abc release and retiming
29 Date: Sun, 13 Nov 2005 20:31:18 -0500 (EST)
30 From: Luca Carloni <luca@cs.columbia.edu>
31 To: Alan Mishchenko <alanmi@eecs.berkeley.edu>
32 
33 Alan,
34 
35 My graph-representation file format is based on an adjacency list
36 representation and is indeed quite simple, in fact maybe too simple... I
37 used it in order to reason on relatively small weighed direct graphs. I
38 simply list all vertices, one per line and for each vertex "V_source" I
39 list all vertices that are "sinks" with respect to it, i.e. such that
40 there is a distinct arc between "V_source" and each of them (in
41 paranthesis I list the name of the edge and its weight (number of latency
42 on that path). For instance, if you look at the following graph, you have
43 that vertex "v_5" is connected to vertex "v_6" through a directed arc
44 called "v_5_to_v_6" whose latency is equal to 3, i.e. there are three
45 flip-flops on this arc. Still, notice that I sometime interpret the graph
46 also as the representation of a LIS where each node corresponds to a
47 shell encapsulating a sequential core module (i.e. a module which does not
48 contain any combinational path between its inputs and its outputs). With
49 this representation an arc of latency 3 is interpreted as a wire where two
50 relay stations have been inserted in addition to the flip-flop terminating
51 the output of the core module.
52 
53 Finally, notice that the name of the arc does not necessarily have to be
54 "v_5_to_v_6", but it could have been something like "arc_222" or "xyz" as
55 long as it is a unique name in the graph.
56 
57 Thanks,
58 Luca
59 
60 Example of graph representation
61 -----------------------------------------------------------------------------
62 v_5 > v_6 ([v_5_to_v_6] = 3), v_12 ([v_5_to_v_12] = 2).
63 v_2 > v_4 ([v_2_to_v_4] = 1), v_10_s0 ([v_2_to_v_10_s0] = 6), v_12 ([v_2_to_v_12] = 3).
64 v_9 > v_10_s0 ([v_9_to_v_10_s0] = 5), v_12 ([v_9_to_v_12] = 2).
65 v_12 > v_13 ([v_12_to_v_13] = 5).
66 v_13 > v_14 ([v_13_to_v_14] = 1).
67 v_6 > v_7 ([v_6_to_v_7] = 2).
68 v_4 > v_5 ([v_4_to_v_5] = 2).
69 v_1 > v_2 ([v_1_to_v_2] = 1).
70 v_7 > v_8 ([v_7_to_v_8] = 2).
71 t > .
72 v_14 > t ([v_14_to_t] = 1), v_5 ([v_14_to_v_5] = 1).
73 v_8 > v_9 ([v_8_to_v_9] = 2).
74 s > v_1 ([s_to_v_1] = 1).
75 v_10_s0 > v_10_s1 ([v_10_s0_to_v_10_s1] = 1).
76 v_10_s1 > v_4 ([v_10_s1__v_4] = 1), v_8 ([v_10_s1__v_8] = 1).
77 -----------------------------------------------------------------------------
78 */
79 
80 ////////////////////////////////////////////////////////////////////////
81 /// DECLARATIONS ///
82 ////////////////////////////////////////////////////////////////////////
83 
84 static void Io_WriteListEdge( FILE * pFile, Abc_Obj_t * pObj );
85 static void Io_WriteListHost( FILE * pFile, Abc_Ntk_t * pNtk );
86 
87 ////////////////////////////////////////////////////////////////////////
88 /// FUNCTION DEFINITIONS ///
89 ////////////////////////////////////////////////////////////////////////
90 
91 /**Function*************************************************************
92 
93  Synopsis [Writes the adjacency list for a sequential AIG.]
94 
95  Description []
96 
97  SideEffects []
98 
99  SeeAlso []
100 
101 ***********************************************************************/
102 void Io_WriteList( Abc_Ntk_t * pNtk, char * pFileName, int fUseHost )
103 {
104  FILE * pFile;
105  Abc_Obj_t * pObj;
106  int i;
107 
108 // assert( Abc_NtkIsSeq(pNtk) );
109 
110  // start the output stream
111  pFile = fopen( pFileName, "w" );
112  if ( pFile == NULL )
113  {
114  fprintf( stdout, "Io_WriteList(): Cannot open the output file \"%s\".\n", pFileName );
115  return;
116  }
117 
118  fprintf( pFile, "# Adjacency list for sequential AIG \"%s\"\n", pNtk->pName );
119  fprintf( pFile, "# written by ABC on %s\n", Extra_TimeStamp() );
120 
121  // write the constant node
122  if ( Abc_ObjFanoutNum( Abc_AigConst1(pNtk) ) > 0 )
123  Io_WriteListEdge( pFile, Abc_AigConst1(pNtk) );
124 
125  // write the PI edges
126  Abc_NtkForEachPi( pNtk, pObj, i )
127  Io_WriteListEdge( pFile, pObj );
128 
129  // write the internal nodes
130  Abc_AigForEachAnd( pNtk, pObj, i )
131  Io_WriteListEdge( pFile, pObj );
132 
133  // write the host node
134  if ( fUseHost )
135  Io_WriteListHost( pFile, pNtk );
136  else
137  Abc_NtkForEachPo( pNtk, pObj, i )
138  Io_WriteListEdge( pFile, pObj );
139 
140  fprintf( pFile, "\n" );
141  fclose( pFile );
142 }
143 
144 /**Function*************************************************************
145 
146  Synopsis [Writes the adjacency list for one edge in a sequential AIG.]
147 
148  Description []
149 
150  SideEffects []
151 
152  SeeAlso []
153 
154 ***********************************************************************/
155 void Io_WriteListEdge( FILE * pFile, Abc_Obj_t * pObj )
156 {
157  Abc_Obj_t * pFanout;
158  int i;
159  fprintf( pFile, "%-10s > ", Abc_ObjName(pObj) );
160  Abc_ObjForEachFanout( pObj, pFanout, i )
161  {
162  fprintf( pFile, " %s", Abc_ObjName(pFanout) );
163  fprintf( pFile, " ([%s_to_", Abc_ObjName(pObj) );
164 // fprintf( pFile, "%s] = %d)", Abc_ObjName(pFanout), Seq_ObjFanoutL(pObj, pFanout) );
165  fprintf( pFile, "%s] = %d)", Abc_ObjName(pFanout), 0 );
166  if ( i != Abc_ObjFanoutNum(pObj) - 1 )
167  fprintf( pFile, "," );
168  }
169  fprintf( pFile, "." );
170  fprintf( pFile, "\n" );
171 }
172 
173 /**Function*************************************************************
174 
175  Synopsis [Writes the adjacency list for one edge in a sequential AIG.]
176 
177  Description []
178 
179  SideEffects []
180 
181  SeeAlso []
182 
183 ***********************************************************************/
184 void Io_WriteListHost( FILE * pFile, Abc_Ntk_t * pNtk )
185 {
186  Abc_Obj_t * pObj;
187  int i;
188 
189  Abc_NtkForEachPo( pNtk, pObj, i )
190  {
191  fprintf( pFile, "%-10s > ", Abc_ObjName(pObj) );
192  fprintf( pFile, " %s ([%s_to_%s] = %d)", "HOST", Abc_ObjName(pObj), "HOST", 0 );
193  fprintf( pFile, "." );
194  fprintf( pFile, "\n" );
195  }
196 
197  fprintf( pFile, "%-10s > ", "HOST" );
198  Abc_NtkForEachPi( pNtk, pObj, i )
199  {
200  fprintf( pFile, " %s", Abc_ObjName(pObj) );
201  fprintf( pFile, " ([%s_to_%s] = %d)", "HOST", Abc_ObjName(pObj), 0 );
202  if ( i != Abc_NtkPiNum(pNtk) - 1 )
203  fprintf( pFile, "," );
204  }
205  fprintf( pFile, "." );
206  fprintf( pFile, "\n" );
207 }
208 
209 
210 /**Function*************************************************************
211 
212  Synopsis [Writes the adjacency list for a sequential AIG.]
213 
214  Description []
215 
216  SideEffects []
217 
218  SeeAlso []
219 
220 ***********************************************************************/
221 void Io_WriteCellNet( Abc_Ntk_t * pNtk, char * pFileName )
222 {
223  FILE * pFile;
224  Abc_Obj_t * pObj, * pFanout;
225  int i, k;
226 
227  assert( Abc_NtkIsLogic(pNtk) );
228 
229  // start the output stream
230  pFile = fopen( pFileName, "w" );
231  if ( pFile == NULL )
232  {
233  fprintf( stdout, "Io_WriteCellNet(): Cannot open the output file \"%s\".\n", pFileName );
234  return;
235  }
236 
237  fprintf( pFile, "# CellNet file for network \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
238 
239  // the only tricky part with writing is handling latches:
240  // each latch comes with (a) single-input latch-input node, (b) latch proper, (c) single-input latch-output node
241  // we arbitrarily decide to use the interger ID of the latch-input node to represent the latch in the file
242  // (this ID is used for both the cell and the net driven by that cell)
243 
244  // write the PIs
245  Abc_NtkForEachPi( pNtk, pObj, i )
246  fprintf( pFile, "cell %d is 0\n", pObj->Id );
247  // write the POs
248  Abc_NtkForEachPo( pNtk, pObj, i )
249  fprintf( pFile, "cell %d is 1\n", pObj->Id );
250  // write the latches (use the ID of latch input)
251  Abc_NtkForEachLatch( pNtk, pObj, i )
252  fprintf( pFile, "cell %d is 2\n", Abc_ObjFanin0(pObj)->Id );
253  // write the logic nodes
254  Abc_NtkForEachNode( pNtk, pObj, i )
255  fprintf( pFile, "cell %d is %d\n", pObj->Id, 3+Abc_ObjFaninNum(pObj) );
256 
257  // write the nets driven by PIs
258  Abc_NtkForEachPi( pNtk, pObj, i )
259  {
260  fprintf( pFile, "net %d %d 0", pObj->Id, pObj->Id );
261  Abc_ObjForEachFanout( pObj, pFanout, k )
262  fprintf( pFile, " %d %d", pFanout->Id, 1 + Abc_ObjFanoutFaninNum(pFanout, pObj) );
263  fprintf( pFile, "\n" );
264  }
265  // write the nets driven by latches
266  Abc_NtkForEachLatch( pNtk, pObj, i )
267  {
268  fprintf( pFile, "net %d %d 0", Abc_ObjFanin0(pObj)->Id, Abc_ObjFanin0(pObj)->Id );
269  pObj = Abc_ObjFanout0(pObj);
270  Abc_ObjForEachFanout( pObj, pFanout, k )
271  fprintf( pFile, " %d %d", pFanout->Id, 1 + Abc_ObjFanoutFaninNum(pFanout, pObj) );
272  fprintf( pFile, "\n" );
273  }
274  // write the nets driven by nodes
275  Abc_NtkForEachNode( pNtk, pObj, i )
276  {
277  fprintf( pFile, "net %d %d 0", pObj->Id, pObj->Id );
278  Abc_ObjForEachFanout( pObj, pFanout, k )
279  fprintf( pFile, " %d %d", pFanout->Id, 1 + Abc_ObjFanoutFaninNum(pFanout, pObj) );
280  fprintf( pFile, "\n" );
281  }
282 
283  fprintf( pFile, "\n" );
284  fclose( pFile );
285 }
286 
287 ////////////////////////////////////////////////////////////////////////
288 /// END OF FILE ///
289 ////////////////////////////////////////////////////////////////////////
290 
291 
293 
static int Abc_NtkIsLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:250
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
Definition: abcAig.c:683
static int Abc_ObjFanoutNum(Abc_Obj_t *pObj)
Definition: abc.h:365
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
void Io_WriteCellNet(Abc_Ntk_t *pNtk, char *pFileName)
Definition: ioWriteList.c:221
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
#define Abc_AigForEachAnd(pNtk, pNode, i)
Definition: abc.h:485
static ABC_NAMESPACE_IMPL_START void Io_WriteListEdge(FILE *pFile, Abc_Obj_t *pObj)
DECLARATIONS ///.
Definition: ioWriteList.c:155
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
#define Abc_NtkForEachLatch(pNtk, pObj, i)
Definition: abc.h:497
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
void Io_WriteList(Abc_Ntk_t *pNtk, char *pFileName, int fUseHost)
FUNCTION DEFINITIONS ///.
Definition: ioWriteList.c:102
#define Abc_ObjForEachFanout(pObj, pFanout, i)
Definition: abc.h:526
int Id
Definition: abc.h:132
static int Abc_NtkPiNum(Abc_Ntk_t *pNtk)
Definition: abc.h:285
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
char * Extra_TimeStamp()
ABC_DLL int Abc_ObjFanoutFaninNum(Abc_Obj_t *pFanout, Abc_Obj_t *pFanin)
Definition: abcFanio.c:321
#define assert(ex)
Definition: util_old.h:213
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition: abc.h:517
static void Io_WriteListHost(FILE *pFile, Abc_Ntk_t *pNtk)
Definition: ioWriteList.c:184
char * pName
Definition: abc.h:158
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition: abc.h:513