add isl_basic_set_lexmax
[isl.git] / isl_ctx.c
blob13f9e8ad0d11f23b54d8e8fb2043800ef8102b05
1 #include "isl_ctx.h"
2 #include "isl_vec.h"
3 #ifdef ISL_POLYLIB
4 #include <polylib/polylibgmp.h>
5 #endif
7 isl_ctx *isl_ctx_alloc_with_options(struct isl_options *opt)
9 struct isl_ctx *ctx = NULL;
11 if (!opt)
12 return NULL;
14 ctx = isl_calloc_type(NULL, struct isl_ctx);
15 if (!ctx)
16 goto error;
18 if (isl_hash_table_init(ctx, &ctx->name_hash, 0))
19 goto error;
21 ctx->stats = isl_calloc_type(ctx, struct isl_stats);
22 if (!ctx->stats)
23 goto error;
25 ctx->opt = opt;
26 ctx->ref = 0;
28 isl_int_init(ctx->one);
29 isl_int_set_si(ctx->one, 1);
31 isl_int_init(ctx->negone);
32 isl_int_set_si(ctx->negone, -1);
34 isl_int_init(ctx->normalize_gcd);
36 ctx->n_cached = 0;
38 #ifdef ISL_POLYLIB
39 ctx->MaxRays = POL_NO_DUAL | POL_INTEGER;
40 #endif
42 return ctx;
43 error:
44 free(ctx);
45 return NULL;
48 struct isl_ctx *isl_ctx_alloc()
50 struct isl_options *opt;
52 opt = isl_options_new_with_defaults();
54 return isl_ctx_alloc_with_options(opt);
57 void isl_ctx_ref(struct isl_ctx *ctx)
59 ctx->ref++;
62 void isl_ctx_deref(struct isl_ctx *ctx)
64 isl_assert(ctx, ctx->ref > 0, return);
65 ctx->ref--;
68 void isl_ctx_free(struct isl_ctx *ctx)
70 if (!ctx)
71 return;
72 isl_assert(ctx, ctx->ref == 0, return);
73 isl_hash_table_clear(&ctx->name_hash);
74 isl_blk_clear_cache(ctx);
75 isl_int_clear(ctx->one);
76 isl_int_clear(ctx->negone);
77 isl_int_clear(ctx->normalize_gcd);
78 free(ctx->opt);
79 free(ctx->stats);
80 free(ctx);
83 struct isl_options *isl_ctx_options(isl_ctx *ctx)
85 if (!ctx)
86 return NULL;
87 return ctx->opt;