ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
wlnRtl.c
Go to the documentation of this file.
1
20
21#include "wln.h"
22#include "base/main/main.h"
23
24#ifdef WIN32
25#include <process.h>
26#define unlink _unlink
27#else
28#include <unistd.h>
29#endif
30
32
36
40
52#define MAX_LINE 1000000
53
54void Rtl_NtkCleanFile( char * pFileName )
55{
56 char * pBuffer, * pFileName2 = "_temp__.rtlil";
57 FILE * pFile = fopen( pFileName, "rb" );
58 FILE * pFile2;
59 if ( pFile == NULL )
60 {
61 printf( "Cannot open file \"%s\" for reading.\n", pFileName );
62 return;
63 }
64 pFile2 = fopen( pFileName2, "wb" );
65 if ( pFile2 == NULL )
66 {
67 fclose( pFile );
68 printf( "Cannot open file \"%s\" for writing.\n", pFileName2 );
69 return;
70 }
71 pBuffer = ABC_ALLOC( char, MAX_LINE );
72 while ( fgets( pBuffer, MAX_LINE, pFile ) != NULL )
73 if ( !strstr(pBuffer, "attribute \\src") )
74 fputs( pBuffer, pFile2 );
75 ABC_FREE( pBuffer );
76 fclose( pFile );
77 fclose( pFile2 );
78}
79
80void Rtl_NtkCleanFile2( char * pFileName )
81{
82 char * pBuffer, * pFileName2 = "_temp__.v";
83 FILE * pFile = fopen( pFileName, "rb" );
84 FILE * pFile2;
85 if ( pFile == NULL )
86 {
87 printf( "Cannot open file \"%s\" for reading.\n", pFileName );
88 return;
89 }
90 pFile2 = fopen( pFileName2, "wb" );
91 if ( pFile2 == NULL )
92 {
93 fclose( pFile );
94 printf( "Cannot open file \"%s\" for writing.\n", pFileName2 );
95 return;
96 }
97 pBuffer = ABC_ALLOC( char, MAX_LINE );
98 while ( fgets( pBuffer, MAX_LINE, pFile ) != NULL )
99 if ( !strstr(pBuffer, "//") )
100 fputs( pBuffer, pFile2 );
101 ABC_FREE( pBuffer );
102 fclose( pFile );
103 fclose( pFile2 );
104}
105
107{
108 char * pYosysName = NULL;
109 char * pYosysNameWin = "yosys.exe";
110 char * pYosysNameUnix = "yosys";
111 if ( Abc_FrameReadFlag("yosyswin") )
112 pYosysNameWin = Abc_FrameReadFlag("yosyswin");
113 if ( Abc_FrameReadFlag("yosysunix") )
114 pYosysNameUnix = Abc_FrameReadFlag("yosysunix");
115#ifdef WIN32
116 pYosysName = pYosysNameWin;
117#else
118 pYosysName = pYosysNameUnix;
119#endif
120 return pYosysName;
121}
122int Wln_ConvertToRtl( char * pCommand, char * pFileTemp )
123{
124#if defined(__wasm)
125 return 0;
126#else
127 FILE * pFile;
128 if ( system( pCommand ) == -1 )
129 {
130 fprintf( stdout, "Cannot execute \"%s\".\n", pCommand );
131 return 0;
132 }
133 if ( (pFile = fopen(pFileTemp, "r")) == NULL )
134 {
135 fprintf( stdout, "Cannot open intermediate file \"%s\".\n", pFileTemp );
136 return 0;
137 }
138 fclose( pFile );
139 return 1;
140#endif
141}
142Rtl_Lib_t * Wln_ReadSystemVerilog( char * pFileName, char * pTopModule, char * pDefines, int fCollapse, int fVerbose )
143{
144 Rtl_Lib_t * pNtk = NULL;
145 char Command[1000];
146 char * pFileTemp = "_temp_.rtlil";
147 int fSVlog = strstr(pFileName, ".sv") != NULL;
148 if ( strstr(pFileName, ".rtl") )
149 return Rtl_LibReadFile( pFileName, pFileName );
150 sprintf( Command, "%s -qp \"read_verilog %s%s %s%s; hierarchy %s%s; %sproc; write_rtlil %s\"",
152 pDefines ? "-D" : "",
153 pDefines ? pDefines : "",
154 fSVlog ? "-sv " : "",
155 pFileName,
156 pTopModule ? "-top " : "",
157 pTopModule ? pTopModule : "",
158 fCollapse ? "flatten; ": "",
159 pFileTemp );
160 if ( fVerbose )
161 printf( "%s\n", Command );
162 if ( !Wln_ConvertToRtl(Command, pFileTemp) )
163 return NULL;
164 pNtk = Rtl_LibReadFile( pFileTemp, pFileName );
165 if ( pNtk == NULL )
166 {
167 printf( "Dumped the design into file \"%s\".\n", pFileTemp );
168 return NULL;
169 }
170 Rtl_NtkCleanFile( pFileTemp );
171 unlink( pFileTemp );
172 return pNtk;
173}
174Gia_Man_t * Wln_BlastSystemVerilog( char * pFileName, char * pTopModule, char * pDefines, int fSkipStrash, int fInvert, int fTechMap, int fLibInDir, int fVerbose )
175{
176 Gia_Man_t * pGia = NULL;
177 char Command[1000];
178 char * pFileTemp = "_temp_.aig";
179 int fRtlil = strstr(pFileName, ".rtl") != NULL;
180 int fSVlog = strstr(pFileName, ".sv") != NULL;
181 sprintf( Command, "%s -qp \"%s %s%s %s%s; hierarchy %s%s; flatten; proc; %saigmap; write_aiger %s\"",
183 fRtlil ? "read_rtlil" : "read_verilog",
184 pDefines ? "-D" : "",
185 pDefines ? pDefines : "",
186 fSVlog ? "-sv " : "",
187 pFileName,
188 pTopModule ? "-top " : "-auto-top",
189 pTopModule ? pTopModule : "",
190 fTechMap ? (fLibInDir ? "techmap -map techmap.v; setundef -zero; " : "techmap; setundef -zero; ") : "", pFileTemp );
191 if ( fVerbose )
192 printf( "%s\n", Command );
193 if ( !Wln_ConvertToRtl(Command, pFileTemp) )
194 return NULL;
195 pGia = Gia_AigerRead( pFileTemp, 0, fSkipStrash, 0 );
196 if ( pGia == NULL )
197 {
198 printf( "Converting to AIG has failed.\n" );
199 return NULL;
200 }
201 ABC_FREE( pGia->pName );
202 pGia->pName = pTopModule ? Abc_UtilStrsav(pTopModule) :
204 unlink( pFileTemp );
205 // complement the outputs
206 if ( fInvert )
207 {
208 Gia_Obj_t * pObj; int i;
209 Gia_ManForEachPo( pGia, pObj, i )
210 Gia_ObjFlipFaninC0( pObj );
211 }
212 return pGia;
213}
214Abc_Ntk_t * Wln_ReadMappedSystemVerilog( char * pFileName, char * pTopModule, char * pDefines, char * pLibrary, int fVerbose )
215{
216 Abc_Ntk_t * pNtk = NULL;
217 char Command[1000];
218 char * pFileTemp = "_temp_.blif";
219 int fSVlog = strstr(pFileName, ".sv") != NULL;
220 sprintf( Command, "%s -qp \"read_liberty -lib %s; read %s %s%s %s; hierarchy %s%s; flatten; proc; write_blif %s%s -impltf -gates %s\"",
222 pLibrary,
223 fSVlog ? "-sv " : "-vlog95",
224 pDefines ? "-D" : "",
225 pDefines ? pDefines : "",
226 pFileName,
227 pTopModule ? "-top " : "-auto-top",
228 pTopModule ? pTopModule : "",
229 pTopModule ? "-top " : "",
230 pTopModule ? pTopModule : "",
231 pFileTemp );
232 if ( fVerbose )
233 printf( "%s\n", Command );
234 if ( !Wln_ConvertToRtl(Command, pFileTemp) )
235 return NULL;
236 sprintf( Command, "read_lib %s", pLibrary );
238 {
239 fprintf( stdout, "Cannot execute ABC command \"%s\".\n", Command );
240 unlink( pFileTemp );
241 return NULL;
242 }
243 pNtk = Io_Read( pFileTemp, IO_FILE_BLIF, 1, 0 );
244 if ( pNtk == NULL )
245 {
246 printf( "Reading mapped BLIF from file \"%s\" has failed.\n", pFileTemp );
247 return NULL;
248 }
249 if ( pTopModule ) {
250 ABC_FREE( pNtk->pName );
251 pNtk->pName = Abc_UtilStrsav(pTopModule);
252 }
253 unlink( pFileTemp );
254 return pNtk;
255}
256
260
261
263
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
ABC_DLL char * Abc_FrameReadFlag(char *pFlag)
Definition mainFrame.c:69
ABC_DLL Abc_Frame_t * Abc_FrameReadGlobalFrame()
Definition mainFrame.c:666
ABC_DLL int Cmd_CommandExecute(Abc_Frame_t *pAbc, const char *sCommand)
Definition cmdApi.c:193
char * Extra_FileNameWithoutPath(char *FileName)
char * Extra_FileNameGeneric(char *FileName)
#define MAX_LINE
DECLARATIONS ///.
Definition giaGig.c:32
#define Gia_ManForEachPo(p, pObj, i)
Definition gia.h:1250
Gia_Man_t * Gia_AigerRead(char *pFileName, int fGiaSimple, int fSkipStrash, int fCheck)
Definition giaAiger.c:1017
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
@ IO_FILE_BLIF
Definition ioAbc.h:52
Abc_Ntk_t * Io_Read(char *pFileName, Io_FileType_t FileType, int fCheck, int fBarBufs)
Definition ioUtil.c:241
char * pName
Definition abc.h:158
char * pName
Definition gia.h:99
int system()
char * sprintf()
char * strstr()
Abc_Ntk_t * Wln_ReadMappedSystemVerilog(char *pFileName, char *pTopModule, char *pDefines, char *pLibrary, int fVerbose)
Definition wlnRtl.c:214
void Rtl_NtkCleanFile(char *pFileName)
Definition wlnRtl.c:54
char * Wln_GetYosysName()
Definition wlnRtl.c:106
int Wln_ConvertToRtl(char *pCommand, char *pFileTemp)
Definition wlnRtl.c:122
Gia_Man_t * Wln_BlastSystemVerilog(char *pFileName, char *pTopModule, char *pDefines, int fSkipStrash, int fInvert, int fTechMap, int fLibInDir, int fVerbose)
Definition wlnRtl.c:174
Rtl_Lib_t * Wln_ReadSystemVerilog(char *pFileName, char *pTopModule, char *pDefines, int fCollapse, int fVerbose)
Definition wlnRtl.c:142
void Rtl_NtkCleanFile2(char *pFileName)
Definition wlnRtl.c:80
struct Rtl_Lib_t_ Rtl_Lib_t
Definition wln.h:255
Rtl_Lib_t * Rtl_LibReadFile(char *pFileName, char *pFileSpec)
Definition wlnRead.c:1492