remove spurious include of isl/config.h
[isl.git] / include / isl / ctx.h
blob1eff415b4f8923914e0d0903e7429ba73d8bc42f
1 /*
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
8 */
10 #ifndef ISL_CTX_H
11 #define ISL_CTX_H
13 #include <stdio.h>
14 #include <stdlib.h>
16 #include <isl/arg.h>
17 #include <isl/hash.h>
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_constructor
35 #define __isl_constructor
36 #endif
37 #ifndef __isl_subclass
38 #define __isl_subclass(super)
39 #endif
41 #if defined(__cplusplus)
42 extern "C" {
43 #endif
45 /* Nearly all isa functions require a struct isl_ctx allocated using
46 * isl_ctx_alloc. This ctx contains (or will contain) options that
47 * control the behavior of the library and some caches.
49 * An object allocated within a given ctx should never be used inside
50 * another ctx. Functions for moving objects from one ctx to another
51 * will be added as the need arises.
53 * A given context should only be used inside a single thread.
54 * A global context for synchronization between different threads
55 * as well as functions for moving a context to a different thread
56 * will be added as the need arises.
58 * If anything goes wrong (out of memory, failed assertion), then
59 * the library will currently simply abort. This will be made
60 * configurable in the future.
61 * Users of the library should expect functions that return
62 * a pointer to a structure, to return NULL, indicating failure.
63 * Any function accepting a pointer to a structure will treat
64 * a NULL argument as a failure, resulting in the function freeing
65 * the remaining structures (if any) and returning NULL itself
66 * (in case of pointer return type).
67 * The only exception is the isl_ctx argument, which should never be NULL.
69 struct isl_stats {
70 long gbr_solved_lps;
72 enum isl_error {
73 isl_error_none = 0,
74 isl_error_abort,
75 isl_error_alloc,
76 isl_error_unknown,
77 isl_error_internal,
78 isl_error_invalid,
79 isl_error_quota,
80 isl_error_unsupported
82 struct isl_ctx;
83 typedef struct isl_ctx isl_ctx;
85 /* Some helper macros */
87 #define ISL_FL_INIT(l, f) (l) = (f) /* Specific flags location. */
88 #define ISL_FL_SET(l, f) ((l) |= (f))
89 #define ISL_FL_CLR(l, f) ((l) &= ~(f))
90 #define ISL_FL_ISSET(l, f) (!!((l) & (f)))
92 #define ISL_F_INIT(p, f) ISL_FL_INIT((p)->flags, f) /* Structure element flags. */
93 #define ISL_F_SET(p, f) ISL_FL_SET((p)->flags, f)
94 #define ISL_F_CLR(p, f) ISL_FL_CLR((p)->flags, f)
95 #define ISL_F_ISSET(p, f) ISL_FL_ISSET((p)->flags, f)
97 void *isl_malloc_or_die(isl_ctx *ctx, size_t size);
98 void *isl_calloc_or_die(isl_ctx *ctx, size_t nmemb, size_t size);
99 void *isl_realloc_or_die(isl_ctx *ctx, void *ptr, size_t size);
101 #define isl_alloc(ctx,type,size) ((type *)isl_malloc_or_die(ctx, size))
102 #define isl_calloc(ctx,type,size) ((type *)isl_calloc_or_die(ctx,\
103 1, size))
104 #define isl_realloc(ctx,ptr,type,size) ((type *)isl_realloc_or_die(ctx,\
105 ptr, size))
106 #define isl_alloc_type(ctx,type) isl_alloc(ctx,type,sizeof(type))
107 #define isl_calloc_type(ctx,type) isl_calloc(ctx,type,sizeof(type))
108 #define isl_realloc_type(ctx,ptr,type) isl_realloc(ctx,ptr,type,sizeof(type))
109 #define isl_alloc_array(ctx,type,n) isl_alloc(ctx,type,(n)*sizeof(type))
110 #define isl_calloc_array(ctx,type,n) ((type *)isl_calloc_or_die(ctx,\
111 n, sizeof(type)))
112 #define isl_realloc_array(ctx,ptr,type,n) \
113 isl_realloc(ctx,ptr,type,(n)*sizeof(type))
115 #define isl_die(ctx,errno,msg,code) \
116 do { \
117 isl_handle_error(ctx, errno, msg, __FILE__, __LINE__); \
118 code; \
119 } while (0)
121 void isl_handle_error(isl_ctx *ctx, enum isl_error error, const char *msg,
122 const char *file, int line);
124 #define isl_assert4(ctx,test,code,errno) \
125 do { \
126 if (test) \
127 break; \
128 isl_die(ctx, errno, "Assertion \"" #test "\" failed", code); \
129 } while (0)
130 #define isl_assert(ctx,test,code) \
131 isl_assert4(ctx,test,code,isl_error_unknown)
133 #define isl_min(a,b) ((a < b) ? (a) : (b))
135 /* struct isl_ctx functions */
137 struct isl_options *isl_ctx_options(isl_ctx *ctx);
139 isl_ctx *isl_ctx_alloc_with_options(struct isl_args *args,
140 __isl_take void *opt);
141 isl_ctx *isl_ctx_alloc(void);
142 void *isl_ctx_peek_options(isl_ctx *ctx, struct isl_args *args);
143 int isl_ctx_parse_options(isl_ctx *ctx, int argc, char **argv, unsigned flags);
144 void isl_ctx_ref(struct isl_ctx *ctx);
145 void isl_ctx_deref(struct isl_ctx *ctx);
146 void isl_ctx_free(isl_ctx *ctx);
148 void isl_ctx_abort(isl_ctx *ctx);
149 void isl_ctx_resume(isl_ctx *ctx);
150 int isl_ctx_aborted(isl_ctx *ctx);
152 void isl_ctx_set_max_operations(isl_ctx *ctx, unsigned long max_operations);
153 unsigned long isl_ctx_get_max_operations(isl_ctx *ctx);
154 void isl_ctx_reset_operations(isl_ctx *ctx);
156 #define ISL_ARG_CTX_DECL(prefix,st,args) \
157 st *isl_ctx_peek_ ## prefix(isl_ctx *ctx);
159 #define ISL_ARG_CTX_DEF(prefix,st,args) \
160 st *isl_ctx_peek_ ## prefix(isl_ctx *ctx) \
162 return (st *)isl_ctx_peek_options(ctx, &(args)); \
165 #define ISL_CTX_GET_INT_DEF(prefix,st,args,field) \
166 int prefix ## _get_ ## field(isl_ctx *ctx) \
168 st *options; \
169 options = isl_ctx_peek_ ## prefix(ctx); \
170 if (!options) \
171 isl_die(ctx, isl_error_invalid, \
172 "isl_ctx does not reference " #prefix, \
173 return -1); \
174 return options->field; \
177 #define ISL_CTX_SET_INT_DEF(prefix,st,args,field) \
178 int prefix ## _set_ ## field(isl_ctx *ctx, int val) \
180 st *options; \
181 options = isl_ctx_peek_ ## prefix(ctx); \
182 if (!options) \
183 isl_die(ctx, isl_error_invalid, \
184 "isl_ctx does not reference " #prefix, \
185 return -1); \
186 options->field = val; \
187 return 0; \
190 #define ISL_CTX_GET_STR_DEF(prefix,st,args,field) \
191 const char *prefix ## _get_ ## field(isl_ctx *ctx) \
193 st *options; \
194 options = isl_ctx_peek_ ## prefix(ctx); \
195 if (!options) \
196 isl_die(ctx, isl_error_invalid, \
197 "isl_ctx does not reference " #prefix, \
198 return NULL); \
199 return options->field; \
202 #define ISL_CTX_SET_STR_DEF(prefix,st,args,field) \
203 int prefix ## _set_ ## field(isl_ctx *ctx, const char *val) \
205 st *options; \
206 options = isl_ctx_peek_ ## prefix(ctx); \
207 if (!options) \
208 isl_die(ctx, isl_error_invalid, \
209 "isl_ctx does not reference " #prefix, \
210 return -1); \
211 if (!val) \
212 return -1; \
213 free(options->field); \
214 options->field = strdup(val); \
215 if (!options->field) \
216 return -1; \
217 return 0; \
220 #define ISL_CTX_GET_BOOL_DEF(prefix,st,args,field) \
221 ISL_CTX_GET_INT_DEF(prefix,st,args,field)
223 #define ISL_CTX_SET_BOOL_DEF(prefix,st,args,field) \
224 ISL_CTX_SET_INT_DEF(prefix,st,args,field)
226 #define ISL_CTX_GET_CHOICE_DEF(prefix,st,args,field) \
227 ISL_CTX_GET_INT_DEF(prefix,st,args,field)
229 #define ISL_CTX_SET_CHOICE_DEF(prefix,st,args,field) \
230 ISL_CTX_SET_INT_DEF(prefix,st,args,field)
232 enum isl_error isl_ctx_last_error(isl_ctx *ctx);
233 void isl_ctx_reset_error(isl_ctx *ctx);
234 void isl_ctx_set_error(isl_ctx *ctx, enum isl_error error);
236 #if defined(__cplusplus)
238 #endif
240 #endif