2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
33 #ifndef __isl_constructor
34 #define __isl_constructor
36 #ifndef __isl_subclass
37 #define __isl_subclass(super)
40 #if defined(__cplusplus)
44 /* Nearly all isa functions require a struct isl_ctx allocated using
45 * isl_ctx_alloc. This ctx contains (or will contain) options that
46 * control the behavior of the library and some caches.
48 * An object allocated within a given ctx should never be used inside
49 * another ctx. Functions for moving objects from one ctx to another
50 * will be added as the need arises.
52 * A given context should only be used inside a single thread.
53 * A global context for synchronization between different threads
54 * as well as functions for moving a context to a different thread
55 * will be added as the need arises.
57 * If anything goes wrong (out of memory, failed assertion), then
58 * the library will currently simply abort. This will be made
59 * configurable in the future.
60 * Users of the library should expect functions that return
61 * a pointer to a structure, to return NULL, indicating failure.
62 * Any function accepting a pointer to a structure will treat
63 * a NULL argument as a failure, resulting in the function freeing
64 * the remaining structures (if any) and returning NULL itself
65 * (in case of pointer return type).
66 * The only exception is the isl_ctx argument, which should never be NULL.
91 typedef struct isl_ctx isl_ctx
;
93 /* Some helper macros */
95 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
96 #define ISL_DEPRECATED __attribute__((__deprecated__))
98 #define ISL_DEPRECATED
101 #define ISL_FL_INIT(l, f) (l) = (f) /* Specific flags location. */
102 #define ISL_FL_SET(l, f) ((l) |= (f))
103 #define ISL_FL_CLR(l, f) ((l) &= ~(f))
104 #define ISL_FL_ISSET(l, f) (!!((l) & (f)))
106 #define ISL_F_INIT(p, f) ISL_FL_INIT((p)->flags, f) /* Structure element flags. */
107 #define ISL_F_SET(p, f) ISL_FL_SET((p)->flags, f)
108 #define ISL_F_CLR(p, f) ISL_FL_CLR((p)->flags, f)
109 #define ISL_F_ISSET(p, f) ISL_FL_ISSET((p)->flags, f)
111 void *isl_malloc_or_die(isl_ctx
*ctx
, size_t size
);
112 void *isl_calloc_or_die(isl_ctx
*ctx
, size_t nmemb
, size_t size
);
113 void *isl_realloc_or_die(isl_ctx
*ctx
, void *ptr
, size_t size
);
115 #define isl_alloc(ctx,type,size) ((type *)isl_malloc_or_die(ctx, size))
116 #define isl_calloc(ctx,type,size) ((type *)isl_calloc_or_die(ctx,\
118 #define isl_realloc(ctx,ptr,type,size) ((type *)isl_realloc_or_die(ctx,\
120 #define isl_alloc_type(ctx,type) isl_alloc(ctx,type,sizeof(type))
121 #define isl_calloc_type(ctx,type) isl_calloc(ctx,type,sizeof(type))
122 #define isl_realloc_type(ctx,ptr,type) isl_realloc(ctx,ptr,type,sizeof(type))
123 #define isl_alloc_array(ctx,type,n) isl_alloc(ctx,type,(n)*sizeof(type))
124 #define isl_calloc_array(ctx,type,n) ((type *)isl_calloc_or_die(ctx,\
126 #define isl_realloc_array(ctx,ptr,type,n) \
127 isl_realloc(ctx,ptr,type,(n)*sizeof(type))
129 #define isl_die(ctx,errno,msg,code) \
131 isl_handle_error(ctx, errno, msg, __FILE__, __LINE__); \
135 void isl_handle_error(isl_ctx
*ctx
, enum isl_error error
, const char *msg
,
136 const char *file
, int line
);
138 #define isl_assert4(ctx,test,code,errno) \
142 isl_die(ctx, errno, "Assertion \"" #test "\" failed", code); \
144 #define isl_assert(ctx,test,code) \
145 isl_assert4(ctx,test,code,isl_error_unknown)
147 #define isl_min(a,b) ((a < b) ? (a) : (b))
149 /* struct isl_ctx functions */
151 struct isl_options
*isl_ctx_options(isl_ctx
*ctx
);
153 isl_ctx
*isl_ctx_alloc_with_options(struct isl_args
*args
,
154 __isl_take
void *opt
);
155 isl_ctx
*isl_ctx_alloc(void);
156 void *isl_ctx_peek_options(isl_ctx
*ctx
, struct isl_args
*args
);
157 int isl_ctx_parse_options(isl_ctx
*ctx
, int argc
, char **argv
, unsigned flags
);
158 void isl_ctx_ref(struct isl_ctx
*ctx
);
159 void isl_ctx_deref(struct isl_ctx
*ctx
);
160 void isl_ctx_free(isl_ctx
*ctx
);
162 void isl_ctx_abort(isl_ctx
*ctx
);
163 void isl_ctx_resume(isl_ctx
*ctx
);
164 int isl_ctx_aborted(isl_ctx
*ctx
);
166 void isl_ctx_set_max_operations(isl_ctx
*ctx
, unsigned long max_operations
);
167 unsigned long isl_ctx_get_max_operations(isl_ctx
*ctx
);
168 void isl_ctx_reset_operations(isl_ctx
*ctx
);
170 #define ISL_ARG_CTX_DECL(prefix,st,args) \
171 st *isl_ctx_peek_ ## prefix(isl_ctx *ctx);
173 #define ISL_ARG_CTX_DEF(prefix,st,args) \
174 st *isl_ctx_peek_ ## prefix(isl_ctx *ctx) \
176 return (st *)isl_ctx_peek_options(ctx, &(args)); \
179 #define ISL_CTX_GET_INT_DEF(prefix,st,args,field) \
180 int prefix ## _get_ ## field(isl_ctx *ctx) \
183 options = isl_ctx_peek_ ## prefix(ctx); \
185 isl_die(ctx, isl_error_invalid, \
186 "isl_ctx does not reference " #prefix, \
188 return options->field; \
191 #define ISL_CTX_SET_INT_DEF(prefix,st,args,field) \
192 isl_stat prefix ## _set_ ## field(isl_ctx *ctx, int val) \
195 options = isl_ctx_peek_ ## prefix(ctx); \
197 isl_die(ctx, isl_error_invalid, \
198 "isl_ctx does not reference " #prefix, \
199 return isl_stat_error); \
200 options->field = val; \
201 return isl_stat_ok; \
204 #define ISL_CTX_GET_STR_DEF(prefix,st,args,field) \
205 const char *prefix ## _get_ ## field(isl_ctx *ctx) \
208 options = isl_ctx_peek_ ## prefix(ctx); \
210 isl_die(ctx, isl_error_invalid, \
211 "isl_ctx does not reference " #prefix, \
213 return options->field; \
216 #define ISL_CTX_SET_STR_DEF(prefix,st,args,field) \
217 isl_stat prefix ## _set_ ## field(isl_ctx *ctx, const char *val) \
220 options = isl_ctx_peek_ ## prefix(ctx); \
222 isl_die(ctx, isl_error_invalid, \
223 "isl_ctx does not reference " #prefix, \
224 return isl_stat_error); \
226 return isl_stat_error; \
227 free(options->field); \
228 options->field = strdup(val); \
229 if (!options->field) \
230 return isl_stat_error; \
231 return isl_stat_ok; \
234 #define ISL_CTX_GET_BOOL_DEF(prefix,st,args,field) \
235 ISL_CTX_GET_INT_DEF(prefix,st,args,field)
237 #define ISL_CTX_SET_BOOL_DEF(prefix,st,args,field) \
238 ISL_CTX_SET_INT_DEF(prefix,st,args,field)
240 #define ISL_CTX_GET_CHOICE_DEF(prefix,st,args,field) \
241 ISL_CTX_GET_INT_DEF(prefix,st,args,field)
243 #define ISL_CTX_SET_CHOICE_DEF(prefix,st,args,field) \
244 ISL_CTX_SET_INT_DEF(prefix,st,args,field)
246 enum isl_error
isl_ctx_last_error(isl_ctx
*ctx
);
247 void isl_ctx_reset_error(isl_ctx
*ctx
);
248 void isl_ctx_set_error(isl_ctx
*ctx
, enum isl_error error
);
250 #if defined(__cplusplus)