abc/src/base/main/mainFrame.c

638 lines
18 KiB
C
Raw Normal View History

2005-07-29 17:01:00 +02:00
/**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 "abc.h"
2010-11-01 09:35:04 +01:00
#include "mainInt.h"
2005-09-02 17:01:00 +02:00
#include "dec.h"
2005-07-29 17:01:00 +02:00
2010-11-01 09:35:04 +01:00
ABC_NAMESPACE_IMPL_START
2005-07-29 17:01:00 +02:00
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
2005-09-05 17:01:00 +02:00
static Abc_Frame_t * s_GlobalFrame = NULL;
2005-07-29 17:01:00 +02:00
////////////////////////////////////////////////////////////////////////
2008-01-31 05:01:00 +01:00
/// FUNCTION DEFINITIONS ///
2005-07-29 17:01:00 +02:00
////////////////////////////////////////////////////////////////////////
2005-09-05 17:01:00 +02:00
/**Function*************************************************************
Synopsis [APIs to access parameters in the flobal frame.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
2010-11-01 09:35:04 +01:00
Vec_Ptr_t * Abc_FrameReadStore() { return s_GlobalFrame->vStore; }
int Abc_FrameReadStoreSize() { return Vec_PtrSize(s_GlobalFrame->vStore); }
void * Abc_FrameReadLibLut() { return s_GlobalFrame->pLibLut; }
void * Abc_FrameReadLibGen() { return s_GlobalFrame->pLibGen; }
void * Abc_FrameReadLibGen2() { return s_GlobalFrame->pLibGen2; }
void * Abc_FrameReadLibSuper() { return s_GlobalFrame->pLibSuper; }
void * Abc_FrameReadLibVer() { return s_GlobalFrame->pLibVer; }
void * Abc_FrameReadManDd() { if ( s_GlobalFrame->dd == NULL ) s_GlobalFrame->dd = Cudd_Init( 0, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 ); return s_GlobalFrame->dd; }
void * Abc_FrameReadManDec() { if ( s_GlobalFrame->pManDec == NULL ) s_GlobalFrame->pManDec = Dec_ManStart(); return s_GlobalFrame->pManDec; }
char * Abc_FrameReadFlag( char * pFlag ) { return Cmd_FlagReadByName( s_GlobalFrame, pFlag ); }
int Abc_FrameReadBmcFrames( Abc_Frame_t * p ) { return s_GlobalFrame->nFrames; }
int Abc_FrameReadProbStatus( Abc_Frame_t * p ) { return s_GlobalFrame->Status; }
void * Abc_FrameReadCex( Abc_Frame_t * p ) { return s_GlobalFrame->pCex; }
int Abc_FrameReadCexPiNum( Abc_Frame_t * p ) { return s_GlobalFrame->pCex->nPis; }
int Abc_FrameReadCexRegNum( Abc_Frame_t * p ) { return s_GlobalFrame->pCex->nRegs; }
int Abc_FrameReadCexPo( Abc_Frame_t * p ) { return s_GlobalFrame->pCex->iPo; }
int Abc_FrameReadCexFrame( Abc_Frame_t * p ) { return s_GlobalFrame->pCex->iFrame; }
void Abc_FrameSetLibLut( void * pLib ) { s_GlobalFrame->pLibLut = pLib; }
void Abc_FrameSetLibGen( void * pLib ) { s_GlobalFrame->pLibGen = pLib; }
void Abc_FrameSetLibGen2( void * pLib ) { s_GlobalFrame->pLibGen2 = pLib; }
void Abc_FrameSetLibSuper( void * pLib ) { s_GlobalFrame->pLibSuper = pLib; }
void Abc_FrameSetLibVer( void * pLib ) { s_GlobalFrame->pLibVer = pLib; }
void Abc_FrameSetFlag( char * pFlag, char * pValue ) { Cmd_FlagUpdateValue( s_GlobalFrame, pFlag, pValue ); }
2005-09-05 17:01:00 +02:00
/**Function*************************************************************
Synopsis [Returns 1 if the flag is enabled without value or with value 1.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
2010-11-01 09:35:04 +01:00
int Abc_FrameIsFlagEnabled( char * pFlag )
2005-09-05 17:01:00 +02:00
{
char * pValue;
// if flag is not defined, it is not enabled
pValue = Abc_FrameReadFlag( pFlag );
if ( pValue == NULL )
return 0;
// if flag is defined but value is not empty (no parameter) or "1", it is not enabled
if ( strcmp(pValue, "") && strcmp(pValue, "1") )
return 0;
return 1;
}
2005-07-29 17:01:00 +02:00
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Abc_Frame_t * Abc_FrameAllocate()
{
Abc_Frame_t * p;
2008-01-31 05:01:00 +01:00
extern void define_cube_size( int n );
extern void set_espresso_flags();
2005-07-29 17:01:00 +02:00
// allocate and clean
2010-11-01 09:35:04 +01:00
p = ABC_CALLOC( Abc_Frame_t, 1 );
2005-07-29 17:01:00 +02:00
// get version
p->sVersion = Abc_UtilsGetVersion( p );
// set streams
p->Err = stderr;
p->Out = stdout;
p->Hst = NULL;
2010-11-01 09:35:04 +01:00
p->Status = -1;
p->nFrames = -1;
2005-07-29 17:01:00 +02:00
// set the starting step
2010-11-01 09:35:04 +01:00
p->nSteps = 1;
p->fBatchMode = 0;
2008-01-31 05:01:00 +01:00
// networks to be used by choice
p->vStore = Vec_PtrAlloc( 16 );
2005-09-02 17:01:00 +02:00
// initialize decomposition manager
2008-07-17 17:01:00 +02:00
// define_cube_size(20);
// set_espresso_flags();
2008-01-31 05:01:00 +01:00
// initialize the trace manager
// Abc_HManStart();
2010-11-01 09:35:04 +01:00
p->vPlugInComBinPairs = Vec_PtrAlloc( 100 );
2005-07-29 17:01:00 +02:00
return p;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_FrameDeallocate( Abc_Frame_t * p )
{
2008-01-31 05:01:00 +01:00
extern void Rwt_ManGlobalStop();
extern void undefine_cube_size();
// extern void Ivy_TruthManStop();
// Abc_HManStop();
2008-07-17 17:01:00 +02:00
// undefine_cube_size();
2008-01-31 05:01:00 +01:00
Rwt_ManGlobalStop();
// Ivy_TruthManStop();
2010-11-01 09:35:04 +01:00
if ( p->pLibVer ) Abc_LibFree( (Abc_Lib_t *)p->pLibVer, NULL );
if ( p->pManDec ) Dec_ManStop( (Dec_Man_t *)p->pManDec );
2008-01-31 05:01:00 +01:00
if ( p->dd ) Extra_StopManager( p->dd );
if ( p->vStore ) Vec_PtrFree( p->vStore );
2010-11-01 09:35:04 +01:00
if ( p->pSave1 ) Aig_ManStop( (Aig_Man_t *)p->pSave1 );
if ( p->pSave2 ) Aig_ManStop( (Aig_Man_t *)p->pSave2 );
if ( p->pSave3 ) Aig_ManStop( (Aig_Man_t *)p->pSave3 );
if ( p->pSave4 ) Aig_ManStop( (Aig_Man_t *)p->pSave4 );
if ( p->vPlugInComBinPairs )
{
char * pTemp;
int i;
Vec_PtrForEachEntry( char *, p->vPlugInComBinPairs, pTemp, i )
ABC_FREE( pTemp );
Vec_PtrFree( p->vPlugInComBinPairs );
}
2005-07-29 17:01:00 +02:00
Abc_FrameDeleteAllNetworks( p );
2010-11-01 09:35:04 +01:00
ABC_FREE( p->pCex );
2009-02-15 17:01:00 +01:00
ABC_FREE( p );
2008-01-31 05:01:00 +01:00
s_GlobalFrame = NULL;
2005-07-29 17:01:00 +02:00
}
2005-07-29 17:01:00 +02:00
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_FrameRestart( Abc_Frame_t * p )
{
}
2008-01-31 05:01:00 +01:00
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
2010-11-01 09:35:04 +01:00
void Abc_FrameClearVerifStatus( Abc_Frame_t * p )
{
p->nFrames = -1;
p->Status = -1;
ABC_FREE( p->pCex );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Abc_FrameShowProgress( Abc_Frame_t * p )
2008-01-31 05:01:00 +01:00
{
return Abc_FrameIsFlagEnabled( "progressbar" );
}
2005-07-29 17:01:00 +02:00
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
2008-01-31 05:01:00 +01:00
Abc_Ntk_t * Abc_FrameReadNtk( Abc_Frame_t * p )
2005-07-29 17:01:00 +02:00
{
return p->pNtkCur;
}
2010-11-29 10:15:16 +01:00
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Gia_Man_t * Abc_FrameReadGia( Abc_Frame_t * p )
{
return p->pGia;
}
2005-07-29 17:01:00 +02:00
/**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 []
***********************************************************************/
2010-11-01 09:35:04 +01:00
int Abc_FrameSetMode( Abc_Frame_t * p, int fNameMode )
2005-07-29 17:01:00 +02:00
{
char Buffer[2];
2010-11-01 09:35:04 +01:00
int fNameModeOld;
2005-07-29 17:01:00 +02:00
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 []
***********************************************************************/
2005-08-07 17:01:00 +02:00
void Abc_FrameSetCurrentNetwork( Abc_Frame_t * p, Abc_Ntk_t * pNtkNew )
2005-07-29 17:01:00 +02:00
{
2005-08-07 17:01:00 +02:00
Abc_Ntk_t * pNtk, * pNtk2, * pNtk3;
2005-07-29 17:01:00 +02:00
int nNetsPresent;
int nNetsToSave;
char * pValue;
// link it to the previous network
2005-08-07 17:01:00 +02:00
Abc_NtkSetBackup( pNtkNew, p->pNtkCur );
2005-07-29 17:01:00 +02:00
// set the step of this network
2005-08-07 17:01:00 +02:00
Abc_NtkSetStep( pNtkNew, ++p->nSteps );
2005-07-29 17:01:00 +02:00
// set this network to be the current network
2005-08-07 17:01:00 +02:00
p->pNtkCur = pNtkNew;
2005-07-29 17:01:00 +02:00
// 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;
2005-08-07 17:01:00 +02:00
pNtk2 = pNtk3 = NULL;
for ( pNtk = p->pNtkCur; pNtk; pNtk = Abc_NtkBackup(pNtk2) )
2005-07-29 17:01:00 +02:00
{
nNetsPresent++;
2005-08-07 17:01:00 +02:00
pNtk3 = pNtk2;
pNtk2 = pNtk;
2005-07-29 17:01:00 +02:00
}
// remove the earliest backup network if it is more steps away than we store
if ( nNetsPresent - 1 > nNetsToSave )
{ // delete the last network
2005-08-07 17:01:00 +02:00
Abc_NtkDelete( pNtk2 );
2005-07-29 17:01:00 +02:00
// clean the pointer of the network before the last one
2005-08-07 17:01:00 +02:00
Abc_NtkSetBackup( pNtk3, NULL );
2005-07-29 17:01:00 +02:00
}
}
/**Function*************************************************************
Synopsis [This procedure swaps the current and the backup network.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_FrameSwapCurrentAndBackup( Abc_Frame_t * p )
{
2005-08-07 17:01:00 +02:00
Abc_Ntk_t * pNtkCur, * pNtkBack, * pNtkBack2;
2005-07-29 17:01:00 +02:00
int iStepCur, iStepBack;
pNtkCur = p->pNtkCur;
2005-08-07 17:01:00 +02:00
pNtkBack = Abc_NtkBackup( pNtkCur );
2005-07-29 17:01:00 +02:00
iStepCur = Abc_NtkStep ( pNtkCur );
// if there is no backup nothing to reset
2005-08-07 17:01:00 +02:00
if ( pNtkBack == NULL )
2005-07-29 17:01:00 +02:00
return;
// remember the backup of the backup
2005-08-07 17:01:00 +02:00
pNtkBack2 = Abc_NtkBackup( pNtkBack );
iStepBack = Abc_NtkStep ( pNtkBack );
2005-07-29 17:01:00 +02:00
// set pNtkCur to be the next after the backup's backup
2005-08-07 17:01:00 +02:00
Abc_NtkSetBackup( pNtkCur, pNtkBack2 );
2005-07-29 17:01:00 +02:00
Abc_NtkSetStep ( pNtkCur, iStepBack );
// set pNtkCur to be the next after the backup
2005-08-07 17:01:00 +02:00
Abc_NtkSetBackup( pNtkBack, pNtkCur );
Abc_NtkSetStep ( pNtkBack, iStepCur );
2005-07-29 17:01:00 +02:00
// set the current network
2005-08-07 17:01:00 +02:00
p->pNtkCur = pNtkBack;
2005-07-29 17:01:00 +02:00
}
/**Function*************************************************************
Synopsis [Replaces the current network by the given one.]
Description [This procedure does not modify the stack of saved
networks.]
SideEffects []
SeeAlso []
***********************************************************************/
2005-08-07 17:01:00 +02:00
void Abc_FrameReplaceCurrentNetwork( Abc_Frame_t * p, Abc_Ntk_t * pNtk )
2005-07-29 17:01:00 +02:00
{
2005-08-07 17:01:00 +02:00
if ( pNtk == NULL )
2005-07-29 17:01:00 +02:00
return;
// transfer the parameters to the new network
2005-09-05 17:01:00 +02:00
if ( p->pNtkCur && Abc_FrameIsFlagEnabled( "backup" ) )
2005-07-29 17:01:00 +02:00
{
2005-08-07 17:01:00 +02:00
Abc_NtkSetBackup( pNtk, Abc_NtkBackup(p->pNtkCur) );
Abc_NtkSetStep( pNtk, Abc_NtkStep(p->pNtkCur) );
2005-07-29 17:01:00 +02:00
// delete the current network
Abc_NtkDelete( p->pNtkCur );
}
else
{
2005-08-07 17:01:00 +02:00
Abc_NtkSetBackup( pNtk, NULL );
Abc_NtkSetStep( pNtk, ++p->nSteps );
2005-09-05 17:01:00 +02:00
// delete the current network if present but backup is disabled
if ( p->pNtkCur )
Abc_NtkDelete( p->pNtkCur );
2005-07-29 17:01:00 +02:00
}
// set the new current network
2005-08-07 17:01:00 +02:00
p->pNtkCur = pNtk;
}
/**Function*************************************************************
Synopsis [Removes library binding of all currently stored networks.]
Description [This procedure is called when the library is freed.]
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_FrameUnmapAllNetworks( Abc_Frame_t * p )
{
Abc_Ntk_t * pNtk;
for ( pNtk = p->pNtkCur; pNtk; pNtk = Abc_NtkBackup(pNtk) )
2005-08-29 17:01:00 +02:00
if ( Abc_NtkHasMapping(pNtk) )
2008-01-31 05:01:00 +01:00
Abc_NtkMapToSop( pNtk );
2005-07-29 17:01:00 +02:00
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_FrameDeleteAllNetworks( Abc_Frame_t * p )
{
2005-08-07 17:01:00 +02:00
Abc_Ntk_t * pNtk, * pNtk2;
2005-07-29 17:01:00 +02:00
// delete all the currently saved networks
2005-08-07 17:01:00 +02:00
for ( pNtk = p->pNtkCur,
pNtk2 = pNtk? Abc_NtkBackup(pNtk): NULL;
pNtk;
pNtk = pNtk2,
pNtk2 = pNtk? Abc_NtkBackup(pNtk): NULL )
Abc_NtkDelete( pNtk );
2005-07-29 17:01:00 +02:00
// set the current network empty
p->pNtkCur = NULL;
2008-01-31 05:01:00 +01:00
// fprintf( p->Out, "All networks have been deleted.\n" );
2005-07-29 17:01:00 +02:00
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_FrameSetGlobalFrame( Abc_Frame_t * p )
{
2005-09-05 17:01:00 +02:00
s_GlobalFrame = p;
2005-07-29 17:01:00 +02:00
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Abc_Frame_t * Abc_FrameGetGlobalFrame()
{
2005-09-05 17:01:00 +02:00
if ( s_GlobalFrame == 0 )
2005-07-29 17:01:00 +02:00
{
// start the framework
2005-09-05 17:01:00 +02:00
s_GlobalFrame = Abc_FrameAllocate();
2005-07-29 17:01:00 +02:00
// perform initializations
2005-09-05 17:01:00 +02:00
Abc_FrameInit( s_GlobalFrame );
2005-07-29 17:01:00 +02:00
}
2005-09-05 17:01:00 +02:00
return s_GlobalFrame;
2005-07-29 17:01:00 +02:00
}
2008-09-18 17:01:00 +02:00
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Abc_Frame_t * Abc_FrameReadGlobalFrame()
{
return s_GlobalFrame;
}
2005-07-29 17:01:00 +02:00
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_FrameSetSave1( void * pAig )
{
Abc_Frame_t * pFrame = Abc_FrameGetGlobalFrame();
if ( pFrame->pSave1 )
2010-11-01 09:35:04 +01:00
Aig_ManStop( (Aig_Man_t *)pFrame->pSave1 );
pFrame->pSave1 = pAig;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_FrameSetSave2( void * pAig )
{
Abc_Frame_t * pFrame = Abc_FrameGetGlobalFrame();
if ( pFrame->pSave2 )
2010-11-01 09:35:04 +01:00
Aig_ManStop( (Aig_Man_t *)pFrame->pSave2 );
pFrame->pSave2 = pAig;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void * Abc_FrameReadSave1() { void * pAig = Abc_FrameGetGlobalFrame()->pSave1; Abc_FrameGetGlobalFrame()->pSave1 = NULL; return pAig; }
void * Abc_FrameReadSave2() { void * pAig = Abc_FrameGetGlobalFrame()->pSave2; Abc_FrameGetGlobalFrame()->pSave2 = NULL; return pAig; }
2005-07-29 17:01:00 +02:00
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
2010-11-01 09:35:04 +01:00
ABC_NAMESPACE_IMPL_END