add isl_basic_set_print and isl_set_print for printing in PolyLib format
[platform/upstream/isl.git] / isl_vec.c
1 #include "isl_vec.h"
2
3 struct isl_vec *isl_vec_alloc(struct isl_ctx *ctx, unsigned size)
4 {
5         struct isl_vec *vec;
6
7         vec = isl_alloc_type(ctx, struct isl_vec);
8         if (!vec)
9                 return NULL;
10
11         vec->block = isl_blk_alloc(ctx, size);
12         if (isl_blk_is_error(vec->block))
13                 goto error;
14
15         vec->ref = 1;
16         vec->size = size;
17
18         return vec;
19 error:
20         isl_blk_free(ctx, vec->block);
21         return NULL;
22 }
23
24 struct isl_vec *isl_vec_copy(struct isl_ctx *ctx, struct isl_vec *vec)
25 {
26         if (!vec)
27                 return NULL;
28
29         vec->ref++;
30         return vec;
31 }
32
33 void isl_vec_free(struct isl_ctx *ctx, struct isl_vec *vec)
34 {
35         if (!vec)
36                 return;
37
38         if (--vec->ref > 0)
39                 return;
40
41         isl_blk_free(ctx, vec->block);
42         free(vec);
43 }
44
45 void isl_vec_dump(struct isl_ctx *ctx, struct isl_vec *vec,
46                                 FILE *out, int indent)
47 {
48         int i;
49         fprintf(out, "%*s[", indent, "");
50         for (i = 0; i < vec->size; ++i) {
51                 if (i)
52                     fprintf(out, ",");
53                 isl_int_print(out, vec->block.data[i], 0);
54         }
55         fprintf(out, "]\n");
56 }