ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
ioWriteSmv.c
Go to the documentation of this file.
1
20
21#include "ioAbc.h"
22
24
25
29
30static int Io_WriteSmvCheckNames( Abc_Ntk_t * pNtk );
31
32static int Io_WriteSmvOne( FILE * pFile, Abc_Ntk_t * pNtk );
33static int Io_WriteSmvOneNode( FILE * pFile, Abc_Obj_t * pNode );
34
38
39// This returns a pointer to a static area, so be careful in using results
40// of this function i.e. don't call this twice in the same printf call.
41//
42// This function replaces '|' with '_' I think abc introduces '|' when
43// flattening hierarchy. The '|' is interpreted as a or function by nusmv
44// which is unfortunate. This probably should be fixed elsewhere.
45static char *cleanUNSAFE( const char *s )
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}
54
55static int hasPrefix(const char *needle, const char *haystack)
56{
57 return (strncmp(haystack, needle, strlen(needle)) == 0);
58}
59
71int Io_WriteSmv( Abc_Ntk_t * pNtk, char * pFileName )
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 parentheses 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}
98
110int Io_WriteSmvOne( FILE * pFile, Abc_Ntk_t * pNtk )
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",
123 cleanUNSAFE(Abc_ObjName(Abc_ObjFanout0(pNode))) );
124 fprintf ( pFile, "\n" );
125
126 fprintf( pFile, "VAR -- state variables\n");
127 Abc_NtkForEachLatch( pNtk, pNode, i )
128 fprintf( pFile, " %s : boolean;\n",
129 cleanUNSAFE(Abc_ObjName(Abc_ObjFanout0(Abc_ObjFanout0(pNode)))) );
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",
159 cleanUNSAFE(Abc_ObjName(Abc_ObjFanout0(Abc_ObjFanout0(pNode)))),
160 Reset - 1);
161 }
162 fprintf( pFile, " next(%s) := ",
163 cleanUNSAFE(Abc_ObjName(Abc_ObjFanout0(Abc_ObjFanout0(pNode)))) );
164 fprintf( pFile, "%s;\n",
165 cleanUNSAFE(Abc_ObjName(Abc_ObjFanin0(Abc_ObjFanin0(pNode)))) );
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}
190
202int Io_WriteSmvOneNode( FILE * pFile, Abc_Obj_t * pNode )
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}
235
247int Io_WriteSmvCheckNames( Abc_Ntk_t * pNtk )
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}
258
262
263
265
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
ABC_DLL int Abc_NodeIsBuf(Abc_Obj_t *pNode)
Definition abcObj.c:948
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition abc.h:520
#define Abc_NtkForEachLatch(pNtk, pObj, i)
Definition abc.h:500
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition abc.h:449
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition abcNames.c:49
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition abc.h:516
ABC_DLL int Abc_NodeIsConst1(Abc_Obj_t *pNode)
Definition abcObj.c:916
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition abc.h:464
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
Definition bbrNtbdd.c:27
void Extra_ProgressBarStop(ProgressBar *p)
char * Extra_TimeStamp()
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
int Io_WriteSmv(Abc_Ntk_t *pNtk, char *pFileName)
Definition ioWriteSmv.c:71
char * Nm_ManFindNameById(Nm_Man_t *p, int ObjId)
Definition nmApi.c:199
char * pName
Definition abc.h:158
Nm_Man_t * pManName
Definition abc.h:160
#define assert(ex)
Definition util_old.h:213
int strncmp()
int strlen()
char * strcpy()