ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
mainUtils.c
Go to the documentation of this file.
1
20
21#include "base/abc/abc.h"
22#include "mainInt.h"
23
24#ifdef ABC_USE_READLINE
25#include <readline/readline.h>
26#include <readline/history.h>
27#endif
28
30
34
35static char * DateReadFromDateString( char * datestr );
36
40
53{
54 static char Version[1000];
55#if __GNUC__
56 #pragma GCC diagnostic push
57 #pragma GCC diagnostic ignored "-Wdate-time"
58#endif
59 sprintf(Version, "%s (compiled %s %s)", ABC_VERSION, __DATE__, __TIME__);
60#if __GNUC__
61 #pragma GCC diagnostic pop
62#endif
63 return Version;
64}
65
78{
79 static char Prompt[5000];
80 sprintf( Prompt, "abc %02d> ", pAbc->nSteps );
81#ifdef ABC_USE_READLINE
82 {
83 static char * line = NULL;
84 if (line != NULL) ABC_FREE(line);
85 line = readline(Prompt);
86 if (line == NULL){ printf("***EOF***\n"); exit(0); }
87 add_history(line);
88 return line;
89 }
90#else
91 {
92 char * pRetValue;
93 fprintf( pAbc->Out, "%s", Prompt );
94 pRetValue = fgets( Prompt, 5000, stdin );
95 return Prompt;
96 }
97#endif
98}
99
112{
113 fprintf( pAbc->Out, "%s\n", pAbc->sVersion );
114}
115
127void Abc_UtilsPrintUsage( Abc_Frame_t * pAbc, char * ProgName )
128{
129 fprintf( pAbc->Err, "\n" );
130 fprintf( pAbc->Err,
131 "usage: %s [-c cmd] [-q cmd] [-C cmd] [-Q cmd] [-f script] [-h] [-o file] [-s] [-t type] [-T type] [-x] [-b] [file]\n",
132 ProgName);
133 fprintf( pAbc->Err, " -c cmd\texecute commands `cmd'\n");
134 fprintf( pAbc->Err, " -q cmd\texecute commands `cmd' quietly\n");
135 fprintf( pAbc->Err, " -C cmd\texecute commands `cmd', then continue in interactive mode\n");
136 fprintf( pAbc->Err, " -Q cmd\texecute commands `cmd' quietly, then continue in interactive mode\n");
137 fprintf( pAbc->Err, " -F script\texecute commands from a script file and echo commands\n");
138 fprintf( pAbc->Err, " -f script\texecute commands from a script file\n");
139 fprintf( pAbc->Err, " -h\t\tprint the command usage\n");
140 fprintf( pAbc->Err, " -o file\tspecify output filename to store the result\n");
141 fprintf( pAbc->Err, " -s\t\tdo not read any initialization file\n");
142 fprintf( pAbc->Err, " -t type\tspecify input type (blif_mv (default), blif_mvs, blif, or none)\n");
143 fprintf( pAbc->Err, " -T type\tspecify output type (blif_mv (default), blif_mvs, blif, or none)\n");
144 fprintf( pAbc->Err, " -x\t\tequivalent to '-t none -T none'\n");
145 fprintf( pAbc->Err, " -b\t\trunning in bridge mode\n");
146 fprintf( pAbc->Err, "\n" );
147}
148
161{
162#ifdef WIN32
163 if ( Cmd_CommandExecute(pAbc, "source abc.rc") )
164 {
165 if ( Cmd_CommandExecute(pAbc, "source ..\\abc.rc") == 0 )
166 printf( "Loaded \"abc.rc\" from the parent directory.\n" );
167 else if ( Cmd_CommandExecute(pAbc, "source ..\\..\\abc.rc") == 0 )
168 printf( "Loaded \"abc.rc\" from the grandparent directory.\n" );
169 }
170#else
171
172#if 0
173 {
174 char * sPath1, * sPath2;
175
176 // If .rc is present in both the home and current directories, then read
177 // it from the home directory. Otherwise, read it from wherever it's located.
178 sPath1 = Extra_UtilFileSearch(".rc", "~/", "r");
179 sPath2 = Extra_UtilFileSearch(".rc", ".", "r");
180
181 if ( sPath1 && sPath2 ) {
182 /* ~/.rc == .rc : Source the file only once */
183 (void) Cmd_CommandExecute(pAbc, "source -s ~/.rc");
184 }
185 else {
186 if (sPath1) {
187 (void) Cmd_CommandExecute(pAbc, "source -s ~/.rc");
188 }
189 if (sPath2) {
190 (void) Cmd_CommandExecute(pAbc, "source -s .rc");
191 }
192 }
193 if ( sPath1 ) ABC_FREE(sPath1);
194 if ( sPath2 ) ABC_FREE(sPath2);
195
196 /* execute the abc script which can be open with the "open_path" */
197 Cmd_CommandExecute( pAbc, "source -s abc.rc" );
198 }
199#endif
200
201 {
202 char * sPath1, * sPath2;
203 char * home;
204
205 // If .rc is present in both the home and current directories, then read
206 // it from the home directory. Otherwise, read it from wherever it's located.
207 home = getenv("HOME");
208 if (home){
209 char * sPath3 = ABC_ALLOC(char, strlen(home) + 2);
210 (void) sprintf(sPath3, "%s/", home);
211 sPath1 = Extra_UtilFileSearch(".abc.rc", sPath3, "r");
212 ABC_FREE(sPath3);
213 }else
214 sPath1 = NULL;
215
216 sPath2 = Extra_UtilFileSearch(".abc.rc", ".", "r");
217
218 if ( sPath1 && sPath2 ) {
219 /* ~/.rc == .rc : Source the file only once */
220 char *tmp_cmd = ABC_ALLOC(char, strlen(sPath1)+12);
221 (void) sprintf(tmp_cmd, "source -s %s", sPath1);
222 // (void) Cmd_CommandExecute(pAbc, "source -s ~/.abc.rc");
223 (void) Cmd_CommandExecute(pAbc, tmp_cmd);
224 ABC_FREE(tmp_cmd);
225 }
226 else {
227 if (sPath1) {
228 char *tmp_cmd = ABC_ALLOC(char, strlen(sPath1)+12);
229 (void) sprintf(tmp_cmd, "source -s %s", sPath1);
230 // (void) Cmd_CommandExecute(pAbc, "source -s ~/.abc.rc");
231 (void) Cmd_CommandExecute(pAbc, tmp_cmd);
232 ABC_FREE(tmp_cmd);
233 }
234 if (sPath2) {
235 char *tmp_cmd = ABC_ALLOC(char, strlen(sPath2)+12);
236 (void) sprintf(tmp_cmd, "source -s %s", sPath2);
237 // (void) Cmd_CommandExecute(pAbc, "source -s .abc.rc");
238 (void) Cmd_CommandExecute(pAbc, tmp_cmd);
239 ABC_FREE(tmp_cmd);
240 }
241 }
242 if ( sPath1 ) ABC_FREE(sPath1);
243 if ( sPath2 ) ABC_FREE(sPath2);
244
245 /* execute the abc script which can be open with the "open_path" */
246 Cmd_CommandExecute( pAbc, "source -s abc.rc" );
247 }
248
249#endif //WIN32
250}
251
262char * DateReadFromDateString( char * datestr )
263{
264 static char result[100];
265 char day[10];
266 char month[10];
267 char zone[10];
268 char *at;
269 int date;
270 int hour;
271 int minute;
272 int second;
273 int year;
274
275 if (sscanf(datestr, "%s %s %2d %2d:%2d:%2d %s %4d",
276 day, month, &date, &hour, &minute, &second, zone, &year) == 8) {
277 if (hour >= 12) {
278 if (hour >= 13) hour -= 12;
279 at = "PM";
280 }
281 else {
282 if (hour == 0) hour = 12;
283 at = "AM";
284 }
285 (void) sprintf(result, "%d-%3s-%02d at %d:%02d %s",
286 date, month, year % 100, hour, minute, at);
287 return result;
288 }
289 else {
290 return datestr;
291 }
292}
293
304{
305 if ( pAbc->pHash )
306 Hsh_VecManStop( pAbc->pHash );
307 pAbc->pHash = NULL;
308}
310{
311 Abc_FrameStoreStop( pAbc );
312 pAbc->pHash = Hsh_VecManStart( 1000 );
313 pAbc->pHash->vEntry = Vec_IntAlloc( 1000 );
314 pAbc->pHash->vValue = Vec_IntAlloc( 1000 );
315}
317{
318 if ( pAbc->pHash == NULL )
319 Abc_FrameStoreStart( pAbc );
320 Gia_Man_t * p = Gia_ManIsoCanonicize( pGia, 0 );
321 Vec_IntClear( pAbc->pHash->vEntry );
322 Vec_IntPush( pAbc->pHash->vEntry, 0 );
323 Vec_IntPush( pAbc->pHash->vEntry, Gia_ManPiNum(p) );
324 Vec_IntPush( pAbc->pHash->vEntry, Gia_ManPoNum(p) );
325 Vec_IntPush( pAbc->pHash->vEntry, Gia_ManRegNum(p) );
326 Gia_Obj_t * pObj; int i;
327 Gia_ManForEachAnd( p, pObj, i )
328 Vec_IntPushTwo( pAbc->pHash->vEntry, Gia_ObjFaninLit0(pObj, i), Gia_ObjFaninLit1(pObj, i) );
329 int iEntry = Hsh_VecManAdd( pAbc->pHash, pAbc->pHash->vEntry );
330 if ( Vec_IntSize(pAbc->pHash->vValue) == iEntry )
331 Vec_IntPush( pAbc->pHash->vValue, 0 );
332 Vec_IntAddToEntry( pAbc->pHash->vValue, iEntry, 1 );
333 assert( Vec_IntSize(pAbc->pHash->vValue) == Hsh_VecSize(pAbc->pHash) );
334 Gia_ManStop( p );
335}
337{
338 if ( pAbc->pHash == NULL )
339 Abc_FrameStoreStart( pAbc );
340 int i, Entry, nAll = 0, Max = Vec_IntFindMax( pAbc->pHash->vValue );
341 Vec_Int_t * vCounts = Vec_IntStart( Max+1 );
342 Vec_IntForEachEntry( pAbc->pHash->vValue, Entry, i )
343 Vec_IntAddToEntry( vCounts, Entry, 1 );
344 printf( "Distribution of %d stored items by reference count (<ref_count>=<num_items>): ", Hsh_VecSize(pAbc->pHash) );
345 Vec_IntForEachEntry( vCounts, Entry, i )
346 if ( Entry )
347 printf( "%d=%d ", i, Entry ), nAll += i * Entry;
348 printf( "ALL=%d\n", nAll );
349 Vec_IntFree( vCounts );
350}
351
355
356
#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
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
Definition abcapis.h:38
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
ABC_DLL int Cmd_CommandExecute(Abc_Frame_t *pAbc, const char *sCommand)
Definition cmdApi.c:193
Cube * p
Definition exorList.c:222
char * Extra_UtilFileSearch(char *file, char *path, char *mode)
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
#define Gia_ManForEachAnd(p, pObj, i)
Definition gia.h:1214
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
Gia_Man_t * Gia_ManIsoCanonicize(Gia_Man_t *p, int fVerbose)
Definition giaIso.c:958
#define ABC_VERSION
INCLUDES ///.
Definition mainInt.h:49
char * Abc_UtilsGetUsersInput(Abc_Frame_t *pAbc)
Definition mainUtils.c:77
void Abc_FrameStoreAdd(Abc_Frame_t *pAbc, Gia_Man_t *pGia)
Definition mainUtils.c:316
void Abc_UtilsPrintHello(Abc_Frame_t *pAbc)
Definition mainUtils.c:111
void Abc_FrameStorePrint(Abc_Frame_t *pAbc)
Definition mainUtils.c:336
void Abc_UtilsSource(Abc_Frame_t *pAbc)
Definition mainUtils.c:160
void Abc_FrameStoreStart(Abc_Frame_t *pAbc)
Definition mainUtils.c:309
char * Abc_UtilsGetVersion(Abc_Frame_t *pAbc)
FUNCTION DEFINITIONS ///.
Definition mainUtils.c:52
void Abc_UtilsPrintUsage(Abc_Frame_t *pAbc, char *ProgName)
Definition mainUtils.c:127
void Abc_FrameStoreStop(Abc_Frame_t *pAbc)
Definition mainUtils.c:303
const char * date()
#define assert(ex)
Definition util_old.h:213
int strlen()
char * sprintf()
char * getenv()
VOID_HACK exit()
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54