X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=isl_obj.c;h=7eba67139913a0e18d89ed7203a1f0c084406f16;hb=82e48de0422ba8469fa52009563a2a686cb73145;hp=5fa218e645b45b0d39d5aa8563a280d67eec1131;hpb=e9ac9c48ab2ca26e3b88ac30e8886db2336e4ac8;p=platform%2Fupstream%2Fisl.git diff --git a/isl_obj.c b/isl_obj.c index 5fa218e..7eba671 100644 --- a/isl_obj.c +++ b/isl_obj.c @@ -1,14 +1,196 @@ /* * Copyright 2010 INRIA Saclay * - * 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, INRIA Saclay - Ile-de-France, * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod, * 91893 Orsay, France */ -#include +#include +#include +#include +#include + +struct isl_int_obj { + int ref; + isl_ctx *ctx; + isl_int v; +}; + +__isl_give isl_int_obj *isl_int_obj_alloc(isl_ctx *ctx, isl_int v) +{ + isl_int_obj *i; + + i = isl_alloc_type(ctx, isl_int_obj); + if (!i) + return NULL; + + i->ctx = ctx; + isl_ctx_ref(ctx); + i->ref = 1; + isl_int_init(i->v); + isl_int_set(i->v, v); + + return i; +} + +__isl_give isl_int_obj *isl_int_obj_copy(__isl_keep isl_int_obj *i) +{ + if (!i) + return NULL; + + i->ref++; + return i; +} + +__isl_give isl_int_obj *isl_int_obj_dup(__isl_keep isl_int_obj *i) +{ + if (!i) + return NULL; + + return isl_int_obj_alloc(i->ctx, i->v); +} + +__isl_give isl_int_obj *isl_int_obj_cow(__isl_take isl_int_obj *i) +{ + if (!i) + return NULL; + + if (i->ref == 1) + return i; + i->ref--; + return isl_int_obj_dup(i); +} + +void isl_int_obj_free(__isl_take isl_int_obj *i) +{ + if (!i) + return; + + if (--i->ref > 0) + return; + + isl_ctx_deref(i->ctx); + isl_int_clear(i->v); + free(i); +} + +__isl_give isl_int_obj *isl_int_obj_add(__isl_take isl_int_obj *i1, + __isl_take isl_int_obj *i2) +{ + i1 = isl_int_obj_cow(i1); + if (!i1 || !i2) + goto error; + + isl_int_add(i1->v, i1->v, i2->v); + + isl_int_obj_free(i2); + return i1; +error: + isl_int_obj_free(i1); + isl_int_obj_free(i2); + return NULL; +} + +__isl_give isl_int_obj *isl_int_obj_sub(__isl_take isl_int_obj *i1, + __isl_take isl_int_obj *i2) +{ + i1 = isl_int_obj_cow(i1); + if (!i1 || !i2) + goto error; + + isl_int_sub(i1->v, i1->v, i2->v); + + isl_int_obj_free(i2); + return i1; +error: + isl_int_obj_free(i1); + isl_int_obj_free(i2); + return NULL; +} + +__isl_give isl_int_obj *isl_int_obj_mul(__isl_take isl_int_obj *i1, + __isl_take isl_int_obj *i2) +{ + i1 = isl_int_obj_cow(i1); + if (!i1 || !i2) + goto error; + + isl_int_mul(i1->v, i1->v, i2->v); + + isl_int_obj_free(i2); + return i1; +error: + isl_int_obj_free(i1); + isl_int_obj_free(i2); + return NULL; +} + +void isl_int_obj_get_int(__isl_keep isl_int_obj *i, isl_int *v) +{ + if (!i) + return; + isl_int_set(*v, i->v); +} + +static void *isl_obj_int_copy(void *v) +{ + return isl_int_obj_copy((isl_int_obj *)v); +} + +static void isl_obj_int_free(void *v) +{ + isl_int_obj_free((isl_int_obj *)v); +} + +static __isl_give isl_printer *isl_obj_int_print(__isl_take isl_printer *p, + void *v) +{ + isl_int_obj *i = v; + return isl_printer_print_isl_int(p, i->v); +} + +static void *isl_obj_int_add(void *v1, void *v2) +{ + return isl_int_obj_add((isl_int_obj *)v1, (isl_int_obj *)v2); +} + +struct isl_obj_vtable isl_obj_int_vtable = { + isl_obj_int_copy, + isl_obj_int_add, + isl_obj_int_print, + isl_obj_int_free +}; + +static void *isl_obj_val_copy(void *v) +{ + return isl_val_copy((isl_val *)v); +} + +static void isl_obj_val_free(void *v) +{ + isl_val_free((isl_val *)v); +} + +static __isl_give isl_printer *isl_obj_val_print(__isl_take isl_printer *p, + void *v) +{ + return isl_printer_print_val(p, (isl_val *)v); +} + +static void *isl_obj_val_add(void *v1, void *v2) +{ + return isl_val_add((isl_val *) v1, (isl_val *) v2); +} + +struct isl_obj_vtable isl_obj_val_vtable = { + isl_obj_val_copy, + isl_obj_val_add, + isl_obj_val_print, + isl_obj_val_free +}; static void *isl_obj_map_copy(void *v) {