iscc: use simplified CLooG interface
[barvinok.git] / collect_polytopes2.c
blob1d9c219419cf4a07f9e59551fd8fc7d2b435de90
1 #include <assert.h>
2 #include <dlfcn.h>
3 #include <limits.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <barvinok/evalue.h>
8 #include <barvinok/barvinok.h>
10 /* gcc -shared -g collect_polytopes2.c -rdynamic -o libcollect2.so -ldl -lc -lgmp */
12 evalue* barvinok_enumerate_ev(Polyhedron *P, Polyhedron* C, unsigned MaxRays)
14 static evalue *(*orig)(Polyhedron *, Polyhedron *c, unsigned) = NULL;
15 static char *prefix = NULL;
16 evalue *res;
17 static int counter = 0;
19 fprintf(stderr, "IN INSTRUMENTED BARVINOK_ENUMERATE_EV");
20 fflush(stderr);
21 if (!orig) {
22 void *handle = dlopen("libbarvinok.so", RTLD_LAZY);
23 assert(handle);
24 orig = dlsym(handle, "barvinok_enumerate_ev");
25 assert(orig);
26 dlclose(handle);
28 prefix = getenv("POLYTOPE_PREFIX");
29 if (prefix)
30 prefix = strdup(prefix);
33 if (prefix) {
34 char path[PATH_MAX];
35 FILE *f;
36 int i, j;
37 unsigned nr, nc;
39 snprintf(path, PATH_MAX, "%s%05d", prefix, counter++);
40 f = fopen(path, "w");
41 fprintf(f, "%d %d\n", nr=P->NbConstraints, nc=P->Dimension+2);
42 for (i=0; i < nr; i++) {
43 for (j=0; j < nc; j++) {
44 value_print(f," "P_VALUE_FMT" ", P->Constraint[i][j]);
46 fprintf(f, "\n");
48 fprintf(f, "\n0 %d\n", C->Dimension+2);
49 fclose(f);
52 res = orig(P, C, MaxRays);
54 return res;