ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcDebug.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 int Abc_NtkCountFaninsTotal( Abc_Ntk_t * pNtk );
32static Abc_Ntk_t * Abc_NtkAutoDebugModify( Abc_Ntk_t * pNtk, int ObjNum, int fConst1 );
33
37
50void Abc_NtkAutoDebug( Abc_Ntk_t * pNtk, int (*pFuncError) (Abc_Ntk_t *) )
51{
52 Abc_Ntk_t * pNtkMod;
53 char * pFileName = "bug_found.blif";
54 int i, nSteps, nIter, ModNum, RandNum = 1;
55 abctime clk, clkTotal = Abc_Clock();
56 assert( Abc_NtkIsLogic(pNtk) );
57 srand( 0x123123 );
58 // create internal copy of the network
59 pNtk = Abc_NtkDup(pNtk);
60 if ( !(*pFuncError)( pNtk ) )
61 {
62 printf( "The original network does not cause the bug. Quitting.\n" );
63 Abc_NtkDelete( pNtk );
64 return;
65 }
66 // perform incremental modifications
67 for ( nIter = 0; ; nIter++ )
68 {
69 clk = Abc_Clock();
70 // count how many ways of modifying the network exists
71 nSteps = 2 * Abc_NtkCountFaninsTotal(pNtk);
72 // try modifying the network as many times
73 RandNum ^= rand();
74 for ( i = 0; i < nSteps; i++ )
75 {
76 // get the shifted number of bug
77 ModNum = (i + RandNum) % nSteps;
78 // get the modified network
79 pNtkMod = Abc_NtkAutoDebugModify( pNtk, ModNum/2, ModNum%2 );
80 // write the network
81 Io_WriteBlifLogic( pNtk, "bug_temp.blif", 1 );
82 // check if the bug is still there
83 if ( (*pFuncError)( pNtkMod ) ) // bug is still there
84 {
85 Abc_NtkDelete( pNtk );
86 pNtk = pNtkMod;
87 break;
88 }
89 else // no bug
90 Abc_NtkDelete( pNtkMod );
91 }
92 printf( "Iter %6d : Latches = %6d. Nodes = %6d. Steps = %6d. Error step = %3d. ",
93 nIter, Abc_NtkLatchNum(pNtk), Abc_NtkNodeNum(pNtk), nSteps, i );
94 ABC_PRT( "Time", Abc_Clock() - clk );
95 if ( i == nSteps ) // could not modify it while preserving the bug
96 break;
97 }
98 // write out the final network
99 Io_WriteBlifLogic( pNtk, pFileName, 1 );
100 printf( "Final network written into file \"%s\". ", pFileName );
101 ABC_PRT( "Total time", Abc_Clock() - clkTotal );
102 Abc_NtkDelete( pNtk );
103}
104
116int Abc_NtkCountFaninsTotal( Abc_Ntk_t * pNtk )
117{
118 Abc_Obj_t * pObj, * pFanin;
119 int i, k, Counter = 0;
120 Abc_NtkForEachObj( pNtk, pObj, i )
121 Abc_ObjForEachFanin( pObj, pFanin, k )
122 {
123 if ( !Abc_ObjIsNode(pObj) && !Abc_ObjIsPo(pObj) )
124 continue;
125 if ( Abc_ObjIsPo(pObj) && Abc_NtkPoNum(pNtk) == 1 )
126 continue;
127 if ( Abc_ObjIsNode(pObj) && Abc_NodeIsConst(pFanin) )
128 continue;
129 Counter++;
130 }
131 return Counter;
132}
133
145int Abc_NtkFindGivenFanin( Abc_Ntk_t * pNtk, int Step, Abc_Obj_t ** ppObj, Abc_Obj_t ** ppFanin )
146{
147 Abc_Obj_t * pObj, * pFanin;
148 int i, k, Counter = 0;
149 Abc_NtkForEachObj( pNtk, pObj, i )
150 Abc_ObjForEachFanin( pObj, pFanin, k )
151 {
152 if ( !Abc_ObjIsNode(pObj) && !Abc_ObjIsPo(pObj) )
153 continue;
154 if ( Abc_ObjIsPo(pObj) && Abc_NtkPoNum(pNtk) == 1 )
155 continue;
156 if ( Abc_ObjIsNode(pObj) && Abc_NodeIsConst(pFanin) )
157 continue;
158 if ( Counter++ == Step )
159 {
160 *ppObj = pObj;
161 *ppFanin = pFanin;
162 return 1;
163 }
164 }
165 return 0;
166}
167
179Abc_Ntk_t * Abc_NtkAutoDebugModify( Abc_Ntk_t * pNtkInit, int Step, int fConst1 )
180{
181 extern void Abc_NtkCycleInitStateSop( Abc_Ntk_t * pNtk, int nFrames, int fVerbose );
182 Abc_Ntk_t * pNtk;
183 Abc_Obj_t * pObj, * pFanin, * pConst;
184 // copy the network
185 pNtk = Abc_NtkDup( pNtkInit );
186 assert( Abc_NtkNodeNum(pNtk) == Abc_NtkNodeNum(pNtkInit) );
187 // find the object number
188 Abc_NtkFindGivenFanin( pNtk, Step, &pObj, &pFanin );
189 // consider special case
190 if ( Abc_ObjIsPo(pObj) && Abc_NodeIsConst(pFanin) )
191 {
192 Abc_NtkDeleteAll_rec( pObj );
193 return pNtk;
194 }
195 // plug in a constant node
196 pConst = fConst1? Abc_NtkCreateNodeConst1(pNtk) : Abc_NtkCreateNodeConst0(pNtk);
197 Abc_ObjTransferFanout( pFanin, pConst );
198 Abc_NtkDeleteAll_rec( pFanin );
199
200 Abc_NtkSweep( pNtk, 0 );
201 Abc_NtkCleanupSeq( pNtk, 0, 0, 0 );
202 Abc_NtkToSop( pNtk, -1, ABC_INFINITY );
203 Abc_NtkCycleInitStateSop( pNtk, 50, 0 );
204 return pNtk;
205}
206
210
211
213
int Abc_NtkFindGivenFanin(Abc_Ntk_t *pNtk, int Step, Abc_Obj_t **ppObj, Abc_Obj_t **ppFanin)
Definition abcDebug.c:145
void Abc_NtkAutoDebug(Abc_Ntk_t *pNtk, int(*pFuncError)(Abc_Ntk_t *))
FUNCTION DEFINITIONS ///.
Definition abcDebug.c:50
ABC_DLL int Abc_NtkSweep(Abc_Ntk_t *pNtk, int fVerbose)
Definition abcSweep.c:692
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst1(Abc_Ntk_t *pNtk)
Definition abcObj.c:643
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition abc.h:449
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst0(Abc_Ntk_t *pNtk)
Definition abcObj.c:612
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition abc.h:527
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
ABC_DLL void Abc_ObjTransferFanout(Abc_Obj_t *pObjOld, Abc_Obj_t *pObjNew)
Definition abcFanio.c:292
ABC_DLL int Abc_NodeIsConst(Abc_Obj_t *pNode)
Definition abcObj.c:867
ABC_DLL int Abc_NtkToSop(Abc_Ntk_t *pNtk, int fMode, int nCubeLimit)
Definition abcFunc.c:1261
ABC_DLL int Abc_NtkCleanupSeq(Abc_Ntk_t *pNtk, int fLatchSweep, int fAutoSweep, int fVerbose)
Definition abcSweep.c:919
ABC_DLL void Abc_NtkDeleteAll_rec(Abc_Obj_t *pObj)
Definition abcObj.c:315
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
ABC_DLL Abc_Ntk_t * Abc_NtkDup(Abc_Ntk_t *pNtk)
Definition abcNtk.c:472
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_PRT(a, t)
Definition abc_global.h:255
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition abc_global.h:250
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void Io_WriteBlifLogic(Abc_Ntk_t *pNtk, char *pFileName, int fWriteLatches)
FUNCTION DEFINITIONS ///.
Definition ioWriteBlif.c:59
void Abc_NtkCycleInitStateSop(Abc_Ntk_t *pNtk, int nFrames, int fVerbose)
Definition retInit.c:314
#define assert(ex)
Definition util_old.h:213