abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcLog.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [abcLog.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Network and node package.]
8 
9  Synopsis [Log file printing.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: abcLog.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "base/abc/abc.h"
22 #include "aig/gia/gia.h"
23 
25 
26 
27 ////////////////////////////////////////////////////////////////////////
28 /// DECLARATIONS ///
29 ////////////////////////////////////////////////////////////////////////
30 
31 /*
32  Log file format (Jiang, Mon, 28 Sep 2009; updated by Alan in Jan 2011)
33 
34  <result> <bug_free_depth> <engine_name> <0-based_output_num> <0-based_frame>
35  <INIT_STATE> : default is empty line.
36  <TRACE> : default is empty line
37 
38  <result> is one of the following: "snl_SAT", "snl_UNSAT", "snl_UNK", "snl_ABORT".
39  <bug_free_depth> is the number of timeframes exhaustively explored without counter-examples
40  <0-based_output_num> only need to be given if the problem is SAT.
41  <0-based_frame> only need to be given if the problem is SAT and <0-based_frame> is different from <bug_free_depth>.
42  <INIT_STATE> : initial state
43  <TRACE> : input vector
44 
45  <INIT_STATE>and <TRACE> are strings of 0/1/- ( - means don't care). The length is equivalent to #input*#<cyc>.
46 */
47 
48 
49 
50 
51 
52 
53 ////////////////////////////////////////////////////////////////////////
54 /// FUNCTION DEFINITIONS ///
55 ////////////////////////////////////////////////////////////////////////
56 
57 /**Function*************************************************************
58 
59  Synopsis []
60 
61  Description []
62 
63  SideEffects []
64 
65  SeeAlso []
66 
67 ***********************************************************************/
68 void Abc_NtkWriteLogFile( char * pFileName, Abc_Cex_t * pCex, int Status, int nFrames, char * pCommand )
69 {
70  FILE * pFile;
71  int i;
72  pFile = fopen( pFileName, "w" );
73  if ( pFile == NULL )
74  {
75  printf( "Cannot open log file for writing \"%s\".\n" , pFileName );
76  return;
77  }
78  // write <result>
79  if ( Status == 1 )
80  fprintf( pFile, "snl_UNSAT" );
81  else if ( Status == 0 )
82  fprintf( pFile, "snl_SAT" );
83  else if ( Status == -1 )
84  fprintf( pFile, "snl_UNK" );
85  else
86  printf( "Abc_NtkWriteLogFile(): Cannot recognize solving status.\n" );
87  fprintf( pFile, " " );
88  // write <bug_free_depth>
89  fprintf( pFile, "%d", nFrames );
90  fprintf( pFile, " " );
91  // write <engine_name>
92  fprintf( pFile, "%s", pCommand ? pCommand : "unknown" );
93  if ( pCex && Status == 0 )
94  fprintf( pFile, " %d", pCex->iPo );
95  // write <cyc>
96  if ( pCex && pCex->iFrame != nFrames )
97  fprintf( pFile, " %d", pCex->iFrame );
98  fprintf( pFile, "\n" );
99  // write <INIT_STATE>
100  if ( pCex == NULL )
101  fprintf( pFile, "NULL" );
102  else
103  {
104  for ( i = 0; i < pCex->nRegs; i++ )
105  fprintf( pFile, "%d", Abc_InfoHasBit(pCex->pData,i) );
106  }
107  fprintf( pFile, "\n" );
108  // write <TRACE>
109  if ( pCex == NULL )
110  fprintf( pFile, "NULL" );
111  else
112  {
113  assert( pCex->nBits - pCex->nRegs == pCex->nPis * (pCex->iFrame + 1) );
114  for ( i = pCex->nRegs; i < pCex->nBits; i++ )
115  fprintf( pFile, "%d", Abc_InfoHasBit(pCex->pData,i) );
116  }
117  fprintf( pFile, "\n" );
118  fclose( pFile );
119 }
120 
121 /**Function*************************************************************
122 
123  Synopsis []
124 
125  Description []
126 
127  SideEffects []
128 
129  SeeAlso []
130 
131 ***********************************************************************/
132 int Abc_NtkReadLogFile( char * pFileName, Abc_Cex_t ** ppCex, int * pnFrames )
133 {
134  FILE * pFile;
135  Abc_Cex_t * pCex;
136  Vec_Int_t * vNums;
137  char Buffer[1000], * pToken, * RetValue;
138  int c, nRegs = -1, nFrames = -1, iPo = -1, Status = -1, nFrames2 = -1;
139  pFile = fopen( pFileName, "r" );
140  if ( pFile == NULL )
141  {
142  printf( "Cannot open log file for reading \"%s\".\n" , pFileName );
143  return -1;
144  }
145  RetValue = fgets( Buffer, 1000, pFile );
146  if ( !strncmp( Buffer, "snl_UNSAT", strlen("snl_UNSAT") ) )
147  {
148  Status = 1;
149  nFrames = atoi( Buffer + strlen("snl_UNSAT") );
150  }
151  else if ( !strncmp( Buffer, "snl_SAT", strlen("snl_SAT") ) )
152  {
153  Status = 0;
154 // nFrames = atoi( Buffer + strlen("snl_SAT") );
155  pToken = strtok( Buffer + strlen("snl_SAT"), " \t\n" );
156  nFrames = atoi( pToken );
157  pToken = strtok( NULL, " \t\n" );
158  pToken = strtok( NULL, " \t\n" );
159  if ( pToken != NULL )
160  {
161  iPo = atoi( pToken );
162  pToken = strtok( NULL, " \t\n" );
163  if ( pToken )
164  nFrames2 = atoi( pToken );
165  }
166 // else
167 // printf( "Warning! The current status is SAT but the current CEX is not given.\n" );
168  }
169  else if ( !strncmp( Buffer, "snl_UNK", strlen("snl_UNK") ) )
170  {
171  Status = -1;
172  nFrames = atoi( Buffer + strlen("snl_UNK") );
173  }
174  else
175  {
176  printf( "Unrecognized status.\n" );
177  }
178  // found regs till the new line
179  vNums = Vec_IntAlloc( 100 );
180  while ( (c = fgetc(pFile)) != EOF )
181  {
182  if ( c == '\n' )
183  break;
184  if ( c == '0' || c == '1' )
185  Vec_IntPush( vNums, c - '0' );
186  }
187  nRegs = Vec_IntSize(vNums);
188  // skip till the new line
189  while ( (c = fgetc(pFile)) != EOF )
190  {
191  if ( c == '0' || c == '1' )
192  Vec_IntPush( vNums, c - '0' );
193  }
194  fclose( pFile );
195  if ( Vec_IntSize(vNums) )
196  {
197  int iFrameCex = (nFrames2 == -1) ? nFrames : nFrames2;
198  if ( nRegs < 0 )
199  {
200  printf( "Cannot read register number.\n" );
201  Vec_IntFree( vNums );
202  return -1;
203  }
204  if ( Vec_IntSize(vNums)-nRegs == 0 )
205  {
206  printf( "Cannot read counter example.\n" );
207  Vec_IntFree( vNums );
208  return -1;
209  }
210  if ( (Vec_IntSize(vNums)-nRegs) % (iFrameCex + 1) != 0 )
211  {
212  printf( "Incorrect number of bits.\n" );
213  Vec_IntFree( vNums );
214  return -1;
215  }
216  pCex = Abc_CexAlloc( nRegs, (Vec_IntSize(vNums)-nRegs)/(iFrameCex + 1), iFrameCex + 1 );
217  pCex->iPo = iPo;
218  pCex->iFrame = iFrameCex;
219  assert( Vec_IntSize(vNums) == pCex->nBits );
220  for ( c = 0; c < pCex->nBits; c++ )
221  if ( Vec_IntEntry(vNums, c) )
222  Abc_InfoSetBit( pCex->pData, c );
223  Vec_IntFree( vNums );
224  if ( ppCex )
225  *ppCex = pCex;
226  else
227  ABC_FREE( pCex );
228  }
229  else
230  Vec_IntFree( vNums );
231  if ( pnFrames )
232  *pnFrames = nFrames;
233  return Status;
234 }
235 
236 ////////////////////////////////////////////////////////////////////////
237 /// END OF FILE ///
238 ////////////////////////////////////////////////////////////////////////
239 
240 
242 
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int Abc_InfoHasBit(unsigned *p, int i)
Definition: abc_global.h:258
ABC_NAMESPACE_IMPL_START Abc_Cex_t * Abc_CexAlloc(int nRegs, int nRealPis, int nFrames)
DECLARATIONS ///.
Definition: utilCex.c:51
int Abc_NtkReadLogFile(char *pFileName, Abc_Cex_t **ppCex, int *pnFrames)
Definition: abcLog.c:132
char * strtok()
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
ABC_NAMESPACE_IMPL_START void Abc_NtkWriteLogFile(char *pFileName, Abc_Cex_t *pCex, int Status, int nFrames, char *pCommand)
DECLARATIONS ///.
Definition: abcLog.c:68
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static void Abc_InfoSetBit(unsigned *p, int i)
Definition: abc_global.h:259
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define ABC_FREE(obj)
Definition: abc_global.h:232
int strncmp()
#define assert(ex)
Definition: util_old.h:213
int strlen()
typedefABC_NAMESPACE_HEADER_START struct Abc_Cex_t_ Abc_Cex_t
INCLUDES ///.
Definition: utilCex.h:39
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235