abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
demo.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [demo.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [ABC as a static library.]
8 
9  Synopsis [A demo program illustrating the use of ABC as a static library.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: demo.c,v 1.00 2005/11/14 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include <stdio.h>
22 #include <time.h>
23 
24 ////////////////////////////////////////////////////////////////////////
25 /// DECLARATIONS ///
26 ////////////////////////////////////////////////////////////////////////
27 
28 // procedures to start and stop the ABC framework
29 // (should be called before and after the ABC procedures are called)
30 extern void Abc_Start();
31 extern void Abc_Stop();
32 
33 // procedures to get the ABC framework and execute commands in it
34 extern void * Abc_FrameGetGlobalFrame();
35 extern int Cmd_CommandExecute( void * pAbc, char * sCommand );
36 
37 ////////////////////////////////////////////////////////////////////////
38 /// FUNCTION DEFINITIONS ///
39 ////////////////////////////////////////////////////////////////////////
40 
41 /**Function*************************************************************
42 
43  Synopsis [The main() procedure.]
44 
45  Description [This procedure compiles into a stand-alone program for
46  DAG-aware rewriting of the AIGs. A BLIF or PLA file to be considered
47  for rewriting should be given as a command-line argument. Implementation
48  of the rewriting is inspired by the paper: Per Bjesse, Arne Boralv,
49  "DAG-aware circuit compression for formal verification", Proc. ICCAD 2004.]
50 
51  SideEffects []
52 
53  SeeAlso []
54 
55 ***********************************************************************/
56 int main( int argc, char * argv[] )
57 {
58  // parameters
59  int fUseResyn2 = 0;
60  int fPrintStats = 1;
61  int fVerify = 1;
62  // variables
63  void * pAbc;
64  char * pFileName;
65  char Command[1000];
66  clock_t clkRead, clkResyn, clkVer, clk;
67 
68  //////////////////////////////////////////////////////////////////////////
69  // get the input file name
70  if ( argc != 2 )
71  {
72  printf( "Wrong number of command-line arguments.\n" );
73  return 1;
74  }
75  pFileName = argv[1];
76 
77  //////////////////////////////////////////////////////////////////////////
78  // start the ABC framework
79  Abc_Start();
80  pAbc = Abc_FrameGetGlobalFrame();
81 
82 clk = clock();
83  //////////////////////////////////////////////////////////////////////////
84  // read the file
85  sprintf( Command, "read %s", pFileName );
86  if ( Cmd_CommandExecute( pAbc, Command ) )
87  {
88  fprintf( stdout, "Cannot execute command \"%s\".\n", Command );
89  return 1;
90  }
91 
92  //////////////////////////////////////////////////////////////////////////
93  // balance
94  sprintf( Command, "balance" );
95  if ( Cmd_CommandExecute( pAbc, Command ) )
96  {
97  fprintf( stdout, "Cannot execute command \"%s\".\n", Command );
98  return 1;
99  }
100 clkRead = clock() - clk;
101 
102  //////////////////////////////////////////////////////////////////////////
103  // print stats
104  if ( fPrintStats )
105  {
106  sprintf( Command, "print_stats" );
107  if ( Cmd_CommandExecute( pAbc, Command ) )
108  {
109  fprintf( stdout, "Cannot execute command \"%s\".\n", Command );
110  return 1;
111  }
112  }
113 
114 clk = clock();
115  //////////////////////////////////////////////////////////////////////////
116  // synthesize
117  if ( fUseResyn2 )
118  {
119  sprintf( Command, "balance; rewrite -l; refactor -l; balance; rewrite -l; rewrite -lz; balance; refactor -lz; rewrite -lz; balance" );
120  if ( Cmd_CommandExecute( pAbc, Command ) )
121  {
122  fprintf( stdout, "Cannot execute command \"%s\".\n", Command );
123  return 1;
124  }
125  }
126  else
127  {
128  sprintf( Command, "balance; rewrite -l; rewrite -lz; balance; rewrite -lz; balance" );
129  if ( Cmd_CommandExecute( pAbc, Command ) )
130  {
131  fprintf( stdout, "Cannot execute command \"%s\".\n", Command );
132  return 1;
133  }
134  }
135 clkResyn = clock() - clk;
136 
137  //////////////////////////////////////////////////////////////////////////
138  // print stats
139  if ( fPrintStats )
140  {
141  sprintf( Command, "print_stats" );
142  if ( Cmd_CommandExecute( pAbc, Command ) )
143  {
144  fprintf( stdout, "Cannot execute command \"%s\".\n", Command );
145  return 1;
146  }
147  }
148 
149  //////////////////////////////////////////////////////////////////////////
150  // write the result in blif
151  sprintf( Command, "write_blif result.blif" );
152  if ( Cmd_CommandExecute( pAbc, Command ) )
153  {
154  fprintf( stdout, "Cannot execute command \"%s\".\n", Command );
155  return 1;
156  }
157 
158  //////////////////////////////////////////////////////////////////////////
159  // perform verification
160 clk = clock();
161  if ( fVerify )
162  {
163  sprintf( Command, "cec %s result.blif", pFileName );
164  if ( Cmd_CommandExecute( pAbc, Command ) )
165  {
166  fprintf( stdout, "Cannot execute command \"%s\".\n", Command );
167  return 1;
168  }
169  }
170 clkVer = clock() - clk;
171 
172  printf( "Reading = %6.2f sec ", (float)(clkRead)/(float)(CLOCKS_PER_SEC) );
173  printf( "Rewriting = %6.2f sec ", (float)(clkResyn)/(float)(CLOCKS_PER_SEC) );
174  printf( "Verification = %6.2f sec\n", (float)(clkVer)/(float)(CLOCKS_PER_SEC) );
175 
176  //////////////////////////////////////////////////////////////////////////
177  // stop the ABC framework
178  Abc_Stop();
179  return 0;
180 }
181 
int main(int argc, char *argv[])
FUNCTION DEFINITIONS ///.
Definition: demo.c:56
void Abc_Start()
DECLARATIONS ///.
Definition: mainLib.c:52
char * sprintf()
int Cmd_CommandExecute(void *pAbc, char *sCommand)
void * Abc_FrameGetGlobalFrame()
Definition: mainFrame.c:593
void Abc_Stop()
Definition: mainLib.c:76