ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
extraUtilUtil.c File Reference
#include <stdio.h>
#include <string.h>
#include "extra.h"
#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>
Include dependency graph for extraUtilUtil.c:

Go to the source code of this file.

Macros

#define EXTRA_RLIMIT_DATA_DEFAULT   67108864
 DECLARATIONS ///.
 

Functions

int Extra_GetSoftDataLimit ()
 FUNCTION DEFINITIONS ///.
 
void Extra_UtilGetoptReset ()
 
int Extra_UtilGetopt (int argc, char *argv[], const char *optstring)
 
char * Extra_UtilPrintTime (long t)
 
char * Extra_UtilStrsav (const char *s)
 
char * Extra_UtilTildeExpand (char *fname)
 
int Extra_UtilCheckFile (char *filename, const char *mode)
 
char * Extra_UtilFileSearch (char *file, char *path, char *mode)
 
void Extra_UtilMMout_Of_Memory (long size)
 
abctime Extra_CpuTime ()
 
ABC_NAMESPACE_IMPL_END ABC_NAMESPACE_IMPL_START double Extra_CpuTimeDouble ()
 
void Extra_MemTest ()
 

Variables

const char * globalUtilOptarg
 
int globalUtilOptind = 0
 
void(* Extra_UtilMMoutOfMemory )(long size) = (void (*)( long size ))Extra_UtilMMout_Of_Memory
 

Macro Definition Documentation

◆ EXTRA_RLIMIT_DATA_DEFAULT

#define EXTRA_RLIMIT_DATA_DEFAULT   67108864

DECLARATIONS ///.

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

FileName [extraUtilUtil.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [extra]

Synopsis [Old SIS utilities.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

Id
extraUtilUtil.c,v 1.0 2003/02/01 00:00:00 alanmi Exp

]

Definition at line 31 of file extraUtilUtil.c.

Function Documentation

◆ Extra_CpuTime()

abctime Extra_CpuTime ( )

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

Synopsis [util_cpu_time()]

Description []

SideEffects []

SeeAlso []

Definition at line 364 of file extraUtilUtil.c.

365{
366 return Abc_Clock();
367}

◆ Extra_CpuTimeDouble()

ABC_NAMESPACE_IMPL_END ABC_NAMESPACE_IMPL_START double Extra_CpuTimeDouble ( )

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

Synopsis [util_cpu_time()]

Description []

SideEffects []

SeeAlso []

Definition at line 395 of file extraUtilUtil.c.

396{
397/*
398 struct rusage ru;
399 getrusage(RUSAGE_SELF, &ru);
400 return (double)ru.ru_utime.tv_sec + (double)ru.ru_utime.tv_usec / 1000000;
401*/
402 struct timespec ts;
403 if ( clock_gettime(CLOCK_MONOTONIC, &ts) < 0 )
404 return (double)-1;
405 double res = ((double) ts.tv_sec);
406 res += ((double) ts.tv_nsec) / 1000000000;
407 return res;
408}
Here is the caller graph for this function:

◆ Extra_GetSoftDataLimit()

int Extra_GetSoftDataLimit ( )

FUNCTION DEFINITIONS ///.

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

Synopsis [getSoftDataLimit()]

Description []

SideEffects []

SeeAlso []

Definition at line 64 of file extraUtilUtil.c.

65{
67}
#define EXTRA_RLIMIT_DATA_DEFAULT
DECLARATIONS ///.

◆ Extra_MemTest()

void Extra_MemTest ( )

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

Synopsis [Testing memory leaks.]

Description []

SideEffects []

SeeAlso []

Definition at line 422 of file extraUtilUtil.c.

423{
424// ABC_ALLOC( char, 1002 );
425}

◆ Extra_UtilCheckFile()

int Extra_UtilCheckFile ( char * filename,
const char * mode )

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

Synopsis [check_file()]

Description []

SideEffects []

SeeAlso []

Definition at line 242 of file extraUtilUtil.c.

243{
244 FILE *fp;
245 int got_file;
246
247 if (strcmp(mode, "x") == 0) {
248 mode = "r";
249 }
250 fp = fopen(filename, mode);
251 got_file = (fp != 0);
252 if (fp != 0) {
253 (void) fclose(fp);
254 }
255 return got_file;
256}
char * filename
Definition globals.c:40
Definition mode.h:11
int strcmp()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Extra_UtilFileSearch()

char * Extra_UtilFileSearch ( char * file,
char * path,
char * mode )

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

Synopsis [util_file_search()]

Description []

SideEffects []

SeeAlso []

Definition at line 269 of file extraUtilUtil.c.

273{
274 int quit;
275 char *buffer, *filename, *save_path, *cp;
276
277 if (path == 0 || strcmp(path, "") == 0) {
278 path = "."; /* just look in the current directory */
279 }
280
281 save_path = path = Extra_UtilStrsav(path);
282 quit = 0;
283 for (;;) {
284 cp = strchr(path, ':');
285 if (cp != 0) {
286 *cp = '\0';
287 } else {
288 quit = 1;
289 }
290
291 /* cons up the filename out of the path and file name */
292 if (strcmp(path, ".") == 0) {
293 buffer = Extra_UtilStrsav(file);
294 } else {
295 buffer = ABC_ALLOC(char, strlen(path) + strlen(file) + 4);
296 (void) sprintf(buffer, "%s/%s", path, file);
297 }
299 ABC_FREE(buffer);
300
301 /* see if we can access it */
303 ABC_FREE(save_path);
304 return filename;
305 }
307 if (quit) {
308 break;
309 } else {
310 path = ++cp;
311 }
312 }
313
314 ABC_FREE(save_path);
315 return 0;
316}
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
char * Extra_UtilStrsav(const char *s)
char * Extra_UtilTildeExpand(char *fname)
int Extra_UtilCheckFile(char *filename, const char *mode)
Definition file.h:23
int strlen()
char * sprintf()
char * strchr()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Extra_UtilGetopt()

