2005-07-29 17:01:00 +02:00
|
|
|
/**CFile****************************************************************
|
|
|
|
|
|
|
|
|
|
FileName [cmdApi.c]
|
|
|
|
|
|
|
|
|
|
SystemName [ABC: Logic synthesis and verification system.]
|
|
|
|
|
|
|
|
|
|
PackageName [Command processing package.]
|
|
|
|
|
|
|
|
|
|
Synopsis [External procedures of the command package.]
|
|
|
|
|
|
|
|
|
|
Author [Alan Mishchenko]
|
|
|
|
|
|
|
|
|
|
Affiliation [UC Berkeley]
|
|
|
|
|
|
|
|
|
|
Date [Ver. 1.0. Started - June 20, 2005.]
|
|
|
|
|
|
|
|
|
|
Revision [$Id: cmdApi.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
2012-07-08 05:14:12 +02:00
|
|
|
#include "base/abc/abc.h"
|
|
|
|
|
#include "base/main/mainInt.h"
|
2005-07-29 17:01:00 +02:00
|
|
|
#include "cmdInt.h"
|
2010-11-01 09:35:04 +01:00
|
|
|
|
|
|
|
|
ABC_NAMESPACE_IMPL_START
|
|
|
|
|
|
2005-07-29 17:01:00 +02:00
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// DECLARATIONS ///
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2008-01-31 05:01:00 +01:00
|
|
|
/// FUNCTION DEFINITIONS ///
|
2005-07-29 17:01:00 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2014-11-18 22:54:16 +01:00
|
|
|
int Cmd_CommandIsDefined( Abc_Frame_t * pAbc, const char * sName )
|
|
|
|
|
{
|
|
|
|
|
return st__is_member( pAbc->tCommands, sName );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2010-11-01 09:35:04 +01:00
|
|
|
void Cmd_CommandAdd( Abc_Frame_t * pAbc, const char * sGroup, const char * sName, Cmd_CommandFuncType pFunc, int fChanges )
|
2005-07-29 17:01:00 +02:00
|
|
|
{
|
2010-11-01 09:35:04 +01:00
|
|
|
const char * key;
|
|
|
|
|
char * value;
|
2005-07-29 17:01:00 +02:00
|
|
|
Abc_Command * pCommand;
|
|
|
|
|
int fStatus;
|
|
|
|
|
|
|
|
|
|
key = sName;
|
2012-09-29 23:11:03 +02:00
|
|
|
if ( st__delete( pAbc->tCommands, &key, &value ) )
|
2005-07-29 17:01:00 +02:00
|
|
|
{
|
|
|
|
|
// delete existing definition for this command
|
|
|
|
|
fprintf( pAbc->Err, "Cmd warning: redefining '%s'\n", sName );
|
|
|
|
|
CmdCommandFree( (Abc_Command *)value );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// create the new command
|
2009-02-15 17:01:00 +01:00
|
|
|
pCommand = ABC_ALLOC( Abc_Command, 1 );
|
2008-01-31 05:01:00 +01:00
|
|
|
pCommand->sName = Extra_UtilStrsav( sName );
|
|
|
|
|
pCommand->sGroup = Extra_UtilStrsav( sGroup );
|
2005-07-29 17:01:00 +02:00
|
|
|
pCommand->pFunc = pFunc;
|
|
|
|
|
pCommand->fChange = fChanges;
|
2012-09-29 23:11:03 +02:00
|
|
|
fStatus = st__insert( pAbc->tCommands, pCommand->sName, (char *)pCommand );
|
2005-07-29 17:01:00 +02:00
|
|
|
assert( !fStatus ); // the command should not be in the table
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 21:07:55 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
int Cmd_CommandHandleSpecial( Abc_Frame_t * pAbc, const char * sCommand )
|
|
|
|
|
{
|
|
|
|
|
Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
|
2019-10-26 15:29:05 +02:00
|
|
|
int piCountNew = (pNtk && Abc_NtkHasMapping(pNtk)) ? Abc_NtkCiNum(pNtk) : 0, piCount = 0;
|
|
|
|
|
int poCountNew = (pNtk && Abc_NtkHasMapping(pNtk)) ? Abc_NtkCoNum(pNtk) : 0, poCount = 0;
|
|
|
|
|
int ndCountNew = (pNtk && Abc_NtkHasMapping(pNtk)) ? Abc_NtkNodeNum(pNtk) : 0, ndCount = 0;
|
|
|
|
|
double AreaNew = (pNtk && Abc_NtkHasMapping(pNtk)) ? Abc_NtkGetMappedArea(pNtk) : 0, Area = 0;
|
|
|
|
|
int DepthNew = (pNtk && Abc_NtkHasMapping(pNtk)) ? Abc_NtkLevel(pNtk) : 0, Depth = 0;
|
2019-03-20 21:07:55 +01:00
|
|
|
if ( strstr(sCommand, "#PS") )
|
|
|
|
|
{
|
|
|
|
|
printf( "pi=%d ", piCountNew );
|
|
|
|
|
printf( "po=%d ", poCountNew );
|
|
|
|
|
printf( "fn=%d ", ndCountNew );
|
|
|
|
|
printf( "ma=%.1f ", AreaNew );
|
|
|
|
|
printf( "de=%d ", DepthNew );
|
|
|
|
|
printf( "\n" );
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if ( strstr(sCommand, "#CEC") )
|
|
|
|
|
{
|
|
|
|
|
//int proofStatus = Abc_NtkVerifyUsingCec(pNtk);
|
|
|
|
|
int proofStatus = 1;
|
|
|
|
|
// -1 (undecided), 0 (different), 1 (equivalent)
|
|
|
|
|
printf( "proofStatus=%d\n", proofStatus );
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if ( strstr(sCommand, "#ASSERT") )
|
|
|
|
|
{
|
|
|
|
|
int Status = 0;
|
2020-04-17 19:14:44 +02:00
|
|
|
char * pNumb = strrchr( (char *)sCommand, '=' );
|
2019-03-20 21:07:55 +01:00
|
|
|
if ( strstr(sCommand, "_PI_") )
|
|
|
|
|
{
|
|
|
|
|
piCount = pNumb ? atoi(pNumb+1) : 0;
|
|
|
|
|
if ( strstr( sCommand, "==" ) )
|
|
|
|
|
Status = piCountNew == piCount;
|
|
|
|
|
else if ( strstr( sCommand, "<=" ) )
|
|
|
|
|
Status = piCountNew <= piCount;
|
|
|
|
|
else return 0;
|
|
|
|
|
}
|
|
|
|
|
else if ( strstr(sCommand, "_PO_") )
|
|
|
|
|
{
|
|
|
|
|
poCount = pNumb ? atoi(pNumb+1) : 0;
|
|
|
|
|
if ( strstr( sCommand, "==" ) )
|
|
|
|
|
Status = poCountNew == poCount;
|
|
|
|
|
else if ( strstr( sCommand, "<=" ) )
|
|
|
|
|
Status = poCountNew <= poCount;
|
|
|
|
|
else return 0;
|
|
|
|
|
}
|
|
|
|
|
else if ( strstr(sCommand, "_NODE_") )
|
|
|
|
|
{
|
|
|
|
|
ndCount = pNumb ? atoi(pNumb+1) : 0;
|
|
|
|
|
if ( strstr( sCommand, "==" ) )
|
|
|
|
|
Status = ndCountNew == ndCount;
|
|
|
|
|
else if ( strstr( sCommand, "<=" ) )
|
|
|
|
|
Status = ndCountNew <= ndCount;
|
|
|
|
|
else return 0;
|
|
|
|
|
}
|
|
|
|
|
else if ( strstr(sCommand, "_AREA_") )
|
|
|
|
|
{
|
|
|
|
|
double Eplison = 1.0;
|
|
|
|
|
Area = pNumb ? atof(pNumb+1) : 0;
|
|
|
|
|
if ( strstr( sCommand, "==" ) )
|
|
|
|
|
Status = AreaNew >= Area - Eplison && AreaNew <= Area + Eplison;
|
|
|
|
|
else if ( strstr( sCommand, "<=" ) )
|
|
|
|
|
Status = AreaNew <= Area + Eplison;
|
|
|
|
|
else return 0;
|
|
|
|
|
}
|
|
|
|
|
else if ( strstr(sCommand, "_DEPTH_") )
|
|
|
|
|
{
|
|
|
|
|
Depth = pNumb ? atoi(pNumb+1) : 0;
|
|
|
|
|
if ( strstr( sCommand, "==" ) )
|
|
|
|
|
Status = DepthNew == Depth;
|
|
|
|
|
else if ( strstr( sCommand, "<=" ) )
|
|
|
|
|
Status = DepthNew <= Depth;
|
|
|
|
|
else return 0;
|
|
|
|
|
}
|
|
|
|
|
else return 0;
|
|
|
|
|
printf( "%s\n", Status ? "succeeded" : "failed" );
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-29 17:01:00 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2010-11-01 09:35:04 +01:00
|
|
|
int Cmd_CommandExecute( Abc_Frame_t * pAbc, const char * sCommand )
|
2005-07-29 17:01:00 +02:00
|
|
|
{
|
|
|
|
|
int fStatus = 0, argc, loop;
|
2010-11-01 09:35:04 +01:00
|
|
|
const char * sCommandNext;
|
|
|
|
|
char **argv;
|
2005-07-29 17:01:00 +02:00
|
|
|
|
2012-08-25 00:44:33 +02:00
|
|
|
if ( !pAbc->fAutoexac && !pAbc->fSource )
|
2005-07-29 17:01:00 +02:00
|
|
|
Cmd_HistoryAddCommand(pAbc, sCommand);
|
|
|
|
|
sCommandNext = sCommand;
|
|
|
|
|
do
|
|
|
|
|
{
|
2019-03-20 21:07:55 +01:00
|
|
|
if ( sCommandNext[0] == '#' && Cmd_CommandHandleSpecial( pAbc, sCommandNext ) )
|
|
|
|
|
break;
|
|
|
|
|
sCommandNext = CmdSplitLine( pAbc, sCommandNext, &argc, &argv );
|
2005-07-29 17:01:00 +02:00
|
|
|
loop = 0;
|
|
|
|
|
fStatus = CmdApplyAlias( pAbc, &argc, &argv, &loop );
|
|
|
|
|
if ( fStatus == 0 )
|
2008-07-05 17:01:00 +02:00
|
|
|
fStatus = CmdCommandDispatch( pAbc, &argc, &argv );
|
2019-03-20 21:07:55 +01:00
|
|
|
CmdFreeArgv( argc, argv );
|
2005-07-29 17:01:00 +02:00
|
|
|
}
|
|
|
|
|
while ( fStatus == 0 && *sCommandNext != '\0' );
|
|
|
|
|
return fStatus;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// END OF FILE ///
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
2010-11-01 09:35:04 +01:00
|
|
|
ABC_NAMESPACE_IMPL_END
|
|
|
|
|
|