abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ioWriteSmv.c File Reference
#include "ioAbc.h"

Go to the source code of this file.

Functions

static ABC_NAMESPACE_IMPL_START int Io_WriteSmvCheckNames (Abc_Ntk_t *pNtk)
 DECLARATIONS ///. More...
 
static int Io_WriteSmvOne (FILE *pFile, Abc_Ntk_t *pNtk)
 
static int Io_WriteSmvOneNode (FILE *pFile, Abc_Obj_t *pNode)
 
static char * cleanUNSAFE (const char *s)
 FUNCTION DEFINITIONS ///. More...
 
static int hasPrefix (const char *needle, const char *haystack)
 
int Io_WriteSmv (Abc_Ntk_t *pNtk, char *pFileName)
 

Function Documentation

static char* cleanUNSAFE ( const char *  s)
static

FUNCTION DEFINITIONS ///.

Definition at line 45 of file ioWriteSmv.c.

46 {
47  char *t;
48  static char buffer[1024];
49  assert (strlen(s) < 1024);
50  strcpy(buffer, s);
51  for (t = buffer; *t != 0; ++t) *t = (*t == '|') ? '_' : *t;
52  return buffer;
53 }
char * strcpy()
#define assert(ex)
Definition: util_old.h:213
int strlen()
static int hasPrefix ( const char *  needle,
const char *  haystack 
)
static

Definition at line 55 of file ioWriteSmv.c.

56 {
57  return (strncmp(haystack, needle, strlen(needle)) == 0);
58 }
int strncmp()
int strlen()
int Io_WriteSmv ( Abc_Ntk_t pNtk,
char *  pFileName 
)

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

Synopsis [Writes the network in SMV format.]

Description []

SideEffects []

SeeAlso []

Definition at line 71 of file ioWriteSmv.c.

