2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
5 * Use of this software is governed by the GNU LGPLv2.1 license
7 * Written by Sven Verdoolaege, K.U.Leuven, Departement
8 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
9 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
10 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
15 static void print_constraint_polylib(struct isl_basic_set *bset,
17 FILE *out, int indent, const char *prefix, const char *suffix)
20 unsigned dim = isl_basic_set_n_dim(bset);
21 unsigned nparam = isl_basic_set_n_param(bset);
22 isl_int *c = ineq ? bset->ineq[n] : bset->eq[n];
24 fprintf(out, "%*s%s", indent, "", prefix ? prefix : "");
25 fprintf(out, "%d", ineq);
26 for (i = 0; i < dim; ++i) {
28 isl_int_print(out, c[1+nparam+i], 5);
30 for (i = 0; i < bset->n_div; ++i) {
32 isl_int_print(out, c[1+nparam+dim+i], 5);
34 for (i = 0; i < nparam; ++i) {
36 isl_int_print(out, c[1+i], 5);
39 isl_int_print(out, c[0], 5);
40 fprintf(out, "%s\n", suffix ? suffix : "");
43 static void print_constraints_polylib(struct isl_basic_set *bset,
44 FILE *out, int indent, const char *prefix, const char *suffix)
48 for (i = 0; i < bset->n_eq; ++i)
49 print_constraint_polylib(bset, 0, i, out,
50 indent, prefix, suffix);
51 for (i = 0; i < bset->n_ineq; ++i)
52 print_constraint_polylib(bset, 1, i, out,
53 indent, prefix, suffix);
56 static void isl_basic_set_print_polylib(struct isl_basic_set *bset, FILE *out,
57 int indent, const char *prefix, const char *suffix)
59 unsigned total = isl_basic_set_total_dim(bset);
60 fprintf(out, "%*s%s", indent, "", prefix ? prefix : "");
61 fprintf(out, "%d %d", bset->n_eq + bset->n_ineq, 1 + total + 1);
62 fprintf(out, "%s\n", suffix ? suffix : "");
63 print_constraints_polylib(bset, out, indent, prefix, suffix);
66 static void isl_set_print_polylib(struct isl_set *set, FILE *out, int indent)
70 fprintf(out, "%*s", indent, "");
71 fprintf(out, "%d\n", set->n);
72 for (i = 0; i < set->n; ++i) {
74 isl_basic_set_print_polylib(set->p[i], out, indent, NULL, NULL);
78 static print_name(struct isl_dim *dim, FILE *out,
79 enum isl_dim_type type, unsigned pos, int set)
83 name = type == isl_dim_div ? NULL : isl_dim_get_name(dim, type, pos);
86 fprintf(out, "%s", name);
89 if (type == isl_dim_param)
91 else if (type == isl_dim_div)
93 else if (set || type == isl_dim_in)
97 fprintf(out, "%s%d", prefix, pos);
101 static void print_var_list(struct isl_dim *dim, FILE *out,
102 enum isl_dim_type type, int set)
106 for (i = 0; i < isl_dim_size(dim, type); ++i) {
109 print_name(dim, out, type, i, set);
113 static void print_tuple(__isl_keep isl_dim *dim, FILE *out,
114 enum isl_dim_type type, int set)
117 print_var_list(dim, out, type, set);
121 static void print_omega_parameters(struct isl_dim *dim, FILE *out,
122 int indent, const char *prefix, const char *suffix)
124 if (isl_dim_size(dim, isl_dim_param) == 0)
127 fprintf(out, "%*s%ssymbolic ", indent, "", prefix ? prefix : "");
128 print_var_list(dim, out, isl_dim_param, 0);
129 fprintf(out, ";%s\n", suffix ? suffix : "");
132 static void print_term(__isl_keep isl_dim *dim,
133 isl_int c, int pos, FILE *out, int set)
135 enum isl_dim_type type;
136 unsigned n_in = isl_dim_size(dim, isl_dim_in);
137 unsigned n_out = isl_dim_size(dim, isl_dim_out);
138 unsigned nparam = isl_dim_size(dim, isl_dim_param);
141 isl_int_print(out, c, 0);
145 if (!isl_int_is_one(c))
146 isl_int_print(out, c, 0);
147 if (pos < 1 + nparam) {
148 type = isl_dim_param;
150 } else if (pos < 1 + nparam + n_in) {
153 } else if (pos < 1 + nparam + n_in + n_out) {
155 pos -= 1 + nparam + n_in;
158 pos -= 1 + nparam + n_in + n_out;
160 print_name(dim, out, type, pos, set);
163 static void print_affine(__isl_keep isl_basic_map *bmap, FILE *out,
168 unsigned len = 1 + isl_basic_map_total_dim(bmap);
170 for (i = 0, first = 1; i < len; ++i) {
171 if (isl_int_is_zero(c[i]))
173 if (!first && isl_int_is_pos(c[i]))
176 print_term(bmap->dim, c[i], i, out, set);
182 static void print_constraint(struct isl_basic_map *bmap, FILE *out,
183 isl_int *c, const char *suffix, int first_constraint, int set)
185 if (!first_constraint)
186 fprintf(out, " and ");
188 print_affine(bmap, out, c, set);
190 fprintf(out, " %s", suffix);
193 static void print_constraints(__isl_keep isl_basic_map *bmap, FILE *out,
198 for (i = 0; i < bmap->n_eq; ++i)
199 print_constraint(bmap, out, bmap->eq[i], "= 0", !i, set);
200 for (i = 0; i < bmap->n_ineq; ++i)
201 print_constraint(bmap, out, bmap->ineq[i], ">= 0",
202 !bmap->n_eq && !i, set);
205 static void print_omega_constraints(__isl_keep isl_basic_map *bmap, FILE *out,
208 if (bmap->n_eq + bmap->n_ineq == 0)
212 if (bmap->n_div > 0) {
214 fprintf(out, "exists (");
215 for (i = 0; i < bmap->n_div; ++i) {
218 print_name(bmap->dim, out, isl_dim_div, i, 0);
222 print_constraints(bmap, out, set);
227 static void basic_map_print_omega(struct isl_basic_map *bmap, FILE *out)
230 print_var_list(bmap->dim, out, isl_dim_in, 0);
231 fprintf(out, "] -> [");
232 print_var_list(bmap->dim, out, isl_dim_out, 0);
234 print_omega_constraints(bmap, out, 0);
238 static void isl_basic_map_print_omega(struct isl_basic_map *bmap, FILE *out,
239 int indent, const char *prefix, const char *suffix)
241 print_omega_parameters(bmap->dim, out, indent, prefix, suffix);
243 fprintf(out, "%*s%s", indent, "", prefix ? prefix : "");
244 basic_map_print_omega(bmap, out);
245 fprintf(out, "%s\n", suffix ? suffix : "");
248 static void basic_set_print_omega(struct isl_basic_set *bset, FILE *out)
251 print_var_list(bset->dim, out, isl_dim_set, 1);
253 print_omega_constraints((isl_basic_map *)bset, out, 1);
257 static void isl_basic_set_print_omega(struct isl_basic_set *bset, FILE *out,
258 int indent, const char *prefix, const char *suffix)
260 print_omega_parameters(bset->dim, out, indent, prefix, suffix);
262 fprintf(out, "%*s%s", indent, "", prefix ? prefix : "");
263 basic_set_print_omega(bset, out);
264 fprintf(out, "%s\n", suffix ? suffix : "");
267 static void isl_map_print_omega(struct isl_map *map, FILE *out, int indent)
271 print_omega_parameters(map->dim, out, indent, "", "");
273 fprintf(out, "%*s", indent, "");
274 for (i = 0; i < map->n; ++i) {
276 fprintf(out, " union ");
277 basic_map_print_omega(map->p[i], out);
282 static void isl_set_print_omega(struct isl_set *set, FILE *out, int indent)
286 print_omega_parameters(set->dim, out, indent, "", "");
288 fprintf(out, "%*s", indent, "");
289 for (i = 0; i < set->n; ++i) {
291 fprintf(out, " union ");
292 basic_set_print_omega(set->p[i], out);
297 static void print_disjunct(__isl_keep isl_basic_map *bmap, FILE *out, int set)
299 if (bmap->n_div > 0) {
301 fprintf(out, "exists (");
302 for (i = 0; i < bmap->n_div; ++i) {
305 print_name(bmap->dim, out, isl_dim_div, i, 0);
306 if (isl_int_is_zero(bmap->div[i][0]))
308 fprintf(out, " = [(");
309 print_affine(bmap, out, bmap->div[i] + 1, set);
311 isl_int_print(out, bmap->div[i][0], 0);
317 print_constraints(bmap, out, set);
323 static void isl_basic_map_print_isl(__isl_keep isl_basic_map *bmap, FILE *out,
324 int indent, const char *prefix, const char *suffix)
328 fprintf(out, "%*s%s", indent, "", prefix ? prefix : "");
329 if (isl_basic_map_dim(bmap, isl_dim_param) > 0) {
330 print_tuple(bmap->dim, out, isl_dim_param, 0);
331 fprintf(out, " -> ");
334 print_tuple(bmap->dim, out, isl_dim_in, 0);
335 fprintf(out, " -> ");
336 print_tuple(bmap->dim, out, isl_dim_out, 0);
338 print_disjunct(bmap, out, 0);
339 fprintf(out, " }%s\n", suffix ? suffix : "");
342 static void isl_basic_set_print_isl(__isl_keep isl_basic_set *bset, FILE *out,
343 int indent, const char *prefix, const char *suffix)
347 fprintf(out, "%*s%s", indent, "", prefix ? prefix : "");
348 if (isl_basic_set_dim(bset, isl_dim_param) > 0) {
349 print_tuple(bset->dim, out, isl_dim_param, 0);
350 fprintf(out, " -> ");
353 print_tuple(bset->dim, out, isl_dim_set, 1);
355 print_disjunct((isl_basic_map *)bset, out, 1);
356 fprintf(out, " }%s\n", suffix ? suffix : "");
359 static void isl_map_print_isl(__isl_keep isl_map *map, FILE *out, int indent)
363 fprintf(out, "%*s", indent, "");
364 if (isl_map_dim(map, isl_dim_param) > 0) {
365 print_tuple(map->dim, out, isl_dim_param, 0);
366 fprintf(out, " -> ");
369 print_tuple(map->dim, out, isl_dim_in, 0);
370 fprintf(out, " -> ");
371 print_tuple(map->dim, out, isl_dim_out, 0);
374 fprintf(out, "1 = 0");
375 for (i = 0; i < map->n; ++i) {
377 fprintf(out, " or ");
378 print_disjunct(map->p[i], out, 0);
380 fprintf(out, " }\n");
383 static void isl_set_print_isl(__isl_keep isl_set *set, FILE *out, int indent)
387 fprintf(out, "%*s", indent, "");
388 if (isl_set_dim(set, isl_dim_param) > 0) {
389 print_tuple(set->dim, out, isl_dim_param, 0);
390 fprintf(out, " -> ");
393 print_tuple(set->dim, out, isl_dim_set, 1);
396 fprintf(out, "1 = 0");
397 for (i = 0; i < set->n; ++i) {
399 fprintf(out, " or ");
400 print_disjunct((isl_basic_map *)set->p[i], out, 1);
402 fprintf(out, " }\n");
405 void isl_basic_map_print(__isl_keep isl_basic_map *bmap, FILE *out, int indent,
406 const char *prefix, const char *suffix, unsigned output_format)
410 if (output_format == ISL_FORMAT_ISL)
411 isl_basic_map_print_isl(bmap, out, indent, prefix, suffix);
412 else if (output_format == ISL_FORMAT_OMEGA)
413 isl_basic_map_print_omega(bmap, out, indent, prefix, suffix);
415 isl_assert(bmap->ctx, 0, return);
418 void isl_basic_set_print(struct isl_basic_set *bset, FILE *out, int indent,
419 const char *prefix, const char *suffix, unsigned output_format)
423 if (output_format == ISL_FORMAT_ISL)
424 isl_basic_set_print_isl(bset, out, indent, prefix, suffix);
425 else if (output_format == ISL_FORMAT_POLYLIB)
426 isl_basic_set_print_polylib(bset, out, indent, prefix, suffix);
427 else if (output_format == ISL_FORMAT_POLYLIB_CONSTRAINTS)
428 print_constraints_polylib(bset, out, indent, prefix, suffix);
429 else if (output_format == ISL_FORMAT_OMEGA)
430 isl_basic_set_print_omega(bset, out, indent, prefix, suffix);
432 isl_assert(bset->ctx, 0, return);
435 void isl_set_print(struct isl_set *set, FILE *out, int indent,
436 unsigned output_format)
440 if (output_format == ISL_FORMAT_ISL)
441 isl_set_print_isl(set, out, indent);
442 else if (output_format == ISL_FORMAT_POLYLIB)
443 isl_set_print_polylib(set, out, indent);
444 else if (output_format == ISL_FORMAT_OMEGA)
445 isl_set_print_omega(set, out, indent);
447 isl_assert(set->ctx, 0, return);
450 void isl_map_print(__isl_keep isl_map *map, FILE *out, int indent,
451 unsigned output_format)
455 if (output_format == ISL_FORMAT_ISL)
456 isl_map_print_isl(map, out, indent);
457 else if (output_format == ISL_FORMAT_OMEGA)
458 isl_map_print_omega(map, out, indent);
460 isl_assert(map->ctx, 0, return);