src/base/io/ioWriteBlif.c File Reference

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

Go to the source code of this file.

Functions

static void Io_NtkWrite (FILE *pFile, Abc_Ntk_t *pNtk, int fWriteLatches)
static void Io_NtkWriteOne (FILE *pFile, Abc_Ntk_t *pNtk, int fWriteLatches)
static void Io_NtkWritePis (FILE *pFile, Abc_Ntk_t *pNtk, int fWriteLatches)
static void Io_NtkWritePos (FILE *pFile, Abc_Ntk_t *pNtk, int fWriteLatches)
static void Io_NtkWriteSubckt (FILE *pFile, Abc_Obj_t *pNode)
static void Io_NtkWriteAsserts (FILE *pFile, Abc_Ntk_t *pNtk)
static void Io_NtkWriteNodeGate (FILE *pFile, Abc_Obj_t *pNode, int Length)
static void Io_NtkWriteNodeFanins (FILE *pFile, Abc_Obj_t *pNode)
static void Io_NtkWriteNode (FILE *pFile, Abc_Obj_t *pNode, int Length)
static void Io_NtkWriteLatch (FILE *pFile, Abc_Obj_t *pLatch)
void Io_WriteBlifLogic (Abc_Ntk_t *pNtk, char *FileName, int fWriteLatches)
void Io_WriteBlif (Abc_Ntk_t *pNtk, char *FileName, int fWriteLatches)
void Io_WriteTimingInfo (FILE *pFile, Abc_Ntk_t *pNtk)

Function Documentation

void Io_NtkWrite ( FILE *  pFile,
Abc_Ntk_t pNtk,
int  fWriteLatches 
) [static]

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

FileName [ioWriteBlif.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Command processing package.]