72 {
73  Abc_Ntk_t * pExdc;
74  FILE * pFile;
75  assert( Abc_NtkIsSopNetlist(pNtk) );
76  if ( !Io_WriteSmvCheckNames(pNtk) )
77  {
78  fprintf( stdout, "Io_WriteSmv(): Signal names in this benchmark contain parantheses making them impossible to reproduce in the SMV format. Use \"short_names\".\n" );
79  return 0;
80  }
81  pFile = fopen( pFileName, "w" );
82  if ( pFile == NULL )
83  {
84  fprintf( stdout, "Io_WriteSmv(): Cannot open the output file.\n" );
85  return 0;
86  }
87  fprintf( pFile, "-- benchmark \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
88  // write the network
89  Io_WriteSmvOne( pFile, pNtk );
90  // write EXDC network if it exists
91  pExdc = Abc_NtkExdc( pNtk );
92  if ( pExdc )
93  printf( "Io_WriteSmv: EXDC is not written (warning).\n" );
94  // finalize the file
95  fclose( pFile );
96  return 1;
97 }
static Abc_Ntk_t * Abc_NtkExdc(Abc_Ntk_t *pNtk)
Definition: abc.h:272
static int Io_WriteSmvOne(FILE *pFile, Abc_Ntk_t *pNtk)
Definition: ioWriteSmv.c:110
char * Extra_TimeStamp()
static int Abc_NtkIsSopNetlist(Abc_Ntk_t *pNtk)
Definition: abc.h:260
static ABC_NAMESPACE_IMPL_START int Io_WriteSmvCheckNames(Abc_Ntk_t *pNtk)
DECLARATIONS ///.
Definition: ioWriteSmv.c:247
#define assert(ex)
Definition: util_old.h:213
char * pName
Definition: abc.h:158
int Io_WriteSmvCheckNames ( Abc_Ntk_t pNtk)
static

DECLARATIONS ///.

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

FileName [ioWriteSmv.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Command processing package.]

Synopsis [Procedures to write the network in SMV format.]

Author [Satrajit Chatterjee]

Affiliation [UC Berkeley]

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

Revision [

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

]

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

Synopsis [Returns 1 if the names cannot be written into the bench file.]

Description []

SideEffects []

SeeAlso []

Definition at line 247 of file ioWriteSmv.c.

248 {
249  Abc_Obj_t * pObj;
250  char * pName;
251  int i;
252  Abc_NtkForEachObj( pNtk, pObj, i )
253  for ( pName = Nm_ManFindNameById(pNtk->pManName, i); pName && *pName; pName++ )
254  if ( *pName == '(' || *pName == ')' )
255  return 0;
256  return 1;
257 }
for(p=first;p->value< newval;p=p->next)
if(last==0)
Definition: sparse_int.h:34
char * Nm_ManFindNameById(Nm_Man_t *p, int ObjId)
Definition: nmApi.c:199
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446
int Io_WriteSmvOne ( FILE *  pFile,
Abc_Ntk_t pNtk 
)
static

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

Synopsis [Writes the network in SMV format.]

Description []

SideEffects []

SeeAlso []

Definition at line 110 of file ioWriteSmv.c.

111 {
112  ProgressBar * pProgress;
113  Abc_Obj_t * pNode;
114  int i;
115 
116  // write the PIs/POs/latches
117  fprintf( pFile, "MODULE main\n"); // nusmv needs top module to be main
118  fprintf ( pFile, "\n" );
119 
120  fprintf( pFile, "VAR -- inputs\n");
121  Abc_NtkForEachPi( pNtk, pNode, i )
122  fprintf( pFile, " %s : boolean;\n",
124  fprintf ( pFile, "\n" );
125 
126  fprintf( pFile, "VAR -- state variables\n");
127  Abc_NtkForEachLatch( pNtk, pNode, i )
128  fprintf( pFile, " %s : boolean;\n",
130  fprintf ( pFile, "\n" );
131 
132  // No outputs needed for NuSMV:
133  // TODO: Add sepcs by recognizing assume_.* and assert_.*
134  //
135  // Abc_NtkForEachPo( pNtk, pNode, i )
136  // fprintf( pFile, "OUTPUT(%s)\n", Abc_ObjName(Abc_ObjFanin0(pNode)) );
137 
138  // write internal nodes
139  fprintf( pFile, "DEFINE\n");
140  pProgress = Extra_ProgressBarStart( stdout, Abc_NtkObjNumMax(pNtk) );
141  Abc_NtkForEachNode( pNtk, pNode, i )
142  {
143  Extra_ProgressBarUpdate( pProgress, i, NULL );
144  Io_WriteSmvOneNode( pFile, pNode );
145  }
146  Extra_ProgressBarStop( pProgress );
147  fprintf ( pFile, "\n" );
148 
149  fprintf( pFile, "ASSIGN\n");
150  Abc_NtkForEachLatch( pNtk, pNode, i )
151  {
152  int Reset = (int)(ABC_PTRUINT_T)Abc_ObjData( pNode );
153  assert (Reset >= 1);
154  assert (Reset <= 3);
155 
156  if (Reset != 3)
157  {
158  fprintf( pFile, " init(%s) := %d;\n",
160  Reset - 1);
161  }
162  fprintf( pFile, " next(%s) := ",
164  fprintf( pFile, "%s;\n",
166  }
167 
168  fprintf ( pFile, "\n" );
169  Abc_NtkForEachPo( pNtk, pNode, i )
170  {
171  const char *n = cleanUNSAFE(Abc_ObjName(Abc_ObjFanin0(pNode)));
172  // fprintf( pFile, "-- output %s;\n", n );
173  if (hasPrefix("assume_fair_", n))
174  {
175  fprintf( pFile, "FAIRNESS %s;\n", n );
176  }
177  else if (hasPrefix("Assert_", n) ||
178  hasPrefix("assert_safety_", n))
179  {
180  fprintf( pFile, "INVARSPEC %s;\n", n );
181  }
182  else if (hasPrefix("assert_fair_", n))
183  {
184  fprintf( pFile, "LTLSPEC G F %s;\n", n );
185  }
186  }
187 
188  return 1;
189 }
static int Abc_NtkObjNumMax(Abc_Ntk_t *pNtk)
Definition: abc.h:284
static int Io_WriteSmvOneNode(FILE *pFile, Abc_Obj_t *pNode)
Definition: ioWriteSmv.c:202
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
static int hasPrefix(const char *needle, const char *haystack)
Definition: ioWriteSmv.c:55
DECLARATIONS ///.
#define Abc_NtkForEachLatch(pNtk, pObj, i)
Definition: abc.h:497
void Extra_ProgressBarStop(ProgressBar *p)
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
static char * cleanUNSAFE(const char *s)
FUNCTION DEFINITIONS ///.
Definition: ioWriteSmv.c:45
#define assert(ex)
Definition: util_old.h:213
static void Extra_ProgressBarUpdate(ProgressBar *p, int nItemsCur, char *pString)
Definition: extra.h:243
static void * Abc_ObjData(Abc_Obj_t *pObj)
Definition: abc.h:336
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition: abc.h:517
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition: abc.h:513
int Io_WriteSmvOneNode ( FILE *  pFile,
Abc_Obj_t pNode 
)
static

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

Synopsis [Writes the network in SMV format.]

Description []

SideEffects []

SeeAlso []

Definition at line 202 of file ioWriteSmv.c.

203 {
204  int nFanins;
205 
206  assert( Abc_ObjIsNode(pNode) );
207  nFanins = Abc_ObjFaninNum(pNode);
208  if ( nFanins == 0 )
209  { // write the constant 1 node
210  assert( Abc_NodeIsConst1(pNode) );
211  fprintf( pFile, " %s", cleanUNSAFE(Abc_ObjName(Abc_ObjFanout0(pNode)) ) );
212  fprintf( pFile, " := 1;\n" );
213  }
214  else if ( nFanins == 1 )
215  { // write the interver/buffer
216  if ( Abc_NodeIsBuf(pNode) )
217  {
218  fprintf( pFile, " %s := ", cleanUNSAFE(Abc_ObjName(Abc_ObjFanout0(pNode))) );
219  fprintf( pFile, "%s;\n", cleanUNSAFE(Abc_ObjName(Abc_ObjFanin0(pNode))) );
220  }
221  else
222  {
223  fprintf( pFile, " %s := !", cleanUNSAFE(Abc_ObjName(Abc_ObjFanout0(pNode))) );
224  fprintf( pFile, "%s;\n", cleanUNSAFE(Abc_ObjName(Abc_ObjFanin0(pNode))) );
225  }
226  }
227  else
228  { // write the AND gate
229  fprintf( pFile, " %s", cleanUNSAFE(Abc_ObjName(Abc_ObjFanout0(pNode))) );
230  fprintf( pFile, " := %s & ", cleanUNSAFE(Abc_ObjName(Abc_ObjFanin0(pNode))) );
231  fprintf( pFile, "%s;\n", cleanUNSAFE(Abc_ObjName(Abc_ObjFanin1(pNode))) );
232  }
233  return 1;
234 }
static Abc_Obj_t * Abc_ObjFanin1(Abc_Obj_t *pObj)
Definition: abc.h:374
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
ABC_DLL int Abc_NodeIsBuf(Abc_Obj_t *pNode)
Definition: abcObj.c:920
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
static char * cleanUNSAFE(const char *s)
FUNCTION DEFINITIONS ///.
Definition: ioWriteSmv.c:45
ABC_DLL int Abc_NodeIsConst1(Abc_Obj_t *pNode)
Definition: abcObj.c:890
#define assert(ex)
Definition: util_old.h:213
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371