X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=isl_ctx.c;h=7720be47a7af1cc6474612964707374bad90477d;hb=63fb8a7f484648c3caa25351c8c94ac2395ec563;hp=21108bfb6f2c0bf390b90c2afc438a4bf66364c5;hpb=0d458c47aefdc037512282a3250de99d9d24b8c9;p=platform%2Fupstream%2Fisl.git diff --git a/isl_ctx.c b/isl_ctx.c index 21108bf..7720be4 100644 --- a/isl_ctx.c +++ b/isl_ctx.c @@ -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 @@ -9,21 +9,47 @@ #include #include +#include -static struct isl_options *find_nested_options(struct isl_arg *arg, - void *opt, struct isl_arg *wanted) +#define __isl_calloc(type,size) ((type *)calloc(1, size)) +#define __isl_calloc_type(type) __isl_calloc(type,sizeof(type)) + +void isl_handle_error(isl_ctx *ctx, enum isl_error error, const char *msg, + const char *file, int line) +{ + if (!ctx) + return; + + isl_ctx_set_error(ctx, error); + + switch (ctx->opt->on_error) { + case ISL_ON_ERROR_WARN: + fprintf(stderr, "%s:%d: %s\n", file, line, msg); + return; + case ISL_ON_ERROR_CONTINUE: + return; + case ISL_ON_ERROR_ABORT: + fprintf(stderr, "%s:%d: %s\n", file, line, msg); + abort(); + return; + } +} + +static struct isl_options *find_nested_options(struct isl_args *args, + void *opt, struct isl_args *wanted) { int i; struct isl_options *options; - if (arg == wanted) + if (args == wanted) return opt; - for (i = 0; arg[i].type != isl_arg_end; ++i) { - if (arg[i].type != isl_arg_child) + for (i = 0; args->args[i].type != isl_arg_end; ++i) { + if (args->args[i].type != isl_arg_child) continue; - options = find_nested_options(arg[i].u.child.child, - *(void **)(((char *)opt) + arg->offset), wanted); + options = find_nested_options(args->args[i].u.child.child, + *(void **)(((char *)opt) + args->args[i].offset), + wanted); if (options) return options; } @@ -31,20 +57,22 @@ static struct isl_options *find_nested_options(struct isl_arg *arg, return NULL; } -static struct isl_options *find_nested_isl_options(struct isl_arg *arg, +static struct isl_options *find_nested_isl_options(struct isl_args *args, void *opt) { - return find_nested_options(arg, opt, isl_options_arg); + return find_nested_options(args, opt, &isl_options_args); } -void *isl_ctx_peek_options(isl_ctx *ctx, struct isl_arg *arg) +void *isl_ctx_peek_options(isl_ctx *ctx, struct isl_args *args) { if (!ctx) return NULL; - return find_nested_options(ctx->user_arg, ctx->user_opt, arg); + if (args == &isl_options_args) + return ctx->opt; + return find_nested_options(ctx->user_args, ctx->user_opt, args); } -isl_ctx *isl_ctx_alloc_with_options(struct isl_arg *arg, void *user_opt) +isl_ctx *isl_ctx_alloc_with_options(struct isl_args *args, void *user_opt) { struct isl_ctx *ctx = NULL; struct isl_options *opt = NULL; @@ -53,7 +81,7 @@ isl_ctx *isl_ctx_alloc_with_options(struct isl_arg *arg, void *user_opt) if (!user_opt) return NULL; - opt = find_nested_isl_options(arg, user_opt); + opt = find_nested_isl_options(args, user_opt); if (!opt) { opt = isl_options_new_with_defaults(); if (!opt) @@ -61,7 +89,7 @@ isl_ctx *isl_ctx_alloc_with_options(struct isl_arg *arg, void *user_opt) opt_allocated = 1; } - ctx = isl_calloc_type(NULL, struct isl_ctx); + ctx = __isl_calloc_type(struct isl_ctx); if (!ctx) goto error; @@ -72,7 +100,7 @@ isl_ctx *isl_ctx_alloc_with_options(struct isl_arg *arg, void *user_opt) if (!ctx->stats) goto error; - ctx->user_arg = arg; + ctx->user_args = args; ctx->user_opt = user_opt; ctx->opt_allocated = opt_allocated; ctx->opt = opt; @@ -99,7 +127,7 @@ isl_ctx *isl_ctx_alloc_with_options(struct isl_arg *arg, void *user_opt) return ctx; error: - isl_arg_free(arg, user_opt); + isl_args_free(args, user_opt); if (opt_allocated) isl_options_free(opt); free(ctx); @@ -112,7 +140,7 @@ struct isl_ctx *isl_ctx_alloc() opt = isl_options_new_with_defaults(); - return isl_ctx_alloc_with_options(isl_options_arg, opt); + return isl_ctx_alloc_with_options(&isl_options_args, opt); } void isl_ctx_ref(struct isl_ctx *ctx) @@ -130,7 +158,11 @@ void isl_ctx_free(struct isl_ctx *ctx) { if (!ctx) return; - isl_assert(ctx, ctx->ref == 0, return); + if (ctx->ref != 0) + isl_die(ctx, isl_error_invalid, + "isl_ctx freed, but some objects still reference it", + return); + isl_hash_table_clear(&ctx->id_table); isl_blk_clear_cache(ctx); isl_int_clear(ctx->zero); @@ -138,9 +170,9 @@ void isl_ctx_free(struct isl_ctx *ctx) isl_int_clear(ctx->two); isl_int_clear(ctx->negone); isl_int_clear(ctx->normalize_gcd); - isl_arg_free(ctx->user_arg, ctx->user_opt); + isl_args_free(ctx->user_args, ctx->user_opt); if (ctx->opt_allocated) - free(ctx->opt); + isl_options_free(ctx->opt); free(ctx->stats); free(ctx); } @@ -184,3 +216,10 @@ int isl_ctx_aborted(isl_ctx *ctx) { return ctx ? ctx->abort : -1; } + +int isl_ctx_parse_options(isl_ctx *ctx, int argc, char **argv, unsigned flags) +{ + if (!ctx) + return -1; + return isl_args_parse(ctx->user_args, argc, argv, ctx->user_opt, flags); +}