summaryrefslogtreecommitdiffstats
path: root/src/base/io/ioReadBlif.c
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2005-08-12 08:01:00 -0700
committerAlan Mishchenko <alanmi@berkeley.edu>2005-08-12 08:01:00 -0700
commit80983617b3f2843a176c8de1fee84de17a507fe9 (patch)
treeb86f3532e055c1fc6492a5a361404f7b75964c77 /src/base/io/ioReadBlif.c
parent273ba03041ee4cac93385f180d1397b49f8094ca (diff)
downloadabc-80983617b3f2843a176c8de1fee84de17a507fe9.tar.gz
abc-80983617b3f2843a176c8de1fee84de17a507fe9.tar.bz2
abc-80983617b3f2843a176c8de1fee84de17a507fe9.zip
Version abc50812
Diffstat (limited to 'src/base/io/ioReadBlif.c')
-rw-r--r--src/base/io/ioReadBlif.c217
1 files changed, 151 insertions, 66 deletions
diff --git a/src/base/io/ioReadBlif.c b/src/base/io/ioReadBlif.c
index 10346729..693f1104 100644
--- a/src/base/io/ioReadBlif.c
+++ b/src/base/io/ioReadBlif.c
@@ -19,6 +19,8 @@
***********************************************************************/
#include "io.h"
+#include "main.h"
+#include "mio.h"
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
@@ -28,19 +30,19 @@ typedef struct Io_ReadBlif_t_ Io_ReadBlif_t; // all reading info
struct Io_ReadBlif_t_
{
// general info about file
- char * pFileName; // the name of the file
- Extra_FileReader_t* pReader; // the input file reader
+ char * pFileName; // the name of the file
+ Extra_FileReader_t * pReader; // the input file reader
// current processing info
- Abc_Ntk_t * pNtk; // the primary network
- Abc_Ntk_t * pNtkExdc; // the exdc network
- int fParsingExdc; // this flag is on, when we are parsing EXDC network
- int LineCur; // the line currently parsed
+ Abc_Ntk_t * pNtk; // the primary network
+ Abc_Ntk_t * pNtkExdc; // the exdc network
+ int fParsingExdc; // this flag is on, when we are parsing EXDC network
+ int LineCur; // the line currently parsed
// temporary storage for tokens
- Vec_Ptr_t * vNewTokens; // the temporary storage for the tokens
- Vec_Str_t * vCubes; // the temporary storage for the tokens
+ Vec_Ptr_t * vNewTokens; // the temporary storage for the tokens
+ Vec_Str_t * vCubes; // the temporary storage for the tokens
// the error message
- FILE * Output; // the output stream
- char sError[1000]; // the error string generated during parsing
+ FILE * Output; // the output stream
+ char sError[1000]; // the error string generated during parsing
};
static Io_ReadBlif_t * Io_ReadBlifFile( char * pFileName );
@@ -48,11 +50,13 @@ static void Io_ReadBlifFree( Io_ReadBlif_t * p );
static void Io_ReadBlifPrintErrorMessage( Io_ReadBlif_t * p );
static Vec_Ptr_t * Io_ReadBlifGetTokens( Io_ReadBlif_t * p );
static Abc_Ntk_t * Io_ReadBlifNetwork( Io_ReadBlif_t * p );
+static char * Io_ReadBlifCleanName( char * pName );
static int Io_ReadBlifNetworkInputs( Io_ReadBlif_t * p, Vec_Ptr_t * vTokens );
static int Io_ReadBlifNetworkOutputs( Io_ReadBlif_t * p, Vec_Ptr_t * vTokens );
static int Io_ReadBlifNetworkLatch( Io_ReadBlif_t * p, Vec_Ptr_t * vTokens );
static int Io_ReadBlifNetworkNames( Io_ReadBlif_t * p, Vec_Ptr_t ** pvTokens );
+static int Io_ReadBlifNetworkGate( Io_ReadBlif_t * p, Vec_Ptr_t * vTokens );
static int Io_ReadBlifNetworkInputArrival( Io_ReadBlif_t * p, Vec_Ptr_t * vTokens );
static int Io_ReadBlifNetworkDefaultInputArrival( Io_ReadBlif_t * p, Vec_Ptr_t * vTokens );
@@ -271,7 +275,7 @@ Abc_Ntk_t * Io_ReadBlifNetwork( Io_ReadBlif_t * p )
{
ProgressBar * pProgress;
Vec_Ptr_t * vTokens;
- char * pModelName;
+ char * pModelName, * pDirective;
int iLine, fTokensReady, fStatus;
// read the model name
@@ -288,12 +292,12 @@ Abc_Ntk_t * Io_ReadBlifNetwork( Io_ReadBlif_t * p )
}
pModelName = vTokens->pArray[1];
// allocate the empty network
- p->pNtk = Abc_NtkAlloc( ABC_NTK_NETLIST );
+ p->pNtk = Abc_NtkAlloc( ABC_NTK_NETLIST_SOP );
p->pNtk->pName = util_strsav( pModelName );
p->pNtk->pSpec = util_strsav( p->pFileName );
}
else
- p->pNtk = Abc_NtkAlloc( ABC_NTK_NETLIST );
+ p->pNtk = Abc_NtkAlloc( ABC_NTK_NETLIST_SOP );
// read the inputs/outputs
pProgress = Extra_ProgressBarStart( stdout, Extra_FileReaderGetFileSize(p->pReader) );
@@ -305,32 +309,35 @@ Abc_Ntk_t * Io_ReadBlifNetwork( Io_ReadBlif_t * p )
// consider different line types
fTokensReady = 0;
- if ( !strcmp( vTokens->pArray[0], ".names" ) )
+ pDirective = vTokens->pArray[0];
+ if ( !strcmp( pDirective, ".names" ) )
{ fStatus = Io_ReadBlifNetworkNames( p, &vTokens ); fTokensReady = 1; }
- else if ( !strcmp( vTokens->pArray[0], ".latch" ) )
+ else if ( !strcmp( pDirective, ".gate" ) )
+ fStatus = Io_ReadBlifNetworkGate( p, vTokens );
+ else if ( !strcmp( pDirective, ".latch" ) )
fStatus = Io_ReadBlifNetworkLatch( p, vTokens );
- else if ( !strcmp( vTokens->pArray[0], ".inputs" ) )
+ else if ( !strcmp( pDirective, ".inputs" ) )
fStatus = Io_ReadBlifNetworkInputs( p, vTokens );
- else if ( !strcmp( vTokens->pArray[0], ".outputs" ) )
+ else if ( !strcmp( pDirective, ".outputs" ) )
fStatus = Io_ReadBlifNetworkOutputs( p, vTokens );
- else if ( !strcmp( vTokens->pArray[0], ".input_arrival" ) )
+ else if ( !strcmp( pDirective, ".input_arrival" ) )
fStatus = Io_ReadBlifNetworkInputArrival( p, vTokens );
- else if ( !strcmp( vTokens->pArray[0], ".default_input_arrival" ) )
+ else if ( !strcmp( pDirective, ".default_input_arrival" ) )
fStatus = Io_ReadBlifNetworkDefaultInputArrival( p, vTokens );
- else if ( !strcmp( vTokens->pArray[0], ".exdc" ) )
+ else if ( !strcmp( pDirective, ".exdc" ) )
{ p->fParsingExdc = 1; break; }
- else if ( !strcmp( vTokens->pArray[0], ".end" ) )
+ else if ( !strcmp( pDirective, ".end" ) )
break;
else
printf( "%s (line %d): Skipping directive \"%s\".\n", p->pFileName,
- Extra_FileReaderGetLineNumber(p->pReader, 0), vTokens->pArray[0] );
+ Extra_FileReaderGetLineNumber(p->pReader, 0), pDirective );
if ( vTokens == NULL ) // some files do not have ".end" in the end
break;
if ( fStatus == 1 )
return NULL;
}
Extra_ProgressBarStop( pProgress );
- Io_ReadSetNonDrivenNets( p->pNtk );
+ Abc_NtkFinalizeRead( p->pNtk );
return p->pNtk;
}
@@ -347,17 +354,9 @@ Abc_Ntk_t * Io_ReadBlifNetwork( Io_ReadBlif_t * p )
***********************************************************************/
int Io_ReadBlifNetworkInputs( Io_ReadBlif_t * p, Vec_Ptr_t * vTokens )
{
- Abc_Ntk_t * pNtk = p->pNtk;
- Abc_Obj_t * pNet;
int i;
for ( i = 1; i < vTokens->nSize; i++ )
- {
- pNet = Abc_NtkFindOrCreateNet( pNtk, vTokens->pArray[i] );
- if ( Abc_ObjIsPi(pNet) )
- printf( "Warning: PI net \"%s\" appears twice in the list.\n", vTokens->pArray[i] );
- else
- Abc_NtkMarkNetPi( pNet );
- }
+ Io_ReadCreatePi( p->pNtk, vTokens->pArray[i] );
return 0;
}
@@ -374,17 +373,9 @@ int Io_ReadBlifNetworkInputs( Io_ReadBlif_t * p, Vec_Ptr_t * vTokens )
***********************************************************************/
int Io_ReadBlifNetworkOutputs( Io_ReadBlif_t * p, Vec_Ptr_t * vTokens )
{
- Abc_Ntk_t * pNtk = p->pNtk;
- Abc_Obj_t * pNet;
int i;
for ( i = 1; i < vTokens->nSize; i++ )
- {
- pNet = Abc_NtkFindOrCreateNet( pNtk, vTokens->pArray[i] );
- if ( Abc_ObjIsPo(pNet) )
- printf( "Warning: PO net \"%s\" appears twice in the list.\n", vTokens->pArray[i] );
- else
- Abc_NtkMarkNetPo( pNet );
- }
+ Io_ReadCreatePo( p->pNtk, vTokens->pArray[i] );
return 0;
}
@@ -402,7 +393,7 @@ int Io_ReadBlifNetworkOutputs( Io_ReadBlif_t * p, Vec_Ptr_t * vTokens )
int Io_ReadBlifNetworkLatch( Io_ReadBlif_t * p, Vec_Ptr_t * vTokens )
{
Abc_Ntk_t * pNtk = p->pNtk;
- Abc_Obj_t * pNet, * pLatch;
+ Abc_Obj_t * pLatch;
int ResetValue;
if ( vTokens->nSize < 3 )
@@ -412,16 +403,8 @@ int Io_ReadBlifNetworkLatch( Io_ReadBlif_t * p, Vec_Ptr_t * vTokens )
Io_ReadBlifPrintErrorMessage( p );
return 1;
}
- // create a new node and add it to the network
- pLatch = Abc_NtkCreateLatch( pNtk );
- // create the LO (PI)
- pNet = Abc_NtkFindOrCreateNet( pNtk, vTokens->pArray[2] );
- Abc_ObjAddFanin( pNet, pLatch );
- Abc_ObjSetSubtype( pNet, ABC_OBJ_SUBTYPE_LO );
- // save the LI (PO)
- pNet = Abc_NtkFindOrCreateNet( pNtk, vTokens->pArray[1] );
- Abc_ObjAddFanin( pLatch, pNet );
- Abc_ObjSetSubtype( pNet, ABC_OBJ_SUBTYPE_LI );
+ // create the latch
+ pLatch = Io_ReadCreateLatch( pNtk, vTokens->pArray[1], vTokens->pArray[2] );
// get the latch reset value
if ( vTokens->nSize == 3 )
ResetValue = 2;
@@ -455,12 +438,11 @@ int Io_ReadBlifNetworkNames( Io_ReadBlif_t * p, Vec_Ptr_t ** pvTokens )
{
Vec_Ptr_t * vTokens = *pvTokens;
Abc_Ntk_t * pNtk = p->pNtk;
- Abc_Obj_t * pNet, * pNode;
- char * pToken, Char;
- int i, nFanins;
+ Abc_Obj_t * pNode;
+ char * pToken, Char, ** ppNames;
+ int nFanins, nNames;
// create a new node and add it to the network
- pNode = Abc_NtkCreateNode( pNtk );
if ( vTokens->nSize < 2 )
{
p->LineCur = Extra_FileReaderGetLineNumber(p->pReader, 0);
@@ -468,19 +450,17 @@ int Io_ReadBlifNetworkNames( Io_ReadBlif_t * p, Vec_Ptr_t ** pvTokens )
Io_ReadBlifPrintErrorMessage( p );
return 1;
}
- // go through the nets
- for ( i = 1; i < vTokens->nSize - 1; i++ )
- {
- pNet = Abc_NtkFindOrCreateNet( pNtk, vTokens->pArray[i] );
- Abc_ObjAddFanin( pNode, pNet );
- }
- pNet = Abc_NtkFindOrCreateNet( pNtk, vTokens->pArray[vTokens->nSize - 1] );
- Abc_ObjAddFanin( pNet, pNode );
+
+ // create the node
+ ppNames = (char **)vTokens->pArray + 1;
+ nNames = vTokens->nSize - 2;
+ pNode = Io_ReadCreateNode( pNtk, ppNames[nNames], ppNames, nNames );
// derive the functionality of the node
p->vCubes->nSize = 0;
nFanins = vTokens->nSize - 2;
if ( nFanins == 0 )
+ {
while ( vTokens = Io_ReadBlifGetTokens(p) )
{
pToken = vTokens->pArray[0];
@@ -500,7 +480,9 @@ int Io_ReadBlifNetworkNames( Io_ReadBlif_t * p, Vec_Ptr_t ** pvTokens )
Vec_StrPush( p->vCubes, Char );
Vec_StrPush( p->vCubes, '\n' );
}
+ }
else
+ {
while ( vTokens = Io_ReadBlifGetTokens(p) )
{
pToken = vTokens->pArray[0];
@@ -515,8 +497,7 @@ int Io_ReadBlifNetworkNames( Io_ReadBlif_t * p, Vec_Ptr_t ** pvTokens )
return 1;
}
// create the cube
- for ( i = 0; i < nFanins; i++ )
- Vec_StrPush( p->vCubes, ((char *)vTokens->pArray[0])[i] );
+ Vec_StrAppend( p->vCubes, vTokens->pArray[0] );
// check the char
Char = ((char *)vTokens->pArray[1])[0];
if ( Char != '0' && Char != '1' )
@@ -530,6 +511,7 @@ int Io_ReadBlifNetworkNames( Io_ReadBlif_t * p, Vec_Ptr_t ** pvTokens )
Vec_StrPush( p->vCubes, Char );
Vec_StrPush( p->vCubes, '\n' );
}
+ }
// if there is nothing there
if ( p->vCubes->nSize == 0 )
{
@@ -539,13 +521,116 @@ int Io_ReadBlifNetworkNames( Io_ReadBlif_t * p, Vec_Ptr_t ** pvTokens )
Vec_StrPush( p->vCubes, '\n' );
}
Vec_StrPush( p->vCubes, 0 );
+
// set the pointer to the functionality of the node
Abc_ObjSetData( pNode, Abc_SopRegister(pNtk->pManFunc, p->vCubes->pArray) );
+
// return the last array of tokens
*pvTokens = vTokens;
return 0;
}
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Io_ReadBlifNetworkGate( Io_ReadBlif_t * p, Vec_Ptr_t * vTokens )
+{
+ Mio_Library_t * pGenlib;
+ Mio_Gate_t * pGate;
+ Abc_Obj_t * pNode;
+ char ** ppNames;
+ int i, nNames;
+
+ // check that the library is available
+ pGenlib = Abc_FrameReadLibGen(Abc_FrameGetGlobalFrame());
+ if ( pGenlib == NULL )
+ {
+ p->LineCur = Extra_FileReaderGetLineNumber(p->pReader, 0);
+ sprintf( p->sError, "The current library is not available." );
+ Io_ReadBlifPrintErrorMessage( p );
+ return 1;
+ }
+
+ // create a new node and add it to the network
+ if ( vTokens->nSize < 2 )
+ {
+ p->LineCur = Extra_FileReaderGetLineNumber(p->pReader, 0);
+ sprintf( p->sError, "The .gate line has less than two tokens." );
+ Io_ReadBlifPrintErrorMessage( p );
+ return 1;
+ }
+
+ // get the gate
+ pGate = Mio_LibraryReadGateByName( pGenlib, vTokens->pArray[1] );
+ if ( pGate == NULL )
+ {
+ p->LineCur = Extra_FileReaderGetLineNumber(p->pReader, 0);
+ sprintf( p->sError, "Cannot find gate \"%s\" in the library.", vTokens->pArray[1] );
+ Io_ReadBlifPrintErrorMessage( p );
+ return 1;
+ }
+
+ // if this is the first line with gate, update the network type
+ if ( Abc_NtkNodeNum(p->pNtk) == 0 )
+ {
+ assert( p->pNtk->Type = ABC_NTK_NETLIST_SOP );
+ p->pNtk->Type = ABC_NTK_NETLIST_MAP;
+ Extra_MmFlexStop( p->pNtk->pManFunc, 0 );
+ p->pNtk->pManFunc = pGenlib;
+ }
+
+ // remove the formal parameter names
+ for ( i = 2; i < vTokens->nSize; i++ )
+ {
+ vTokens->pArray[i] = Io_ReadBlifCleanName( vTokens->pArray[i] );
+ if ( vTokens->pArray[i] == NULL )
+ {
+ p->LineCur = Extra_FileReaderGetLineNumber(p->pReader, 0);
+ sprintf( p->sError, "Invalid gate input assignment." );
+ Io_ReadBlifPrintErrorMessage( p );
+ return 1;
+ }
+ }
+
+ // create the node
+ ppNames = (char **)vTokens->pArray + 2;
+ nNames = vTokens->nSize - 3;
+ pNode = Io_ReadCreateNode( p->pNtk, ppNames[nNames], ppNames, nNames );
+
+ // set the pointer to the functionality of the node
+ Abc_ObjSetData( pNode, pGate );
+ return 0;
+}
+
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+char * Io_ReadBlifCleanName( char * pName )
+{
+ int i, Length;
+ Length = strlen(pName);
+ for ( i = 0; i < Length; i++ )
+ if ( pName[i] == '=' )
+ return pName + i + 1;
+ return NULL;
+}
/**Function*************************************************************