abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcMini.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [abcMini.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Network and node package.]
8 
9  Synopsis [Interface to the minimalistic AIG package.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: abcMini.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "base/abc/abc.h"
22 #include "base/main/main.h"
23 #include "aig/miniaig/miniaig.h"
24 
26 
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// DECLARATIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
32 ////////////////////////////////////////////////////////////////////////
33 /// FUNCTION DEFINITIONS ///
34 ////////////////////////////////////////////////////////////////////////
35 
36 
37 /**Function*************************************************************
38 
39  Synopsis [Converts the network from the AIG manager into ABC.]
40 
41  Description []
42 
43  SideEffects []
44 
45  SeeAlso []
46 
47 ***********************************************************************/
48 Abc_Obj_t * Abc_NodeFanin0Copy( Abc_Ntk_t * pNtk, Vec_Int_t * vCopies, Mini_Aig_t * p, int Id )
49 {
50  int Lit = Mini_AigNodeFanin0( p, Id );
51  int AbcLit = Abc_LitNotCond( Vec_IntEntry(vCopies, Abc_Lit2Var(Lit)), Abc_LitIsCompl(Lit) );
52  return Abc_ObjFromLit( pNtk, AbcLit );
53 }
54 Abc_Obj_t * Abc_NodeFanin1Copy( Abc_Ntk_t * pNtk, Vec_Int_t * vCopies, Mini_Aig_t * p, int Id )
55 {
56  int Lit = Mini_AigNodeFanin1( p, Id );
57  int AbcLit = Abc_LitNotCond( Vec_IntEntry(vCopies, Abc_Lit2Var(Lit)), Abc_LitIsCompl(Lit) );
58  return Abc_ObjFromLit( pNtk, AbcLit );
59 }
61 {
62  Abc_Ntk_t * pNtk;
63  Abc_Obj_t * pObj;
64  Vec_Int_t * vCopies;
65  int i, nNodes;
66  // get the number of nodes
67  nNodes = Mini_AigNodeNum(p);
68  // create ABC network
70  pNtk->pName = Abc_UtilStrsav( "MiniAig" );
71  // create mapping from MiniAIG objects into ABC objects
72  vCopies = Vec_IntAlloc( nNodes );
74  // iterate through the objects
75  for ( i = 1; i < nNodes; i++ )
76  {
77  if ( Mini_AigNodeIsPi( p, i ) )
78  pObj = Abc_NtkCreatePi(pNtk);
79  else if ( Mini_AigNodeIsPo( p, i ) )
80  Abc_ObjAddFanin( (pObj = Abc_NtkCreatePo(pNtk)), Abc_NodeFanin0Copy(pNtk, vCopies, p, i) );
81  else if ( Mini_AigNodeIsAnd( p, i ) )
82  pObj = Abc_AigAnd((Abc_Aig_t *)pNtk->pManFunc, Abc_NodeFanin0Copy(pNtk, vCopies, p, i), Abc_NodeFanin1Copy(pNtk, vCopies, p, i));
83  else assert( 0 );
84  Vec_IntPush( vCopies, Abc_ObjToLit(pObj) );
85  }
86  assert( Vec_IntSize(vCopies) == nNodes );
87  Abc_AigCleanup( (Abc_Aig_t *)pNtk->pManFunc );
88  Vec_IntFree( vCopies );
89  Abc_NtkAddDummyPiNames( pNtk );
90  Abc_NtkAddDummyPoNames( pNtk );
91  if ( !Abc_NtkCheck( pNtk ) )
92  fprintf( stdout, "Abc_NtkFromMini(): Network check has failed.\n" );
93  // add latches
94  if ( Mini_AigRegNum(p) > 0 )
95  {
96  extern Abc_Ntk_t * Abc_NtkRestrashWithLatches( Abc_Ntk_t * pNtk, int nLatches );
97  Abc_Ntk_t * pTemp;
98  pNtk = Abc_NtkRestrashWithLatches( pTemp = pNtk, Mini_AigRegNum(p) );
99  Abc_NtkDelete( pTemp );
100  }
101  return pNtk;
102 }
103 
104 /**Function*************************************************************
105 
106  Synopsis [Converts the network from ABC into the AIG manager.]
107 
108  Description []
109 
110  SideEffects []
111 
112  SeeAlso []
113 
114 ***********************************************************************/
116 {
117  return Abc_LitNotCond( Abc_ObjFanin0(pObj)->iTemp, Abc_ObjFaninC0(pObj) );
118 }
120 {
121  return Abc_LitNotCond( Abc_ObjFanin1(pObj)->iTemp, Abc_ObjFaninC1(pObj) );
122 }
124 {
125  Mini_Aig_t * p;
126  Abc_Obj_t * pObj;
127  int i;
128  assert( Abc_NtkIsStrash(pNtk) );
129  // create the manager
130  p = Mini_AigStart();
131  // create mapping from MiniAIG into ABC objects
132  Abc_NtkCleanCopy( pNtk );
134  // create primary inputs
135  Abc_NtkForEachCi( pNtk, pObj, i )
136  pObj->iTemp = Mini_AigCreatePi(p);
137  // create internal nodes
138  Abc_NtkForEachNode( pNtk, pObj, i )
139  pObj->iTemp = Mini_AigAnd( p, Abc_NodeFanin0Copy2(pObj), Abc_NodeFanin1Copy2(pObj) );
140  // create primary outputs
141  Abc_NtkForEachCo( pNtk, pObj, i )
142  pObj->iTemp = Mini_AigCreatePo( p, Abc_NodeFanin0Copy2(pObj) );
143  // set registers
145  return p;
146 }
147 
148 /**Function*************************************************************
149 
150  Synopsis [Procedures to update internal ABC network using AIG node array.]
151 
152  Description []
153 
154  SideEffects []
155 
156  SeeAlso []
157 
158 ***********************************************************************/
159 void Abc_NtkInputMiniAig( Abc_Frame_t * pAbc, void * p )
160 {
161  Abc_Ntk_t * pNtk;
162  if ( pAbc == NULL )
163  printf( "ABC framework is not initialized by calling Abc_Start()\n" );
164  pNtk = Abc_NtkFromMiniAig( (Mini_Aig_t *)p );
165  Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
166 // Abc_NtkDelete( pNtk );
167 }
169 {
170  Abc_Ntk_t * pNtk;
171  if ( pAbc == NULL )
172  printf( "ABC framework is not initialized by calling Abc_Start()\n" );
173  pNtk = Abc_FrameReadNtk( pAbc );
174  if ( pNtk == NULL )
175  printf( "Current network in ABC framework is not defined.\n" );
176  return Abc_NtkToMiniAig( pNtk );
177 }
178 
179 
180 /**Function*************************************************************
181 
182  Synopsis [Testing the above code.]
183 
184  Description []
185 
186  SideEffects []
187 
188  SeeAlso []
189 
190 ***********************************************************************/
192 {
193  Abc_Ntk_t * pNtkNew;
194  Mini_Aig_t * p;
195  p = Abc_NtkToMiniAig( pNtk );
196  pNtkNew = Abc_NtkFromMiniAig( p );
197  Mini_AigStop( p );
198  Abc_NtkPrintStats( pNtkNew, 0, 0, 0, 0, 0, 0, 0, 0 );
199  Abc_NtkDelete( pNtkNew );
200 
201  // test dumping
202  p = Abc_NtkToMiniAig( pNtk );
203  Mini_AigDump( p, "miniaig.data" );
204  Mini_AigPrintStats( p );
205  Mini_AigStop( p );
206 
207  p = Mini_AigLoad( "miniaig.data" );
208  Mini_AigPrintStats( p );
209  Mini_AigStop( p );
210 }
211 
212 /*
213  if ( pNtk )
214  {
215  extern void Abc_NtkMiniAigTest( Abc_Ntk_t * pNtk );
216  Abc_NtkMiniAigTest( pNtk );
217 
218  }
219 */
220 
221 ////////////////////////////////////////////////////////////////////////
222 /// END OF FILE ///
223 ////////////////////////////////////////////////////////////////////////
224 
225 
227 
int iTemp
Definition: abc.h:149
ABC_DLL void Abc_FrameReplaceCurrentNetwork(Abc_Frame_t *p, Abc_Ntk_t *pNet)
Definition: mainFrame.c:493
static int Abc_NtkIsStrash(Abc_Ntk_t *pNtk)
Definition: abc.h:251
static Abc_Obj_t * Abc_ObjFromLit(Abc_Ntk_t *p, int iLit)
Definition: abc.h:390
static void Mini_AigSetRegNum(Mini_Aig_t *p, int n)
Definition: miniaig.h:122
static Abc_Obj_t * Abc_ObjFanin1(Abc_Obj_t *pObj)
Definition: abc.h:374
static int Mini_AigLitConst1()
Definition: miniaig.h:109
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
Definition: abcAig.c:683
static Mini_Aig_t * Mini_AigStart()
Definition: miniaig.h:131
static int Mini_AigNodeIsPi(Mini_Aig_t *p, int Id)
Definition: miniaig.h:116
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Abc_ObjFaninC1(Abc_Obj_t *pObj)
Definition: abc.h:378
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
void Abc_NtkInputMiniAig(Abc_Frame_t *pAbc, void *p)
Definition: abcMini.c:159
static int Mini_AigCreatePo(Mini_Aig_t *p, int Lit0)
Definition: miniaig.h:206
static int Mini_AigCreatePi(Mini_Aig_t *p)
Definition: miniaig.h:200
int Abc_NodeFanin0Copy2(Abc_Obj_t *pObj)
Definition: abcMini.c:115
static int Abc_NtkLatchNum(Abc_Ntk_t *pNtk)
Definition: abc.h:294
static int Abc_ObjFaninC0(Abc_Obj_t *pObj)
Definition: abc.h:377
void * Abc_NtkOutputMiniAig(Abc_Frame_t *pAbc)
Definition: abcMini.c:168
static int Mini_AigRegNum(Mini_Aig_t *p)
Definition: miniaig.h:121
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition: abc.h:519
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcCheck.c:61
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
static int Mini_AigNodeIsPo(Mini_Aig_t *p, int Id)
Definition: miniaig.h:117
static int Abc_LitNotCond(int Lit, int c)
Definition: abc_global.h:267
DECLARATIONS ///.
Definition: abcAig.c:52
static int Mini_AigNodeFanin0(Mini_Aig_t *p, int Id)
Definition: miniaig.h:89
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:1233
static int Mini_AigNodeFanin1(Mini_Aig_t *p, int Id)
Definition: miniaig.h:94
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition: abcFanio.c:84
ABC_DLL Abc_Ntk_t * Abc_NtkAlloc(Abc_NtkType_t Type, Abc_NtkFunc_t Func, int fUseMemMan)
DECLARATIONS ///.
Definition: abcNtk.c:50
static Mini_Aig_t * Mini_AigLoad(char *pFileName)
Definition: miniaig.h:176
void * pManFunc
Definition: abc.h:191
static void Mini_AigStop(Mini_Aig_t *p)
Definition: miniaig.h:140
ABC_DLL Abc_Obj_t * Abc_AigAnd(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
Definition: abcAig.c:700
ABC_DLL void Abc_NtkAddDummyPoNames(Abc_Ntk_t *pNtk)
Definition: abcNames.c:398
ABC_DLL void Abc_NtkPrintStats(Abc_Ntk_t *pNtk, int fFactored, int fSaveBest, int fDumpResult, int fUseLutLib, int fPrintMuxes, int fPower, int fGlitch, int fSkipBuf)
Definition: abcPrint.c:207
static int Abc_LitIsCompl(int Lit)
Definition: abc_global.h:265
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static int Mini_AigAnd(Mini_Aig_t *p, int Lit0, int Lit1)
Definition: miniaig.h:215
ABC_DLL int Abc_AigCleanup(Abc_Aig_t *pMan)
Definition: abcAig.c:194
static int Mini_AigNodeIsAnd(Mini_Aig_t *p, int Id)
Definition: miniaig.h:118
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Abc_Ntk_t * Abc_NtkRestrashWithLatches(Abc_Ntk_t *pNtk, int nLatches)
Definition: abcNtk.c:528
int Abc_NodeFanin1Copy2(Abc_Obj_t *pObj)
Definition: abcMini.c:119
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static void Mini_AigPrintStats(Mini_Aig_t *p)
Definition: miniaig.h:145
static Abc_Obj_t * Abc_NtkCreatePi(Abc_Ntk_t *pNtk)
Definition: abc.h:303
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
ABC_NAMESPACE_IMPL_START Abc_Obj_t * Abc_NodeFanin0Copy(Abc_Ntk_t *pNtk, Vec_Int_t *vCopies, Mini_Aig_t *p, int Id)
DECLARATIONS ///.
Definition: abcMini.c:48
ABC_DLL Abc_Ntk_t * Abc_FrameReadNtk(Abc_Frame_t *p)
Definition: mainFrame.c:282
static int Abc_LitNot(int Lit)
Definition: abc_global.h:266
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition: abc.h:515
Mini_Aig_t * Abc_NtkToMiniAig(Abc_Ntk_t *pNtk)
Definition: abcMini.c:123
static int Mini_AigNodeNum(Mini_Aig_t *p)
Definition: miniaig.h:114
Abc_Obj_t * Abc_NodeFanin1Copy(Abc_Ntk_t *pNtk, Vec_Int_t *vCopies, Mini_Aig_t *p, int Id)
Definition: abcMini.c:54
static int Abc_Lit2Var(int Lit)
Definition: abc_global.h:264
static int Abc_ObjToLit(Abc_Obj_t *p)
Definition: abc.h:391
void Abc_NtkMiniAigTest(Abc_Ntk_t *pNtk)
Definition: abcMini.c:191
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
Definition: abcUtil.c:507
#define assert(ex)
Definition: util_old.h:213
static void Mini_AigDump(Mini_Aig_t *p, char *pFileName)
Definition: miniaig.h:161
Abc_Ntk_t * Abc_NtkFromMiniAig(Mini_Aig_t *p)
Definition: abcMini.c:60
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
ABC_DLL void Abc_NtkAddDummyPiNames(Abc_Ntk_t *pNtk)
Definition: abcNames.c:378
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
static Abc_Obj_t * Abc_NtkCreatePo(Abc_Ntk_t *pNtk)
Definition: abc.h:304
char * pName
Definition: abc.h:158