remove WARN_UNUSED from public header
[isl.git] / include / isl / ctx.h
blob777ba6509ab25c874f244280f8cd297dd2fbf02b
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>
18 #include <isl/config.h>
20 #ifndef __isl_give
21 #define __isl_give
22 #endif
23 #ifndef __isl_take
24 #define __isl_take
25 #endif
26 #ifndef __isl_keep
27 #define __isl_keep
28 #endif
29 #ifndef __isl_null
30 #define __isl_null
31 #endif
32 #ifndef __isl_export
33 #define __isl_export
34 #endif
35 #ifndef __isl_constructor
36 #define __isl_constructor
37 #endif
38 #ifndef __isl_subclass
39 #define __isl_subclass(super)
40 #endif
42 #if defined(__cplusplus)
43 extern "C" {
44 #endif
46 /* Nearly all isa functions require a struct isl_ctx allocated using
47 * isl_ctx_alloc. This ctx contains (or will contain) options that
48 * control the behavior of the library and some caches.
50 * An object allocated within a given ctx should never be used inside
51 * another ctx. Functions for moving objects from one ctx to another
52 * will be added as the need arises.
54 * A given context should only be used inside a single thread.
55 * A global context for synchronization between different threads
56 * as well as functions for moving a context to a different thread
57 * will be added as the need arises.
59 * If anything goes wrong (out of memory, failed assertion), then
60 * the library will currently simply abort. This will be made
61 * configurable in the future.
62 * Users of the library should expect functions that return
63 * a pointer to a structure, to return NULL, indicating failure.
64 * Any function accepting a pointer to a structure will treat
65 * a NULL argument as a failure, resulting in the function freeing
66 * the remaining structures (if any) and returning NULL itself
67 * (in case of pointer return type).
68 * The only exception is the isl_ctx argument, which should never be NULL.
70 struct isl_stats {
71 long gbr_solved_lps;
73 enum isl_error {
74 isl_error_none = 0,
75 isl_error_abort,
76 isl_error_alloc,
77 isl_error_unknown,
78 isl_error_internal,
79 isl_error_invalid,
80 isl_error_quota,
81 isl_error_unsupported
83 struct isl_ctx;
84 typedef struct isl_ctx isl_ctx;
86 /* Some helper macros */
88 #define ISL_FL_INIT(l, f) (l) = (f) /* Specific flags location. */
89 #define ISL_FL_SET(l, f) ((l) |= (f))
90 #define ISL_FL_CLR(l, f) ((l) &= ~(f))
91 #define ISL_FL_ISSET(l, f) (!!((l) & (f)))
93 #define ISL_F_INIT(p, f) ISL_FL_INIT((p)->flags, f) /* Structure element flags. */
94 #define ISL_F_SET(p, f) ISL_FL_SET((p)->flags, f)
95 #define ISL_F_CLR(p, f) ISL_FL_CLR((p)->flags, f)
96 #define ISL_F_ISSET(p, f) ISL_FL_ISSET((p)->flags, f)
98 void *isl_malloc_or_die(isl_ctx *ctx, size_t size);
99 void *isl_calloc_or_die(isl_ctx *ctx, size_t nmemb, size_t size);
100 void *isl_realloc_or_die(isl_ctx *ctx, void *ptr, size_t size);
102 #define isl_alloc(ctx,type,size) ((type *)isl_malloc_or_die(ctx, size))
103 #define isl_calloc(ctx,type,size) ((type *)isl_calloc_or_die(ctx,\
104 1, size))
105 #define isl_realloc(ctx,ptr,type,size) ((type *)isl_realloc_or_die(ctx,\
106 ptr, size))
107 #define isl_alloc_type(ctx,type) isl_alloc(ctx,type,sizeof(type))
108 #define isl_calloc_type(ctx,type) isl_calloc(ctx,type,sizeof(type))
109 #define isl_realloc_type(ctx,ptr,type) isl_realloc(ctx,ptr,type,sizeof(type))
110 #define isl_alloc_array(ctx,type,n) isl_alloc(ctx,type,(n)*sizeof(type))
111 #define isl_calloc_array(ctx,type,n) ((type *)isl_calloc_or_die(ctx,\
112 n, sizeof(type)))
113 #define isl_realloc_array(ctx,ptr,type,n) \
114 isl_realloc(ctx,ptr,type,(n)*sizeof(type))
116 #define isl_die(ctx,errno,msg,code) \
117 do { \
118 isl_handle_error(ctx, errno, msg, __FILE__, __LINE__); \
119 code; \
120 } while (0)
122 void isl_handle_error(isl_ctx *ctx, enum isl_error error, const char *msg,
123 const char *file, int line);
125 #define isl_assert4(ctx,test,code,errno) \
126 do { \
127 if (test) \
128 break; \
129 isl_die(ctx, errno, "Assertion \"" #test "\" failed", code); \
130 } while (0)
131 #define isl_assert(ctx,test,code) \
132 isl_assert4(ctx,test,code,isl_error_unknown)
134 #define isl_min(a,b) ((a < b) ? (a) : (b))
136 /* struct isl_ctx functions */
138 struct isl_options *isl_ctx_options(isl_ctx *ctx);
140 isl_ctx *isl_ctx_alloc_with_options(struct isl_args *args,
141 __isl_take void *opt);
142 isl_ctx *isl_ctx_alloc(void);
143 void *isl_ctx_peek_options(isl_ctx *ctx, struct isl_args *args);
144 int isl_ctx_parse_options(isl_ctx *ctx, int argc, char **argv, unsigned flags);
145 void isl_ctx_ref(struct isl_ctx *ctx);
146 void isl_ctx_deref(struct isl_ctx *ctx);
147 void isl_ctx_free(isl_ctx *ctx);
149 void isl_ctx_abort(isl_ctx *ctx);
150 void isl_ctx_resume(isl_ctx *ctx);
151 int isl_ctx_aborted(isl_ctx *ctx);
153 void isl_ctx_set_max_operations(isl_ctx *ctx, unsigned long max_operations);
154 unsigned long isl_ctx_get_max_operations(isl_ctx *ctx);
155 void isl_ctx_reset_operations(isl_ctx *ctx);
157 #define ISL_ARG_CTX_DECL(prefix,st,args) \
158 st *isl_ctx_peek_ ## prefix(isl_ctx *ctx);
160 #define ISL_ARG_CTX_DEF(prefix,st,args) \
161 st *isl_ctx_peek_ ## prefix(isl_ctx *ctx) \
163 return (st *)isl_ctx_peek_options(ctx, &(args)); \
166 #define ISL_CTX_GET_INT_DEF(prefix,st,args,field) \
167 int prefix ## _get_ ## field(isl_ctx *ctx) \
169 st *options; \
170 options = isl_ctx_peek_ ## prefix(ctx); \
171 if (!options) \
172 isl_die(ctx, isl_error_invalid, \
173 "isl_ctx does not reference " #prefix, \
174 return -1); \
175 return options->field; \
178 #define ISL_CTX_SET_INT_DEF(prefix,st,args,field) \
179 int prefix ## _set_ ## field(isl_ctx *ctx, int val) \
181 st *options; \
182 options = isl_ctx_peek_ ## prefix(ctx); \
183 if (!options) \
184 isl_die(ctx, isl_error_invalid, \
185 "isl_ctx does not reference " #prefix, \
186 return -1); \
187 options->field = val; \
188 return 0; \
191 #define ISL_CTX_GET_STR_DEF(prefix,st,args,field) \
192 const char *prefix ## _get_ ## field(isl_ctx *ctx) \
194 st *options; \
195 options = isl_ctx_peek_ ## prefix(ctx); \
196 if (!options) \
197 isl_die(ctx, isl_error_invalid, \
198 "isl_ctx does not reference " #prefix, \
199 return NULL); \
200 return options->field; \
203 #define ISL_CTX_SET_STR_DEF(prefix,st,args,field) \
204 int prefix ## _set_ ## field(isl_ctx *ctx, const char *val) \
206 st *options; \
207 options = isl_ctx_peek_ ## prefix(ctx); \
208 if (!options) \
209 isl_die(ctx, isl_error_invalid, \
210 "isl_ctx does not reference " #prefix, \
211 return -1); \
212 if (!val) \
213 return -1; \
214 free(options->field); \
215 options->field = strdup(val); \
216 if (!options->field) \
217 return -1; \
218 return 0; \
221 #define ISL_CTX_GET_BOOL_DEF(prefix,st,args,field) \
222 ISL_CTX_GET_INT_DEF(prefix,st,args,field)
224 #define ISL_CTX_SET_BOOL_DEF(prefix,st,args,field) \
225 ISL_CTX_SET_INT_DEF(prefix,st,args,field)
227 #define ISL_CTX_GET_CHOICE_DEF(prefix,st,args,field) \
228 ISL_CTX_GET_INT_DEF(prefix,st,args,field)
230 #define ISL_CTX_SET_CHOICE_DEF(prefix,st,args,field) \
231 ISL_CTX_SET_INT_DEF(prefix,st,args,field)
233 enum isl_error isl_ctx_last_error(isl_ctx *ctx);
234 void isl_ctx_reset_error(isl_ctx *ctx);
235 void isl_ctx_set_error(isl_ctx *ctx, enum isl_error error);
237 #if defined(__cplusplus)
239 #endif
241 #endif