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
10 #include <isl_ctx_private.h>
13 static struct isl_options *find_nested_options(struct isl_args *args,
14 void *opt, struct isl_args *wanted)
17 struct isl_options *options;
22 for (i = 0; args->args[i].type != isl_arg_end; ++i) {
23 if (args->args[i].type != isl_arg_child)
25 options = find_nested_options(args->args[i].u.child.child,
26 *(void **)(((char *)opt) + args->args[i].offset),
35 static struct isl_options *find_nested_isl_options(struct isl_args *args,
38 return find_nested_options(args, opt, &isl_options_args);
41 void *isl_ctx_peek_options(isl_ctx *ctx, struct isl_args *args)
45 return find_nested_options(ctx->user_args, ctx->user_opt, args);
48 isl_ctx *isl_ctx_alloc_with_options(struct isl_args *args, void *user_opt)
50 struct isl_ctx *ctx = NULL;
51 struct isl_options *opt = NULL;
52 int opt_allocated = 0;
57 opt = find_nested_isl_options(args, user_opt);
59 opt = isl_options_new_with_defaults();
65 ctx = isl_calloc_type(NULL, struct isl_ctx);
69 if (isl_hash_table_init(ctx, &ctx->id_table, 0))
72 ctx->stats = isl_calloc_type(ctx, struct isl_stats);
76 ctx->user_args = args;
77 ctx->user_opt = user_opt;
78 ctx->opt_allocated = opt_allocated;
82 isl_int_init(ctx->zero);
83 isl_int_set_si(ctx->zero, 0);
85 isl_int_init(ctx->one);
86 isl_int_set_si(ctx->one, 1);
88 isl_int_init(ctx->two);
89 isl_int_set_si(ctx->two, 2);
91 isl_int_init(ctx->negone);
92 isl_int_set_si(ctx->negone, -1);
94 isl_int_init(ctx->normalize_gcd);
99 ctx->error = isl_error_none;
103 isl_args_free(args, user_opt);
105 isl_options_free(opt);
110 struct isl_ctx *isl_ctx_alloc()
112 struct isl_options *opt;
114 opt = isl_options_new_with_defaults();
116 return isl_ctx_alloc_with_options(&isl_options_args, opt);
119 void isl_ctx_ref(struct isl_ctx *ctx)
124 void isl_ctx_deref(struct isl_ctx *ctx)
126 isl_assert(ctx, ctx->ref > 0, return);
130 void isl_ctx_free(struct isl_ctx *ctx)
134 isl_assert(ctx, ctx->ref == 0, return);
135 isl_hash_table_clear(&ctx->id_table);
136 isl_blk_clear_cache(ctx);
137 isl_int_clear(ctx->zero);
138 isl_int_clear(ctx->one);
139 isl_int_clear(ctx->two);
140 isl_int_clear(ctx->negone);
141 isl_int_clear(ctx->normalize_gcd);
142 isl_args_free(ctx->user_args, ctx->user_opt);
143 if (ctx->opt_allocated)
149 struct isl_options *isl_ctx_options(isl_ctx *ctx)
156 enum isl_error isl_ctx_last_error(isl_ctx *ctx)
161 void isl_ctx_reset_error(isl_ctx *ctx)
163 ctx->error = isl_error_none;
166 void isl_ctx_set_error(isl_ctx *ctx, enum isl_error error)
172 void isl_ctx_abort(isl_ctx *ctx)
178 void isl_ctx_resume(isl_ctx *ctx)
184 int isl_ctx_aborted(isl_ctx *ctx)
186 return ctx ? ctx->abort : -1;
189 int isl_ctx_parse_options(isl_ctx *ctx, int argc, char **argv, unsigned flags)
193 return isl_args_parse(ctx->user_args, argc, argv, ctx->user_opt, flags);