mirror of https://github.com/YosysHQ/abc.git
Adding command to read ROM data.
This commit is contained in:
parent
e2b7750d3b
commit
1a62954eb8
|
|
@ -287,8 +287,11 @@ int Abc_NtkFxCheck( Abc_Ntk_t * pNtk )
|
|||
// Abc_NtkForEachObj( pNtk, pNode, i )
|
||||
// Abc_ObjPrint( stdout, pNode );
|
||||
Abc_NtkForEachNode( pNtk, pNode, i )
|
||||
if ( !Vec_IntCheckUniqueSmall( &pNode->vFanins ) )
|
||||
if ( !Vec_IntCheckUniqueSmall( &pNode->vFanins ) ) {
|
||||
printf( "Fanins of node %d: ", i );
|
||||
Vec_IntPrint( &pNode->vFanins );
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ static int IoCommandReadStatus ( Abc_Frame_t * pAbc, int argc, char **argv );
|
|||
static int IoCommandReadGig ( Abc_Frame_t * pAbc, int argc, char **argv );
|
||||
static int IoCommandReadJson ( Abc_Frame_t * pAbc, int argc, char **argv );
|
||||
static int IoCommandReadSF ( Abc_Frame_t * pAbc, int argc, char **argv );
|
||||
static int IoCommandReadRom ( Abc_Frame_t * pAbc, int argc, char **argv );
|
||||
|
||||
static int IoCommandWrite ( Abc_Frame_t * pAbc, int argc, char **argv );
|
||||
static int IoCommandWriteHie ( Abc_Frame_t * pAbc, int argc, char **argv );
|
||||
|
|
@ -133,6 +134,7 @@ void Io_Init( Abc_Frame_t * pAbc )
|
|||
Cmd_CommandAdd( pAbc, "I/O", "&read_gig", IoCommandReadGig, 0 );
|
||||
Cmd_CommandAdd( pAbc, "I/O", "read_json", IoCommandReadJson, 0 );
|
||||
Cmd_CommandAdd( pAbc, "I/O", "read_sf", IoCommandReadSF, 0 );
|
||||
Cmd_CommandAdd( pAbc, "I/O", "read_rom", IoCommandReadRom, 1 );
|
||||
|
||||
Cmd_CommandAdd( pAbc, "I/O", "write", IoCommandWrite, 0 );
|
||||
Cmd_CommandAdd( pAbc, "I/O", "write_hie", IoCommandWriteHie, 0 );
|
||||
|
|
@ -1927,6 +1929,73 @@ usage:
|
|||
}
|
||||
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis []
|
||||
|
||||
Description []
|
||||
|
||||
SideEffects []
|
||||
|
||||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
int IoCommandReadRom( Abc_Frame_t * pAbc, int argc, char ** argv )
|
||||
{
|
||||
extern void Io_TransformROM2PLA( char * pNameIn, char * pNameOut );
|
||||
|
||||
Abc_Ntk_t * pNtk;
|
||||
FILE * pFile;
|
||||
char * pFileName, * pFileTemp = "_temp_rom_.pla";
|
||||
int c;
|
||||
|
||||
Extra_UtilGetoptReset();
|
||||
while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
|
||||
{
|
||||
switch ( c )
|
||||
{
|
||||
case 'h':
|
||||
goto usage;
|
||||
default:
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
if ( argc != globalUtilOptind + 1 )
|
||||
{
|
||||
goto usage;
|
||||
}
|
||||
|
||||
// get the input file name
|
||||
pFileName = argv[globalUtilOptind];
|
||||
if ( (pFile = fopen( pFileName, "r" )) == NULL )
|
||||
{
|
||||
fprintf( pAbc->Err, "Cannot open input file \"%s\". \n", pFileName );
|
||||
return 1;
|
||||
}
|
||||
fclose( pFile );
|
||||
Io_TransformROM2PLA( pFileName, pFileTemp );
|
||||
pNtk = Io_Read( pFileTemp, IO_FILE_PLA, 1, 0 );
|
||||
//unlink( pFileTemp );
|
||||
if ( pNtk == NULL )
|
||||
return 1;
|
||||
ABC_FREE( pNtk->pName );
|
||||
pNtk->pName = Extra_FileNameGeneric( pFileName );
|
||||
ABC_FREE( pNtk->pSpec );
|
||||
pNtk->pSpec = Abc_UtilStrsav( pFileName );
|
||||
// replace the current network
|
||||
Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
|
||||
Abc_FrameClearVerifStatus( pAbc );
|
||||
|
||||
return 0;
|
||||
|
||||
usage:
|
||||
fprintf( pAbc->Err, "usage: read_rom [-h] <file>\n" );
|
||||
fprintf( pAbc->Err, "\t reads ROM file\n" );
|
||||
fprintf( pAbc->Err, "\t-h : prints the command summary\n" );
|
||||
fprintf( pAbc->Err, "\tfile : the name of a file to read\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis []
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "ioAbc.h"
|
||||
#include "base/main/main.h"
|
||||
#include "misc/util/utilTruth.h"
|
||||
|
||||
ABC_NAMESPACE_IMPL_START
|
||||
|
||||
|
|
@ -890,7 +891,7 @@ void Io_TransformSF2PLA( char * pNameIn, char * pNameOut )
|
|||
if ( pFileOut == NULL )
|
||||
{
|
||||
if ( pFileIn ) fclose( pFileIn );
|
||||
printf( "Cannot open file \"%s\" for reading.\n", pNameOut );
|
||||
printf( "Cannot open file \"%s\" for writing.\n", pNameOut );
|
||||
return;
|
||||
}
|
||||
pBuffer = ABC_ALLOC( char, Size );
|
||||
|
|
@ -920,6 +921,58 @@ void Io_TransformSF2PLA( char * pNameIn, char * pNameOut )
|
|||
ABC_FREE( pBuffer );
|
||||
}
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis [Tranform SF into PLA.]
|
||||
|
||||
Description []
|
||||
|
||||
SideEffects []
|
||||
|
||||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
void Io_TransformROM2PLA( char * pNameIn, char * pNameOut )
|
||||
{
|
||||
FILE * pFileOut = fopen( pNameOut, "wb" );
|
||||
if ( pFileOut == NULL ) {
|
||||
printf( "Cannot open file \"%s\" for writing.\n", pNameOut );
|
||||
return;
|
||||
}
|
||||
int nWords = -1;
|
||||
Vec_Wrd_t * vData = Vec_WrdReadHex( pNameIn, &nWords, 0 );
|
||||
if ( vData == NULL ) {
|
||||
fclose( pFileOut );
|
||||
return;
|
||||
}
|
||||
//Vec_WrdDumpHex( "temp.txt", vData, 1, 1 );
|
||||
int v, i, nLines = Vec_WrdSize(vData) / nWords;
|
||||
int nIns = Abc_Base2Log(nLines), nOuts;
|
||||
assert( nLines * nWords == Vec_WrdSize(vData) );
|
||||
word * pTemp = ABC_CALLOC( word, nWords );
|
||||
for ( i = 0; i < nLines; i++ )
|
||||
Abc_TtOr( pTemp, pTemp, Vec_WrdEntryP(vData, nWords*i), nWords );
|
||||
for ( nOuts = nWords*64; nOuts > 0; nOuts-- )
|
||||
if ( Abc_TtGetBit(pTemp, nOuts-1) )
|
||||
break;
|
||||
ABC_FREE( pTemp );
|
||||
assert( nOuts > 0 );
|
||||
fprintf( pFileOut, ".i %d\n", nIns );
|
||||
fprintf( pFileOut, ".o %d\n", nOuts );
|
||||
fprintf( pFileOut, ".p %d\n", nLines );
|
||||
fprintf( pFileOut, ".type fr\n" );
|
||||
for ( i = 0; i < nLines; i++ ) {
|
||||
word * pData = Vec_WrdEntryP(vData, nWords*i);
|
||||
for ( v = 0; v < nIns; v++ )
|
||||
fprintf( pFileOut, "%d", (i >> v) & 1 );
|
||||
fprintf( pFileOut, " " );
|
||||
for ( v = 0; v < nOuts; v++ )
|
||||
fprintf( pFileOut, "%d", Abc_TtGetBit(pData, v) );
|
||||
fprintf( pFileOut, "\n" );
|
||||
}
|
||||
fprintf( pFileOut, ".e\n\n" );
|
||||
fclose( pFileOut );
|
||||
}
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis [Reads CNF from file.]
|
||||
|
|
|
|||
Loading…
Reference in New Issue