add isl_ctx_peek_options
authorSven Verdoolaege <skimo@kotnet.org>
Sun, 23 May 2010 16:23:04 +0000 (18:23 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Sat, 12 Jun 2010 11:16:36 +0000 (13:16 +0200)
include/isl_ctx.h
isl_ctx.c

index ffe66b0..240120b 100644 (file)
@@ -121,10 +121,20 @@ 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();
+void *isl_ctx_peek_options(isl_ctx *ctx, struct isl_arg *arg);
 void isl_ctx_ref(struct isl_ctx *ctx);
 void isl_ctx_deref(struct isl_ctx *ctx);
 void isl_ctx_free(isl_ctx *ctx);
 
+#define ISL_ARG_CTX_DECL(prefix,st,arg)                                        \
+st *isl_ctx_peek_ ## prefix(isl_ctx *ctx);
+
+#define ISL_ARG_CTX_DEF(prefix,st,arg)                                 \
+st *isl_ctx_peek_ ## prefix(isl_ctx *ctx)                              \
+{                                                                      \
+       return (st *)isl_ctx_peek_options(ctx, arg);                    \
+}
+
 #if defined(__cplusplus)
 }
 #endif
index e844e56..dbda731 100644 (file)
--- a/isl_ctx.c
+++ b/isl_ctx.c
 #include "isl_ctx.h"
 #include "isl_vec.h"
 
-static struct isl_options *find_nested_isl_options(struct isl_arg *arg,
-       void *opt)
+static struct isl_options *find_nested_options(struct isl_arg *arg,
+       void *opt, struct isl_arg *wanted)
 {
        int i;
        struct isl_options *options;
 
-       if (arg == isl_options_arg)
+       if (arg == wanted)
                return opt;
 
        for (i = 0; arg[i].type != isl_arg_end; ++i) {
                if (arg[i].type != isl_arg_child)
                        continue;
-               options = find_nested_isl_options(arg[i].u.child.child,
-                                   *(void **)(((char *)opt) + arg->offset));
+               options = find_nested_options(arg[i].u.child.child,
+                               *(void **)(((char *)opt) + arg->offset), wanted);
                if (options)
                        return options;
        }
@@ -31,6 +31,19 @@ static struct isl_options *find_nested_isl_options(struct isl_arg *arg,
        return NULL;
 }
 
+static struct isl_options *find_nested_isl_options(struct isl_arg *arg,
+       void *opt)
+{
+       return find_nested_options(arg, opt, isl_options_arg);
+}
+
+void *isl_ctx_peek_options(isl_ctx *ctx, struct isl_arg *arg)
+{
+       if (!ctx)
+               return NULL;
+       return find_nested_options(ctx->user_arg, ctx->user_opt, arg);
+}
+
 isl_ctx *isl_ctx_alloc_with_options(struct isl_arg *arg, void *user_opt)
 {
        struct isl_ctx *ctx = NULL;