Polly 23.0.0git
ctx.h
Go to the documentation of this file.
1/*
2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 *
4 * Use of this software is governed by the MIT license
5 *
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
8 */
9
10#ifndef ISL_CTX_H
11#define ISL_CTX_H
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <string.h>
16
17#include <isl/arg.h>
18
19#ifndef __isl_give
20#define __isl_give
21#endif
22#ifndef __isl_take
23#define __isl_take
24#endif
25#ifndef __isl_keep
26#define __isl_keep
27#endif
28#ifndef __isl_null
29#define __isl_null
30#endif
31#ifndef __isl_export
32#define __isl_export
33#endif
34#ifndef __isl_overload
35#define __isl_overload
36#endif
37#ifndef __isl_constructor
38#define __isl_constructor
39#endif
40#ifndef __isl_subclass
41#define __isl_subclass(super)
42#endif
43
44#if defined(__cplusplus)
45extern "C" {
46#endif
47
48/* Nearly all isa functions require a struct isl_ctx allocated using
49 * isl_ctx_alloc. This ctx contains (or will contain) options that
50 * control the behavior of the library and some caches.
51 *
52 * An object allocated within a given ctx should never be used inside
53 * another ctx. Functions for moving objects from one ctx to another
54 * will be added as the need arises.
55 *
56 * A given context should only be used inside a single thread.
57 * A global context for synchronization between different threads
58 * as well as functions for moving a context to a different thread
59 * will be added as the need arises.
60 *
61 * If anything goes wrong (out of memory, failed assertion), then
62 * the library will currently simply abort. This will be made
63 * configurable in the future.
64 * Users of the library should expect functions that return
65 * a pointer to a structure, to return NULL, indicating failure.
66 * Any function accepting a pointer to a structure will treat
67 * a NULL argument as a failure, resulting in the function freeing
68 * the remaining structures (if any) and returning NULL itself
69 * (in case of pointer return type).
70 * The only exception is the isl_ctx argument, which should never be NULL.
71 */
72struct isl_stats {
74};
85typedef enum {
88} isl_stat;
89isl_stat isl_stat_non_null(const void *obj);
98typedef int isl_size;
99#define isl_size_error ((int) -1)
100struct isl_ctx;
101typedef struct isl_ctx isl_ctx;
102
103/* Some helper macros */
104
105#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
106#define ISL_DEPRECATED __attribute__((__deprecated__))
107#else
108#define ISL_DEPRECATED
109#endif
110
111#define ISL_FL_INIT(l, f) (l) = (f) /* Specific flags location. */
112#define ISL_FL_SET(l, f) ((l) |= (f))
113#define ISL_FL_CLR(l, f) ((l) &= ~(f))
114#define ISL_FL_ISSET(l, f) (!!((l) & (f)))
115
116#define ISL_F_INIT(p, f) ISL_FL_INIT((p)->flags, f) /* Structure element flags. */
117#define ISL_F_SET(p, f) ISL_FL_SET((p)->flags, f)
118#define ISL_F_CLR(p, f) ISL_FL_CLR((p)->flags, f)
119#define ISL_F_ISSET(p, f) ISL_FL_ISSET((p)->flags, f)
120
121void *isl_malloc_or_die(isl_ctx *ctx, size_t size);
122void *isl_calloc_or_die(isl_ctx *ctx, size_t nmemb, size_t size);
123void *isl_realloc_or_die(isl_ctx *ctx, void *ptr, size_t size);
124
125#define isl_alloc(ctx,type,size) ((type *)isl_malloc_or_die(ctx, size))
126#define isl_calloc(ctx,type,size) ((type *)isl_calloc_or_die(ctx,\
127 1, size))
128#define isl_realloc(ctx,ptr,type,size) ((type *)isl_realloc_or_die(ctx,\
129 ptr, size))
130#define isl_alloc_type(ctx,type) isl_alloc(ctx,type,sizeof(type))
131#define isl_calloc_type(ctx,type) isl_calloc(ctx,type,sizeof(type))
132#define isl_realloc_type(ctx,ptr,type) isl_realloc(ctx,ptr,type,sizeof(type))
133#define isl_alloc_array(ctx,type,n) isl_alloc(ctx,type,(n)*sizeof(type))
134#define isl_calloc_array(ctx,type,n) ((type *)isl_calloc_or_die(ctx,\
135 n, sizeof(type)))
136#define isl_realloc_array(ctx,ptr,type,n) \
137 isl_realloc(ctx,ptr,type,(n)*sizeof(type))
138
139#define isl_die(ctx,errno,msg,code) \
140 do { \
141 isl_handle_error(ctx, errno, msg, __FILE__, __LINE__); \
142 code; \
143 } while (0)
144
145void isl_handle_error(isl_ctx *ctx, enum isl_error error, const char *msg,
146 const char *file, int line);
147
148#define isl_assert4(ctx,test,code,errno) \
149 do { \
150 if (test) \
151 break; \
152 isl_die(ctx, errno, "Assertion \"" #test "\" failed", code); \
153 } while (0)
154#define isl_assert(ctx,test,code) \
155 isl_assert4(ctx,test,code,isl_error_unknown)
156
157#define isl_min(a,b) ((a < b) ? (a) : (b))
158
159/* struct isl_ctx functions */
160
162
164 __isl_take void *opt);
166void *isl_ctx_peek_options(isl_ctx *ctx, struct isl_args *args);
167int isl_ctx_parse_options(isl_ctx *ctx, int argc, char **argv, unsigned flags);
168void isl_ctx_ref(struct isl_ctx *ctx);
169void isl_ctx_deref(struct isl_ctx *ctx);
170void isl_ctx_free(isl_ctx *ctx);
171
172void isl_ctx_abort(isl_ctx *ctx);
173void isl_ctx_resume(isl_ctx *ctx);
174int isl_ctx_aborted(isl_ctx *ctx);
175
176void isl_ctx_set_max_operations(isl_ctx *ctx, unsigned long max_operations);
177unsigned long isl_ctx_get_max_operations(isl_ctx *ctx);
179
180#define ISL_ARG_CTX_DECL(prefix,st,args) \
181st *isl_ctx_peek_ ## prefix(isl_ctx *ctx);
182
183#define ISL_ARG_CTX_DEF(prefix,st,args) \
184st *isl_ctx_peek_ ## prefix(isl_ctx *ctx) \
185{ \
186 return (st *)isl_ctx_peek_options(ctx, &(args)); \
187}
188
189#define ISL_CTX_GET_INT_DEF(prefix,st,args,field) \
190int prefix ## _get_ ## field(isl_ctx *ctx) \
191{ \
192 st *options; \
193 options = isl_ctx_peek_ ## prefix(ctx); \
194 if (!options) \
195 isl_die(ctx, isl_error_invalid, \
196 "isl_ctx does not reference " #prefix, \
197 return -1); \
198 return options->field; \
199}
200
201#define ISL_CTX_SET_INT_DEF(prefix,st,args,field) \
202isl_stat prefix ## _set_ ## field(isl_ctx *ctx, int val) \
203{ \
204 st *options; \
205 options = isl_ctx_peek_ ## prefix(ctx); \
206 if (!options) \
207 isl_die(ctx, isl_error_invalid, \
208 "isl_ctx does not reference " #prefix, \
209 return isl_stat_error); \
210 options->field = val; \
211 return isl_stat_ok; \
212}
213
214#define ISL_CTX_GET_STR_DEF(prefix,st,args,field) \
215const char *prefix ## _get_ ## field(isl_ctx *ctx) \
216{ \
217 st *options; \
218 options = isl_ctx_peek_ ## prefix(ctx); \
219 if (!options) \
220 isl_die(ctx, isl_error_invalid, \
221 "isl_ctx does not reference " #prefix, \
222 return NULL); \
223 return options->field; \
224}
225
226#define ISL_CTX_SET_STR_DEF(prefix,st,args,field) \
227isl_stat prefix ## _set_ ## field(isl_ctx *ctx, const char *val) \
228{ \
229 st *options; \
230 options = isl_ctx_peek_ ## prefix(ctx); \
231 if (!options) \
232 isl_die(ctx, isl_error_invalid, \
233 "isl_ctx does not reference " #prefix, \
234 return isl_stat_error); \
235 if (!val) \
236 return isl_stat_error; \
237 free(options->field); \
238 options->field = strdup(val); \
239 if (!options->field) \
240 return isl_stat_error; \
241 return isl_stat_ok; \
242}
243
244#define ISL_CTX_APPEND_STR_LIST_DEF(prefix,st,args,field_n,field) \
245isl_stat prefix ## _append_ ## field(isl_ctx *ctx, const char *val) \
246{ \
247 st *options; \
248 options = isl_ctx_peek_ ## prefix(ctx); \
249 if (!options) \
250 isl_die(ctx, isl_error_invalid, \
251 "isl_ctx does not reference " #prefix, \
252 return isl_stat_error); \
253 if (!val) \
254 return isl_stat_error; \
255 return isl_arg_str_list_append(&options->field_n, \
256 &options->field, val); \
257}
258
259#define ISL_CTX_GET_BOOL_DEF(prefix,st,args,field) \
260 ISL_CTX_GET_INT_DEF(prefix,st,args,field)
261
262#define ISL_CTX_SET_BOOL_DEF(prefix,st,args,field) \
263 ISL_CTX_SET_INT_DEF(prefix,st,args,field)
264
265#define ISL_CTX_GET_CHOICE_DEF(prefix,st,args,field) \
266 ISL_CTX_GET_INT_DEF(prefix,st,args,field)
267
268#define ISL_CTX_SET_CHOICE_DEF(prefix,st,args,field) \
269 ISL_CTX_SET_INT_DEF(prefix,st,args,field)
270
272const char *isl_ctx_last_error_msg(isl_ctx *ctx);
273const char *isl_ctx_last_error_file(isl_ctx *ctx);
276void isl_ctx_set_error(isl_ctx *ctx, enum isl_error error);
277
278#if defined(__cplusplus)
279}
280#endif
281
282#endif
isl_ctx * isl_ctx_alloc_with_options(struct isl_args *args, __isl_take void *opt)
#define __isl_take
Definition ctx.h:23
const char * isl_ctx_last_error_file(isl_ctx *ctx)
Definition isl_ctx.c:347
enum isl_error isl_ctx_last_error(isl_ctx *ctx)
Definition isl_ctx.c:333
isl_stat
Definition ctx.h:85
@ isl_stat_error
Definition ctx.h:86
@ isl_stat_ok
Definition ctx.h:87
int isl_ctx_aborted(isl_ctx *ctx)
Definition isl_ctx.c:386
isl_ctx * isl_ctx_alloc(void)
Definition isl_ctx.c:273
void * isl_realloc_or_die(isl_ctx *ctx, void *ptr, size_t size)
Definition isl_ctx.c:121
void isl_handle_error(isl_ctx *ctx, enum isl_error error, const char *msg, const char *file, int line)
Definition isl_ctx.c:142
void isl_ctx_deref(struct isl_ctx *ctx)
Definition isl_ctx.c:287
unsigned long isl_ctx_get_max_operations(isl_ctx *ctx)
Definition isl_ctx.c:409
void isl_ctx_reset_operations(isl_ctx *ctx)
Definition isl_ctx.c:416
isl_bool isl_bool_ok(int b)
Definition isl_ctx.c:58
isl_error
Definition ctx.h:75
@ isl_error_unknown
Definition ctx.h:79
@ isl_error_abort
Definition ctx.h:77
@ isl_error_unsupported
Definition ctx.h:83
@ isl_error_invalid
Definition ctx.h:81
@ isl_error_internal
Definition ctx.h:80
@ isl_error_none
Definition ctx.h:76
@ isl_error_alloc
Definition ctx.h:78
@ isl_error_quota
Definition ctx.h:82
void isl_ctx_resume(isl_ctx *ctx)
Definition isl_ctx.c:380
isl_stat isl_stat_non_null(const void *obj)
Definition isl_ctx.c:34
void isl_ctx_reset_error(isl_ctx *ctx)
Definition isl_ctx.c:359
void * isl_calloc_or_die(isl_ctx *ctx, size_t nmemb, size_t size)
Definition isl_ctx.c:111
int isl_size
Definition ctx.h:98
void isl_ctx_set_error(isl_ctx *ctx, enum isl_error error)
Definition isl_ctx.c:369
int isl_ctx_last_error_line(isl_ctx *ctx)
Definition isl_ctx.c:354
void isl_ctx_abort(isl_ctx *ctx)
Definition isl_ctx.c:374
void isl_ctx_ref(struct isl_ctx *ctx)
Definition isl_ctx.c:282
isl_stat isl_stat_non_error_bool(isl_bool b)
Definition isl_ctx.c:22
struct isl_options * isl_ctx_options(isl_ctx *ctx)
Definition isl_ctx.c:326
isl_bool isl_bool_not(isl_bool b)
Definition isl_ctx.c:44
void * isl_malloc_or_die(isl_ctx *ctx, size_t size)
Definition isl_ctx.c:101
const char * isl_ctx_last_error_msg(isl_ctx *ctx)
Definition isl_ctx.c:340
isl_bool
Definition ctx.h:90
@ isl_bool_false
Definition ctx.h:92
@ isl_bool_true
Definition ctx.h:93
@ isl_bool_error
Definition ctx.h:91
void * isl_ctx_peek_options(isl_ctx *ctx, struct isl_args *args)
Definition isl_ctx.c:199
void isl_ctx_set_max_operations(isl_ctx *ctx, unsigned long max_operations)
Definition isl_ctx.c:400
int isl_ctx_parse_options(isl_ctx *ctx, int argc, char **argv, unsigned flags)
Definition isl_ctx.c:391
void isl_ctx_free(isl_ctx *ctx)
Definition isl_ctx.c:300
const char * obj
Definition isl_test.c:3109
b(9)
enum isl_error error
unsigned long max_operations
long gbr_solved_lps
Definition ctx.h:73