From 7adc3116c28a60bd8975a04e0041ea6005613249 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Fri, 21 May 2010 16:26:43 +0200 Subject: [PATCH] isl_ctx: keep track of user options --- bound.c | 3 +-- cat.c | 4 +--- closure.c | 2 +- include/isl_ctx.h | 5 ++++- isl_ctx.c | 47 +++++++++++++++++++++++++++++++++++++++++++---- pip.c | 4 +--- 6 files changed, 51 insertions(+), 14 deletions(-) diff --git a/bound.c b/bound.c index b32b65a..53a0fdc 100644 --- a/bound.c +++ b/bound.c @@ -235,7 +235,7 @@ int main(int argc, char **argv) assert(options); argc = bound_options_parse(options, argc, argv, ISL_ARG_ALL); - ctx = isl_ctx_alloc_with_options(options->isl); + ctx = isl_ctx_alloc_with_options(bound_options_arg, options); options->isl = NULL; s = isl_stream_new_file(ctx, stdin); @@ -260,7 +260,6 @@ int main(int argc, char **argv) isl_stream_free(s); isl_ctx_free(ctx); - free(options); return r; } diff --git a/cat.c b/cat.c index 96722cc..18d1748 100644 --- a/cat.c +++ b/cat.c @@ -32,8 +32,7 @@ int main(int argc, char **argv) assert(options); argc = cat_options_parse(options, argc, argv, ISL_ARG_ALL); - ctx = isl_ctx_alloc_with_options(options->isl); - options->isl = NULL; + ctx = isl_ctx_alloc_with_options(cat_options_arg, options); map = isl_map_read_from_file(ctx, stdin, -1); isl_map_print(map, stdout, 0, options->format); @@ -42,7 +41,6 @@ int main(int argc, char **argv) isl_map_free(map); isl_ctx_free(ctx); - free(options); return 0; } diff --git a/closure.c b/closure.c index 05093a0..f80ccac 100644 --- a/closure.c +++ b/closure.c @@ -12,7 +12,7 @@ int main(int argc, char **argv) assert(options); argc = isl_options_parse(options, argc, argv, ISL_ARG_ALL); - ctx = isl_ctx_alloc_with_options(options); + ctx = isl_ctx_alloc_with_options(isl_options_arg, options); map = isl_map_read_from_file(ctx, stdin, -1); map = isl_map_transitive_closure(map, &exact); diff --git a/include/isl_ctx.h b/include/isl_ctx.h index 331bfda..ffe66b0 100644 --- a/include/isl_ctx.h +++ b/include/isl_ctx.h @@ -65,7 +65,10 @@ struct isl_ctx { struct isl_stats *stats; + int opt_allocated; struct isl_options *opt; + void *user_opt; + struct isl_arg *user_arg; isl_int zero; isl_int one; @@ -116,7 +119,7 @@ typedef struct isl_ctx isl_ctx; struct isl_options *isl_ctx_options(isl_ctx *ctx); -isl_ctx *isl_ctx_alloc_with_options(struct isl_options *opt); +isl_ctx *isl_ctx_alloc_with_options(struct isl_arg *arg, __isl_take void *opt); isl_ctx *isl_ctx_alloc(); void isl_ctx_ref(struct isl_ctx *ctx); void isl_ctx_deref(struct isl_ctx *ctx); diff --git a/isl_ctx.c b/isl_ctx.c index b1c9028..e844e56 100644 --- a/isl_ctx.c +++ b/isl_ctx.c @@ -10,13 +10,44 @@ #include "isl_ctx.h" #include "isl_vec.h" -isl_ctx *isl_ctx_alloc_with_options(struct isl_options *opt) +static struct isl_options *find_nested_isl_options(struct isl_arg *arg, + void *opt) +{ + int i; + struct isl_options *options; + + if (arg == isl_options_arg) + 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)); + if (options) + return options; + } + + return NULL; +} + +isl_ctx *isl_ctx_alloc_with_options(struct isl_arg *arg, void *user_opt) { struct isl_ctx *ctx = NULL; + struct isl_options *opt = NULL; + int opt_allocated = 0; - if (!opt) + if (!user_opt) return NULL; + opt = find_nested_isl_options(arg, user_opt); + if (!opt) { + opt = isl_options_new_with_defaults(); + if (!opt) + goto error; + opt_allocated = 1; + } + ctx = isl_calloc_type(NULL, struct isl_ctx); if (!ctx) goto error; @@ -28,6 +59,9 @@ isl_ctx *isl_ctx_alloc_with_options(struct isl_options *opt) if (!ctx->stats) goto error; + ctx->user_arg = arg; + ctx->user_opt = user_opt; + ctx->opt_allocated = opt_allocated; ctx->opt = opt; ctx->ref = 0; @@ -46,6 +80,9 @@ isl_ctx *isl_ctx_alloc_with_options(struct isl_options *opt) return ctx; error: + isl_arg_free(arg, user_opt); + if (opt_allocated) + isl_options_free(opt); free(ctx); return NULL; } @@ -56,7 +93,7 @@ struct isl_ctx *isl_ctx_alloc() opt = isl_options_new_with_defaults(); - return isl_ctx_alloc_with_options(opt); + return isl_ctx_alloc_with_options(isl_options_arg, opt); } void isl_ctx_ref(struct isl_ctx *ctx) @@ -81,7 +118,9 @@ void isl_ctx_free(struct isl_ctx *ctx) isl_int_clear(ctx->one); isl_int_clear(ctx->negone); isl_int_clear(ctx->normalize_gcd); - free(ctx->opt); + isl_arg_free(ctx->user_arg, ctx->user_opt); + if (ctx->opt_allocated) + free(ctx->opt); free(ctx->stats); free(ctx); } diff --git a/pip.c b/pip.c index c097b9d..9f528ad 100644 --- a/pip.c +++ b/pip.c @@ -316,8 +316,7 @@ int main(int argc, char **argv) assert(options); argc = pip_options_parse(options, argc, argv, ISL_ARG_ALL); - ctx = isl_ctx_alloc_with_options(options->isl); - options->isl = NULL; + ctx = isl_ctx_alloc_with_options(pip_options_arg, options); context = isl_basic_set_read_from_file(ctx, stdin, 0); assert(context); @@ -371,7 +370,6 @@ int main(int argc, char **argv) isl_set_free(set); isl_set_free(empty); isl_ctx_free(ctx); - free(options); return 0; } -- 2.7.4