#include "io.h"
Go to the source code of this file.
Functions | |
static unsigned | Io_ObjMakeLit (int Var, int fCompl) |
static unsigned | Io_ObjAigerNum (Abc_Obj_t *pObj) |
static void | Io_ObjSetAigerNum (Abc_Obj_t *pObj, unsigned Num) |
int | Io_WriteAigerEncode (char *pBuffer, int Pos, unsigned x) |
void | Io_WriteAiger (Abc_Ntk_t *pNtk, char *pFileName, int fWriteSymbols) |
static unsigned Io_ObjAigerNum | ( | Abc_Obj_t * | pObj | ) | [static] |
Definition at line 129 of file ioWriteAiger.c.
00129 { return (unsigned)pObj->pCopy; }
static unsigned Io_ObjMakeLit | ( | int | Var, | |
int | fCompl | |||
) | [static] |
CFile****************************************************************
FileName [ioWriteAiger.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Command processing package.]
Synopsis [Procedures to write binary AIGER format developed by Armin Biere, Johannes Kepler University (http://fmv.jku.at/)]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - December 16, 2006.]
Revision [
] DECLARATIONS ///
Definition at line 128 of file ioWriteAiger.c.
static void Io_ObjSetAigerNum | ( | Abc_Obj_t * | pObj, | |
unsigned | Num | |||
) | [static] |
Definition at line 130 of file ioWriteAiger.c.
00130 { pObj->pCopy = (void *)Num; }
void Io_WriteAiger | ( | Abc_Ntk_t * | pNtk, | |
char * | pFileName, | |||
int | fWriteSymbols | |||
) |
FUNCTION DEFINITIONS ///Function*************************************************************
Synopsis [Writes the AIG in the binary AIGER format.]
Description []
SideEffects []
SeeAlso []
Definition at line 149 of file ioWriteAiger.c.
00150 { 00151 ProgressBar * pProgress; 00152 FILE * pFile; 00153 Abc_Obj_t * pObj, * pDriver; 00154 int i, nNodes, Pos, nBufferSize; 00155 unsigned char * pBuffer; 00156 unsigned uLit0, uLit1, uLit; 00157 00158 assert( Abc_NtkIsStrash(pNtk) ); 00159 // start the output stream 00160 pFile = fopen( pFileName, "wb" ); 00161 if ( pFile == NULL ) 00162 { 00163 fprintf( stdout, "Io_WriteAiger(): Cannot open the output file \"%s\".\n", pFileName ); 00164 return; 00165 } 00166 Abc_NtkForEachLatch( pNtk, pObj, i ) 00167 if ( !Abc_LatchIsInit0(pObj) ) 00168 { 00169 fprintf( stdout, "Io_WriteAiger(): Cannot write AIGER format with non-0 latch init values. Run \"zero\".\n" ); 00170 return; 00171 } 00172 00173 // set the node numbers to be used in the output file 00174 nNodes = 0; 00175 Io_ObjSetAigerNum( Abc_AigConst1(pNtk), nNodes++ ); 00176 Abc_NtkForEachCi( pNtk, pObj, i ) 00177 Io_ObjSetAigerNum( pObj, nNodes++ ); 00178 Abc_AigForEachAnd( pNtk, pObj, i ) 00179 Io_ObjSetAigerNum( pObj, nNodes++ ); 00180 00181 // write the header "M I L O A" where M = I + L + A 00182 fprintf( pFile, "aig %u %u %u %u %u\n", 00183 Abc_NtkPiNum(pNtk) + Abc_NtkLatchNum(pNtk) + Abc_NtkNodeNum(pNtk), 00184 Abc_NtkPiNum(pNtk), 00185 Abc_NtkLatchNum(pNtk), 00186 Abc_NtkPoNum(pNtk), 00187 Abc_NtkNodeNum(pNtk) ); 00188 00189 // if the driver node is a constant, we need to complement the literal below 00190 // because, in the AIGER format, literal 0/1 is represented as number 0/1 00191 // while, in ABC, constant 1 node has number 0 and so literal 0/1 will be 1/0 00192 00193 // write latch drivers 00194 Abc_NtkForEachLatchInput( pNtk, pObj, i ) 00195 { 00196 pDriver = Abc_ObjFanin0(pObj); 00197 fprintf( pFile, "%u\n", Io_ObjMakeLit( Io_ObjAigerNum(pDriver), Abc_ObjFaninC0(pObj) ^ (Io_ObjAigerNum(pDriver) == 0) ) ); 00198 } 00199 00200 // write PO drivers 00201 Abc_NtkForEachPo( pNtk, pObj, i ) 00202 { 00203 pDriver = Abc_ObjFanin0(pObj); 00204 fprintf( pFile, "%u\n", Io_ObjMakeLit( Io_ObjAigerNum(pDriver), Abc_ObjFaninC0(pObj) ^ (Io_ObjAigerNum(pDriver) == 0) ) ); 00205 } 00206 00207 // write the nodes into the buffer 00208 Pos = 0; 00209 nBufferSize = 6 * Abc_NtkNodeNum(pNtk) + 100; // skeptically assuming 3 chars per one AIG edge 00210 pBuffer = ALLOC( char, nBufferSize ); 00211 pProgress = Extra_ProgressBarStart( stdout, Abc_NtkObjNumMax(pNtk) ); 00212 Abc_AigForEachAnd( pNtk, pObj, i ) 00213 { 00214 Extra_ProgressBarUpdate( pProgress, i, NULL ); 00215 uLit = Io_ObjMakeLit( Io_ObjAigerNum(pObj), 0 ); 00216 uLit0 = Io_ObjMakeLit( Io_ObjAigerNum(Abc_ObjFanin0(pObj)), Abc_ObjFaninC0(pObj) ); 00217 uLit1 = Io_ObjMakeLit( Io_ObjAigerNum(Abc_ObjFanin1(pObj)), Abc_ObjFaninC1(pObj) ); 00218 assert( uLit0 < uLit1 ); 00219 Pos = Io_WriteAigerEncode( pBuffer, Pos, uLit - uLit1 ); 00220 Pos = Io_WriteAigerEncode( pBuffer, Pos, uLit1 - uLit0 ); 00221 if ( Pos > nBufferSize - 10 ) 00222 { 00223 printf( "Io_WriteAiger(): AIGER generation has failed because the allocated buffer is too small.\n" ); 00224 fclose( pFile ); 00225 return; 00226 } 00227 } 00228 assert( Pos < nBufferSize ); 00229 Extra_ProgressBarStop( pProgress ); 00230 00231 // write the buffer 00232 fwrite( pBuffer, 1, Pos, pFile ); 00233 free( pBuffer ); 00234 00235 // write the symbol table 00236 if ( fWriteSymbols ) 00237 { 00238 // write PIs 00239 Abc_NtkForEachPi( pNtk, pObj, i ) 00240 fprintf( pFile, "i%d %s\n", i, Abc_ObjName(pObj) ); 00241 // write latches 00242 Abc_NtkForEachLatch( pNtk, pObj, i ) 00243 fprintf( pFile, "l%d %s\n", i, Abc_ObjName(Abc_ObjFanout0(pObj)) ); 00244 // write POs 00245 Abc_NtkForEachPo( pNtk, pObj, i ) 00246 fprintf( pFile, "o%d %s\n", i, Abc_ObjName(pObj) ); 00247 } 00248 00249 // write the comment 00250 fprintf( pFile, "c\n" ); 00251 if ( pNtk->pName && strlen(pNtk->pName) > 0 ) 00252 fprintf( pFile, ".model %s\n", pNtk->pName ); 00253 fprintf( pFile, "This file was produced by ABC on %s\n", Extra_TimeStamp() ); 00254 fprintf( pFile, "For information about AIGER format, refer to %s\n", "http://fmv.jku.at/aiger" ); 00255 fclose( pFile ); 00256 }
int Io_WriteAigerEncode | ( | char * | pBuffer, | |
int | Pos, | |||
unsigned | x | |||
) |
Function*************************************************************
Synopsis [Adds one unsigned AIG edge to the output buffer.]
Description [This procedure is a slightly modified version of Armin Biere's procedure "void encode (FILE * file, unsigned x)" ]
SideEffects [Returns the current writing position.]
SeeAlso []
Definition at line 270 of file ioWriteAiger.c.