int Extra_UtilGetopt ( int argc,
char * argv[],
const char * optstring )

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

Synopsis [util_getopt()]

Description []

SideEffects []

SeeAlso []

Definition at line 98 of file extraUtilUtil.c.

99{
100 int c;
101 const char *place;
102
103 globalUtilOptarg = NULL;
104
105 if (pScanStr == NULL || *pScanStr == '\0')
106 {
107 if (globalUtilOptind == 0)
109 if (globalUtilOptind >= argc)
110 return EOF;
111 place = argv[globalUtilOptind];
112 if (place[0] != '-' || place[1] == '\0')
113 return EOF;
115 if (place[1] == '-' && place[2] == '\0')
116 return EOF;
117 pScanStr = place+1;
118 }
119
120 c = *pScanStr++;
121 place = strchr(optstring, c);
122 if (place == NULL || c == ':') {
123 (void) fprintf(stderr, "%s: unknown option %c\n", argv[0], c);
124 return '?';
125 }
126 if (*++place == ':')
127 {
128 if (*pScanStr != '\0')
129 {
130 globalUtilOptarg = pScanStr;
131 pScanStr = NULL;
132 }
133 else
134 {
135 if (globalUtilOptind >= argc)
136 {
137 (void) fprintf(stderr, "%s: %c requires an argument\n",
138 argv[0], c);
139 return '?';
140 }
143 }
144 }
145 return c;
146}
int globalUtilOptind
const char * globalUtilOptarg
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Extra_UtilGetoptReset()

void Extra_UtilGetoptReset ( )

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

Synopsis [util_getopt_reset()]

Description []

SideEffects []

SeeAlso []

Definition at line 80 of file extraUtilUtil.c.

81{
84 pScanStr = 0;
85}
Here is the caller graph for this function:

◆ Extra_UtilMMout_Of_Memory()

void Extra_UtilMMout_Of_Memory ( long size)

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

Synopsis [MMout_of_memory()]

Description []

SideEffects []

SeeAlso []

Definition at line 330 of file extraUtilUtil.c.

331{
332 (void) fflush(stdout);
333 (void) fprintf(stderr, "\nout of memory allocating %u bytes\n",
334 (unsigned) size);
335 assert( 0 );
336 exit(1);
337}
#define assert(ex)
Definition util_old.h:213
VOID_HACK exit()
Here is the call graph for this function:

◆ Extra_UtilPrintTime()

char * Extra_UtilPrintTime ( long t)

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

Synopsis [util_print_time()]

Description []

SideEffects []

SeeAlso []

Definition at line 159 of file extraUtilUtil.c.

160{
161 static char s[40];
162
163 (void) sprintf(s, "%ld.%02ld sec", t/1000, (t%1000)/10);
164 return s;
165}
Here is the call graph for this function:

◆ Extra_UtilStrsav()

char * Extra_UtilStrsav ( const char * s)

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

Synopsis [Extra_UtilStrsav()]

Description []

SideEffects []

SeeAlso []

Definition at line 179 of file extraUtilUtil.c.

180{
181 if(s == NULL) { /* added 7/95, for robustness */
182 return NULL;
183 }
184 else {
185 return strcpy(ABC_ALLOC(char, strlen(s)+1), s);
186 }
187}
char * strcpy()
Here is the call graph for this function:

◆ Extra_UtilTildeExpand()

char * Extra_UtilTildeExpand ( char * fname)

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

Synopsis [util_tilde_expand()]

Description [The code contributed by Niklas Sorensson.]

SideEffects []

SeeAlso []

Definition at line 200 of file extraUtilUtil.c.

201{
202 return Extra_UtilStrsav( fname );
203/*
204 int n_tildes = 0;
205 const char* home;
206 char* expanded;
207 int length;
208 int i, j, k;
209
210 for (i = 0; i < (int)strlen(fname); i++)
211 if (fname[i] == '~') n_tildes++;
212
213 home = getenv("HOME");
214 length = n_tildes * strlen(home) + strlen(fname);
215 expanded = ABC_ALLOC(char, length + 1);
216
217 j = 0;
218 for (i = 0; i < (int)strlen(fname); i++){
219 if (fname[i] == '~'){
220 for (k = 0; k < (int)strlen(home); k++)
221 expanded[j++] = home[k];
222 }else
223 expanded[j++] = fname[i];
224 }
225
226 expanded[j] = '\0';
227 return expanded;
228*/
229}
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ Extra_UtilMMoutOfMemory

void(* Extra_UtilMMoutOfMemory) (long size) ( long size) = (void (*)( long size ))Extra_UtilMMout_Of_Memory

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

Synopsis [MMoutOfMemory()]

Description []

SideEffects []

SeeAlso []

Definition at line 350 of file extraUtilUtil.c.

◆ globalUtilOptarg

const char* globalUtilOptarg

Definition at line 44 of file extraUtilUtil.c.

◆ globalUtilOptind

int globalUtilOptind = 0

Definition at line 45 of file extraUtilUtil.c.