ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcDress.c
Go to the documentation of this file.
1
20
21#include "base/abc/abc.h"
22#include "base/io/ioAbc.h"
23
25
26
30
31static stmm_table * Abc_NtkDressDeriveMapping( Abc_Ntk_t * pNtk );
32static void Abc_NtkDressTransferNames( Abc_Ntk_t * pNtk, stmm_table * tMapping, int fVerbose );
33
34extern Abc_Ntk_t * Abc_NtkIvyFraig( Abc_Ntk_t * pNtk, int nConfLimit, int fDoSparse, int fProve, int fTransfer, int fVerbose );
35
39
51void 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
86if ( fVerbose )
87{
88printf( "After mitering:\n" );
89printf( "Logic: Nodes = %5d. Copy = %5d. \n", Abc_NtkNodeNum(pNtkLogic), Abc_NtkCountCopy(pNtkLogic) );
90printf( "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
100if ( fVerbose )
101{
102printf( "After fraiging:\n" );
103printf( "Logic: Nodes = %5d. Copy = %5d. \n", Abc_NtkNodeNum(pNtkLogic), Abc_NtkCountCopy(pNtkLogic) );
104printf( "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
130stmm_table * Abc_NtkDressDeriveMapping( Abc_Ntk_t * pNtk )
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
163void 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
211
212
214
void Abc_NtkDress(Abc_Ntk_t *pNtkLogic, char *pFileName, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition abcDress.c:51
Abc_Ntk_t * Abc_NtkIvyFraig(Abc_Ntk_t *pNtk, int nConfLimit, int fDoSparse, int fProve, int fTransfer, int fVerbose)
Definition abcIvy.c:460
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
ABC_DLL int Abc_NtkCountCopy(Abc_Ntk_t *pNtk)
Definition abcUtil.c:605
ABC_DLL Abc_Ntk_t * Abc_NtkToLogic(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition abcNetlist.c:52
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
ABC_DLL char * Abc_ObjAssignName(Abc_Obj_t *pObj, char *pName, char *pSuffix)
Definition abcNames.c:69
ABC_DLL Abc_Ntk_t * Abc_NtkStrash(Abc_Ntk_t *pNtk, int fAllNodes, int fCleanup, int fRecord)
Definition abcStrash.c:265
ABC_DLL void Abc_NtkTransferCopy(Abc_Ntk_t *pNtk)
Definition abcUtil.c:1962
ABC_DLL int Abc_NtkAppend(Abc_Ntk_t *pNtk1, Abc_Ntk_t *pNtk2, int fAddPos)
Definition abcStrash.c:320
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
Definition abcUtil.c:540
ABC_DLL int Abc_NtkCompareSignals(Abc_Ntk_t *pNtk1, Abc_Ntk_t *pNtk2, int fOnlyPis, int fComb)
Definition abcCheck.c:749
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition abc.h:464
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
Abc_Ntk_t * Io_ReadNetlist(char *pFileName, Io_FileType_t FileType, int fCheck)
Definition ioUtil.c:99
Io_FileType_t Io_ReadFileType(char *pFileName)
DECLARATIONS ///.
Definition ioUtil.c:47
char * Nm_ManFindNameById(Nm_Man_t *p, int ObjId)
Definition nmApi.c:199
int stmm_delete(stmm_table *table, char **keyp, char **value)
Definition stmm.c:430
int stmm_ptrhash(const char *x, int size)
Definition stmm.c:533
int stmm_insert(stmm_table *table, char *key, char *value)
Definition stmm.c:200
int stmm_ptrcmp(const char *x, const char *y)
Definition stmm.c:545
void stmm_free_table(stmm_table *table)
Definition stmm.c:79
stmm_table * stmm_init_table(stmm_compare_func_type compare, stmm_hash_func_type hash)
Definition stmm.c:69
int stmm_lookup(stmm_table *table, char *key, char **value)
Definition stmm.c:134
#define stmm_is_member(table, key)
Definition stmm.h:75
#define stmm_count(table)
Definition stmm.h:76
Nm_Man_t * pManName
Definition abc.h:160
Abc_Ntk_t * pNtk
Definition abc.h:130
int Id
Definition abc.h:132
Abc_Obj_t * pCopy
Definition abc.h:148
#define assert(ex)
Definition util_old.h:213