ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
libSupport.c File Reference
#include <stdio.h>
#include <string.h>
#include "base/abc/abc.h"
#include "mainInt.h"
#include <sys/types.h>
#include <dirent.h>
#include <dlfcn.h>
Include dependency graph for libSupport.c:

Go to the source code of this file.

Macros

#define MAX_LIBS   256
 

Typedefs

typedef void(* lib_init_end_func) (Abc_Frame_t *pAbc)
 

Functions

void open_libs ()
 
void close_libs ()
 
void * get_fnct_ptr (int lib_num, char *sym_name)
 
void call_inits (Abc_Frame_t *pAbc)
 
void call_ends (Abc_Frame_t *pAbc)
 
void Libs_Init (Abc_Frame_t *pAbc)
 
void Libs_End (Abc_Frame_t *pAbc)
 

Macro Definition Documentation

◆ MAX_LIBS

#define MAX_LIBS   256

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

FileName [libSupport.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [The main package.]

Synopsis [Support for external libaries.]

Author [Mike Case]

Affiliation [UC Berkeley]

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

Revision [

Id
libSupport.c,v 1.1 2005/09/06 19:59:51 casem Exp

]

Definition at line 47 of file libSupport.c.

Typedef Documentation

◆ lib_init_end_func

typedef void(* lib_init_end_func) (Abc_Frame_t *pAbc)

Definition at line 50 of file libSupport.c.

Function Documentation

◆ call_ends()

void call_ends ( Abc_Frame_t * pAbc)

Definition at line 187 of file libSupport.c.

187 {
188 int i;
189 lib_init_end_func end_func;
190 for (i = 0; libHandles[i] != 0; i++) {
191 end_func = (lib_init_end_func) get_fnct_ptr(i, "abc_end");
192 if (end_func == 0) {
193 printf("Warning: Failed to end library %d.\n", i);
194 } else {
195 (*end_func)(pAbc);
196 }
197 }
198}
void(* lib_init_end_func)(Abc_Frame_t *pAbc)
Definition libSupport.c:50
void * get_fnct_ptr(int lib_num, char *sym_name)
Definition libSupport.c:159
Here is the call graph for this function:
Here is the caller graph for this function:

◆ call_inits()

void call_inits ( Abc_Frame_t * pAbc)

Definition at line 171 of file libSupport.c.

171 {
172 int i;
173 lib_init_end_func init_func;
174 for (i = 0; libHandles[i] != 0; i++) {
175 init_func = (lib_init_end_func) get_fnct_ptr(i, "abc_init");
176 if (init_func == 0) {
177 printf("Warning: Failed to initialize library %d.\n", i);
178 } else {
179 (*init_func)(pAbc);
180 }
181 }
182}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ close_libs()

void close_libs ( )

Definition at line 142 of file libSupport.c.

142 {
143#ifdef WIN32
144 printf("Warning: close_libs WIN32 not implemented.\n");
145#else
146 int i;
147 for (i = 0; libHandles[i] != 0; i++) {
148 if (dlclose(libHandles[i]) != 0) {
149 printf("Warning: failed to close library %d\n", i);
150 }
151 libHandles[i] = 0;
152 }
153#endif
154}

◆ get_fnct_ptr()

void * get_fnct_ptr ( int lib_num,
char * sym_name )

Definition at line 159 of file libSupport.c.

159 {
160#ifdef WIN32
161 printf("Warning: get_fnct_ptr WIN32 not implemented.\n");
162 return 0;
163#else
164 return dlsym(libHandles[lib_num], sym_name);
165#endif
166}
Here is the caller graph for this function:

◆ Libs_End()

void Libs_End ( Abc_Frame_t * pAbc)

Definition at line 206 of file libSupport.c.

207{
208 call_ends(pAbc);
209
210 // It's good practice to close our libraries at this point, but this can mess up any backtrace printed by Valgind.
211 // close_libs();
212}
void call_ends(Abc_Frame_t *pAbc)
Definition libSupport.c:187
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Libs_Init()

void Libs_Init ( Abc_Frame_t * pAbc)

Definition at line 200 of file libSupport.c.

201{
202 open_libs();
203 call_inits(pAbc);
204}
void open_libs()
Definition libSupport.c:55
void call_inits(Abc_Frame_t *pAbc)
Definition libSupport.c:171
Here is the call graph for this function:
Here is the caller graph for this function:

◆ open_libs()

void open_libs ( )

Definition at line 55 of file libSupport.c.

55 {
56 int curr_lib = 0;
57
58#ifdef WIN32
59// printf("Warning: open_libs WIN32 not implemented.\n");
60#else
61 DIR* dirp;
62 struct dirent* dp;
63 char *env, *init_p, *p;
64 //int done;
65
66 env = getenv ("ABC_LIB_PATH");
67 if (env == NULL) {
68// printf("Warning: ABC_LIB_PATH not defined. Looking into the current directory.\n");
69 init_p = ABC_ALLOC( char, (2*sizeof(char)) );
70 init_p[0]='.'; init_p[1] = 0;
71 } else {
72 init_p = ABC_ALLOC( char, ((strlen(env)+1)*sizeof(char)) );
73 strcpy (init_p, env);
74 }
75
76 // Extract directories and read libraries
77 //done = 0;
78 p = init_p;
79 //while (!done) {
80 for (;;) {
81 char *endp = strchr (p,':');
82 //if (endp == NULL) done = 1; // last directory in the list
83 //else *endp = 0; // end of string
84 if (endp != NULL) *endp = 0; // end of string
85
86 dirp = opendir(p);
87 if (dirp == NULL) {
88// printf("Warning: directory in ABC_LIB_PATH does not exist (%s).\n", p);
89 continue;
90 }
91
92 while ((dp = readdir(dirp)) != NULL) {
93 if ((strncmp("libabc_", dp->d_name, 7) == 0) &&
94 (strcmp(".so", dp->d_name + strlen(dp->d_name) - 3) == 0)) {
95
96 // make sure we don't overflow the handle array
97 if (curr_lib >= MAX_LIBS) {
98 printf("Warning: maximum number of ABC libraries (%d) exceeded. Not loading %s.\n",
100 dp->d_name);
101 }
102
103 // attempt to load it
104 else {
105 char* szPrefixed = ABC_ALLOC( char, ((strlen(dp->d_name) + strlen(p) + 2) *
106 sizeof(char)) );
107 sprintf(szPrefixed, "%s/", p);
108 strcat(szPrefixed, dp->d_name);
109 libHandles[curr_lib] = dlopen(szPrefixed, RTLD_NOW | RTLD_LOCAL);
110
111 // did the load succeed?
112 if (libHandles[curr_lib] != 0) {
113 printf("Loaded ABC library: %s (Abc library extension #%d)\n", szPrefixed, curr_lib);
114 curr_lib++;
115 } else {
116 printf("Warning: failed to load ABC library %s:\n\t%s\n", szPrefixed, dlerror());
117 }
118
119 ABC_FREE(szPrefixed);
120 }
121 }
122 }
123 closedir(dirp);
124 //p = endp+1;
125 if (endp == NULL) {
126 break; // last directory in the list
127 } else {
128 p = endp+1;
129 }
130 }
131
132 ABC_FREE(init_p);
133#endif
134
135 // null terminate the list of handles
136 libHandles[curr_lib] = 0;
137}
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#define DIR
Definition build.h:8
Cube * p
Definition exorList.c:222
#define MAX_LIBS
Definition libSupport.c:47
int strncmp()
int strlen()
int strcmp()
char * sprintf()
char * strcpy()
char * getenv()
char * strchr()
char * strcat()
Here is the call graph for this function:
Here is the caller graph for this function: