add tile_shift_point_loops option
[platform/upstream/isl.git] / include / isl / ctx.h
index 7155577..3d88697 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2008-2009 Katholieke Universiteit Leuven
  *
- * Use of this software is governed by the GNU LGPLv2.1 license
+ * Use of this software is governed by the MIT license
  *
  * Written by Sven Verdoolaege, K.U.Leuven, Departement
  * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
@@ -14,8 +14,8 @@
 #include <stdlib.h>
 
 #include <isl/int.h>
-#include <isl/options.h>
 #include <isl/blk.h>
+#include <isl/arg.h>
 #include <isl/hash.h>
 #include <isl/config.h>
 
@@ -102,28 +102,32 @@ typedef struct isl_ctx isl_ctx;
  * returns the value of 'expr'. It is used to ensure, that always an isl_ctx is
  * passed to the following macros, even if they currently do not use it.
  */
-#define isl_check_ctx(ctx, expr)       (ctx != (isl_ctx *) 0) ? expr : expr
-
-#define isl_alloc(ctx,type,size)       isl_check_ctx(ctx, (type *)malloc(size))
-#define isl_calloc(ctx,type,size)      isl_check_ctx(ctx, \
-                                               (type *)calloc(1, size))
-#define isl_realloc(ctx,ptr,type,size) isl_check_ctx(ctx, \
-                                               (type *)realloc(ptr,size))
+#define isl_check_ctx(ctx, expr)       ((ctx != (isl_ctx *) 0) ? expr : expr)
+
+#define isl_alloc(ctx,type,size)       ((type *)isl_check_ctx(ctx,\
+                                                       malloc(size)))
+#define isl_calloc(ctx,type,size)      ((type *)isl_check_ctx(ctx,\
+                                                       calloc(1, size)))
+#define isl_realloc(ctx,ptr,type,size) ((type *)isl_check_ctx(ctx,\
+                                                       realloc(ptr,size)))
 #define isl_alloc_type(ctx,type)       isl_alloc(ctx,type,sizeof(type))
 #define isl_calloc_type(ctx,type)      isl_calloc(ctx,type,sizeof(type))
 #define isl_realloc_type(ctx,ptr,type) isl_realloc(ctx,ptr,type,sizeof(type))
 #define isl_alloc_array(ctx,type,n)    isl_alloc(ctx,type,(n)*sizeof(type))
-#define isl_calloc_array(ctx,type,n)   isl_check_ctx(ctx,\
-                                               (type *)calloc(n, sizeof(type)))
+#define isl_calloc_array(ctx,type,n)   ((type *)isl_check_ctx(ctx,\
+                                               calloc(n, sizeof(type))))
 #define isl_realloc_array(ctx,ptr,type,n) \
                                    isl_realloc(ctx,ptr,type,(n)*sizeof(type))
 
 #define isl_die(ctx,errno,msg,code)                                    \
        do {                                                            \
-               isl_ctx_set_error(ctx, errno);                          \
-               fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, msg);        \
+               isl_handle_error(ctx, errno, msg, __FILE__, __LINE__);  \
                code;                                                   \
        } while (0)
+
+void isl_handle_error(isl_ctx *ctx, enum isl_error error, const char *msg,
+       const char *file, int line);
+
 #define isl_assert4(ctx,test,code,errno)                               \
        do {                                                            \
                if (test)                                               \
@@ -139,9 +143,10 @@ typedef struct isl_ctx isl_ctx;
 
 struct isl_options *isl_ctx_options(isl_ctx *ctx);
 
-isl_ctx *isl_ctx_alloc_with_options(struct isl_arg *arg, __isl_take void *opt);
+isl_ctx *isl_ctx_alloc_with_options(struct isl_args *args,
+       __isl_take void *opt);
 isl_ctx *isl_ctx_alloc(void);
-void *isl_ctx_peek_options(isl_ctx *ctx, struct isl_arg *arg);
+void *isl_ctx_peek_options(isl_ctx *ctx, struct isl_args *args);
 int isl_ctx_parse_options(isl_ctx *ctx, int argc, char **argv, unsigned flags);
 void isl_ctx_ref(struct isl_ctx *ctx);
 void isl_ctx_deref(struct isl_ctx *ctx);
@@ -151,15 +156,82 @@ void isl_ctx_abort(isl_ctx *ctx);
 void isl_ctx_resume(isl_ctx *ctx);
 int isl_ctx_aborted(isl_ctx *ctx);
 
-#define ISL_ARG_CTX_DECL(prefix,st,arg)                                        \
+#define ISL_ARG_CTX_DECL(prefix,st,args)                               \
 st *isl_ctx_peek_ ## prefix(isl_ctx *ctx);
 
-#define ISL_ARG_CTX_DEF(prefix,st,arg)                                 \
+#define ISL_ARG_CTX_DEF(prefix,st,args)                                        \
 st *isl_ctx_peek_ ## prefix(isl_ctx *ctx)                              \
 {                                                                      \
-       return (st *)isl_ctx_peek_options(ctx, arg);                    \
+       return (st *)isl_ctx_peek_options(ctx, &(args));                \
+}
+
+#define ISL_CTX_GET_INT_DEF(prefix,st,args,field)                      \
+int prefix ## _get_ ## field(isl_ctx *ctx)                             \
+{                                                                      \
+       st *options;                                                    \
+       options = isl_ctx_peek_ ## prefix(ctx);                         \
+       if (!options)                                                   \
+               isl_die(ctx, isl_error_invalid,                         \
+                       "isl_ctx does not reference " #prefix,          \
+                       return -1);                                     \
+       return options->field;                                          \
 }
 
+#define ISL_CTX_SET_INT_DEF(prefix,st,args,field)                      \
+int prefix ## _set_ ## field(isl_ctx *ctx, int val)                    \
+{                                                                      \
+       st *options;                                                    \
+       options = isl_ctx_peek_ ## prefix(ctx);                         \
+       if (!options)                                                   \
+               isl_die(ctx, isl_error_invalid,                         \
+                       "isl_ctx does not reference " #prefix,          \
+                       return -1);                                     \
+       options->field = val;                                           \
+       return 0;                                                       \
+}
+
+#define ISL_CTX_GET_STR_DEF(prefix,st,args,field)                      \
+const char *prefix ## _get_ ## field(isl_ctx *ctx)                     \
+{                                                                      \
+       st *options;                                                    \
+       options = isl_ctx_peek_ ## prefix(ctx);                         \
+       if (!options)                                                   \
+               isl_die(ctx, isl_error_invalid,                         \
+                       "isl_ctx does not reference " #prefix,          \
+                       return NULL);                                   \
+       return options->field;                                          \
+}
+
+#define ISL_CTX_SET_STR_DEF(prefix,st,args,field)                      \
+int prefix ## _set_ ## field(isl_ctx *ctx, const char *val)            \
+{                                                                      \
+       st *options;                                                    \
+       options = isl_ctx_peek_ ## prefix(ctx);                         \
+       if (!options)                                                   \
+               isl_die(ctx, isl_error_invalid,                         \
+                       "isl_ctx does not reference " #prefix,          \
+                       return -1);                                     \
+       if (!val)                                                       \
+               return -1;                                              \
+       free(options->field);                                           \
+       options->field = strdup(val);                                   \
+       if (!options->field)                                            \
+               return -1;                                              \
+       return 0;                                                       \
+}
+
+#define ISL_CTX_GET_BOOL_DEF(prefix,st,args,field)                     \
+       ISL_CTX_GET_INT_DEF(prefix,st,args,field)
+
+#define ISL_CTX_SET_BOOL_DEF(prefix,st,args,field)                     \
+       ISL_CTX_SET_INT_DEF(prefix,st,args,field)
+
+#define ISL_CTX_GET_CHOICE_DEF(prefix,st,args,field)                   \
+       ISL_CTX_GET_INT_DEF(prefix,st,args,field)
+
+#define ISL_CTX_SET_CHOICE_DEF(prefix,st,args,field)                   \
+       ISL_CTX_SET_INT_DEF(prefix,st,args,field)
+
 enum isl_error isl_ctx_last_error(isl_ctx *ctx);
 void isl_ctx_reset_error(isl_ctx *ctx);
 void isl_ctx_set_error(isl_ctx *ctx, enum isl_error error);