48 #ifdef ABC_PYTHON_EMBED
50 #endif /* ABC_PYTHON_EMBED */
52 #include "base/abc/abc.h"
55 ABC_NAMESPACE_IMPL_START
62 static int TypeCheck( Abc_Frame_t * pAbc, const char * s);
80 int Abc_RealMain( int argc, char * argv[] )
83 char sCommandUsr[ABC_MAX_STR] = {0}, sCommandTmp[ABC_MAX_STR], sReadCmd[1000], sWriteCmd[1000];
84 const char * sOutFile, * sInFile;
87 int c, fInitSource, fInitRead, fFinalWrite;
90 INTERACTIVE, // interactive mode
91 BATCH, // batch mode, run a command and quit
92 BATCH_THEN_INTERACTIVE, // run a command, then back to interactive mode
93 BATCH_QUIET // as in batch mode, but don't echo the command
96 // added to detect memory leaks
97 // watch for {,,msvcrtd.dll}*__p__crtBreakAlloc()
98 // (http://support.microsoft.com/kb/151585)
99 #if defined(_DEBUG) && defined(_MSC_VER)
100 _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
103 // get global frame (singleton pattern)
104 // will be initialized on first call
105 pAbc = Abc_FrameGetGlobalFrame();
106 pAbc->sBinary = argv[0];
108 #ifdef ABC_PYTHON_EMBED
111 void init_pyabc(void);
113 Py_SetProgramName(argv[0]);
119 pModule = PyImport_ImportModule("pyabc");
126 fprintf( pAbc->Err, "error: pyabc.py not found. PYTHONPATH may not be set properly.\n");
129 #endif /* ABC_PYTHON_EMBED */
132 fBatch = INTERACTIVE;
136 sInFile = sOutFile = NULL;
137 sprintf( sReadCmd, "read" );
138 sprintf( sWriteCmd, "write" );
140 Extra_UtilGetoptReset();
141 while ((c = Extra_UtilGetopt(argc, argv, "c:q:C:hf:F:o:st:T:xb")) != EOF) {
144 strcpy( sCommandUsr, globalUtilOptarg );
149 strcpy( sCommandUsr, globalUtilOptarg );
150 fBatch = BATCH_QUIET;
154 strcpy( sCommandUsr, globalUtilOptarg );
155 fBatch = BATCH_THEN_INTERACTIVE;
159 sprintf(sCommandUsr, "source %s", globalUtilOptarg);
164 sprintf(sCommandUsr, "source -x %s", globalUtilOptarg);
173 sOutFile = globalUtilOptarg;
182 if ( TypeCheck( pAbc, globalUtilOptarg ) )
184 if ( !strcmp(globalUtilOptarg, "none") == 0 )
187 sprintf( sReadCmd, "read_%s", globalUtilOptarg );
197 if ( TypeCheck( pAbc, globalUtilOptarg ) )
199 if (!strcmp(globalUtilOptarg, "none") == 0)
202 sprintf( sWriteCmd, "write_%s", globalUtilOptarg);
218 Abc_FrameSetBridgeMode();
226 if ( Abc_FrameIsBridgeMode() )
228 extern Gia_Man_t * Gia_ManFromBridge( FILE * pFile, Vec_Int_t ** pvInit );
229 pAbc->pGia = Gia_ManFromBridge( stdin, NULL );
231 else if ( fBatch!=INTERACTIVE && fBatch!=BATCH_QUIET && sCommandUsr[0] )
232 Abc_Print( 1, "ABC command line: \"%s\".\n\n", sCommandUsr );
234 if ( fBatch!=INTERACTIVE )
236 pAbc->fBatchMode = 1;
239 if (argc - globalUtilOptind == 0)
243 else if (argc - globalUtilOptind == 1)
246 sInFile = argv[globalUtilOptind];
250 Abc_UtilsPrintUsage( pAbc, argv[0] );
253 // source the resource file
256 Abc_UtilsSource( pAbc );
260 if ( fInitRead && sInFile )
262 sprintf( sCommandTmp, "%s %s", sReadCmd, sInFile );
263 fStatus = Cmd_CommandExecute( pAbc, sCommandTmp );
268 /* cmd line contains `source <file>' */
269 fStatus = Cmd_CommandExecute( pAbc, sCommandUsr );
270 if ( (fStatus == 0 || fStatus == -1) && fFinalWrite && sOutFile )
272 sprintf( sCommandTmp, "%s %s", sWriteCmd, sOutFile );
273 fStatus = Cmd_CommandExecute( pAbc, sCommandTmp );
277 if (fBatch == BATCH_THEN_INTERACTIVE){
278 fBatch = INTERACTIVE;
279 pAbc->fBatchMode = 0;
284 if ( fBatch==INTERACTIVE )
286 // start interactive mode
288 // print the hello line
289 Abc_UtilsPrintHello( pAbc );
290 // print history of the recent commands
291 Cmd_HistoryPrint( pAbc, 10 );
293 // source the resource file
296 Abc_UtilsSource( pAbc );
299 // execute commands given by the user
300 while ( !feof(stdin) )
302 // print command line prompt and
303 // get the command from the user
304 sCommand = Abc_UtilsGetUsersInput( pAbc );
306 // execute the user's command
307 fStatus = Cmd_CommandExecute( pAbc, sCommand );
309 // stop if the user quitted or an error occurred
310 if ( fStatus == -1 || fStatus == -2 )
315 #ifdef ABC_PYTHON_EMBED
319 #endif /* ABC_PYTHON_EMBED */
321 // if the memory should be freed, quit packages
322 // if ( fStatus < 0 )
329 Abc_UtilsPrintHello( pAbc );
330 Abc_UtilsPrintUsage( pAbc, argv[0] );
344 static int TypeCheck( Abc_Frame_t * pAbc, const char * s )
346 if (strcmp(s, "blif") == 0)
348 else if (strcmp(s, "bench") == 0)
350 else if (strcmp(s, "pla") == 0)
352 else if (strcmp(s, "none") == 0)
355 fprintf( pAbc->Err, "unknown type %s\n", s );
368 ABC_NAMESPACE_IMPL_END