summaryrefslogtreecommitdiffstats
path: root/src/base/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/base/main')
-rw-r--r--src/base/main/main.c267
-rw-r--r--src/base/main/main.h109
-rw-r--r--src/base/main/mainFrame.c417
-rw-r--r--src/base/main/mainInit.c96
-rw-r--r--src/base/main/mainInt.h107
-rw-r--r--src/base/main/mainUtils.c218
-rw-r--r--src/base/main/module.make4
7 files changed, 1218 insertions, 0 deletions
diff --git a/src/base/main/main.c b/src/base/main/main.c
new file mode 100644
index 00000000..ed1e929d
--- /dev/null
+++ b/src/base/main/main.c
@@ -0,0 +1,267 @@
+/**CFile****************************************************************
+
+ FileName [main.c]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [The main package.]
+
+ Synopsis [Here everything starts.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - June 20, 2005.]
+
+ Revision [$Id: main.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
+
+***********************************************************************/
+
+#include "mainInt.h"
+
+////////////////////////////////////////////////////////////////////////
+/// DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+static int TypeCheck( Abc_Frame_t * pAbc, char * s);
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/**Function*************************************************************
+
+ Synopsis [The main() procedure.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int main( int argc, char * argv[] )
+{
+ Abc_Frame_t * pAbc;
+ char sCommandUsr[500], sCommandTmp[100], sReadCmd[20], sWriteCmd[20], c;
+ char * sCommand, * sOutFile, * sInFile;
+ int fStatus = 0;
+ bool fBatch, fInitSource, fInitRead, fFinalWrite;
+
+ // added to detect memory leaks:
+#ifdef _DEBUG
+ _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
+#endif
+
+ // get global frame (singleton pattern)
+ // will be initialized on first call
+ pAbc = Abc_FrameGetGlobalFrame();
+
+ // default options
+ fBatch = 0;
+ fInitSource = 1;
+ fInitRead = 0;
+ fFinalWrite = 0;
+ sInFile = sOutFile = NULL;
+ sprintf( sReadCmd, "read_blif_mv" );
+ sprintf( sWriteCmd, "write_blif_mv" );
+
+ util_getopt_reset();
+ while ((c = util_getopt(argc, argv, "c:hf:F:o:st:T:x")) != EOF) {
+ switch(c) {
+ case 'c':
+ strcpy( sCommandUsr, util_optarg );
+ fBatch = 1;
+ break;
+
+ case 'f':
+ sprintf(sCommandUsr, "source %s", util_optarg);
+ fBatch = 1;
+ break;
+
+ case 'F':
+ sprintf(sCommandUsr, "source -x %s", util_optarg);
+ fBatch = 1;
+ break;
+
+ case 'h':
+ goto usage;
+ break;
+
+ case 'o':
+ sOutFile = util_optarg;
+ fFinalWrite = 1;
+ break;
+
+ case 's':
+ fInitSource = 0;
+ break;
+
+ case 't':
+ if ( TypeCheck( pAbc, util_optarg ) )
+ {
+ if ( !strcmp(util_optarg, "none") == 0 )
+ {
+ fInitRead = 1;
+ sprintf( sReadCmd, "read_%s", util_optarg );
+ }
+ }
+ else {
+ goto usage;
+ }
+ fBatch = 1;
+ break;
+
+ case 'T':
+ if ( TypeCheck( pAbc, util_optarg ) )
+ {
+ if (!strcmp(util_optarg, "none") == 0)
+ {
+ fFinalWrite = 1;
+ sprintf( sWriteCmd, "write_%s", util_optarg);
+ }
+ }
+ else {
+ goto usage;
+ }
+ fBatch = 1;
+ break;
+
+ case 'x':
+ fFinalWrite = 0;
+ fInitRead = 0;
+ fBatch = 1;
+ break;
+
+ default:
+ goto usage;
+ }
+ }
+
+ if ( fBatch )
+ {
+ pAbc->fBatchMode = 1;
+
+ if (argc - util_optind == 0)
+ {
+ sInFile = NULL;
+ }
+ else if (argc - util_optind == 1)
+ {
+ fInitRead = 1;
+ sInFile = argv[util_optind];
+ }
+ else
+ {
+ Abc_UtilsPrintUsage( pAbc, argv[0] );
+ }
+
+ // source the resource file
+ if ( fInitSource )
+ {
+ Abc_UtilsSource( pAbc );
+ }
+
+ fStatus = 0;
+ if ( fInitRead && sInFile )
+ {
+ sprintf( sCommandTmp, "%s %s", sReadCmd, sInFile );
+ fStatus = Cmd_CommandExecute( pAbc, sCommandTmp );
+ }
+
+ if ( fStatus == 0 )
+ {
+ /* cmd line contains `source <file>' */
+ fStatus = Cmd_CommandExecute( pAbc, sCommandUsr );
+ if ( (fStatus == 0 || fStatus == -1) && fFinalWrite && sOutFile )
+ {
+ sprintf( sCommandTmp, "%s %s", sWriteCmd, sOutFile );
+ fStatus = Cmd_CommandExecute( pAbc, sCommandTmp );
+ }
+ }
+
+ }
+ else
+ {
+ // start interactive mode
+ // print the hello line
+ Abc_UtilsPrintHello( pAbc );
+
+ // source the resource file
+ if ( fInitSource )
+ {
+ Abc_UtilsSource( pAbc );
+ }
+
+ // execute commands given by the user
+ while ( !feof(stdin) )
+ {
+ // print command line prompt and
+ // get the command from the user
+ sCommand = Abc_UtilsGetUsersInput( pAbc );
+
+ // execute the user's command
+ fStatus = Cmd_CommandExecute( pAbc, sCommand );
+
+ // stop if the user quitted or an error occurred
+ if ( fStatus == -1 || fStatus == -2 )
+ break;
+ }
+ }
+
+ // if the memory should be freed, quit packages
+ if ( fStatus == -2 )
+ {
+ // perform uninitializations
+ Abc_FrameEnd( pAbc );
+ // stop the framework
+ Abc_FrameDeallocate( pAbc );
+ }
+ return 0;
+
+usage:
+ Abc_UtilsPrintHello( pAbc );
+ Abc_UtilsPrintUsage( pAbc, argv[0] );
+ return 1;
+}
+
+
+/**Function********************************************************************
+
+ Synopsis [Returns 1 if s is a file type recognized, else returns 0.]
+
+ Description [Returns 1 if s is a file type recognized by VIS, else returns
+ 0. Recognized types are "blif", "blif_mv", "blif_mvs", and "none".]
+
+ SideEffects []
+
+******************************************************************************/
+static int
+TypeCheck(
+ Abc_Frame_t * pAbc,
+ char * s)
+{
+ if (strcmp(s, "blif") == 0) {
+ return 1;
+ }
+ else if (strcmp(s, "blif_mv") == 0) {
+ return 1;
+ }
+ else if (strcmp(s, "blif_mvs") == 0) {
+ return 1;
+ }
+ else if (strcmp(s, "none") == 0) {
+ return 1;
+ }
+ else {
+ fprintf( pAbc->Err, "unknown type %s\n", s );
+ return 0;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
+
diff --git a/src/base/main/main.h b/src/base/main/main.h
new file mode 100644
index 00000000..c5d6a0c8
--- /dev/null
+++ b/src/base/main/main.h
@@ -0,0 +1,109 @@
+/**CFile****************************************************************
+
+ FileName [main.h]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [The main package.]
+
+ Synopsis [External declarations of the main package.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - June 20, 2005.]
+
+ Revision [$Id: main.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
+
+***********************************************************************/
+
+#ifndef __MAIN_H__
+#define __MAIN_H__
+
+////////////////////////////////////////////////////////////////////////
+/// TYPEDEFS ///
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+/// STRUCTURE DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+// the framework containing all data
+typedef struct Abc_Frame_t_ Abc_Frame_t;
+
+////////////////////////////////////////////////////////////////////////
+/// INCLUDES ///
+////////////////////////////////////////////////////////////////////////
+
+// this include should be the first one in the list
+// it is used to catch memory leaks on Windows
+#include "leaks.h"
+
+// standard includes
+#include <stdio.h>
+#include <string.h>
+
+// includes from GLU
+#include "util.h"
+#include "st.h"
+
+// data structure packages
+#include "extra.h"
+#include "vec.h"
+
+// core packages
+#include "abc.h"
+#include "cmd.h"
+#include "io.h"
+
+////////////////////////////////////////////////////////////////////////
+/// PARAMETERS ///
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+/// GLOBAL VARIABLES ///
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+/// MACRO DEFITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/*=== mvFrame.c ===========================================================*/
+extern Abc_Ntk_t * Abc_FrameReadNet( Abc_Frame_t * p );
+extern FILE * Abc_FrameReadOut( Abc_Frame_t * p );
+extern FILE * Abc_FrameReadErr( Abc_Frame_t * p );
+extern bool Abc_FrameReadMode( Abc_Frame_t * p );
+extern bool Abc_FrameSetMode( Abc_Frame_t * p, bool fNameMode );
+extern void Abc_FrameRestart( Abc_Frame_t * p );
+
+extern void Abc_FrameSetCurrentNetwork( Abc_Frame_t * p, Abc_Ntk_t * pNet );
+extern void Abc_FrameSwapCurrentAndBackup( Abc_Frame_t * p );
+extern void Abc_FrameReplaceCurrentNetwork( Abc_Frame_t * p, Abc_Ntk_t * pNet );
+extern void Abc_FrameDeleteAllNetworks( Abc_Frame_t * p );
+
+extern void Abc_FrameSetGlobalFrame( Abc_Frame_t * p );
+extern Abc_Frame_t * Abc_FrameGetGlobalFrame();
+
+extern Abc_Ntk_t * Abc_FrameReadNtkStore ( Abc_Frame_t * pFrame );
+extern int Abc_FrameReadNtkStoreSize ( Abc_Frame_t * pFrame );
+extern void Abc_FrameSetNtkStore ( Abc_Frame_t * pFrame, Abc_Ntk_t * pNtk );
+extern void Abc_FrameSetNtkStoreSize ( Abc_Frame_t * pFrame, int nStored );
+
+extern void * Abc_FrameReadLibLut ( Abc_Frame_t * pFrame );
+extern void * Abc_FrameReadLibGen ( Abc_Frame_t * pFrame );
+extern void * Abc_FrameReadLibSuper ( Abc_Frame_t * pFrame );
+extern void Abc_FrameSetLibLut ( Abc_Frame_t * pFrame, void * pLib );
+extern void Abc_FrameSetLibGen ( Abc_Frame_t * pFrame, void * pLib );
+extern void Abc_FrameSetLibSuper ( Abc_Frame_t * pFrame, void * pLib );
+
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
+#endif
diff --git a/src/base/main/mainFrame.c b/src/base/main/mainFrame.c
new file mode 100644
index 00000000..0b0cbbbd
--- /dev/null
+++ b/src/base/main/mainFrame.c
@@ -0,0 +1,417 @@
+/**CFile****************************************************************
+
+ FileName [mainFrame.c]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [The main package.]
+
+ Synopsis [The global framework resides in this file.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - June 20, 2005.]
+
+ Revision [$Id: mainFrame.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
+
+***********************************************************************/
+
+#include "mainInt.h"
+#include "abc.h"
+
+////////////////////////////////////////////////////////////////////////
+/// DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+static Abc_Frame_t * Abc_FrameGlobalFrame = 0;
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Abc_Frame_t * Abc_FrameAllocate()
+{
+ Abc_Frame_t * p;
+
+ // allocate and clean
+ p = ALLOC( Abc_Frame_t, 1 );
+ memset( p, 0, sizeof(Abc_Frame_t) );
+ // get version
+ p->sVersion = Abc_UtilsGetVersion( p );
+ // set streams
+ p->Err = stderr;
+ p->Out = stdout;
+ p->Hst = NULL;
+ // set the starting step
+ p->nSteps = 1;
+ p->fBatchMode = 0;
+ return p;
+}
+
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Abc_FrameDeallocate( Abc_Frame_t * p )
+{
+ Abc_FrameDeleteAllNetworks( p );
+ free( p );
+ p = NULL;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Abc_FrameRestart( Abc_Frame_t * p )
+{
+}
+
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Abc_Ntk_t * Abc_FrameReadNet( Abc_Frame_t * p )
+{
+ return p->pNtkCur;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+FILE * Abc_FrameReadOut( Abc_Frame_t * p )
+{
+ return p->Out;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+FILE * Abc_FrameReadErr( Abc_Frame_t * p )
+{
+ return p->Err;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Abc_FrameReadMode( Abc_Frame_t * p )
+{
+ int fShortNames;
+ char * pValue;
+ pValue = Cmd_FlagReadByName( p, "namemode" );
+ if ( pValue == NULL )
+ fShortNames = 0;
+ else
+ fShortNames = atoi(pValue);
+ return fShortNames;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+bool Abc_FrameSetMode( Abc_Frame_t * p, bool fNameMode )
+{
+ char Buffer[2];
+ bool fNameModeOld;
+ fNameModeOld = Abc_FrameReadMode( p );
+ Buffer[0] = '0' + fNameMode;
+ Buffer[1] = 0;
+ Cmd_FlagUpdateValue( p, "namemode", (char *)Buffer );
+ return fNameModeOld;
+}
+
+
+/**Function*************************************************************
+
+ Synopsis [Sets the given network to be the current one.]
+
+ Description [Takes the network and makes it the current network.
+ The previous current network is attached to the given network as
+ a backup copy. In the stack of backup networks contains too many
+ networks (defined by the paramater "savesteps"), the bottom
+ most network is deleted.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Abc_FrameSetCurrentNetwork( Abc_Frame_t * p, Abc_Ntk_t * pNetNew )
+{
+ Abc_Ntk_t * pNet, * pNet2, * pNet3;
+ int nNetsPresent;
+ int nNetsToSave;
+ char * pValue;
+
+ // link it to the previous network
+ Abc_NtkSetBackup( pNetNew, p->pNtkCur );
+ // set the step of this network
+ Abc_NtkSetStep( pNetNew, ++p->nSteps );
+ // set this network to be the current network
+ p->pNtkCur = pNetNew;
+
+ // remove any extra network that may happen to be in the stack
+ pValue = Cmd_FlagReadByName( p, "savesteps" );
+ // if the value of steps to save is not set, assume 1-level undo
+ if ( pValue == NULL )
+ nNetsToSave = 1;
+ else
+ nNetsToSave = atoi(pValue);
+
+ // count the network, remember the last one, and the one before the last one
+ nNetsPresent = 0;
+ pNet2 = pNet3 = NULL;
+ for ( pNet = p->pNtkCur; pNet; pNet = Abc_NtkBackup(pNet2) )
+ {
+ nNetsPresent++;
+ pNet3 = pNet2;
+ pNet2 = pNet;
+ }
+
+ // remove the earliest backup network if it is more steps away than we store
+ if ( nNetsPresent - 1 > nNetsToSave )
+ { // delete the last network
+ Abc_NtkDelete( pNet2 );
+ // clean the pointer of the network before the last one
+ Abc_NtkSetBackup( pNet3, NULL );
+ }
+}
+
+/**Function*************************************************************
+
+ Synopsis [This procedure swaps the current and the backup network.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Abc_FrameSwapCurrentAndBackup( Abc_Frame_t * p )
+{
+ Abc_Ntk_t * pNtkCur, * pNetBack, * pNetBack2;
+ int iStepCur, iStepBack;
+
+ pNtkCur = p->pNtkCur;
+ pNetBack = Abc_NtkBackup( pNtkCur );
+ iStepCur = Abc_NtkStep ( pNtkCur );
+
+ // if there is no backup nothing to reset
+ if ( pNetBack == NULL )
+ return;
+
+ // remember the backup of the backup
+ pNetBack2 = Abc_NtkBackup( pNetBack );
+ iStepBack = Abc_NtkStep ( pNetBack );
+
+ // set pNtkCur to be the next after the backup's backup
+ Abc_NtkSetBackup( pNtkCur, pNetBack2 );
+ Abc_NtkSetStep ( pNtkCur, iStepBack );
+
+ // set pNtkCur to be the next after the backup
+ Abc_NtkSetBackup( pNetBack, pNtkCur );
+ Abc_NtkSetStep ( pNetBack, iStepCur );
+
+ // set the current network
+ p->pNtkCur = pNetBack;
+}
+
+
+/**Function*************************************************************
+
+ Synopsis [Replaces the current network by the given one.]
+
+ Description [This procedure does not modify the stack of saved
+ networks.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Abc_FrameReplaceCurrentNetwork( Abc_Frame_t * p, Abc_Ntk_t * pNet )
+{
+ if ( pNet == NULL )
+ return;
+
+ // transfer the parameters to the new network
+ if ( p->pNtkCur )
+ {
+ Abc_NtkSetBackup( pNet, Abc_NtkBackup(p->pNtkCur) );
+ Abc_NtkSetStep( pNet, Abc_NtkStep(p->pNtkCur) );
+ // delete the current network
+ Abc_NtkDelete( p->pNtkCur );
+ }
+ else
+ {
+ Abc_NtkSetBackup( pNet, NULL );
+ Abc_NtkSetStep( pNet, ++p->nSteps );
+ }
+ // set the new current network
+ p->pNtkCur = pNet;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Abc_FrameDeleteAllNetworks( Abc_Frame_t * p )
+{
+ Abc_Ntk_t * pNet, * pNet2;
+ // delete all the currently saved networks
+ for ( pNet = p->pNtkCur,
+ pNet2 = pNet? Abc_NtkBackup(pNet): NULL;
+ pNet;
+ pNet = pNet2,
+ pNet2 = pNet? Abc_NtkBackup(pNet): NULL )
+ Abc_NtkDelete( pNet );
+ // set the current network empty
+ p->pNtkCur = NULL;
+ fprintf( p->Out, "All networks have been deleted.\n" );
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Abc_FrameSetGlobalFrame( Abc_Frame_t * p )
+{
+ Abc_FrameGlobalFrame = p;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Abc_Frame_t * Abc_FrameGetGlobalFrame()
+{
+ if ( Abc_FrameGlobalFrame == 0 )
+ {
+ // start the framework
+ Abc_FrameGlobalFrame = Abc_FrameAllocate();
+ // perform initializations
+ Abc_FrameInit( Abc_FrameGlobalFrame );
+ }
+ return Abc_FrameGlobalFrame;
+}
+
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Abc_Ntk_t * Abc_FrameReadNtkStore ( Abc_Frame_t * pFrame ) { return pFrame->pStored; }
+int Abc_FrameReadNtkStoreSize ( Abc_Frame_t * pFrame ) { return pFrame->nStored; }
+void Abc_FrameSetNtkStore ( Abc_Frame_t * pFrame, Abc_Ntk_t * pNtk ) { pFrame->pStored = pNtk; }
+void Abc_FrameSetNtkStoreSize ( Abc_Frame_t * pFrame, int nStored ) { pFrame->nStored = nStored; }
+
+void * Abc_FrameReadLibLut ( Abc_Frame_t * pFrame ) { return pFrame->pLibLut; }
+void * Abc_FrameReadLibGen ( Abc_Frame_t * pFrame ) { return pFrame->pLibGen; }
+void * Abc_FrameReadLibSuper ( Abc_Frame_t * pFrame ) { return pFrame->pLibSuper; }
+void Abc_FrameSetLibLut ( Abc_Frame_t * pFrame, void * pLib ) { pFrame->pLibLut = pLib; }
+void Abc_FrameSetLibGen ( Abc_Frame_t * pFrame, void * pLib ) { pFrame->pLibGen = pLib; }
+void Abc_FrameSetLibSuper ( Abc_Frame_t * pFrame, void * pLib ) { pFrame->pLibSuper = pLib; }
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
+
diff --git a/src/base/main/mainInit.c b/src/base/main/mainInit.c
new file mode 100644
index 00000000..13710dcb
--- /dev/null
+++ b/src/base/main/mainInit.c
@@ -0,0 +1,96 @@
+/**CFile****************************************************************
+
+ FileName [mainInit.c]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [The main package.]
+
+ Synopsis [Initialization procedures.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - June 20, 2005.]
+
+ Revision [$Id: mainInit.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
+
+***********************************************************************/
+
+#include "mainInt.h"
+
+////////////////////////////////////////////////////////////////////////
+/// DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+extern void Abc_Init( Abc_Frame_t * pAbc );
+extern void Abc_End ( Abc_Frame_t * pAbc );
+extern void Io_Init( Abc_Frame_t * pAbc );
+extern void Io_End ( Abc_Frame_t * pAbc );
+extern void Cmd_Init( Abc_Frame_t * pAbc );
+extern void Cmd_End ( Abc_Frame_t * pAbc );
+extern void Fpga_Init( Abc_Frame_t * pAbc );
+extern void Fpga_End ( Abc_Frame_t * pAbc );
+extern void Map_Init( Abc_Frame_t * pAbc );
+extern void Map_End ( Abc_Frame_t * pAbc );
+extern void Mio_Init( Abc_Frame_t * pAbc );
+extern void Mio_End ( Abc_Frame_t * pAbc );
+extern void Super_Init( Abc_Frame_t * pAbc );
+extern void Super_End ( Abc_Frame_t * pAbc );
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/**Function*************************************************************
+
+ Synopsis [Starts all the packages.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Abc_FrameInit( Abc_Frame_t * pAbc )
+{
+ Cmd_Init( pAbc );
+ Io_Init( pAbc );
+ Abc_Init( pAbc );
+ Fpga_Init( pAbc );
+ Map_Init( pAbc );
+ Mio_Init( pAbc );
+ Super_Init( pAbc );
+}
+
+
+/**Function*************************************************************
+
+ Synopsis [Stops all the packages.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Abc_FrameEnd( Abc_Frame_t * pAbc )
+{
+ Abc_End( pAbc );
+ Io_End( pAbc );
+ Cmd_End( pAbc );
+ Fpga_End( pAbc );
+ Map_End( pAbc );
+ Mio_End( pAbc );
+ Super_End( pAbc );
+}
+
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
+
diff --git a/src/base/main/mainInt.h b/src/base/main/mainInt.h
new file mode 100644
index 00000000..557c4e2f
--- /dev/null
+++ b/src/base/main/mainInt.h
@@ -0,0 +1,107 @@
+/**CFile****************************************************************
+
+ FileName [mainInt.h]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [The main package.]
+
+ Synopsis [Internal declarations of the main package.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - June 20, 2005.]
+
+ Revision [$Id: mainInt.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
+
+***********************************************************************/
+
+#ifndef __Abc_INT_H__
+#define __Abc_INT_H__
+
+////////////////////////////////////////////////////////////////////////
+/// INCLUDES ///
+////////////////////////////////////////////////////////////////////////
+
+#include "main.h"
+
+////////////////////////////////////////////////////////////////////////
+/// PARAMETERS ///
+////////////////////////////////////////////////////////////////////////
+
+// the current version
+#define ABC_VERSION "UC Berkeley, ABC 1.0"
+
+// the maximum length of an input line
+#define MAX_STR 32768
+
+////////////////////////////////////////////////////////////////////////
+/// STRUCTURE DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+struct Abc_Frame_t_
+{
+ // general info
+ char * sVersion; // the name of the current version
+ // commands, aliases, etc
+ st_table * tCommands; // the command table
+ st_table * tAliases; // the alias table
+ st_table * tFlags; // the flag table
+ Vec_Ptr_t * aHistory; // the command history
+ // the functionality
+ Abc_Ntk_t * pNtkCur; // the current network
+ int nSteps; // the counter of different network processed
+ // when this flag is 1, the current command is executed in autoexec mode
+ int fAutoexac;
+ // output streams
+ FILE * Out;
+ FILE * Err;
+ FILE * Hst;
+ // used for runtime measurement
+ int TimeCommand; // the runtime of the last command
+ int TimeTotal; // the total runtime of all commands
+ int fBatchMode; // are we invoked in batch mode?
+ // temporary storage for structural choices
+ Abc_Ntk_t * pStored; // the stored networks
+ int nStored; // the number of stored networks
+
+ void * pLibLut; // the current LUT library
+ void * pLibGen; // the current genlib
+ void * pLibSuper; // the current supergate library
+};
+
+////////////////////////////////////////////////////////////////////////
+/// GLOBAL VARIABLES ///
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+/// MACRO DEFITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/*=== mvMain.c ===========================================================*/
+extern int main( int argc, char * argv[] );
+/*=== mvInit.c ===================================================*/
+extern void Abc_FrameInit( Abc_Frame_t * pAbc );
+extern void Abc_FrameEnd( Abc_Frame_t * pAbc );
+/*=== mvFrame.c =====================================================*/
+extern Abc_Frame_t * Abc_FrameAllocate();
+extern void Abc_FrameDeallocate( Abc_Frame_t * p );
+/*=== mvUtils.c =====================================================*/
+extern char * Abc_UtilsGetVersion( Abc_Frame_t * pAbc );
+extern char * Abc_UtilsGetUsersInput( Abc_Frame_t * pAbc );
+extern void Abc_UtilsPrintHello( Abc_Frame_t * pAbc );
+extern void Abc_UtilsPrintUsage( Abc_Frame_t * pAbc, char * ProgName );
+extern void Abc_UtilsSource( Abc_Frame_t * pAbc );
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
+#endif
diff --git a/src/base/main/mainUtils.c b/src/base/main/mainUtils.c
new file mode 100644
index 00000000..35d3c364
--- /dev/null
+++ b/src/base/main/mainUtils.c
@@ -0,0 +1,218 @@
+/**CFile****************************************************************
+
+ FileName [mainUtils.c]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [The main package.]
+
+ Synopsis [Miscellaneous utilities.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - June 20, 2005.]
+
+ Revision [$Id: mainUtils.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
+
+***********************************************************************/
+
+#include "mainInt.h"
+
+////////////////////////////////////////////////////////////////////////
+/// DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+static char * DateReadFromDateString(char * datestr);
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+char * Abc_UtilsGetVersion( Abc_Frame_t * pAbc )
+{
+ static char Version[1000];
+ sprintf(Version, "%s (compiled %s %s)", ABC_VERSION, __DATE__, __TIME__);
+ return Version;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+char * Abc_UtilsGetUsersInput( Abc_Frame_t * pAbc )
+{
+ static char Buffer[1000], Prompt[1000];
+ sprintf( Prompt, "abc %02d> ", pAbc->nSteps );
+ fprintf( pAbc->Out, "%s", Prompt );
+ fgets( Buffer, 999, stdin );
+ return Buffer;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Abc_UtilsPrintHello( Abc_Frame_t * pAbc )
+{
+ fprintf( pAbc->Out, "%s\n", pAbc->sVersion );
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Abc_UtilsPrintUsage( Abc_Frame_t * pAbc, char * ProgName )
+{
+ fprintf( pAbc->Err, "\n" );
+ fprintf( pAbc->Err,
+ "usage: %s [-c cmd] [-f script] [-h] [-o file] [-s] [-t type] [-T type] [-x] [file]\n",
+ ProgName);
+ fprintf( pAbc->Err, " -c cmd\texecute commands `cmd'\n");
+ fprintf( pAbc->Err, " -F script\texecute commands from a script file and echo commands\n");
+ fprintf( pAbc->Err, " -f script\texecute commands from a script file\n");
+ fprintf( pAbc->Err, " -h\t\tprint the command usage\n");
+ fprintf( pAbc->Err, " -o file\tspecify output filename to store the result\n");
+ fprintf( pAbc->Err, " -s\t\tdo not read any initialization file\n");
+ fprintf( pAbc->Err, " -t type\tspecify input type (blif_mv (default), blif_mvs, blif, or none)\n");
+ fprintf( pAbc->Err, " -T type\tspecify output type (blif_mv (default), blif_mvs, blif, or none)\n");
+ fprintf( pAbc->Err, " -x\t\tequivalent to '-t none -T none'\n");
+ fprintf( pAbc->Err, "\n" );
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Abc_UtilsSource( Abc_Frame_t * pAbc )
+{
+#ifdef WIN32
+ if ( Cmd_CommandExecute(pAbc, "source abc.rc") )
+ {
+ if ( Cmd_CommandExecute(pAbc, "source ..\\abc.rc") == 0 )
+ printf( "Loaded \"abc.rc\" from the parent directory.\n" );
+ else if ( Cmd_CommandExecute(pAbc, "source ..\\..\\abc.rc") == 0 )
+ printf( "Loaded \"abc.rc\" from the grandparent directory.\n" );
+ }
+#else
+ {
+ char * sPath1, * sPath2;
+
+ // If .rc is present in both the home and current directories, then read
+ // it from the home directory. Otherwise, read it from wherever it's located.
+ sPath1 = util_file_search(".rc", "~/", "r");
+ sPath2 = util_file_search(".rc", ".", "r");
+
+ if ( sPath1 && sPath2 ) {
+ /* ~/.rc == .rc : Source the file only once */
+ (void) Cmd_CommandExecute(pAbc, "source -s ~/.rc");
+ }
+ else {
+ if (sPath1) {
+ (void) Cmd_CommandExecute(pAbc, "source -s ~/.rc");
+ }
+ if (sPath2) {
+ (void) Cmd_CommandExecute(pAbc, "source -s .rc");
+ }
+ }
+ if ( sPath1 ) FREE(sPath1);
+ if ( sPath2 ) FREE(sPath2);
+
+ /* execute the abc script which can be open with the "open_path" */
+ Cmd_CommandExecute( pAbc, "source -s abc.rc" );
+ }
+#endif //WIN32
+
+ return;
+}
+
+/**Function********************************************************************
+
+ Synopsis [Returns the date in a brief format assuming its coming from
+ the program `date'.]
+
+ Description [optional]
+
+ SideEffects []
+
+******************************************************************************/
+char *
+DateReadFromDateString(
+ char * datestr)
+{
+ static char result[25];
+ char day[10];
+ char month[10];
+ char zone[10];
+ char *at;
+ int date;
+ int hour;
+ int minute;
+ int second;
+ int year;
+
+ if (sscanf(datestr, "%s %s %2d %2d:%2d:%2d %s %4d",
+ day, month, &date, &hour, &minute, &second, zone, &year) == 8) {
+ if (hour >= 12) {
+ if (hour >= 13) hour -= 12;
+ at = "PM";
+ }
+ else {
+ if (hour == 0) hour = 12;
+ at = "AM";
+ }
+ (void) sprintf(result, "%d-%3s-%02d at %d:%02d %s",
+ date, month, year % 100, hour, minute, at);
+ return result;
+ }
+ else {
+ return datestr;
+ }
+}
+
+
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
+
diff --git a/src/base/main/module.make b/src/base/main/module.make
new file mode 100644
index 00000000..59e1315e
--- /dev/null
+++ b/src/base/main/module.make
@@ -0,0 +1,4 @@
+SRC += src/base/main/main.c \
+ src/base/main/mainFrame.c \
+ src/base/main/mainInit.c \
+ src/base/main/mainUtils.c