2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
13 static struct isl_options *find_nested_isl_options(struct isl_arg *arg,
17 struct isl_options *options;
19 if (arg == isl_options_arg)
22 for (i = 0; arg[i].type != isl_arg_end; ++i) {
23 if (arg[i].type != isl_arg_child)
25 options = find_nested_isl_options(arg[i].u.child.child,
26 *(void **)(((char *)opt) + arg->offset));
34 isl_ctx *isl_ctx_alloc_with_options(struct isl_arg *arg, void *user_opt)
36 struct isl_ctx *ctx = NULL;
37 struct isl_options *opt = NULL;
38 int opt_allocated = 0;
43 opt = find_nested_isl_options(arg, user_opt);
45 opt = isl_options_new_with_defaults();
51 ctx = isl_calloc_type(NULL, struct isl_ctx);
55 if (isl_hash_table_init(ctx, &ctx->name_hash, 0))
58 ctx->stats = isl_calloc_type(ctx, struct isl_stats);
63 ctx->user_opt = user_opt;
64 ctx->opt_allocated = opt_allocated;
68 isl_int_init(ctx->zero);
69 isl_int_set_si(ctx->zero, 0);
71 isl_int_init(ctx->one);
72 isl_int_set_si(ctx->one, 1);
74 isl_int_init(ctx->negone);
75 isl_int_set_si(ctx->negone, -1);
77 isl_int_init(ctx->normalize_gcd);
83 isl_arg_free(arg, user_opt);
85 isl_options_free(opt);
90 struct isl_ctx *isl_ctx_alloc()
92 struct isl_options *opt;
94 opt = isl_options_new_with_defaults();
96 return isl_ctx_alloc_with_options(isl_options_arg, opt);
99 void isl_ctx_ref(struct isl_ctx *ctx)
104 void isl_ctx_deref(struct isl_ctx *ctx)
106 isl_assert(ctx, ctx->ref > 0, return);
110 void isl_ctx_free(struct isl_ctx *ctx)
114 isl_assert(ctx, ctx->ref == 0, return);
115 isl_hash_table_clear(&ctx->name_hash);
116 isl_blk_clear_cache(ctx);
117 isl_int_clear(ctx->zero);
118 isl_int_clear(ctx->one);
119 isl_int_clear(ctx->negone);
120 isl_int_clear(ctx->normalize_gcd);
121 isl_arg_free(ctx->user_arg, ctx->user_opt);
122 if (ctx->opt_allocated)
128 struct isl_options *isl_ctx_options(isl_ctx *ctx)