VPR-6.0

libvpr/include/util.h

Go to the documentation of this file.
00001 #ifndef UTIL_H
00002 #define UTIL_H
00003 
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 #include <math.h>
00007 
00008 #ifndef TRUE                    /* Some compilers predefine TRUE, FALSE */
00009 typedef enum
00010 { FALSE, TRUE }
00011 boolean;
00012 #else
00013 typedef int boolean;
00014 #endif
00015 
00016 /* Parameter tags for preprocessor to strip */
00017 #define INP
00018 #define OUTP
00019 #define INOUTP
00020 
00021 #define ERRTAG "ERROR:\t"
00022 #define WARNTAG "WARN:\t"
00023 
00024 extern int linenum;     /**< line in file being parsed */
00025 
00026 
00027 #define BUFSIZE 65536 /**<  Increased for MCML.blif     Maximum line length for various parsing proc. */
00028 #ifndef max
00029 #define max(a,b) (((a) > (b))? (a) : (b))
00030 #define min(a,b) ((a) > (b)? (b) : (a))
00031 #endif
00032 #define nint(a) ((int) floor (a + 0.5))
00033 
00034 extern int limit_value(int cur, int max, const char *name);
00035 
00036 /** Linked lists of void pointers. */
00037 struct s_linked_vptr
00038 {
00039     void *data_vptr;
00040     struct s_linked_vptr *next;
00041 };
00042 
00043 /** Linked lists of integers. */
00044 typedef struct s_linked_int
00045 {
00046     int data;
00047     struct s_linked_int *next;
00048 } t_linked_int;
00049 
00050 /** Integer vector.  nelem stores length, list[0..nelem-1] stores list of    
00051  * integers.                                                                
00052  */
00053 typedef struct s_ivec
00054 {
00055     int nelem;
00056     int *list;
00057 } t_ivec;
00058 
00059 
00060 /************************ Memory allocation routines *************************/
00061 
00062 extern void* my_malloc(size_t size);
00063 extern void* my_calloc(size_t nelem, size_t size);
00064 extern void *my_realloc(void *ptr, size_t size);
00065 extern void *my_chunk_malloc(size_t size, struct s_linked_vptr **chunk_ptr_head,
00066         int *mem_avail_ptr, char **next_mem_loc_ptr);
00067 extern void free_chunk_memory(struct s_linked_vptr *chunk_ptr_head);
00068 
00069 /******************* Linked list, matrix and vector utilities ****************/
00070 
00071 extern void free_ivec_vector(struct s_ivec *ivec_vector, int nrmin, int nrmax);
00072 extern void free_ivec_matrix(struct s_ivec **ivec_matrix, int nrmin,
00073         int nrmax, int ncmin, int ncmax);
00074 extern void free_ivec_matrix3(struct s_ivec ***ivec_matrix3, int nrmin,
00075         int nrmax, int ncmin, int ncmax, int ndmin, int ndmax);
00076 
00077 extern void** alloc_matrix(int nrmin, int nrmax, int ncmin, int ncmax,
00078         size_t elsize);
00079 extern void ***alloc_matrix3(int nrmin, int nrmax, int ncmin, int ncmax,
00080         int ndmin, int ndmax, size_t elsize);
00081 extern void ****alloc_matrix4(int nrmin, int nrmax, int ncmin, int ncmax,
00082         int ndmin, int ndmax, int nemin, int nemax, size_t elsize);
00083 
00084 extern void free_matrix(void *vptr, int nrmin, int nrmax, int ncmin,
00085         size_t elsize);
00086 extern void free_matrix3(void *vptr, int nrmin, int nrmax, int ncmin,
00087         int ncmax, int ndmin, size_t elsize);
00088 extern void free_matrix4(void *vptr, int nrmin, int nrmax, int ncmin,
00089         int ncmax, int ndmin, int ndmax, int nemin, size_t elsize);
00090 
00091 extern void print_int_matrix3(int ***vptr, int nrmin, int nrmax, int ncmin,
00092         int ncmax, int ndmin, int ndmax, char *file);
00093 
00094 extern struct s_linked_vptr *insert_in_vptr_list(struct s_linked_vptr *head,
00095         void *vptr_to_add);
00096 extern struct s_linked_vptr *delete_in_vptr_list(struct s_linked_vptr *head);
00097 extern t_linked_int *insert_in_int_list(t_linked_int * head,
00098         int data, t_linked_int ** free_list_head_ptr);
00099 extern void free_int_list(t_linked_int ** int_list_head_ptr);
00100 extern void alloc_ivector_and_copy_int_list(t_linked_int ** list_head_ptr,
00101         int num_items, struct s_ivec *ivec, t_linked_int ** free_list_head_ptr);
00102 
00103 /****************** File and parsing utilities *******************************/
00104 
00105 extern int my_atoi(const char *str);
00106 
00107 extern char* my_strdup(const char *str);
00108 extern char *my_strncpy(char *dest, const char *src, size_t size);
00109 extern char *my_strtok(char *ptr, char *tokens, FILE * fp, char *buf);
00110 
00111 extern FILE* my_fopen(const char *fname, const char *flag, int prompt);
00112 extern char *my_fgets(char *buf, int max_size, FILE * fp);
00113 
00114 /*********************** Portable random number generators *******************/
00115 extern void my_srandom(int seed);
00116 extern int my_irand(int imax);
00117 extern float my_frand(void);
00118 
00119 #endif
00120