abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcDebug.c File Reference
#include "base/abc/abc.h"
#include "base/io/ioAbc.h"

Go to the source code of this file.

Functions

static ABC_NAMESPACE_IMPL_START int Abc_NtkCountFaninsTotal (Abc_Ntk_t *pNtk)
 DECLARATIONS ///. More...
 
static Abc_Ntk_tAbc_NtkAutoDebugModify (Abc_Ntk_t *pNtk, int ObjNum, int fConst1)
 
void Abc_NtkAutoDebug (Abc_Ntk_t *pNtk, int(*pFuncError)(Abc_Ntk_t *))
 FUNCTION DEFINITIONS ///. More...
 
int Abc_NtkFindGivenFanin (Abc_Ntk_t *pNtk, int Step, Abc_Obj_t **ppObj, Abc_Obj_t **ppFanin)
 

Function Documentation

void Abc_NtkAutoDebug ( Abc_Ntk_t pNtk,
int(*)(Abc_Ntk_t *)  pFuncError 
)

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis [Takes a network and a procedure to test.]

Description [The network demonstrates the bug in the procedure. Procedure should return 1 if the bug is demonstrated.]

SideEffects []

SeeAlso []

Definition at line 50 of file abcDebug.c.

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 }
static int Abc_NtkIsLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:250
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_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_NtkNodeNum(Abc_Ntk_t *pNtk)
Definition: abc.h:293
static Abc_Ntk_t * Abc_NtkAutoDebugModify(Abc_Ntk_t *pNtk, int ObjNum, int fConst1)
Definition: abcDebug.c:179
#define ABC_PRT(a, t)
Definition: abc_global.h:220
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_INT64_T abctime
Definition: abc_global.h:278
Abc_Ntk_t * Abc_NtkAutoDebugModify ( Abc_Ntk_t pNtkInit,
int  Step,
int  fConst1 
)
static

Function*************************************************************

Synopsis [Perform modification with the given number.]

Description [Modification consists of replacing the node by a constant.]

SideEffects []

SeeAlso []

Definition at line 179 of file abcDebug.c.

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 }
ABC_DLL int Abc_NodeIsConst(Abc_Obj_t *pNode)
Definition: abcObj.c:843
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 int Abc_NtkNodeNum(Abc_Ntk_t *pNtk)
Definition: abc.h:293
ABC_DLL int Abc_NtkToSop(Abc_Ntk_t *pNtk, int fDirect)
Definition: abcFunc.c:1124
void Abc_NtkCycleInitStateSop(Abc_Ntk_t *pNtk, int nFrames, int fVerbose)
Definition: retInit.c:314
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
ABC_DLL int Abc_NtkSweep(Abc_Ntk_t *pNtk, int fVerbose)
Definition: abcSweep.c:574
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
static int Abc_ObjIsPo(Abc_Obj_t *pObj)
Definition: abc.h:348
#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
int Abc_NtkCountFaninsTotal ( Abc_Ntk_t pNtk)
static

DECLARATIONS ///.

CFile****************************************************************

FileName [abcDebug.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Network and node package.]

Synopsis [Automated debugging procedures.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
abcDebug.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Function*************************************************************

Synopsis [Counts the total number of fanins.]

Description []

SideEffects []

SeeAlso []

Definition at line 116 of file abcDebug.c.

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 }
ABC_DLL int Abc_NodeIsConst(Abc_Obj_t *pNode)
Definition: abcObj.c:843
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
static int Counter
static int Abc_NtkPoNum(Abc_Ntk_t *pNtk)
Definition: abc.h:286
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
static int Abc_ObjIsPo(Abc_Obj_t *pObj)
Definition: abc.h:348
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446
int Abc_NtkFindGivenFanin ( Abc_Ntk_t pNtk,
int  Step,
Abc_Obj_t **  ppObj,
Abc_Obj_t **  ppFanin 
)

Function*************************************************************

Synopsis [Returns the node and fanin to be modified.]

Description []

SideEffects []

SeeAlso []

Definition at line 145 of file abcDebug.c.

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 }
ABC_DLL int Abc_NodeIsConst(Abc_Obj_t *pNode)
Definition: abcObj.c:843
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
static int Counter
static int Abc_NtkPoNum(Abc_Ntk_t *pNtk)
Definition: abc.h:286
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
static int Abc_ObjIsPo(Abc_Obj_t *pObj)
Definition: abc.h:348
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446