Synopsis [Procedures to write BLIF files.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

Id
ioWriteBlif.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 123 of file ioWriteBlif.c.

00124 {
00125     Abc_Ntk_t * pExdc;
00126     assert( Abc_NtkIsNetlist(pNtk) );
00127     // write the model name
00128     fprintf( pFile, ".model %s\n", Abc_NtkName(pNtk) );
00129     // write the network
00130     Io_NtkWriteOne( pFile, pNtk, fWriteLatches );
00131     // write EXDC network if it exists
00132     pExdc = Abc_NtkExdc( pNtk );
00133     if ( pExdc )
00134     {
00135         fprintf( pFile, "\n" );
00136         fprintf( pFile, ".exdc\n" );
00137         Io_NtkWriteOne( pFile, pExdc, fWriteLatches );
00138     }
00139     // finalize the file
00140     fprintf( pFile, ".end\n" );
00141 }

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

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

Synopsis [Writes the assertion list.]

Description []

SideEffects []

SeeAlso []

Definition at line 356 of file ioWriteBlif.c.

00357 {
00358     Abc_Obj_t * pTerm, * pNet;
00359     int LineLength;
00360     int AddedLength;
00361     int NameCounter;
00362     int i;
00363 
00364     LineLength  = 8;
00365     NameCounter = 0;
00366 
00367     Abc_NtkForEachAssert( pNtk, pTerm, i )
00368     {
00369         pNet = Abc_ObjFanin0(pTerm);
00370         // get the line length after this name is written
00371         AddedLength = strlen(Abc_ObjName(pNet)) + 1;
00372         if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
00373         { // write the line extender
00374             fprintf( pFile, " \\\n" );
00375             // reset the line length
00376             LineLength  = 0;
00377             NameCounter = 0;
00378         }
00379         fprintf( pFile, " %s", Abc_ObjName(pNet) );
00380         LineLength += AddedLength;
00381         NameCounter++;
00382     }
00383 }

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

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

Synopsis [Write the latch into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 431 of file ioWriteBlif.c.

00432 {
00433     Abc_Obj_t * pNetLi, * pNetLo;
00434     int Reset;
00435     pNetLi = Abc_ObjFanin0( Abc_ObjFanin0(pLatch) );
00436     pNetLo = Abc_ObjFanout0( Abc_ObjFanout0(pLatch) );
00437     Reset  = (int)Abc_ObjData( pLatch );
00438     // write the latch line
00439     fprintf( pFile, ".latch" );
00440     fprintf( pFile, " %10s",    Abc_ObjName(pNetLi) );
00441     fprintf( pFile, " %10s",    Abc_ObjName(pNetLo) );
00442     fprintf( pFile, "  %d\n",   Reset-1 );
00443 }

void Io_NtkWriteNode ( FILE *  pFile,
Abc_Obj_t pNode,
int  Length 
) [static]

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

Synopsis [Write the node into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 457 of file ioWriteBlif.c.

00458 {
00459     if ( Abc_NtkHasMapping(pNode->pNtk) )
00460     {
00461         // write the .gate line
00462         fprintf( pFile, ".gate" );
00463         Io_NtkWriteNodeGate( pFile, pNode, Length );
00464         fprintf( pFile, "\n" );
00465     }
00466     else
00467     {
00468         // write the .names line
00469         fprintf( pFile, ".names" );
00470         Io_NtkWriteNodeFanins( pFile, pNode );
00471         fprintf( pFile, "\n" );
00472         // write the cubes
00473         fprintf( pFile, "%s", Abc_ObjData(pNode) );
00474     }
00475 }

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

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

Synopsis [Writes the primary input list.]

Description []

SideEffects []

SeeAlso []

Definition at line 512 of file ioWriteBlif.c.

00513 {
00514     Abc_Obj_t * pNet;
00515     int LineLength;
00516     int AddedLength;
00517     int NameCounter;
00518     char * pName;
00519     int i;
00520 
00521     LineLength  = 6;
00522     NameCounter = 0;
00523     Abc_ObjForEachFanin( pNode, pNet, i )
00524     {
00525         // get the fanin name
00526         pName = Abc_ObjName(pNet);
00527         // get the line length after the fanin name is written
00528         AddedLength = strlen(pName) + 1;
00529         if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
00530         { // write the line extender
00531             fprintf( pFile, " \\\n" );
00532             // reset the line length
00533             LineLength  = 0;
00534             NameCounter = 0;
00535         }
00536         fprintf( pFile, " %s", pName );
00537         LineLength += AddedLength;
00538         NameCounter++;
00539     }
00540 
00541     // get the output name
00542     pName = Abc_ObjName(Abc_ObjFanout0(pNode));
00543     // get the line length after the output name is written
00544     AddedLength = strlen(pName) + 1;
00545     if ( NameCounter && LineLength + AddedLength > 75 )
00546     { // write the line extender
00547         fprintf( pFile, " \\\n" );
00548         // reset the line length
00549         LineLength  = 0;
00550         NameCounter = 0;
00551     }
00552     fprintf( pFile, " %s", pName );
00553 }

void Io_NtkWriteNodeGate ( FILE *  pFile,
Abc_Obj_t pNode,
int  Length 
) [static]

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

Synopsis [Writes the primary input list.]

Description []

SideEffects []

SeeAlso []

Definition at line 488 of file ioWriteBlif.c.

00489 {
00490     Mio_Gate_t * pGate = pNode->pData;
00491     Mio_Pin_t * pGatePin;
00492     int i;
00493     // write the node
00494     fprintf( pFile, " %-*s ", Length, Mio_GateReadName(pGate) );
00495     for ( pGatePin = Mio_GateReadPins(pGate), i = 0; pGatePin; pGatePin = Mio_PinReadNext(pGatePin), i++ )
00496         fprintf( pFile, "%s=%s ", Mio_PinReadName(pGatePin), Abc_ObjName( Abc_ObjFanin(pNode,i) ) );
00497     assert ( i == Abc_ObjFaninNum(pNode) );
00498     fprintf( pFile, "%s=%s", Mio_GateReadOutName(pGate), Abc_ObjName( Abc_ObjFanout0(pNode) ) );
00499 }

void Io_NtkWriteOne ( FILE *  pFile,
Abc_Ntk_t pNtk,
int  fWriteLatches 
) [static]

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

Synopsis [Write one network.]

Description []

SideEffects []

SeeAlso []

Definition at line 154 of file ioWriteBlif.c.

00155 {
00156     ProgressBar * pProgress;
00157     Abc_Obj_t * pNode, * pLatch;
00158     int i, Length;
00159 
00160     // write the PIs
00161     fprintf( pFile, ".inputs" );
00162     Io_NtkWritePis( pFile, pNtk, fWriteLatches );
00163     fprintf( pFile, "\n" );
00164 
00165     // write the POs
00166     fprintf( pFile, ".outputs" );
00167     Io_NtkWritePos( pFile, pNtk, fWriteLatches );
00168     fprintf( pFile, "\n" );
00169 
00170     // write the assertions
00171     if ( Abc_NtkAssertNum(pNtk) )
00172     {
00173         fprintf( pFile, ".asserts" );
00174         Io_NtkWriteAsserts( pFile, pNtk );
00175         fprintf( pFile, "\n" );
00176     }
00177 
00178     // write the blackbox
00179     if ( Abc_NtkHasBlackbox( pNtk ) )
00180     {
00181         fprintf( pFile, ".blackbox\n" );
00182         return;
00183     }
00184 
00185     // write the timing info
00186     Io_WriteTimingInfo( pFile, pNtk );
00187 
00188     // write the latches
00189     if ( fWriteLatches && !Abc_NtkIsComb(pNtk) )
00190     {
00191         fprintf( pFile, "\n" );
00192         Abc_NtkForEachLatch( pNtk, pLatch, i )
00193             Io_NtkWriteLatch( pFile, pLatch );
00194         fprintf( pFile, "\n" );
00195     }
00196 
00197     // write the subcircuits
00198     assert( Abc_NtkWhiteboxNum(pNtk) == 0 );
00199     if ( Abc_NtkBlackboxNum(pNtk) > 0 )
00200     {
00201         fprintf( pFile, "\n" );
00202         Abc_NtkForEachBlackbox( pNtk, pNode, i )
00203             Io_NtkWriteSubckt( pFile, pNode );
00204         fprintf( pFile, "\n" );
00205     }
00206 
00207     // write each internal node
00208     Length = Abc_NtkHasMapping(pNtk)? Mio_LibraryReadGateNameMax(pNtk->pManFunc) : 0;
00209     pProgress = Extra_ProgressBarStart( stdout, Abc_NtkObjNumMax(pNtk) );
00210     Abc_NtkForEachNode( pNtk, pNode, i )
00211     {
00212         Extra_ProgressBarUpdate( pProgress, i, NULL );
00213         Io_NtkWriteNode( pFile, pNode, Length );
00214     }
00215     Extra_ProgressBarStop( pProgress );
00216 }

void Io_NtkWritePis ( FILE *  pFile,
Abc_Ntk_t pNtk,
int  fWriteLatches 
) [static]

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

Synopsis [Writes the primary input list.]

Description []

SideEffects []

SeeAlso []

Definition at line 230 of file ioWriteBlif.c.

00231 {
00232     Abc_Obj_t * pTerm, * pNet;
00233     int LineLength;
00234     int AddedLength;
00235     int NameCounter;
00236     int i;
00237 
00238     LineLength  = 7;
00239     NameCounter = 0;
00240 
00241     if ( fWriteLatches )
00242     {
00243         Abc_NtkForEachPi( pNtk, pTerm, i )
00244         {
00245             pNet = Abc_ObjFanout0(pTerm);
00246             // get the line length after this name is written
00247             AddedLength = strlen(Abc_ObjName(pNet)) + 1;
00248             if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
00249             { // write the line extender
00250                 fprintf( pFile, " \\\n" );
00251                 // reset the line length
00252                 LineLength  = 0;
00253                 NameCounter = 0;
00254             }
00255             fprintf( pFile, " %s", Abc_ObjName(pNet) );
00256             LineLength += AddedLength;
00257             NameCounter++;
00258         }
00259     }
00260     else
00261     {
00262         Abc_NtkForEachCi( pNtk, pTerm, i )
00263         {
00264             pNet = Abc_ObjFanout0(pTerm);
00265             // get the line length after this name is written
00266             AddedLength = strlen(Abc_ObjName(pNet)) + 1;
00267             if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
00268             { // write the line extender
00269                 fprintf( pFile, " \\\n" );
00270                 // reset the line length
00271                 LineLength  = 0;
00272                 NameCounter = 0;
00273             }
00274             fprintf( pFile, " %s", Abc_ObjName(pNet) );
00275             LineLength += AddedLength;
00276             NameCounter++;
00277         }
00278     }
00279 }

void Io_NtkWritePos ( FILE *  pFile,
Abc_Ntk_t pNtk,
int  fWriteLatches 
) [static]

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

Synopsis [Writes the primary input list.]

Description []

SideEffects []

SeeAlso []

Definition at line 292 of file ioWriteBlif.c.

00293 {
00294     Abc_Obj_t * pTerm, * pNet;
00295     int LineLength;
00296     int AddedLength;
00297     int NameCounter;
00298     int i;
00299 
00300     LineLength  = 8;
00301     NameCounter = 0;
00302 
00303     if ( fWriteLatches )
00304     {
00305         Abc_NtkForEachPo( pNtk, pTerm, i )
00306         {
00307             pNet = Abc_ObjFanin0(pTerm);
00308             // get the line length after this name is written
00309             AddedLength = strlen(Abc_ObjName(pNet)) + 1;
00310             if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
00311             { // write the line extender
00312                 fprintf( pFile, " \\\n" );
00313                 // reset the line length
00314                 LineLength  = 0;
00315                 NameCounter = 0;
00316             }
00317             fprintf( pFile, " %s", Abc_ObjName(pNet) );
00318             LineLength += AddedLength;
00319             NameCounter++;
00320         }
00321     }
00322     else
00323     {
00324         Abc_NtkForEachCo( pNtk, pTerm, i )
00325         {
00326             if ( Abc_ObjIsAssert(pTerm) )
00327                 continue;
00328             pNet = Abc_ObjFanin0(pTerm);
00329             // get the line length after this name is written
00330             AddedLength = strlen(Abc_ObjName(pNet)) + 1;
00331             if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
00332             { // write the line extender
00333                 fprintf( pFile, " \\\n" );
00334                 // reset the line length
00335                 LineLength  = 0;
00336                 NameCounter = 0;
00337             }
00338             fprintf( pFile, " %s", Abc_ObjName(pNet) );
00339             LineLength += AddedLength;
00340             NameCounter++;
00341         }
00342     }
00343 }

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

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

Synopsis [Write the latch into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 396 of file ioWriteBlif.c.

00397 {
00398     Abc_Ntk_t * pModel = pNode->pData;
00399     Abc_Obj_t * pTerm;
00400     int i;
00401     // write the subcircuit
00402 //    fprintf( pFile, ".subckt %s %s", Abc_NtkName(pModel), Abc_ObjName(pNode) );
00403     fprintf( pFile, ".subckt %s", Abc_NtkName(pModel) );
00404     // write pairs of the formal=actual names
00405     Abc_NtkForEachPi( pModel, pTerm, i )
00406     {
00407         fprintf( pFile, " %s", Abc_ObjName(Abc_ObjFanout0(pTerm)) );
00408         pTerm = Abc_ObjFanin( pNode, i );
00409         fprintf( pFile, "=%s", Abc_ObjName(Abc_ObjFanin0(pTerm)) );
00410     }
00411     Abc_NtkForEachPo( pModel, pTerm, i )
00412     {
00413         fprintf( pFile, " %s", Abc_ObjName(Abc_ObjFanin0(pTerm)) );
00414         pTerm = Abc_ObjFanout( pNode, i );
00415         fprintf( pFile, "=%s", Abc_ObjName(Abc_ObjFanout0(pTerm)) );
00416     }
00417     fprintf( pFile, "\n" );
00418 }

void Io_WriteBlif ( Abc_Ntk_t pNtk,
char *  FileName,
int  fWriteLatches 
)

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

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

Description []

SideEffects []

SeeAlso []

Definition at line 80 of file ioWriteBlif.c.

00081 {
00082     FILE * pFile;
00083     Abc_Ntk_t * pNtkTemp;
00084     int i;
00085     assert( Abc_NtkIsNetlist(pNtk) );
00086     // start writing the file
00087     pFile = fopen( FileName, "w" );
00088     if ( pFile == NULL )
00089     {
00090         fprintf( stdout, "Io_WriteBlif(): Cannot open the output file.\n" );
00091         return;
00092     }
00093     fprintf( pFile, "# Benchmark \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
00094     // write the master network
00095     Io_NtkWrite( pFile, pNtk, fWriteLatches );
00096     // make sure there is no logic hierarchy
00097     assert( Abc_NtkWhiteboxNum(pNtk) == 0 );
00098     // write the hierarchy if present
00099     if ( Abc_NtkBlackboxNum(pNtk) > 0 )
00100     {
00101         Vec_PtrForEachEntry( pNtk->pDesign->vModules, pNtkTemp, i )
00102         {
00103             if ( pNtkTemp == pNtk )
00104                 continue;
00105             fprintf( pFile, "\n\n" );
00106             Io_NtkWrite( pFile, pNtkTemp, fWriteLatches );
00107         }
00108     }
00109     fclose( pFile );
00110 }

void Io_WriteBlifLogic ( Abc_Ntk_t pNtk,
char *  FileName,
int  fWriteLatches 
)

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

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

Description []

SideEffects []

SeeAlso []

Definition at line 55 of file ioWriteBlif.c.

00056 {
00057     Abc_Ntk_t * pNtkTemp;
00058     // derive the netlist
00059     pNtkTemp = Abc_NtkToNetlist(pNtk);
00060     if ( pNtkTemp == NULL )
00061     {
00062         fprintf( stdout, "Writing BLIF has failed.\n" );
00063         return;
00064     }
00065     Io_WriteBlif( pNtkTemp, FileName, fWriteLatches );
00066     Abc_NtkDelete( pNtkTemp );
00067 }

void Io_WriteTimingInfo ( FILE *  pFile,
Abc_Ntk_t pNtk 
)

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

Synopsis [Writes the timing info.]

Description []

SideEffects []

SeeAlso []

Definition at line 566 of file ioWriteBlif.c.

00567 {
00568     Abc_Obj_t * pNode;
00569     Abc_Time_t * pTime, * pTimeDef;
00570     int i;
00571 
00572     if ( pNtk->pManTime == NULL )
00573         return;
00574 
00575     pTimeDef = Abc_NtkReadDefaultArrival( pNtk );
00576     fprintf( pFile, ".default_input_arrival %g %g\n", pTimeDef->Rise, pTimeDef->Fall );
00577     Abc_NtkForEachPi( pNtk, pNode, i )
00578     {
00579         pTime = Abc_NodeReadArrival(pNode);
00580         if ( pTime->Rise == pTimeDef->Rise && pTime->Fall == pTimeDef->Fall )
00581             continue;
00582         fprintf( pFile, ".input_arrival %s %g %g\n", Abc_ObjName(pNode), pTime->Rise, pTime->Fall );
00583     }
00584 }


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