Commit 0f29ba75 by Alan Mishchenko

Adding commands to read/write/print gate profiles.

parent 56880eab
......@@ -38,6 +38,9 @@ static int Mio_CommandReadLiberty( Abc_Frame_t * pAbc, int argc, char **argv );
static int Mio_CommandReadGenlib( Abc_Frame_t * pAbc, int argc, char **argv );
static int Mio_CommandWriteGenlib( Abc_Frame_t * pAbc, int argc, char **argv );
static int Mio_CommandPrintGenlib( Abc_Frame_t * pAbc, int argc, char **argv );
static int Mio_CommandReadProfile( Abc_Frame_t * pAbc, int argc, char **argv );
static int Mio_CommandWriteProfile( Abc_Frame_t * pAbc, int argc, char **argv );
static int Mio_CommandPrintProfile( Abc_Frame_t * pAbc, int argc, char **argv );
/*
// internal version of genlib library
......@@ -88,6 +91,10 @@ void Mio_Init( Abc_Frame_t * pAbc )
Cmd_CommandAdd( pAbc, "SC mapping", "write_genlib", Mio_CommandWriteGenlib, 0 );
Cmd_CommandAdd( pAbc, "SC mapping", "print_genlib", Mio_CommandPrintGenlib, 0 );
Cmd_CommandAdd( pAbc, "SC mapping", "read_profile", Mio_CommandReadProfile, 0 );
Cmd_CommandAdd( pAbc, "SC mapping", "write_profile", Mio_CommandWriteProfile, 0 );
Cmd_CommandAdd( pAbc, "SC mapping", "print_profile", Mio_CommandPrintProfile, 0 );
Cmd_CommandAdd( pAbc, "SC mapping", "read_library", Mio_CommandReadGenlib, 0 );
Cmd_CommandAdd( pAbc, "SC mapping", "write_library", Mio_CommandWriteGenlib, 0 );
Cmd_CommandAdd( pAbc, "SC mapping", "print_library", Mio_CommandPrintGenlib, 0 );
......@@ -185,12 +192,10 @@ int Mio_CommandReadLiberty( Abc_Frame_t * pAbc, int argc, char **argv )
char Command[1000];
FILE * pFile;
FILE * pOut, * pErr;
Abc_Ntk_t * pNet;
char * pFileName;
int fVerbose;
int c;
pNet = Abc_FrameReadNtk(pAbc);
pOut = Abc_FrameReadOut(pAbc);
pErr = Abc_FrameReadErr(pAbc);
......@@ -279,14 +284,12 @@ int Mio_CommandReadGenlib( Abc_Frame_t * pAbc, int argc, char **argv )
FILE * pOut, * pErr;
Mio_Library_t * pLib;
Amap_Lib_t * pLib2;
Abc_Ntk_t * pNet;
char * pFileName;
char * pExcludeFile = NULL;
int fVerbose;
double WireDelay;
int c;
pNet = Abc_FrameReadNtk(pAbc);
pOut = Abc_FrameReadOut(pAbc);
pErr = Abc_FrameReadErr(pAbc);
......@@ -399,13 +402,11 @@ usage:
int Mio_CommandWriteGenlib( Abc_Frame_t * pAbc, int argc, char **argv )
{
FILE * pOut, * pErr, * pFile;
Abc_Ntk_t * pNet;
char * pFileName;
int fSelected = 0;
int fVerbose = 0;
int c;
pNet = Abc_FrameReadNtk(pAbc);
pOut = Abc_FrameReadOut(pAbc);
pErr = Abc_FrameReadErr(pAbc);
......@@ -474,13 +475,11 @@ usage:
int Mio_CommandPrintGenlib( Abc_Frame_t * pAbc, int argc, char **argv )
{
FILE * pOut, * pErr;
Abc_Ntk_t * pNet;
int fShort = 0;
int fSelected = 0;
int fVerbose = 0;
int c;
pNet = Abc_FrameReadNtk(pAbc);
pOut = Abc_FrameReadOut(pAbc);
pErr = Abc_FrameReadErr(pAbc);
......@@ -524,6 +523,198 @@ usage:
return 1;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Mio_CommandReadProfile( Abc_Frame_t * pAbc, int argc, char **argv )
{
FILE * pFile, * pOut, * pErr;
Mio_Library_t * pLib;
char * pFileName;
int c;
pOut = Abc_FrameReadOut(pAbc);
pErr = Abc_FrameReadErr(pAbc);
// set the defaults
Extra_UtilGetoptReset();
while ( (c = Extra_UtilGetopt(argc, argv, "h")) != EOF )
{
switch (c)
{
case 'h':
goto usage;
break;
default:
goto usage;
}
}
if ( argc != globalUtilOptind + 1 )
{
goto usage;
}
pLib = (Mio_Library_t *)Abc_FrameReadLibGen();
if ( pLib == NULL )
{
fprintf( pErr, "There is no Genlib library entered.\n" );
return 1;
}
// get the input file name
pFileName = argv[globalUtilOptind];
if ( (pFile = Io_FileOpen( pFileName, "open_path", "r", 0 )) == NULL )
{
fprintf( pErr, "Cannot open input file \"%s\". ", pFileName );
if ( (pFileName = Extra_FileGetSimilarName( pFileName, ".profile", NULL, NULL, NULL, NULL )) )
fprintf( pErr, "Did you mean \"%s\"?", pFileName );
fprintf( pErr, "\n" );
return 1;
}
// set the new network
Mio_LibraryReadProfile( pFile, pLib );
fclose( pFile );
return 0;
usage:
fprintf( pErr, "usage: read_profile [-h] <file>\n");
fprintf( pErr, "\t read a gate profile from a profile file\n" );
fprintf( pErr, "\t-h : enable verbose output\n");
fprintf( pErr, "\t<file> : file name to read the profile\n");
return 1;
}
/**Function*************************************************************
Synopsis [Command procedure to read LUT libraries.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Mio_CommandWriteProfile( Abc_Frame_t * pAbc, int argc, char **argv )
{
FILE * pOut, * pErr, * pFile;
char * pFileName;
int c;
pOut = Abc_FrameReadOut(pAbc);
pErr = Abc_FrameReadErr(pAbc);
Extra_UtilGetoptReset();
while ( (c = Extra_UtilGetopt(argc, argv, "h")) != EOF )
{
switch (c)
{
case 'h':
goto usage;
break;
default:
goto usage;
}
}
if ( Abc_FrameReadLibGen() == NULL )
{
printf( "Library is not available.\n" );
return 1;
}
if ( argc != globalUtilOptind + 1 )
{
printf( "The file name is not given.\n" );
return 1;
}
pFileName = argv[globalUtilOptind];
pFile = fopen( pFileName, "w" );
if ( pFile == NULL )
{
printf( "Error! Cannot open file \"%s\" for writing the library.\n", pFileName );
return 1;
}
Mio_LibraryWriteProfile( pFile, (Mio_Library_t *)Abc_FrameReadLibGen() );
fclose( pFile );
printf( "The current profile is written into file \"%s\".\n", pFileName );
return 0;
usage:
fprintf( pErr, "\nusage: write_profile [-h] <file>\n");
fprintf( pErr, "\t writes the current profile into a file\n" );
fprintf( pErr, "\t-h : print the command usage\n");
fprintf( pErr, "\t<file> : file name to write the profile\n");
return 1;
}
/**Function*************************************************************
Synopsis [Command procedure to read LUT libraries.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Mio_CommandPrintProfile( Abc_Frame_t * pAbc, int argc, char **argv )
{
FILE * pOut, * pErr;
int fShort = 0;
int fSelected = 0;
int fVerbose = 0;
int c;
pOut = Abc_FrameReadOut(pAbc);
pErr = Abc_FrameReadErr(pAbc);
// set the defaults
Extra_UtilGetoptReset();
while ( (c = Extra_UtilGetopt(argc, argv, "savh")) != EOF )
{
switch (c)
{
case 's':
fShort ^= 1;
break;
case 'a':
fSelected ^= 1;
break;
case 'v':
fVerbose ^= 1;
break;
case 'h':
goto usage;
break;
default:
goto usage;
}
}
if ( Abc_FrameReadLibGen() == NULL )
{
printf( "Library is not available.\n" );
return 1;
}
Mio_LibraryWriteProfile( stdout, (Mio_Library_t *)Abc_FrameReadLibGen() );
return 0;
usage:
fprintf( pErr, "\nusage: print_profile [-h]\n");
fprintf( pErr, "\t print the current gate profile\n" );
fprintf( pErr, "\t-h : print the command usage\n");
return 1;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
......
......@@ -152,10 +152,12 @@ extern Vec_Int_t * Mio_GateReadExpr ( Mio_Gate_t * pGate );
extern word Mio_GateReadTruth ( Mio_Gate_t * pGate );
extern int Mio_GateReadValue ( Mio_Gate_t * pGate );
extern int Mio_GateReadCell ( Mio_Gate_t * pGate );
extern int Mio_GateReadProfile ( Mio_Gate_t * pGate );
extern char * Mio_GateReadPinName ( Mio_Gate_t * pGate, int iPin );
extern float Mio_GateReadPinDelay ( Mio_Gate_t * pGate, int iPin );
extern void Mio_GateSetValue ( Mio_Gate_t * pGate, int Value );
extern void Mio_GateSetCell ( Mio_Gate_t * pGate, int Cell );
extern void Mio_GateSetProfile ( Mio_Gate_t * pGate, int Prof );
extern int Mio_GateIsInv ( Mio_Gate_t * pGate );
extern char * Mio_PinReadName ( Mio_Pin_t * pPin );
extern Mio_PinPhase_t Mio_PinReadPhase ( Mio_Pin_t * pPin );
......@@ -200,12 +202,15 @@ extern void Mio_LibraryMultiArea( Mio_Library_t * pLib, double Mult
extern void Mio_LibraryMultiDelay( Mio_Library_t * pLib, double Multi );
extern void Mio_LibraryTransferDelays( Mio_Library_t * pLibD, Mio_Library_t * pLibS );
extern void Mio_LibraryTransferCellIds();
extern void Mio_LibraryReadProfile( FILE * pFile, Mio_Library_t * pLib );
extern void Mio_LibraryWriteProfile( FILE * pFile, Mio_Library_t * pLib );
/*=== sclUtil.c =========================================================*/
extern Mio_Library_t * Abc_SclDeriveGenlibSimple( void * pScl );
extern Mio_Library_t * Abc_SclDeriveGenlib( void * pScl, float Slew, float Gain, int nGatesMin, int fVerbose );
extern int Abc_SclHasDelayInfo( void * pScl );
ABC_NAMESPACE_HEADER_END
#endif
......
......@@ -179,8 +179,10 @@ word Mio_GateReadTruth ( Mio_Gate_t * pGate ) { return
word * Mio_GateReadTruthP ( Mio_Gate_t * pGate ) { return pGate->nInputs <= 6 ? NULL: pGate->pTruth; }
int Mio_GateReadValue ( Mio_Gate_t * pGate ) { return pGate->Value; }
int Mio_GateReadCell ( Mio_Gate_t * pGate ) { return pGate->Cell; }
int Mio_GateReadProfile ( Mio_Gate_t * pGate ) { return pGate->Profile; }
void Mio_GateSetValue ( Mio_Gate_t * pGate, int Value ) { pGate->Value = Value; }
void Mio_GateSetCell ( Mio_Gate_t * pGate, int Cell ) { pGate->Cell = Cell; }
void Mio_GateSetProfile ( Mio_Gate_t * pGate, int Prof ) { pGate->Profile = Prof; }
int Mio_GateIsInv ( Mio_Gate_t * pGate ) { return pGate->uTruth == ABC_CONST(0x5555555555555555); }
/**Function*************************************************************
......
......@@ -95,6 +95,7 @@ struct Mio_GateStruct_t_
// the derived information
int Cell; // cell id
int nInputs; // the number of inputs
int Profile; // the number of occurrences
double dDelayMax; // the maximum delay
char * pSop; // sum-of-products
Vec_Int_t * vExpr; // boolean expression
......
......@@ -1345,6 +1345,49 @@ void Mio_LibraryTransferCellIds()
}
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Mio_LibraryReadProfile( FILE * pFile, Mio_Library_t * pLib )
{
Mio_Gate_t * pGate;
char pBuffer[1000];
while ( fgets( pBuffer, 1000, pFile ) != NULL )
{
char * pToken = strtok( pBuffer, " \t\n" );
if ( pToken == NULL )
continue;
if ( pToken[0] == '#' )
continue;
// read gate
pGate = Mio_LibraryReadGateByName( pLib, pToken, NULL );
if ( pGate == NULL )
{
printf( "Cannot find gate \"%s\" in library \"%s\".\n", Mio_GateReadName(pGate), Mio_LibraryReadName(pLib) );
continue;
}
// read profile
pToken = strtok( NULL, " \t\n" );
Mio_GateSetProfile( pGate, atoi(pToken) );
}
}
void Mio_LibraryWriteProfile( FILE * pFile, Mio_Library_t * pLib )
{
Mio_Gate_t * pGate;
Mio_LibraryForEachGate( pLib, pGate )
if ( Mio_GateReadProfile(pGate) > 0 )
fprintf( pFile, "%-24s %6d\n", Mio_GateReadName(pGate), Mio_GateReadProfile(pGate) );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment