abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcDress.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [abcDress.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Network and node package.]
8 
9  Synopsis [Transfers names from one netlist to the other.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: abcDress.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "base/abc/abc.h"
22 #include "base/io/ioAbc.h"
23 
25 
26 
27 ////////////////////////////////////////////////////////////////////////
28 /// DECLARATIONS ///
29 ////////////////////////////////////////////////////////////////////////
30 
32 static void Abc_NtkDressTransferNames( Abc_Ntk_t * pNtk, stmm_table * tMapping, int fVerbose );
33 
34 extern Abc_Ntk_t * Abc_NtkIvyFraig( Abc_Ntk_t * pNtk, int nConfLimit, int fDoSparse, int fProve, int fTransfer, int fVerbose );
35 
36 ////////////////////////////////////////////////////////////////////////
37 /// FUNCTION DEFINITIONS ///
38 ////////////////////////////////////////////////////////////////////////
39 
40 /**Function*************************************************************
41 
42  Synopsis [Transfers names from one netlist to the other.]
43 
44  Description []
45 
46  SideEffects []
47 
48  SeeAlso []
49 
50 ***********************************************************************/
51 void Abc_NtkDress( Abc_Ntk_t * pNtkLogic, char * pFileName, int fVerbose )
52 {
53  Abc_Ntk_t * pNtkOrig, * pNtkLogicOrig;
54  Abc_Ntk_t * pMiter, * pMiterFraig;
55  stmm_table * tMapping;
56 
57  assert( Abc_NtkIsLogic(pNtkLogic) );
58 
59  // get the original netlist
60  pNtkOrig = Io_ReadNetlist( pFileName, Io_ReadFileType(pFileName), 1 );
61  if ( pNtkOrig == NULL )
62  return;
63  assert( Abc_NtkIsNetlist(pNtkOrig) );
64 
65  Abc_NtkCleanCopy(pNtkLogic);
66  Abc_NtkCleanCopy(pNtkOrig);
67 
68  // convert it into the logic network
69  pNtkLogicOrig = Abc_NtkToLogic( pNtkOrig );
70  // check that the networks have the same PIs/POs/latches
71  if ( !Abc_NtkCompareSignals( pNtkLogic, pNtkLogicOrig, 1, 1 ) )
72  {
73  Abc_NtkDelete( pNtkOrig );
74  Abc_NtkDelete( pNtkLogicOrig );
75  return;
76  }
77 
78  // convert the current logic network into an AIG
79  pMiter = Abc_NtkStrash( pNtkLogic, 1, 0, 0 );
80 
81  // convert it into the AIG and make the netlist point to the AIG
82  Abc_NtkAppend( pMiter, pNtkLogicOrig, 1 );
83  Abc_NtkTransferCopy( pNtkOrig );
84  Abc_NtkDelete( pNtkLogicOrig );
85 
86 if ( fVerbose )
87 {
88 printf( "After mitering:\n" );
89 printf( "Logic: Nodes = %5d. Copy = %5d. \n", Abc_NtkNodeNum(pNtkLogic), Abc_NtkCountCopy(pNtkLogic) );
90 printf( "Orig: Nodes = %5d. Copy = %5d. \n", Abc_NtkNodeNum(pNtkOrig), Abc_NtkCountCopy(pNtkOrig) );
91 }
92 
93  // fraig the miter (miter nodes point to the fraiged miter)
94  pMiterFraig = Abc_NtkIvyFraig( pMiter, 100, 1, 0, 1, 0 );
95  // make netlists point to the fraiged miter
96  Abc_NtkTransferCopy( pNtkLogic );
97  Abc_NtkTransferCopy( pNtkOrig );
98  Abc_NtkDelete( pMiter );
99 
100 if ( fVerbose )
101 {
102 printf( "After fraiging:\n" );
103 printf( "Logic: Nodes = %5d. Copy = %5d. \n", Abc_NtkNodeNum(pNtkLogic), Abc_NtkCountCopy(pNtkLogic) );
104 printf( "Orig: Nodes = %5d. Copy = %5d. \n", Abc_NtkNodeNum(pNtkOrig), Abc_NtkCountCopy(pNtkOrig) );
105 }
106 
107  // derive mapping from the fraiged nodes into their prototype nodes in the original netlist
108  tMapping = Abc_NtkDressDeriveMapping( pNtkOrig );
109 
110  // transfer the names to the new netlist
111  Abc_NtkDressTransferNames( pNtkLogic, tMapping, fVerbose );
112 
113  // clean up
114  stmm_free_table( tMapping );
115  Abc_NtkDelete( pMiterFraig );
116  Abc_NtkDelete( pNtkOrig );
117 }
118 
119 /**Function*************************************************************
120 
121  Synopsis [Returns the mapping from the fraig nodes point into the nodes of the netlist.]
122 
123  Description []
124 
125  SideEffects []
126 
127  SeeAlso []
128 
129 ***********************************************************************/
131 {
132  stmm_table * tResult;
133  Abc_Obj_t * pNode, * pNodeMap, * pNodeFraig;
134  int i;
135  assert( Abc_NtkIsNetlist(pNtk) );
137  Abc_NtkForEachNode( pNtk, pNode, i )
138  {
139  // get the fraiged node
140  pNodeFraig = Abc_ObjRegular(pNode->pCopy);
141  // if this node is already mapped, skip
142  if ( stmm_is_member( tResult, (char *)pNodeFraig ) )
143  continue;
144  // get the mapping of this node
145  pNodeMap = Abc_ObjNotCond( pNode, Abc_ObjIsComplement(pNode->pCopy) );
146  // add the mapping
147  stmm_insert( tResult, (char *)pNodeFraig, (char *)pNodeMap );
148  }
149  return tResult;
150 }
151 
152 /**Function*************************************************************
153 
154  Synopsis [Attaches the names of to the new netlist.]
155 
156  Description []
157 
158  SideEffects []
159 
160  SeeAlso []
161 
162 ***********************************************************************/
163 void Abc_NtkDressTransferNames( Abc_Ntk_t * pNtk, stmm_table * tMapping, int fVerbose )
164 {
165  Abc_Obj_t * pNet, * pNode, * pNodeMap, * pNodeFraig;
166  char * pName;
167  int i, Counter = 0, CounterInv = 0, CounterInit = stmm_count(tMapping);
168  assert( Abc_NtkIsLogic(pNtk) );
169  Abc_NtkForEachNode( pNtk, pNode, i )
170  {
171  // if the node already has a name, quit
172  pName = Nm_ManFindNameById( pNtk->pManName, pNode->Id );
173  if ( pName != NULL )
174  continue;
175  // get the fraiged node
176  pNodeFraig = Abc_ObjRegular(pNode->pCopy);
177  // find the matching node of the original netlist
178  if ( !stmm_lookup( tMapping, (char *)pNodeFraig, (char **)&pNodeMap ) )
179  continue;
180  // find the true match
181  pNodeMap = Abc_ObjNotCond( pNodeMap, Abc_ObjIsComplement(pNode->pCopy) );
182  // get the name
183  pNet = Abc_ObjFanout0(Abc_ObjRegular(pNodeMap));
184  pName = Nm_ManFindNameById( pNet->pNtk->pManName, pNet->Id );
185  assert( pName != NULL );
186  // set the name
187  if ( Abc_ObjIsComplement(pNodeMap) )
188  {
189  Abc_ObjAssignName( pNode, pName, "_inv" );
190  CounterInv++;
191  }
192  else
193  {
194  Abc_ObjAssignName( pNode, pName, NULL );
195  Counter++;
196  }
197  // remove the name
198  stmm_delete( tMapping, (char **)&pNodeFraig, (char **)&pNodeMap );
199  }
200  if ( fVerbose )
201  {
202  printf( "Total number of names collected = %5d.\n", CounterInit );
203  printf( "Total number of names assigned = %5d. (Dir = %5d. Compl = %5d.)\n",
204  Counter + CounterInv, Counter, CounterInv );
205  }
206 }
207 
208 ////////////////////////////////////////////////////////////////////////
209 /// END OF FILE ///
210 ////////////////////////////////////////////////////////////////////////
211 
212 
214 
static int Abc_NtkIsLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:250
Nm_Man_t * pManName
Definition: abc.h:160
stmm_table * stmm_init_table(stmm_compare_func_type compare, stmm_hash_func_type hash)
Definition: stmm.c:69
static int Abc_NtkIsNetlist(Abc_Ntk_t *pNtk)
Definition: abc.h:249
ABC_DLL int Abc_NtkCountCopy(Abc_Ntk_t *pNtk)
Definition: abcUtil.c:572
ABC_DLL Abc_Ntk_t * Abc_NtkStrash(Abc_Ntk_t *pNtk, int fAllNodes, int fCleanup, int fRecord)
Definition: abcStrash.c:265
int stmm_insert(stmm_table *table, char *key, char *value)
Definition: stmm.c:200
Abc_Ntk_t * Io_ReadNetlist(char *pFileName, Io_FileType_t FileType, int fCheck)
Definition: ioUtil.c:98
#define stmm_count(table)
Definition: stmm.h:76
ABC_DLL int Abc_NtkCompareSignals(Abc_Ntk_t *pNtk1, Abc_Ntk_t *pNtk2, int fOnlyPis, int fComb)
Definition: abcCheck.c:741
ABC_DLL char * Abc_ObjAssignName(Abc_Obj_t *pObj, char *pName, char *pSuffix)
Definition: abcNames.c:68
static void Abc_NtkDressTransferNames(Abc_Ntk_t *pNtk, stmm_table *tMapping, int fVerbose)
Definition: abcDress.c:163
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:1233
#define stmm_is_member(table, key)
Definition: stmm.h:75
ABC_DLL Abc_Ntk_t * Abc_NtkToLogic(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcNetlist.c:52
Io_FileType_t Io_ReadFileType(char *pFileName)
DECLARATIONS ///.
Definition: ioUtil.c:46
Abc_Ntk_t * Abc_NtkIvyFraig(Abc_Ntk_t *pNtk, int nConfLimit, int fDoSparse, int fProve, int fTransfer, int fVerbose)
Definition: abcIvy.c:456
static int Abc_NtkNodeNum(Abc_Ntk_t *pNtk)
Definition: abc.h:293
Abc_Obj_t * pCopy
Definition: abc.h:148
int stmm_lookup(stmm_table *table, char *key, char **value)
Definition: stmm.c:134
int stmm_ptrhash(const char *x, int size)
Definition: stmm.c:533
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
char * Nm_ManFindNameById(Nm_Man_t *p, int ObjId)
Definition: nmApi.c:199
static int Counter
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
int stmm_ptrcmp(const char *x, const char *y)
Definition: stmm.c:545
void Abc_NtkDress(Abc_Ntk_t *pNtkLogic, char *pFileName, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: abcDress.c:51
void stmm_free_table(stmm_table *table)
Definition: stmm.c:79
static Abc_Obj_t * Abc_ObjRegular(Abc_Obj_t *p)
Definition: abc.h:323
Abc_Ntk_t * pNtk
Definition: abc.h:130
int Id
Definition: abc.h:132
int stmm_delete(stmm_table *table, char **keyp, char **value)
Definition: stmm.c:430
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
Definition: abcUtil.c:507
static Abc_Obj_t * Abc_ObjNotCond(Abc_Obj_t *p, int c)
Definition: abc.h:325
#define assert(ex)
Definition: util_old.h:213
ABC_DLL void Abc_NtkTransferCopy(Abc_Ntk_t *pNtk)
Definition: abcUtil.c:1922
static int Abc_ObjIsComplement(Abc_Obj_t *p)
Definition: abc.h:322
static ABC_NAMESPACE_IMPL_START stmm_table * Abc_NtkDressDeriveMapping(Abc_Ntk_t *pNtk)
DECLARATIONS ///.
Definition: abcDress.c:130
ABC_DLL int Abc_NtkAppend(Abc_Ntk_t *pNtk1, Abc_Ntk_t *pNtk2, int fAddPos)
Definition: abcStrash.c:320
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371