abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
giaMini.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [giaMini.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Scalable AIG package.]
8 
9  Synopsis [Reader/writer for MiniAIG.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: giaMini.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "gia.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 /**Function*************************************************************
37 
38  Synopsis [Converts MiniAIG into GIA.]
39 
40  Description []
41 
42  SideEffects []
43 
44  SeeAlso []
45 
46 ***********************************************************************/
47 int Gia_ObjFromMiniFanin0Copy( Gia_Man_t * pGia, Vec_Int_t * vCopies, Mini_Aig_t * p, int Id )
48 {
49  int Lit = Mini_AigNodeFanin0( p, Id );
50  return Abc_LitNotCond( Vec_IntEntry(vCopies, Abc_Lit2Var(Lit)), Abc_LitIsCompl(Lit) );
51 }
52 int Gia_ObjFromMiniFanin1Copy( Gia_Man_t * pGia, Vec_Int_t * vCopies, Mini_Aig_t * p, int Id )
53 {
54  int Lit = Mini_AigNodeFanin1( p, Id );
55  return Abc_LitNotCond( Vec_IntEntry(vCopies, Abc_Lit2Var(Lit)), Abc_LitIsCompl(Lit) );
56 }
58 {
59  Gia_Man_t * pGia, * pTemp;
60  Vec_Int_t * vCopies;
61  int i, iGiaLit, nNodes;
62  // get the number of nodes
63  nNodes = Mini_AigNodeNum(p);
64  // create ABC network
65  pGia = Gia_ManStart( nNodes );
66  pGia->pName = Abc_UtilStrsav( "MiniAig" );
67  // create mapping from MiniAIG objects into ABC objects
68  vCopies = Vec_IntAlloc( nNodes );
69  Vec_IntPush( vCopies, 0 );
70  // iterate through the objects
71  Gia_ManHashAlloc( pGia );
72  for ( i = 1; i < nNodes; i++ )
73  {
74  if ( Mini_AigNodeIsPi( p, i ) )
75  iGiaLit = Gia_ManAppendCi(pGia);
76  else if ( Mini_AigNodeIsPo( p, i ) )
77  iGiaLit = Gia_ManAppendCo(pGia, Gia_ObjFromMiniFanin0Copy(pGia, vCopies, p, i));
78  else if ( Mini_AigNodeIsAnd( p, i ) )
79  iGiaLit = Gia_ManHashAnd(pGia, Gia_ObjFromMiniFanin0Copy(pGia, vCopies, p, i), Gia_ObjFromMiniFanin1Copy(pGia, vCopies, p, i));
80  else assert( 0 );
81  Vec_IntPush( vCopies, iGiaLit );
82  }
83  Gia_ManHashStop( pGia );
84  assert( Vec_IntSize(vCopies) == nNodes );
85  Vec_IntFree( vCopies );
86  Gia_ManSetRegNum( pGia, Mini_AigRegNum(p) );
87  pGia = Gia_ManCleanup( pTemp = pGia );
88  Gia_ManStop( pTemp );
89  return pGia;
90 }
91 
92 /**Function*************************************************************
93 
94  Synopsis [Converts GIA into MiniAIG.]
95 
96  Description []
97 
98  SideEffects []
99 
100  SeeAlso []
101 
102 ***********************************************************************/
104 {
105  Mini_Aig_t * p;
106  Gia_Obj_t * pObj;
107  int i;
108  // create the manager
109  p = Mini_AigStart();
111  // create primary inputs
112  Gia_ManForEachCi( pGia, pObj, i )
113  pObj->Value = Mini_AigCreatePi(p);
114  // create internal nodes
115  Gia_ManForEachAnd( pGia, pObj, i )
116  pObj->Value = Mini_AigAnd( p, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
117  // create primary outputs
118  Gia_ManForEachCo( pGia, pObj, i )
119  pObj->Value = Mini_AigCreatePo( p, Gia_ObjFanin0Copy(pObj) );
120  // set registers
121  Mini_AigSetRegNum( p, Gia_ManRegNum(pGia) );
122  return p;
123 }
124 
125 /**Function*************************************************************
126 
127  Synopsis [Procedures to input/output MiniAIG into/from internal GIA.]
128 
129  Description []
130 
131  SideEffects []
132 
133  SeeAlso []
134 
135 ***********************************************************************/
136 void Abc_FrameGiaInputMiniAig( Abc_Frame_t * pAbc, void * p )
137 {
138  Gia_Man_t * pGia;
139  if ( pAbc == NULL )
140  printf( "ABC framework is not initialized by calling Abc_Start()\n" );
141  pGia = Gia_ManFromMiniAig( (Mini_Aig_t *)p );
142  Abc_FrameUpdateGia( pAbc, pGia );
143 // Gia_ManDelete( pGia );
144 }
146 {
147  Gia_Man_t * pGia;
148  if ( pAbc == NULL )
149  printf( "ABC framework is not initialized by calling Abc_Start()\n" );
150  pGia = Abc_FrameReadGia( pAbc );
151  if ( pGia == NULL )
152  printf( "Current network in ABC framework is not defined.\n" );
153  return Gia_ManToMiniAig( pGia );
154 }
155 
156 /**Function*************************************************************
157 
158  Synopsis [Procedures to read/write GIA to/from MiniAIG file.]
159 
160  Description []
161 
162  SideEffects []
163 
164  SeeAlso []
165 
166 ***********************************************************************/
167 Gia_Man_t * Gia_ManReadMiniAig( char * pFileName )
168 {
169  Mini_Aig_t * p = Mini_AigLoad( pFileName );
170  Gia_Man_t * pGia = Gia_ManFromMiniAig( p );
171  ABC_FREE( pGia->pName );
172  pGia->pName = Extra_FileNameGeneric( pFileName );
173  Mini_AigStop( p );
174  return pGia;
175 }
176 void Gia_ManWriteMiniAig( Gia_Man_t * pGia, char * pFileName )
177 {
178  Mini_Aig_t * p = Gia_ManToMiniAig( pGia );
179  Mini_AigDump( p, pFileName );
180  Mini_AigStop( p );
181 }
182 
183 ////////////////////////////////////////////////////////////////////////
184 /// END OF FILE ///
185 ////////////////////////////////////////////////////////////////////////
186 
187 
189 
ABC_DLL Gia_Man_t * Abc_FrameReadGia(Abc_Frame_t *p)
Definition: mainFrame.c:298
static void Mini_AigSetRegNum(Mini_Aig_t *p, int n)
Definition: miniaig.h:122
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
void Gia_ManWriteMiniAig(Gia_Man_t *pGia, char *pFileName)
Definition: giaMini.c:176
#define Gia_ManForEachCo(p, pObj, i)
Definition: gia.h:1022
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 int Gia_ManAppendCo(Gia_Man_t *p, int iLit0)
Definition: gia.h:703
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int Mini_AigLitConst0()
Definition: miniaig.h:108
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
static int Gia_ManAppendCi(Gia_Man_t *p)
Definition: gia.h:583
Gia_Man_t * Gia_ManFromMiniAig(Mini_Aig_t *p)
Definition: giaMini.c:57
Gia_Man_t * Gia_ManReadMiniAig(char *pFileName)
Definition: giaMini.c:167
int Gia_ObjFromMiniFanin1Copy(Gia_Man_t *pGia, Vec_Int_t *vCopies, Mini_Aig_t *p, int Id)
Definition: giaMini.c:52
static int Mini_AigRegNum(Mini_Aig_t *p)
Definition: miniaig.h:121
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
Definition: giaMan.c:628
Mini_Aig_t * Gia_ManToMiniAig(Gia_Man_t *pGia)
Definition: giaMini.c:103
static int Mini_AigNodeIsPo(Mini_Aig_t *p, int Id)
Definition: miniaig.h:117
void Abc_FrameGiaInputMiniAig(Abc_Frame_t *pAbc, void *p)
Definition: giaMini.c:136
static int Abc_LitNotCond(int Lit, int c)
Definition: abc_global.h:267
Definition: gia.h:75
static int Mini_AigNodeFanin0(Mini_Aig_t *p, int Id)
Definition: miniaig.h:89
static int Mini_AigNodeFanin1(Mini_Aig_t *p, int Id)
Definition: miniaig.h:94
static Mini_Aig_t * Mini_AigLoad(char *pFileName)
Definition: miniaig.h:176
#define Gia_ManForEachCi(p, pObj, i)
Definition: gia.h:1016
static void Mini_AigStop(Mini_Aig_t *p)
Definition: miniaig.h:140
static int Abc_LitIsCompl(int Lit)
Definition: abc_global.h:265
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
char * pName
Definition: gia.h:97
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
static int Gia_ObjFanin1Copy(Gia_Obj_t *pObj)
Definition: gia.h:482
static int Mini_AigNodeIsAnd(Mini_Aig_t *p, int Id)
Definition: miniaig.h:118
char * Extra_FileNameGeneric(char *FileName)
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
void * Abc_FrameGiaOutputMiniAig(Abc_Frame_t *pAbc)
Definition: giaMini.c:145
Gia_Man_t * Gia_ManStart(int nObjsMax)
DECLARATIONS ///.
Definition: giaMan.c:52
#define Gia_ManForEachAnd(p, pObj, i)
Definition: gia.h:1002
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static int Gia_ObjFanin0Copy(Gia_Obj_t *pObj)
Definition: gia.h:481
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define ABC_FREE(obj)
Definition: abc_global.h:232
Definition: gia.h:95
static Gia_Obj_t * Gia_ManConst0(Gia_Man_t *p)
Definition: gia.h:400
static int Mini_AigNodeNum(Mini_Aig_t *p)
Definition: miniaig.h:114
static int Abc_Lit2Var(int Lit)
Definition: abc_global.h:264
void Abc_FrameUpdateGia(Abc_Frame_t *pAbc, Gia_Man_t *pNew)
Definition: abc.c:616
#define assert(ex)
Definition: util_old.h:213
static void Mini_AigDump(Mini_Aig_t *p, char *pFileName)
Definition: miniaig.h:161
unsigned Value
Definition: gia.h:87
void Gia_ManHashAlloc(Gia_Man_t *p)
Definition: giaHash.c:99
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
Definition: giaScl.c:84
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition: giaHash.c:572
ABC_NAMESPACE_IMPL_START int Gia_ObjFromMiniFanin0Copy(Gia_Man_t *pGia, Vec_Int_t *vCopies, Mini_Aig_t *p, int Id)
DECLARATIONS ///.
Definition: giaMini.c:47
void Gia_ManHashStop(Gia_Man_t *p)
Definition: giaHash.c:142
static int Gia_ManRegNum(Gia_Man_t *p)
Definition: gia.h:387