abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcDebug.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [abcDebug.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Network and node package.]
8 
9  Synopsis [Automated debugging procedures.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: abcDebug.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 
31 static int Abc_NtkCountFaninsTotal( Abc_Ntk_t * pNtk );
32 static Abc_Ntk_t * Abc_NtkAutoDebugModify( Abc_Ntk_t * pNtk, int ObjNum, int fConst1 );
33 
34 ////////////////////////////////////////////////////////////////////////
35 /// FUNCTION DEFINITIONS ///
36 ////////////////////////////////////////////////////////////////////////
37 
38 /**Function*************************************************************
39 
40  Synopsis [Takes a network and a procedure to test.]
41 
42  Description [The network demonstrates the bug in the procedure.
43  Procedure should return 1 if the bug is demonstrated.]
44 
45  SideEffects []
46 
47  SeeAlso []
48 
49 ***********************************************************************/
50 void 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 
105 /**Function*************************************************************
106 
107  Synopsis [Counts the total number of fanins.]
108 
109  Description []
110 
111  SideEffects []
112 
113  SeeAlso []
114 
115 ***********************************************************************/
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 
134 /**Function*************************************************************
135 
136  Synopsis [Returns the node and fanin to be modified.]
137 
138  Description []
139 
140  SideEffects []
141 
142  SeeAlso []
143 
144 ***********************************************************************/
145 int 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 
168 /**Function*************************************************************
169 
170  Synopsis [Perform modification with the given number.]
171 
172  Description [Modification consists of replacing the node by a constant.]
173 
174  SideEffects []
175 
176  SeeAlso []
177 
178 ***********************************************************************/
179 Abc_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, 0 );
203  Abc_NtkCycleInitStateSop( pNtk, 50, 0 );
204  return pNtk;
205 }
206 
207 ////////////////////////////////////////////////////////////////////////
208 /// END OF FILE ///
209 ////////////////////////////////////////////////////////////////////////
210 
211 
213 
static int Abc_NtkIsLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:250
ABC_DLL int Abc_NodeIsConst(Abc_Obj_t *pNode)
Definition: abcObj.c:843
static ABC_NAMESPACE_IMPL_START int Abc_NtkCountFaninsTotal(Abc_Ntk_t *pNtk)
DECLARATIONS ///.
Definition: abcDebug.c:116
static int Abc_NtkLatchNum(Abc_Ntk_t *pNtk)
Definition: abc.h:294
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst1(Abc_Ntk_t *pNtk)
Definition: abcObj.c:633
ABC_DLL Abc_Ntk_t * Abc_NtkDup(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:419
static abctime Abc_Clock()
Definition: abc_global.h:279
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:1233
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
static int Abc_NtkNodeNum(Abc_Ntk_t *pNtk)
Definition: abc.h:293
void Abc_NtkAutoDebug(Abc_Ntk_t *pNtk, int(*pFuncError)(Abc_Ntk_t *))
FUNCTION DEFINITIONS ///.
Definition: abcDebug.c:50
ABC_DLL int Abc_NtkToSop(Abc_Ntk_t *pNtk, int fDirect)
Definition: abcFunc.c:1124
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static int Counter
void Abc_NtkCycleInitStateSop(Abc_Ntk_t *pNtk, int nFrames, int fVerbose)
Definition: retInit.c:314
static Abc_Ntk_t * Abc_NtkAutoDebugModify(Abc_Ntk_t *pNtk, int ObjNum, int fConst1)
Definition: abcDebug.c:179
int Abc_NtkFindGivenFanin(Abc_Ntk_t *pNtk, int Step, Abc_Obj_t **ppObj, Abc_Obj_t **ppFanin)
Definition: abcDebug.c:145
ABC_DLL void Abc_ObjTransferFanout(Abc_Obj_t *pObjOld, Abc_Obj_t *pObjNew)
Definition: abcFanio.c:264
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static int Abc_NtkPoNum(Abc_Ntk_t *pNtk)
Definition: abc.h:286
ABC_DLL int Abc_NtkSweep(Abc_Ntk_t *pNtk, int fVerbose)
Definition: abcSweep.c:574
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
ABC_DLL void Abc_NtkDeleteAll_rec(Abc_Obj_t *pObj)
Definition: abcObj.c:310
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst0(Abc_Ntk_t *pNtk)
Definition: abcObj.c:604
#define ABC_PRT(a, t)
Definition: abc_global.h:220
static int Abc_ObjIsPo(Abc_Obj_t *pObj)
Definition: abc.h:348
void Io_WriteBlifLogic(Abc_Ntk_t *pNtk, char *pFileName, int fWriteLatches)
FUNCTION DEFINITIONS ///.
Definition: ioWriteBlif.c:59
#define assert(ex)
Definition: util_old.h:213
ABC_DLL int Abc_NtkCleanupSeq(Abc_Ntk_t *pNtk, int fLatchSweep, int fAutoSweep, int fVerbose)
Definition: abcSweep.c:909
ABC_INT64_T abctime
Definition: abc_global.h:278
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446