isl_map_read: accept '*' in affine expressions
[platform/upstream/isl.git] / polytope_scan.c
1 /*
2  * Copyright 2008-2009 Katholieke Universiteit Leuven
3  *
4  * Use of this software is governed by the GNU LGPLv2.1 license
5  *
6  * Written by Sven Verdoolaege, K.U.Leuven, Departement
7  * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
8  */
9
10 #include <assert.h>
11 #include "isl_equalities.h"
12 #include "isl_seq.h"
13 #include "isl_scan.h"
14
15 /* The input of this program is the same as that of the "polytope_scan"
16  * program from the barvinok distribution.
17  *
18  * Constraints of set is PolyLib format.
19  *
20  * The input set is assumed to be bounded.
21  */
22
23 struct scan_samples {
24         struct isl_scan_callback callback;
25         struct isl_mat *samples;
26 };
27
28 static int scan_samples_add_sample(struct isl_scan_callback *cb,
29         __isl_take isl_vec *sample)
30 {
31         struct scan_samples *ss = (struct scan_samples *)cb;
32
33         ss->samples = isl_mat_extend(ss->samples, ss->samples->n_row + 1,
34                                                   ss->samples->n_col);
35         if (!ss->samples)
36                 goto error;
37
38         isl_seq_cpy(ss->samples->row[ss->samples->n_row - 1],
39                     sample->el, sample->size);
40
41         isl_vec_free(sample);
42         return 0;
43 error:
44         isl_vec_free(sample);
45         return -1;
46 }
47
48 static struct isl_mat *isl_basic_set_scan_samples(struct isl_basic_set *bset)
49 {
50         unsigned dim;
51         struct scan_samples ss;
52
53         dim = isl_basic_set_total_dim(bset);
54         ss.callback.add = scan_samples_add_sample;
55         ss.samples = isl_mat_alloc(bset->ctx, 0, 1 + dim);
56         if (!ss.samples)
57                 goto error;
58
59         if (isl_basic_set_scan(bset, &ss.callback) < 0) {
60                 isl_mat_free(ss.samples);
61                 return NULL;
62         }
63
64         return ss.samples;
65 error:
66         isl_basic_set_free(bset);
67         return NULL;
68 }
69
70 static struct isl_mat *isl_basic_set_samples(struct isl_basic_set *bset)
71 {
72         struct isl_mat *T;
73         struct isl_mat *samples;
74
75         if (bset->n_eq == 0)
76                 return isl_basic_set_scan_samples(bset);
77
78         bset = isl_basic_set_remove_equalities(bset, &T, NULL);
79         samples = isl_basic_set_scan_samples(bset);
80         return isl_mat_product(samples, isl_mat_transpose(T));
81 }
82
83 int main(int argc, char **argv)
84 {
85         struct isl_ctx *ctx = isl_ctx_alloc();
86         struct isl_basic_set *bset;
87         struct isl_mat *samples;
88
89         bset = isl_basic_set_read_from_file(ctx, stdin, 0);
90         samples = isl_basic_set_samples(bset);
91         isl_mat_dump(samples, stdout, 0);
92         isl_mat_free(samples);
93         isl_ctx_free(ctx);
94
95         return 0;
96 }