abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ioWritePla.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [ioWritePla.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Command processing package.]
8 
9  Synopsis [Procedures to write the network in BENCH format.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: ioWritePla.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "ioAbc.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 static int Io_WritePlaOne( FILE * pFile, Abc_Ntk_t * pNtk );
31 
32 ////////////////////////////////////////////////////////////////////////
33 /// FUNCTION DEFINITIONS ///
34 ////////////////////////////////////////////////////////////////////////
35 
36 /**Function*************************************************************
37 
38  Synopsis [Writes the network in PLA format.]
39 
40  Description []
41 
42  SideEffects []
43 
44  SeeAlso []
45 
46 ***********************************************************************/
47 int Io_WritePla( Abc_Ntk_t * pNtk, char * pFileName )
48 {
49  Abc_Ntk_t * pExdc;
50  FILE * pFile;
51 
52  assert( Abc_NtkIsSopNetlist(pNtk) );
53  assert( Abc_NtkLevel(pNtk) == 1 );
54 
55  pFile = fopen( pFileName, "w" );
56  if ( pFile == NULL )
57  {
58  fprintf( stdout, "Io_WritePla(): Cannot open the output file.\n" );
59  return 0;
60  }
61  fprintf( pFile, "# Benchmark \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
62  // write the network
63  Io_WritePlaOne( pFile, pNtk );
64  // write EXDC network if it exists
65  pExdc = Abc_NtkExdc( pNtk );
66  if ( pExdc )
67  printf( "Io_WritePla: EXDC is not written (warning).\n" );
68  // finalize the file
69  fclose( pFile );
70  return 1;
71 }
72 
73 /**Function*************************************************************
74 
75  Synopsis [Writes the network in PLA format.]
76 
77  Description []
78 
79  SideEffects []
80 
81  SeeAlso []
82 
83 ***********************************************************************/
84 int Io_WritePlaOne( FILE * pFile, Abc_Ntk_t * pNtk )
85 {
86  ProgressBar * pProgress;
87  Abc_Obj_t * pNode, * pFanin, * pDriver;
88  char * pCubeIn, * pCubeOut, * pCube;
89  int i, k, nProducts, nInputs, nOutputs, nFanins;
90 
91  nProducts = 0;
92  Abc_NtkForEachCo( pNtk, pNode, i )
93  {
94  pDriver = Abc_ObjFanin0Ntk( Abc_ObjFanin0(pNode) );
95  if ( !Abc_ObjIsNode(pDriver) )
96  {
97  nProducts++;
98  continue;
99  }
100  if ( Abc_NodeIsConst(pDriver) )
101  {
102  if ( Abc_NodeIsConst1(pDriver) )
103  nProducts++;
104  continue;
105  }
106  nProducts += Abc_SopGetCubeNum((char *)pDriver->pData);
107  }
108 
109  // collect the parameters
110  nInputs = Abc_NtkCiNum(pNtk);
111  nOutputs = Abc_NtkCoNum(pNtk);
112  pCubeIn = ABC_ALLOC( char, nInputs + 1 );
113  pCubeOut = ABC_ALLOC( char, nOutputs + 1 );
114  memset( pCubeIn, '-', nInputs ); pCubeIn[nInputs] = 0;
115  memset( pCubeOut, '0', nOutputs ); pCubeOut[nOutputs] = 0;
116 
117  // write the header
118  fprintf( pFile, ".i %d\n", nInputs );
119  fprintf( pFile, ".o %d\n", nOutputs );
120  fprintf( pFile, ".ilb" );
121  Abc_NtkForEachCi( pNtk, pNode, i )
122  fprintf( pFile, " %s", Abc_ObjName(Abc_ObjFanout0(pNode)) );
123  fprintf( pFile, "\n" );
124  fprintf( pFile, ".ob" );
125  Abc_NtkForEachCo( pNtk, pNode, i )
126  fprintf( pFile, " %s", Abc_ObjName(Abc_ObjFanin0(pNode)) );
127  fprintf( pFile, "\n" );
128  fprintf( pFile, ".p %d\n", nProducts );
129 
130  // mark the CI nodes
131  Abc_NtkForEachCi( pNtk, pNode, i )
132  pNode->pCopy = (Abc_Obj_t *)(ABC_PTRUINT_T)i;
133 
134  // write the cubes
135  pProgress = Extra_ProgressBarStart( stdout, nOutputs );
136  Abc_NtkForEachCo( pNtk, pNode, i )
137  {
138  // prepare the output cube
139  if ( i - 1 >= 0 )
140  pCubeOut[i-1] = '0';
141  pCubeOut[i] = '1';
142 
143  // consider special cases of nodes
144  pDriver = Abc_ObjFanin0Ntk( Abc_ObjFanin0(pNode) );
145  if ( !Abc_ObjIsNode(pDriver) )
146  {
147  assert( Abc_ObjIsCi(pDriver) );
148  pCubeIn[(int)(ABC_PTRUINT_T)pDriver->pCopy] = '1' - Abc_ObjFaninC0(pNode);
149  fprintf( pFile, "%s %s\n", pCubeIn, pCubeOut );
150  pCubeIn[(int)(ABC_PTRUINT_T)pDriver->pCopy] = '-';
151  continue;
152  }
153  if ( Abc_NodeIsConst(pDriver) )
154  {
155  if ( Abc_NodeIsConst1(pDriver) )
156  fprintf( pFile, "%s %s\n", pCubeIn, pCubeOut );
157  continue;
158  }
159 
160  // make sure the cover is not complemented
161  assert( !Abc_SopIsComplement( (char *)pDriver->pData ) );
162 
163  // write the cubes
164  nFanins = Abc_ObjFaninNum(pDriver);
165  Abc_SopForEachCube( (char *)pDriver->pData, nFanins, pCube )
166  {
167  Abc_ObjForEachFanin( pDriver, pFanin, k )
168  {
169  pFanin = Abc_ObjFanin0Ntk(pFanin);
170  assert( (int)(ABC_PTRUINT_T)pFanin->pCopy < nInputs );
171  pCubeIn[(int)(ABC_PTRUINT_T)pFanin->pCopy] = pCube[k];
172  }
173  fprintf( pFile, "%s %s\n", pCubeIn, pCubeOut );
174  }
175  // clean the cube for future writing
176  Abc_ObjForEachFanin( pDriver, pFanin, k )
177  {
178  pFanin = Abc_ObjFanin0Ntk(pFanin);
179  assert( Abc_ObjIsCi(pFanin) );
180  pCubeIn[(int)(ABC_PTRUINT_T)pFanin->pCopy] = '-';
181  }
182  Extra_ProgressBarUpdate( pProgress, i, NULL );
183  }
184  Extra_ProgressBarStop( pProgress );
185  fprintf( pFile, ".e\n" );
186 
187  // clean the CI nodes
188  Abc_NtkForEachCi( pNtk, pNode, i )
189  pNode->pCopy = NULL;
190  ABC_FREE( pCubeIn );
191  ABC_FREE( pCubeOut );
192  return 1;
193 }
194 
195 
196 ////////////////////////////////////////////////////////////////////////
197 /// END OF FILE ///
198 ////////////////////////////////////////////////////////////////////////
199 
200 
202 
char * memset()
static int Abc_ObjIsCi(Abc_Obj_t *pObj)
Definition: abc.h:351
ABC_DLL int Abc_NodeIsConst(Abc_Obj_t *pNode)
Definition: abcObj.c:843
static Abc_Ntk_t * Abc_NtkExdc(Abc_Ntk_t *pNtk)
Definition: abc.h:272
#define Abc_SopForEachCube(pSop, nFanins, pCube)
Definition: abc.h:531
ABC_DLL int Abc_SopGetCubeNum(char *pSop)
Definition: abcSop.c:489
static Abc_Obj_t * Abc_ObjFanin0Ntk(Abc_Obj_t *pObj)
Definition: abc.h:375
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
static int Abc_ObjFaninC0(Abc_Obj_t *pObj)
Definition: abc.h:377
static int Abc_NtkCiNum(Abc_Ntk_t *pNtk)
Definition: abc.h:287
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition: abc.h:519
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
static int Abc_NtkCoNum(Abc_Ntk_t *pNtk)
Definition: abc.h:288
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
DECLARATIONS ///.
Abc_Obj_t * pCopy
Definition: abc.h:148
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
void Extra_ProgressBarStop(ProgressBar *p)
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition: abc.h:515
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
#define ABC_FREE(obj)
Definition: abc_global.h:232
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
char * Extra_TimeStamp()
static int Abc_NtkIsSopNetlist(Abc_Ntk_t *pNtk)
Definition: abc.h:260
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
ABC_DLL int Abc_NodeIsConst1(Abc_Obj_t *pNode)
Definition: abcObj.c:890
#define assert(ex)
Definition: util_old.h:213
static void Extra_ProgressBarUpdate(ProgressBar *p, int nItemsCur, char *pString)
Definition: extra.h:243
void * pData
Definition: abc.h:145
ABC_DLL int Abc_NtkLevel(Abc_Ntk_t *pNtk)
Definition: abcDfs.c:1265
ABC_DLL int Abc_SopIsComplement(char *pSop)
Definition: abcSop.c:655
int Io_WritePla(Abc_Ntk_t *pNtk, char *pFileName)
FUNCTION DEFINITIONS ///.
Definition: ioWritePla.c:47
char * pName
Definition: abc.h:158
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371
static ABC_NAMESPACE_IMPL_START int Io_WritePlaOne(FILE *pFile, Abc_Ntk_t *pNtk)
DECLARATIONS ///.
Definition: ioWritePla.c:84