src/base/io/ioWriteBlifMv.c File Reference

#include "io.h"
#include "main.h"
#include "mio.h"
Include dependency graph for ioWriteBlifMv.c:

Go to the source code of this file.

Functions

static void Io_NtkWriteBlifMv (FILE *pFile, Abc_Ntk_t *pNtk)
static void Io_NtkWriteBlifMvOne (FILE *pFile, Abc_Ntk_t *pNtk)
static void Io_NtkWriteBlifMvPis (FILE *pFile, Abc_Ntk_t *pNtk)
static void Io_NtkWriteBlifMvPos (FILE *pFile, Abc_Ntk_t *pNtk)
static void Io_NtkWriteBlifMvAsserts (FILE *pFile, Abc_Ntk_t *pNtk)
static void Io_NtkWriteBlifMvNodeFanins (FILE *pFile, Abc_Obj_t *pNode)
static void Io_NtkWriteBlifMvNode (FILE *pFile, Abc_Obj_t *pNode)
static void Io_NtkWriteBlifMvLatch (FILE *pFile, Abc_Obj_t *pLatch)
static void Io_NtkWriteBlifMvSubckt (FILE *pFile, Abc_Obj_t *pNode)
static void Io_NtkWriteBlifMvValues (FILE *pFile, Abc_Obj_t *pNode)
void Io_WriteBlifMv (Abc_Ntk_t *pNtk, char *FileName)

Function Documentation

void Io_NtkWriteBlifMv ( FILE *  pFile,
Abc_Ntk_t pNtk 
) [static]

CFile****************************************************************

FileName [ioWriteBlifMv.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Command processing package.]

Synopsis [Procedures to write BLIF-MV files.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id
ioWriteBlifMv.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

] DECLARATIONS ///

Function*************************************************************

Synopsis [Write the network into a BLIF file with the given name.]

Description []

SideEffects []

SeeAlso []

Definition at line 97 of file ioWriteBlifMv.c.

00098 {
00099     assert( Abc_NtkIsNetlist(pNtk) );
00100     // write the model name
00101     fprintf( pFile, ".model %s\n", Abc_NtkName(pNtk) );
00102     // write the network
00103     Io_NtkWriteBlifMvOne( pFile, pNtk );
00104     // write EXDC network if it exists
00105     if ( Abc_NtkExdc(pNtk) )
00106         printf( "Io_NtkWriteBlifMv(): EXDC is not written.\n" );
00107     // finalize the file
00108     fprintf( pFile, ".end\n\n\n" );
00109 }

void Io_NtkWriteBlifMvAsserts ( FILE *  pFile,
Abc_Ntk_t pNtk 
) [static]

Function*************************************************************

Synopsis [Writes the assertion list.]

Description []

SideEffects []

SeeAlso []

Definition at line 298 of file ioWriteBlifMv.c.

00299 {
00300     Abc_Obj_t * pTerm, * pNet;
00301     int LineLength;
00302     int AddedLength;
00303     int NameCounter;
00304     int i;
00305 
00306     LineLength  = 8;
00307     NameCounter = 0;
00308 
00309     Abc_NtkForEachAssert( pNtk, pTerm, i )
00310     {
00311         pNet = Abc_ObjFanin0(pTerm);
00312         // get the line length after this name is written
00313         AddedLength = strlen(Abc_ObjName(pNet)) + 1;
00314         if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
00315         { // write the line extender
00316             fprintf( pFile, " \\\n" );
00317             // reset the line length
00318             LineLength  = 0;
00319             NameCounter = 0;
00320         }
00321         fprintf( pFile, " %s", Abc_ObjName(pNet) );
00322         LineLength += AddedLength;
00323         NameCounter++;
00324     }
00325 }

void Io_NtkWriteBlifMvLatch ( FILE *  pFile,
Abc_Obj_t pLatch 
) [static]

Function*************************************************************

Synopsis [Write the latch into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 338 of file ioWriteBlifMv.c.

00339 {
00340     Abc_Obj_t * pNetLi, * pNetLo;
00341     int Reset;
00342     pNetLi = Abc_ObjFanin0( Abc_ObjFanin0(pLatch) );
00343     pNetLo = Abc_ObjFanout0( Abc_ObjFanout0(pLatch) );
00344     Reset  = (int)Abc_ObjData( pLatch );
00345     // write the latch line
00346     fprintf( pFile, ".latch" );
00347     fprintf( pFile, " %10s",    Abc_ObjName(pNetLi) );
00348     fprintf( pFile, " %10s",    Abc_ObjName(pNetLo) );
00349     fprintf( pFile, "\n" );
00350     // write the reset node
00351     fprintf( pFile, ".reset %s\n", Abc_ObjName(pNetLo) );
00352     fprintf( pFile, "%d\n", Reset-1 );
00353 }

void Io_NtkWriteBlifMvNode ( FILE *  pFile,
Abc_Obj_t pNode 
) [static]

Function*************************************************************

Synopsis [Write the node into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 409 of file ioWriteBlifMv.c.

00410 {
00411     Abc_Obj_t * pFanin;
00412     char * pCur;
00413     int nValues, iFanin, i;
00414 
00415     // write .mv directives for the fanins
00416     fprintf( pFile, "\n" );
00417     Abc_ObjForEachFanin( pNode, pFanin, i )
00418     {
00419 //        nValues = atoi(pCur);
00420         nValues = Abc_ObjMvVarNum( pFanin );
00421         if ( nValues > 2 )
00422             fprintf( pFile, ".mv %s %d\n", Abc_ObjName(pFanin), nValues );
00423 //        while ( *pCur++ != ' ' );
00424     }
00425 
00426     // write .mv directives for the node
00427 //    nValues = atoi(pCur);
00428     nValues = Abc_ObjMvVarNum( Abc_ObjFanout0(pNode) );
00429     if ( nValues > 2 )
00430         fprintf( pFile, ".mv %s %d\n", Abc_ObjName(Abc_ObjFanout0(pNode)), nValues );
00431 //    while ( *pCur++ != '\n' );
00432 
00433     // write the .names line
00434     fprintf( pFile, ".table" );
00435     Io_NtkWriteBlifMvNodeFanins( pFile, pNode );
00436     fprintf( pFile, "\n" );
00437 
00438     // write the cubes
00439     pCur = Abc_ObjData(pNode);
00440     if ( *pCur == 'd' )
00441     {
00442         fprintf( pFile, ".default " );
00443         pCur++;
00444     }
00445     // write the literals
00446     for ( ; *pCur; pCur++ )
00447     {
00448         fprintf( pFile, "%c", *pCur );
00449         if ( *pCur != '=' )
00450             continue;
00451         // get the number
00452         iFanin = atoi( pCur+1 );
00453         fprintf( pFile, "%s", Abc_ObjName(Abc_ObjFanin(pNode,iFanin)) );
00454         // scroll on to the next symbol
00455         while ( *pCur != ' ' && *pCur != '\n' )
00456             pCur++;
00457         pCur--;
00458     }
00459 }

void Io_NtkWriteBlifMvNodeFanins ( FILE *  pFile,
Abc_Obj_t pNode 
) [static]

Function*************************************************************

Synopsis [Writes the primary input list.]

Description []

SideEffects []

SeeAlso []

Definition at line 472 of file ioWriteBlifMv.c.

00473 {
00474     Abc_Obj_t * pNet;
00475     int LineLength;
00476     int AddedLength;
00477     int NameCounter;
00478     char * pName;
00479     int i;
00480 
00481     LineLength  = 6;
00482     NameCounter = 0;
00483     Abc_ObjForEachFanin( pNode, pNet, i )
00484     {
00485         // get the fanin name
00486         pName = Abc_ObjName(pNet);
00487         // get the line length after the fanin name is written
00488         AddedLength = strlen(pName) + 1;
00489         if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
00490         { // write the line extender
00491             fprintf( pFile, " \\\n" );
00492             // reset the line length
00493             LineLength  = 0;
00494             NameCounter = 0;
00495         }
00496         fprintf( pFile, " %s", pName );
00497         LineLength += AddedLength;
00498         NameCounter++;
00499     }
00500 
00501     // get the output name
00502     pName = Abc_ObjName(Abc_ObjFanout0(pNode));
00503     // get the line length after the output name is written
00504     AddedLength = strlen(pName) + 1;
00505     if ( NameCounter && LineLength + AddedLength > 75 )
00506     { // write the line extender
00507         fprintf( pFile, " \\\n" );
00508         // reset the line length
00509         LineLength  = 0;
00510         NameCounter = 0;
00511     }
00512     fprintf( pFile, " %s", pName );
00513 }

void Io_NtkWriteBlifMvOne ( FILE *  pFile,
Abc_Ntk_t pNtk 
) [static]

Function*************************************************************

Synopsis [Write one network.]

Description []

SideEffects []

SeeAlso []

Definition at line 122 of file ioWriteBlifMv.c.

00123 {
00124     ProgressBar * pProgress;
00125     Abc_Obj_t * pNode, * pTerm, * pLatch;
00126     int i;
00127 
00128     // write the PIs
00129     fprintf( pFile, ".inputs" );
00130     Io_NtkWriteBlifMvPis( pFile, pNtk );
00131     fprintf( pFile, "\n" );
00132 
00133     // write the POs
00134     fprintf( pFile, ".outputs" );
00135     Io_NtkWriteBlifMvPos( pFile, pNtk );
00136     fprintf( pFile, "\n" );
00137 
00138     // write the assertions
00139     if ( Abc_NtkAssertNum(pNtk) )
00140     {
00141         fprintf( pFile, ".asserts" );
00142         Io_NtkWriteBlifMvAsserts( pFile, pNtk );
00143         fprintf( pFile, "\n" );
00144     }
00145 
00146     // write the MV directives
00147     fprintf( pFile, "\n" );
00148     Abc_NtkForEachCi( pNtk, pTerm, i )
00149         if ( Abc_ObjMvVarNum(Abc_ObjFanout0(pTerm)) > 2 )
00150             fprintf( pFile, ".mv %s %d\n", Abc_ObjName(Abc_ObjFanout0(pTerm)), Abc_ObjMvVarNum(Abc_ObjFanout0(pTerm)) );
00151     Abc_NtkForEachCo( pNtk, pTerm, i )
00152         if ( Abc_ObjMvVarNum(Abc_ObjFanin0(pTerm)) > 2 )
00153             fprintf( pFile, ".mv %s %d\n", Abc_ObjName(Abc_ObjFanin0(pTerm)), Abc_ObjMvVarNum(Abc_ObjFanin0(pTerm)) );
00154 
00155     // write the blackbox
00156     if ( Abc_NtkHasBlackbox( pNtk ) )
00157     {
00158         fprintf( pFile, ".blackbox\n" );
00159         return;
00160     }
00161 
00162     // write the timing info
00163 //    Io_WriteTimingInfo( pFile, pNtk );
00164 
00165     // write the latches
00166     if ( !Abc_NtkIsComb(pNtk) )
00167     {
00168         fprintf( pFile, "\n" );
00169         Abc_NtkForEachLatch( pNtk, pLatch, i )
00170             Io_NtkWriteBlifMvLatch( pFile, pLatch );
00171         fprintf( pFile, "\n" );
00172     }
00173 /*
00174     // write the subcircuits
00175     assert( Abc_NtkWhiteboxNum(pNtk) == 0 );
00176     if ( Abc_NtkBlackboxNum(pNtk) > 0 )
00177     {
00178         fprintf( pFile, "\n" );
00179         Abc_NtkForEachBlackbox( pNtk, pNode, i )
00180             Io_NtkWriteBlifMvSubckt( pFile, pNode );
00181         fprintf( pFile, "\n" );
00182     }
00183 */
00184     if ( Abc_NtkBlackboxNum(pNtk) > 0 || Abc_NtkWhiteboxNum(pNtk) > 0 )
00185     {
00186         fprintf( pFile, "\n" );
00187         Abc_NtkForEachBox( pNtk, pNode, i )
00188         {
00189             if ( Abc_ObjIsLatch(pNode) )
00190                 continue;
00191             Io_NtkWriteBlifMvSubckt( pFile, pNode );
00192         }
00193         fprintf( pFile, "\n" );
00194     }
00195 
00196     // write each internal node
00197     pProgress = Extra_ProgressBarStart( stdout, Abc_NtkObjNumMax(pNtk) );
00198     Abc_NtkForEachNode( pNtk, pNode, i )
00199     {
00200         Extra_ProgressBarUpdate( pProgress, i, NULL );
00201         Io_NtkWriteBlifMvNode( pFile, pNode );
00202     }
00203     Extra_ProgressBarStop( pProgress );
00204 }

void Io_NtkWriteBlifMvPis ( FILE *  pFile,
Abc_Ntk_t pNtk 
) [static]

Function*************************************************************

Synopsis [Writes the primary input list.]

Description []

SideEffects []

SeeAlso []

Definition at line 218 of file ioWriteBlifMv.c.

00219 {
00220     Abc_Obj_t * pTerm, * pNet;
00221     int LineLength;
00222     int AddedLength;
00223     int NameCounter;
00224     int i;
00225 
00226     LineLength  = 7;
00227     NameCounter = 0;
00228 
00229     Abc_NtkForEachPi( pNtk, pTerm, i )
00230     {
00231         pNet = Abc_ObjFanout0(pTerm);
00232         // get the line length after this name is written
00233         AddedLength = strlen(Abc_ObjName(pNet)) + 1;
00234         if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
00235         { // write the line extender
00236             fprintf( pFile, " \\\n" );
00237             // reset the line length
00238             LineLength  = 0;
00239             NameCounter = 0;
00240         }
00241         fprintf( pFile, " %s", Abc_ObjName(pNet) );
00242         LineLength += AddedLength;
00243         NameCounter++;
00244     }
00245 }

void Io_NtkWriteBlifMvPos ( FILE *  pFile,
Abc_Ntk_t pNtk 
) [static]

Function*************************************************************

Synopsis [Writes the primary input list.]

Description []

SideEffects []

SeeAlso []

Definition at line 258 of file ioWriteBlifMv.c.

00259 {
00260     Abc_Obj_t * pTerm, * pNet;
00261     int LineLength;
00262     int AddedLength;
00263     int NameCounter;
00264     int i;
00265 
00266     LineLength  = 8;
00267     NameCounter = 0;
00268 
00269     Abc_NtkForEachPo( pNtk, pTerm, i )
00270     {
00271         pNet = Abc_ObjFanin0(pTerm);
00272         // get the line length after this name is written
00273         AddedLength = strlen(Abc_ObjName(pNet)) + 1;
00274         if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
00275         { // write the line extender
00276             fprintf( pFile, " \\\n" );
00277             // reset the line length
00278             LineLength  = 0;
00279             NameCounter = 0;
00280         }
00281         fprintf( pFile, " %s", Abc_ObjName(pNet) );
00282         LineLength += AddedLength;
00283         NameCounter++;
00284     }
00285 }

void Io_NtkWriteBlifMvSubckt ( FILE *  pFile,
Abc_Obj_t pNode 
) [static]

Function*************************************************************

Synopsis [Write the latch into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 366 of file ioWriteBlifMv.c.

00367 {
00368     Abc_Ntk_t * pModel = pNode->pData;
00369     Abc_Obj_t * pTerm;
00370     int i;
00371     // write the MV directives
00372     fprintf( pFile, "\n" );
00373     Abc_ObjForEachFanin( pNode, pTerm, i )
00374         if ( Abc_ObjMvVarNum(pTerm) > 2 )
00375             fprintf( pFile, ".mv %s %d\n", Abc_ObjName(pTerm), Abc_ObjMvVarNum(pTerm) );
00376     Abc_ObjForEachFanout( pNode, pTerm, i )
00377         if ( Abc_ObjMvVarNum(pTerm) > 2 )
00378             fprintf( pFile, ".mv %s %d\n", Abc_ObjName(pTerm), Abc_ObjMvVarNum(pTerm) );
00379     // write the subcircuit
00380     fprintf( pFile, ".subckt %s %s", Abc_NtkName(pModel), Abc_ObjName(pNode) );
00381     // write pairs of the formal=actual names
00382     Abc_NtkForEachPi( pModel, pTerm, i )
00383     {
00384         fprintf( pFile, " %s", Abc_ObjName(Abc_ObjFanout0(pTerm)) );
00385         pTerm = Abc_ObjFanin( pNode, i );
00386         fprintf( pFile, "=%s", Abc_ObjName(Abc_ObjFanin0(pTerm)) );
00387     }
00388     Abc_NtkForEachPo( pModel, pTerm, i )
00389     {
00390         fprintf( pFile, " %s", Abc_ObjName(Abc_ObjFanin0(pTerm)) );
00391         pTerm = Abc_ObjFanout( pNode, i );
00392         fprintf( pFile, "=%s", Abc_ObjName(Abc_ObjFanout0(pTerm)) );
00393     }
00394     fprintf( pFile, "\n" );
00395 }

static void Io_NtkWriteBlifMvValues ( FILE *  pFile,
Abc_Obj_t pNode 
) [static]
void Io_WriteBlifMv ( Abc_Ntk_t pNtk,
char *  FileName 
)

FUNCTION DEFINITIONS ///Function*************************************************************

Synopsis [Write the network into a BLIF file with the given name.]

Description []

SideEffects []

SeeAlso []

Definition at line 55 of file ioWriteBlifMv.c.

00056 {
00057     FILE * pFile;
00058     Abc_Ntk_t * pNtkTemp;
00059     int i;
00060     assert( Abc_NtkIsNetlist(pNtk) );
00061     assert( Abc_NtkHasBlifMv(pNtk) );
00062     // start writing the file
00063     pFile = fopen( FileName, "w" );
00064     if ( pFile == NULL )
00065     {
00066         fprintf( stdout, "Io_WriteBlifMv(): Cannot open the output file.\n" );
00067         return;
00068     }
00069     fprintf( pFile, "# Benchmark \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
00070     // write the master network
00071     Io_NtkWriteBlifMv( pFile, pNtk );
00072     // write the remaining networks
00073     if ( pNtk->pDesign )
00074     {
00075         Vec_PtrForEachEntry( pNtk->pDesign->vModules, pNtkTemp, i )
00076         {
00077             if ( pNtkTemp == pNtk )
00078                 continue;
00079             fprintf( pFile, "\n\n" );
00080             Io_NtkWriteBlifMv( pFile, pNtkTemp );
00081         }
00082     }
00083     fclose( pFile );
00084 }


Generated on Tue Jan 5 12:18:47 2010 for abc70930 by  doxygen 1.6.1