2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
5 * Use of this software is governed by the MIT 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 #include <isl_ctx_private.h>
16 #include <isl_map_private.h>
19 #include <isl_polynomial_private.h>
20 #include <isl_printer_private.h>
21 #include <isl_space_private.h>
22 #include <isl_mat_private.h>
23 #include <isl/union_map.h>
24 #include <isl/constraint.h>
25 #include <isl_local_space_private.h>
26 #include <isl_aff_private.h>
28 static const char *s_to[2] = { " -> ", " \\to " };
29 static const char *s_and[2] = { " and ", " \\wedge " };
30 static const char *s_or[2] = { " or ", " \\vee " };
31 static const char *s_le[2] = { "<=", "\\le" };
32 static const char *s_ge[2] = { ">=", "\\ge" };
33 static const char *s_open_set[2] = { "{ ", "\\{\\, " };
34 static const char *s_close_set[2] = { " }", " \\,\\}" };
35 static const char *s_open_list[2] = { "[", "(" };
36 static const char *s_close_list[2] = { "]", ")" };
37 static const char *s_such_that[2] = { " : ", " \\mid " };
38 static const char *s_open_exists[2] = { "exists (", "\\exists \\, " };
39 static const char *s_close_exists[2] = { ")", "" };
40 static const char *s_div_prefix[2] = { "e", "\\alpha_" };
41 static const char *s_param_prefix[2] = { "p", "p_" };
42 static const char *s_input_prefix[2] = { "i", "i_" };
43 static const char *s_output_prefix[2] = { "o", "o_" };
45 static __isl_give isl_printer *print_constraint_polylib(
46 struct isl_basic_map *bmap, int ineq, int n, __isl_take isl_printer *p)
49 unsigned n_in = isl_basic_map_dim(bmap, isl_dim_in);
50 unsigned n_out = isl_basic_map_dim(bmap, isl_dim_out);
51 unsigned nparam = isl_basic_map_dim(bmap, isl_dim_param);
52 isl_int *c = ineq ? bmap->ineq[n] : bmap->eq[n];
54 p = isl_printer_start_line(p);
55 p = isl_printer_print_int(p, ineq);
56 for (i = 0; i < n_out; ++i) {
57 p = isl_printer_print_str(p, " ");
58 p = isl_printer_print_isl_int(p, c[1+nparam+n_in+i]);
60 for (i = 0; i < n_in; ++i) {
61 p = isl_printer_print_str(p, " ");
62 p = isl_printer_print_isl_int(p, c[1+nparam+i]);
64 for (i = 0; i < bmap->n_div; ++i) {
65 p = isl_printer_print_str(p, " ");
66 p = isl_printer_print_isl_int(p, c[1+nparam+n_in+n_out+i]);
68 for (i = 0; i < nparam; ++i) {
69 p = isl_printer_print_str(p, " ");
70 p = isl_printer_print_isl_int(p, c[1+i]);
72 p = isl_printer_print_str(p, " ");
73 p = isl_printer_print_isl_int(p, c[0]);
74 p = isl_printer_end_line(p);
78 static __isl_give isl_printer *print_constraints_polylib(
79 struct isl_basic_map *bmap, __isl_take isl_printer *p)
83 p = isl_printer_set_isl_int_width(p, 5);
85 for (i = 0; i < bmap->n_eq; ++i)
86 p = print_constraint_polylib(bmap, 0, i, p);
87 for (i = 0; i < bmap->n_ineq; ++i)
88 p = print_constraint_polylib(bmap, 1, i, p);
93 static __isl_give isl_printer *bset_print_constraints_polylib(
94 struct isl_basic_set *bset, __isl_take isl_printer *p)
96 return print_constraints_polylib((struct isl_basic_map *)bset, p);
99 static __isl_give isl_printer *isl_basic_map_print_polylib(
100 __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p, int ext)
102 unsigned total = isl_basic_map_total_dim(bmap);
103 p = isl_printer_start_line(p);
104 p = isl_printer_print_int(p, bmap->n_eq + bmap->n_ineq);
105 p = isl_printer_print_str(p, " ");
106 p = isl_printer_print_int(p, 1 + total + 1);
108 p = isl_printer_print_str(p, " ");
109 p = isl_printer_print_int(p,
110 isl_basic_map_dim(bmap, isl_dim_out));
111 p = isl_printer_print_str(p, " ");
112 p = isl_printer_print_int(p,
113 isl_basic_map_dim(bmap, isl_dim_in));
114 p = isl_printer_print_str(p, " ");
115 p = isl_printer_print_int(p,
116 isl_basic_map_dim(bmap, isl_dim_div));
117 p = isl_printer_print_str(p, " ");
118 p = isl_printer_print_int(p,
119 isl_basic_map_dim(bmap, isl_dim_param));
121 p = isl_printer_end_line(p);
122 return print_constraints_polylib(bmap, p);
125 static __isl_give isl_printer *isl_basic_set_print_polylib(
126 __isl_keep isl_basic_set *bset, __isl_take isl_printer *p, int ext)
128 return isl_basic_map_print_polylib((struct isl_basic_map *)bset, p, ext);
131 static __isl_give isl_printer *isl_map_print_polylib(__isl_keep isl_map *map,
132 __isl_take isl_printer *p, int ext)
136 p = isl_printer_start_line(p);
137 p = isl_printer_print_int(p, map->n);
138 p = isl_printer_end_line(p);
139 for (i = 0; i < map->n; ++i) {
140 p = isl_printer_start_line(p);
141 p = isl_printer_end_line(p);
142 p = isl_basic_map_print_polylib(map->p[i], p, ext);
147 static __isl_give isl_printer *isl_set_print_polylib(__isl_keep isl_set *set,
148 __isl_take isl_printer *p, int ext)
150 return isl_map_print_polylib((struct isl_map *)set, p, ext);
153 static int count_same_name(__isl_keep isl_space *dim,
154 enum isl_dim_type type, unsigned pos, const char *name)
160 for (t = isl_dim_param; t <= type && t <= isl_dim_out; ++t) {
161 s = t == type ? pos : isl_space_dim(dim, t);
162 for (p = 0; p < s; ++p) {
163 const char *n = isl_space_get_dim_name(dim, t, p);
164 if (n && !strcmp(n, name))
171 static __isl_give isl_printer *print_name(__isl_keep isl_space *dim,
172 __isl_take isl_printer *p, enum isl_dim_type type, unsigned pos,
179 name = type == isl_dim_div ? NULL : isl_space_get_dim_name(dim, type, pos);
183 if (type == isl_dim_param)
184 prefix = s_param_prefix[latex];
185 else if (type == isl_dim_div)
186 prefix = s_div_prefix[latex];
187 else if (isl_space_is_set(dim) || type == isl_dim_in)
188 prefix = s_input_prefix[latex];
190 prefix = s_output_prefix[latex];
191 snprintf(buffer, sizeof(buffer), "%s%d", prefix, pos);
194 primes = count_same_name(dim, name == buffer ? isl_dim_div : type,
196 p = isl_printer_print_str(p, name);
198 p = isl_printer_print_str(p, "'");
202 static enum isl_dim_type pos2type(__isl_keep isl_space *dim, unsigned *pos)
204 enum isl_dim_type type;
205 unsigned n_in = isl_space_dim(dim, isl_dim_in);
206 unsigned n_out = isl_space_dim(dim, isl_dim_out);
207 unsigned nparam = isl_space_dim(dim, isl_dim_param);
209 if (*pos < 1 + nparam) {
210 type = isl_dim_param;
212 } else if (*pos < 1 + nparam + n_in) {
215 } else if (*pos < 1 + nparam + n_in + n_out) {
217 *pos -= 1 + nparam + n_in;
220 *pos -= 1 + nparam + n_in + n_out;
226 static __isl_give isl_printer *print_div(__isl_keep isl_space *dim,
227 __isl_keep isl_mat *div, int pos, __isl_take isl_printer *p);
229 static __isl_give isl_printer *print_term(__isl_keep isl_space *dim,
230 __isl_keep isl_mat *div,
231 isl_int c, unsigned pos, __isl_take isl_printer *p, int latex)
233 enum isl_dim_type type;
237 return isl_printer_print_isl_int(p, c);
239 type = pos2type(dim, &pos);
240 print_div_def = type == isl_dim_div && div &&
241 !isl_int_is_zero(div->row[pos][0]);
243 if (isl_int_is_one(c))
245 else if (isl_int_is_negone(c))
246 p = isl_printer_print_str(p, "-");
248 p = isl_printer_print_isl_int(p, c);
249 if (p->output_format == ISL_FORMAT_C || print_div_def)
250 p = isl_printer_print_str(p, "*");
253 p = print_div(dim, div, pos, p);
255 p = print_name(dim, p, type, pos, latex);
259 static __isl_give isl_printer *print_affine_of_len(__isl_keep isl_space *dim,
260 __isl_keep isl_mat *div,
261 __isl_take isl_printer *p, isl_int *c, int len)
266 for (i = 0, first = 1; i < len; ++i) {
268 if (isl_int_is_zero(c[i]))
271 if (isl_int_is_neg(c[i])) {
273 isl_int_neg(c[i], c[i]);
274 p = isl_printer_print_str(p, " - ");
276 p = isl_printer_print_str(p, " + ");
279 p = print_term(dim, div, c[i], i, p, 0);
281 isl_int_neg(c[i], c[i]);
284 p = isl_printer_print_str(p, "0");
288 static __isl_give isl_printer *print_affine(__isl_keep isl_basic_map *bmap,
289 __isl_keep isl_space *dim, __isl_take isl_printer *p, isl_int *c)
291 unsigned len = 1 + isl_basic_map_total_dim(bmap);
292 return print_affine_of_len(dim, NULL, p, c, len);
295 static int defining_equality(__isl_keep isl_basic_map *eq,
296 __isl_keep isl_space *dim, enum isl_dim_type type, int pos)
304 pos += isl_space_offset(dim, type);
305 total = isl_basic_map_total_dim(eq);
307 for (i = 0; i < eq->n_eq; ++i) {
308 if (isl_seq_last_non_zero(eq->eq[i] + 1, total) != pos)
310 if (isl_int_is_one(eq->eq[i][1 + pos]))
311 isl_seq_neg(eq->eq[i], eq->eq[i], 1 + total);
318 static __isl_give isl_printer *print_aff_body(__isl_take isl_printer *p,
319 __isl_keep isl_aff *aff);
321 /* offset is the offset of local_dim inside global_type of global_dim.
323 static __isl_give isl_printer *print_nested_var_list(__isl_take isl_printer *p,
324 __isl_keep isl_space *global_dim, enum isl_dim_type global_type,
325 __isl_keep isl_space *local_dim, enum isl_dim_type local_type,
326 int latex, __isl_keep isl_basic_map *eq,
327 __isl_keep isl_multi_aff *maff, int offset)
331 if (global_dim != local_dim && local_type == isl_dim_out)
332 offset += local_dim->n_in;
334 for (i = 0; i < isl_space_dim(local_dim, local_type); ++i) {
336 p = isl_printer_print_str(p, ", ");
337 if (maff && global_type == isl_dim_out) {
338 p = print_aff_body(p, maff->p[offset + i]);
341 j = defining_equality(eq, global_dim, global_type, offset + i);
343 int pos = 1 + isl_space_offset(global_dim, global_type)
345 p = print_affine_of_len(eq->dim, NULL,
348 p = print_name(global_dim, p, global_type, offset + i,
355 static __isl_give isl_printer *print_var_list(__isl_keep isl_space *dim,
356 __isl_take isl_printer *p, enum isl_dim_type type,
357 int latex, __isl_keep isl_basic_map *eq, __isl_keep isl_multi_aff *maff)
359 return print_nested_var_list(p, dim, type, dim, type, latex,
363 static __isl_give isl_printer *print_nested_map_dim(__isl_take isl_printer *p,
364 __isl_keep isl_space *global_dim, enum isl_dim_type global_type,
365 __isl_keep isl_space *local_dim,
366 int latex, __isl_keep isl_basic_map *eq,
367 __isl_keep isl_multi_aff *maff, int offset);
369 static __isl_give isl_printer *print_nested_tuple(__isl_take isl_printer *p,
370 __isl_keep isl_space *global_dim, enum isl_dim_type global_type,
371 __isl_keep isl_space *local_dim, enum isl_dim_type local_type,
372 int latex, __isl_keep isl_basic_map *eq,
373 __isl_keep isl_multi_aff *maff, int offset)
375 const char *name = NULL;
376 unsigned n = isl_space_dim(local_dim, local_type);
377 if ((local_type == isl_dim_in || local_type == isl_dim_out)) {
378 name = isl_space_get_tuple_name(local_dim, local_type);
381 p = isl_printer_print_str(p, "\\mathrm{");
382 p = isl_printer_print_str(p, name);
384 p = isl_printer_print_str(p, "}");
387 if (!latex || n != 1 || name)
388 p = isl_printer_print_str(p, s_open_list[latex]);
389 if ((local_type == isl_dim_in || local_type == isl_dim_out) &&
390 local_dim->nested[local_type - isl_dim_in]) {
391 if (global_dim != local_dim && local_type == isl_dim_out)
392 offset += local_dim->n_in;
393 p = print_nested_map_dim(p, global_dim, global_type,
394 local_dim->nested[local_type - isl_dim_in],
395 latex, eq, maff, offset);
397 p = print_nested_var_list(p, global_dim, global_type,
398 local_dim, local_type, latex,
400 if (!latex || n != 1 || name)
401 p = isl_printer_print_str(p, s_close_list[latex]);
405 static __isl_give isl_printer *print_tuple(__isl_keep isl_space *dim,
406 __isl_take isl_printer *p, enum isl_dim_type type,
407 int latex, __isl_keep isl_basic_map *eq, __isl_keep isl_multi_aff *maff)
409 return print_nested_tuple(p, dim, type, dim, type, latex, eq, maff, 0);
412 static __isl_give isl_printer *print_nested_map_dim(__isl_take isl_printer *p,
413 __isl_keep isl_space *global_dim, enum isl_dim_type global_type,
414 __isl_keep isl_space *local_dim,
415 int latex, __isl_keep isl_basic_map *eq,
416 __isl_keep isl_multi_aff *maff, int offset)
418 p = print_nested_tuple(p, global_dim, global_type,
419 local_dim, isl_dim_in, latex, eq, maff, offset);
420 p = isl_printer_print_str(p, s_to[latex]);
421 p = print_nested_tuple(p, global_dim, global_type,
422 local_dim, isl_dim_out, latex, eq, maff, offset);
427 static __isl_give isl_printer *print_space(__isl_keep isl_space *dim,
428 __isl_take isl_printer *p, int latex, int rational,
429 __isl_keep isl_basic_map *eq, __isl_keep isl_multi_aff *maff)
431 if (rational && !latex)
432 p = isl_printer_print_str(p, "rat: ");
433 if (isl_space_is_params(dim))
435 else if (isl_space_is_set(dim))
436 p = print_tuple(dim, p, isl_dim_set, latex, eq, maff);
438 p = print_tuple(dim, p, isl_dim_in, latex, eq, maff);
439 p = isl_printer_print_str(p, s_to[latex]);
440 p = print_tuple(dim, p, isl_dim_out, latex, eq, maff);
446 static __isl_give isl_printer *print_omega_parameters(__isl_keep isl_space *dim,
447 __isl_take isl_printer *p)
449 if (isl_space_dim(dim, isl_dim_param) == 0)
452 p = isl_printer_start_line(p);
453 p = isl_printer_print_str(p, "symbolic ");
454 p = print_var_list(dim, p, isl_dim_param, 0, NULL, NULL);
455 p = isl_printer_print_str(p, ";");
456 p = isl_printer_end_line(p);
460 static __isl_give isl_printer *print_constraint(struct isl_basic_map *bmap,
461 __isl_keep isl_space *dim, __isl_take isl_printer *p,
462 isl_int *c, int last, const char *op, int first_constraint, int latex)
464 if (!first_constraint)
465 p = isl_printer_print_str(p, s_and[latex]);
467 isl_int_abs(c[last], c[last]);
469 p = print_term(dim, NULL, c[last], last, p, latex);
471 p = isl_printer_print_str(p, " ");
472 p = isl_printer_print_str(p, op);
473 p = isl_printer_print_str(p, " ");
475 isl_int_set_si(c[last], 0);
476 p = print_affine(bmap, dim, p, c);
481 static __isl_give isl_printer *print_constraints(__isl_keep isl_basic_map *bmap,
482 __isl_keep isl_space *dim, __isl_take isl_printer *p, int latex)
486 unsigned total = isl_basic_map_total_dim(bmap);
488 c = isl_vec_alloc(bmap->ctx, 1 + total);
492 for (i = bmap->n_eq - 1; i >= 0; --i) {
493 int l = isl_seq_last_non_zero(bmap->eq[i], 1 + total);
495 if (i != bmap->n_eq - 1)
496 p = isl_printer_print_str(p, s_and[latex]);
497 p = isl_printer_print_str(p, "0 = 0");
500 if (isl_int_is_neg(bmap->eq[i][l]))
501 isl_seq_cpy(c->el, bmap->eq[i], 1 + total);
503 isl_seq_neg(c->el, bmap->eq[i], 1 + total);
504 p = print_constraint(bmap, dim, p, c->el, l,
505 "=", i == bmap->n_eq - 1, latex);
507 for (i = 0; i < bmap->n_ineq; ++i) {
508 int l = isl_seq_last_non_zero(bmap->ineq[i], 1 + total);
513 s = isl_int_sgn(bmap->ineq[i][l]);
515 isl_seq_cpy(c->el, bmap->ineq[i], 1 + total);
517 isl_seq_neg(c->el, bmap->ineq[i], 1 + total);
518 op = s < 0 ? s_le[latex] : s_ge[latex];
519 p = print_constraint(bmap, dim, p, c->el, l,
520 op, !bmap->n_eq && !i, latex);
532 static __isl_give isl_printer *print_omega_constraints(
533 __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p)
535 if (bmap->n_eq + bmap->n_ineq == 0)
538 p = isl_printer_print_str(p, ": ");
539 if (bmap->n_div > 0) {
541 p = isl_printer_print_str(p, "exists (");
542 for (i = 0; i < bmap->n_div; ++i) {
544 p = isl_printer_print_str(p, ", ");
545 p = print_name(bmap->dim, p, isl_dim_div, i, 0);
547 p = isl_printer_print_str(p, ": ");
549 p = print_constraints(bmap, bmap->dim, p, 0);
551 p = isl_printer_print_str(p, ")");
555 static __isl_give isl_printer *basic_map_print_omega(
556 __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p)
558 p = isl_printer_print_str(p, "{ [");
559 p = print_var_list(bmap->dim, p, isl_dim_in, 0, NULL, NULL);
560 p = isl_printer_print_str(p, "] -> [");
561 p = print_var_list(bmap->dim, p, isl_dim_out, 0, NULL, NULL);
562 p = isl_printer_print_str(p, "] ");
563 p = print_omega_constraints(bmap, p);
564 p = isl_printer_print_str(p, " }");
568 static __isl_give isl_printer *isl_basic_map_print_omega(
569 __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p)
571 p = print_omega_parameters(bmap->dim, p);
573 p = isl_printer_start_line(p);
574 p = basic_map_print_omega(bmap, p);
575 p = isl_printer_end_line(p);
579 static __isl_give isl_printer *basic_set_print_omega(
580 __isl_keep isl_basic_set *bset, __isl_take isl_printer *p)
582 p = isl_printer_print_str(p, "{ [");
583 p = print_var_list(bset->dim, p, isl_dim_set, 0, NULL, NULL);
584 p = isl_printer_print_str(p, "] ");
585 p = print_omega_constraints((isl_basic_map *)bset, p);
586 p = isl_printer_print_str(p, " }");
590 static __isl_give isl_printer *isl_basic_set_print_omega(
591 __isl_keep isl_basic_set *bset, __isl_take isl_printer *p)
593 p = print_omega_parameters(bset->dim, p);
595 p = isl_printer_start_line(p);
596 p = basic_set_print_omega(bset, p);
597 p = isl_printer_end_line(p);
601 static __isl_give isl_printer *isl_map_print_omega(__isl_keep isl_map *map,
602 __isl_take isl_printer *p)
606 p = print_omega_parameters(map->dim, p);
608 p = isl_printer_start_line(p);
609 for (i = 0; i < map->n; ++i) {
611 p = isl_printer_print_str(p, " union ");
612 p = basic_map_print_omega(map->p[i], p);
614 p = isl_printer_end_line(p);
618 static __isl_give isl_printer *isl_set_print_omega(__isl_keep isl_set *set,
619 __isl_take isl_printer *p)
623 p = print_omega_parameters(set->dim, p);
625 p = isl_printer_start_line(p);
626 for (i = 0; i < set->n; ++i) {
628 p = isl_printer_print_str(p, " union ");
629 p = basic_set_print_omega(set->p[i], p);
631 p = isl_printer_end_line(p);
635 static __isl_give isl_printer *print_disjunct(__isl_keep isl_basic_map *bmap,
636 __isl_keep isl_space *dim, __isl_take isl_printer *p, int latex)
638 if (bmap->n_div > 0) {
640 p = isl_printer_print_str(p, s_open_exists[latex]);
641 for (i = 0; i < bmap->n_div; ++i) {
643 p = isl_printer_print_str(p, ", ");
644 p = print_name(dim, p, isl_dim_div, i, latex);
645 if (latex || isl_int_is_zero(bmap->div[i][0]))
647 p = isl_printer_print_str(p, " = [(");
648 p = print_affine(bmap, dim, p, bmap->div[i] + 1);
649 p = isl_printer_print_str(p, ")/");
650 p = isl_printer_print_isl_int(p, bmap->div[i][0]);
651 p = isl_printer_print_str(p, "]");
653 p = isl_printer_print_str(p, ": ");
656 p = print_constraints(bmap, dim, p, latex);
659 p = isl_printer_print_str(p, s_close_exists[latex]);
663 static __isl_give isl_printer *isl_basic_map_print_isl(
664 __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p,
667 int rational = ISL_F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL);
668 if (isl_basic_map_dim(bmap, isl_dim_param) > 0) {
669 p = print_tuple(bmap->dim, p, isl_dim_param, latex, NULL, NULL);
670 p = isl_printer_print_str(p, " -> ");
672 p = isl_printer_print_str(p, "{ ");
673 p = print_space(bmap->dim, p, latex, rational, NULL, NULL);
674 p = isl_printer_print_str(p, " : ");
675 p = print_disjunct(bmap, bmap->dim, p, latex);
676 p = isl_printer_print_str(p, " }");
680 static __isl_give isl_printer *print_disjuncts(__isl_keep isl_map *map,
681 __isl_take isl_printer *p, int latex)
685 if (isl_map_plain_is_universe(map))
688 p = isl_printer_print_str(p, s_such_that[latex]);
690 p = isl_printer_print_str(p, "1 = 0");
691 for (i = 0; i < map->n; ++i) {
693 p = isl_printer_print_str(p, s_or[latex]);
694 if (map->n > 1 && map->p[i]->n_eq + map->p[i]->n_ineq > 1)
695 p = isl_printer_print_str(p, "(");
696 p = print_disjunct(map->p[i], map->dim, p, latex);
697 if (map->n > 1 && map->p[i]->n_eq + map->p[i]->n_ineq > 1)
698 p = isl_printer_print_str(p, ")");
703 /* Print the disjuncts of a map (or set).
704 * If the map turns out to be a universal parameter domain, then
705 * we need to print the colon. Otherwise, the output looks identical
708 static __isl_give isl_printer *print_disjuncts_map(__isl_keep isl_map *map,
709 __isl_take isl_printer *p, int latex)
711 if (isl_map_plain_is_universe(map) && isl_space_is_params(map->dim))
712 return isl_printer_print_str(p, s_such_that[latex]);
714 return print_disjuncts(map, p, latex);
717 struct isl_aff_split {
722 static void free_split(__isl_take struct isl_aff_split *split, int n)
729 for (i = 0; i < n; ++i) {
730 isl_basic_map_free(split[i].aff);
731 isl_map_free(split[i].map);
737 static __isl_give isl_basic_map *get_aff(__isl_take isl_basic_map *bmap)
740 unsigned nparam, n_in, n_out, total;
742 bmap = isl_basic_map_cow(bmap);
745 if (isl_basic_map_free_inequality(bmap, bmap->n_ineq) < 0)
748 nparam = isl_basic_map_dim(bmap, isl_dim_param);
749 n_in = isl_basic_map_dim(bmap, isl_dim_in);
750 n_out = isl_basic_map_dim(bmap, isl_dim_out);
751 total = isl_basic_map_dim(bmap, isl_dim_all);
752 for (i = bmap->n_eq - 1; i >= 0; --i) {
753 j = isl_seq_last_non_zero(bmap->eq[i] + 1, total);
754 if (j >= nparam && j < nparam + n_in + n_out &&
755 (isl_int_is_one(bmap->eq[i][1 + j]) ||
756 isl_int_is_negone(bmap->eq[i][1 + j])))
758 if (isl_basic_map_drop_equality(bmap, i) < 0)
762 bmap = isl_basic_map_finalize(bmap);
766 isl_basic_map_free(bmap);
770 static int aff_split_cmp(const void *p1, const void *p2)
772 const struct isl_aff_split *s1, *s2;
773 s1 = (const struct isl_aff_split *) p1;
774 s2 = (const struct isl_aff_split *) p2;
776 return isl_basic_map_plain_cmp(s1->aff, s2->aff);
779 static __isl_give isl_basic_map *drop_aff(__isl_take isl_basic_map *bmap,
780 __isl_keep isl_basic_map *aff)
788 total = isl_space_dim(bmap->dim, isl_dim_all);
790 for (i = bmap->n_eq - 1; i >= 0; --i) {
791 if (isl_seq_first_non_zero(bmap->eq[i] + 1 + total,
794 for (j = 0; j < aff->n_eq; ++j) {
795 if (!isl_seq_eq(bmap->eq[i], aff->eq[j], 1 + total) &&
796 !isl_seq_is_neg(bmap->eq[i], aff->eq[j], 1 + total))
798 if (isl_basic_map_drop_equality(bmap, i) < 0)
806 isl_basic_map_free(bmap);
810 static __isl_give struct isl_aff_split *split_aff(__isl_keep isl_map *map)
813 struct isl_aff_split *split;
816 ctx = isl_map_get_ctx(map);
817 split = isl_calloc_array(ctx, struct isl_aff_split, map->n);
821 for (i = 0; i < map->n; ++i) {
823 split[i].aff = get_aff(isl_basic_map_copy(map->p[i]));
824 bmap = isl_basic_map_copy(map->p[i]);
825 bmap = isl_basic_map_cow(bmap);
826 bmap = drop_aff(bmap, split[i].aff);
827 split[i].map = isl_map_from_basic_map(bmap);
828 if (!split[i].aff || !split[i].map)
832 qsort(split, map->n, sizeof(struct isl_aff_split), &aff_split_cmp);
835 for (i = n - 1; i >= 1; --i) {
836 if (!isl_basic_map_plain_is_equal(split[i - 1].aff,
839 isl_basic_map_free(split[i].aff);
840 split[i - 1].map = isl_map_union(split[i - 1].map,
843 split[i] = split[n - 1];
844 split[n - 1].aff = NULL;
845 split[n - 1].map = NULL;
851 free_split(split, map->n);
855 static __isl_give isl_printer *print_split_map(__isl_take isl_printer *p,
856 struct isl_aff_split *split, int n)
861 for (i = 0; i < n; ++i) {
866 dim = split[i].map->dim;
867 rational = split[i].map->n > 0 &&
868 ISL_F_ISSET(split[i].map->p[0], ISL_BASIC_MAP_RATIONAL);
870 p = isl_printer_print_str(p, "; ");
871 p = print_space(dim, p, 0, rational, split[i].aff, NULL);
872 p = print_disjuncts_map(split[i].map, p, 0);
878 static __isl_give isl_printer *isl_map_print_isl_body(__isl_keep isl_map *map,
879 __isl_take isl_printer *p)
881 struct isl_aff_split *split = NULL;
885 split = split_aff(map);
887 p = print_split_map(p, split, map->n);
889 rational = map->n > 0 &&
890 ISL_F_ISSET(map->p[0], ISL_BASIC_MAP_RATIONAL);
891 p = print_space(map->dim, p, 0, rational, NULL, NULL);
892 p = print_disjuncts_map(map, p, 0);
894 free_split(split, map->n);
898 static __isl_give isl_printer *isl_map_print_isl(__isl_keep isl_map *map,
899 __isl_take isl_printer *p)
901 if (isl_map_dim(map, isl_dim_param) > 0) {
902 p = print_tuple(map->dim, p, isl_dim_param, 0, NULL, NULL);
903 p = isl_printer_print_str(p, s_to[0]);
905 p = isl_printer_print_str(p, s_open_set[0]);
906 p = isl_map_print_isl_body(map, p);
907 p = isl_printer_print_str(p, s_close_set[0]);
911 static __isl_give isl_printer *print_latex_map(__isl_keep isl_map *map,
912 __isl_take isl_printer *p, __isl_keep isl_basic_map *aff)
914 if (isl_map_dim(map, isl_dim_param) > 0) {
915 p = print_tuple(map->dim, p, isl_dim_param, 1, NULL, NULL);
916 p = isl_printer_print_str(p, s_to[1]);
918 p = isl_printer_print_str(p, s_open_set[1]);
919 p = print_space(map->dim, p, 1, 0, aff, NULL);
920 p = print_disjuncts_map(map, p, 1);
921 p = isl_printer_print_str(p, s_close_set[1]);
926 static __isl_give isl_printer *isl_map_print_latex(__isl_keep isl_map *map,
927 __isl_take isl_printer *p)
930 struct isl_aff_split *split = NULL;
933 split = split_aff(map);
936 return print_latex_map(map, p, NULL);
938 for (i = 0; i < map->n; ++i) {
942 p = isl_printer_print_str(p, " \\cup ");
943 p = print_latex_map(split[i].map, p, split[i].aff);
946 free_split(split, map->n);
950 __isl_give isl_printer *isl_printer_print_basic_map(__isl_take isl_printer *p,
951 __isl_keep isl_basic_map *bmap)
955 if (p->output_format == ISL_FORMAT_ISL)
956 return isl_basic_map_print_isl(bmap, p, 0);
957 else if (p->output_format == ISL_FORMAT_OMEGA)
958 return isl_basic_map_print_omega(bmap, p);
959 isl_assert(bmap->ctx, 0, goto error);
965 void isl_basic_map_print(__isl_keep isl_basic_map *bmap, FILE *out, int indent,
966 const char *prefix, const char *suffix, unsigned output_format)
968 isl_printer *printer;
973 printer = isl_printer_to_file(bmap->ctx, out);
974 printer = isl_printer_set_indent(printer, indent);
975 printer = isl_printer_set_prefix(printer, prefix);
976 printer = isl_printer_set_suffix(printer, suffix);
977 printer = isl_printer_set_output_format(printer, output_format);
978 isl_printer_print_basic_map(printer, bmap);
980 isl_printer_free(printer);
983 __isl_give isl_printer *isl_printer_print_basic_set(__isl_take isl_printer *p,
984 __isl_keep isl_basic_set *bset)
989 if (p->output_format == ISL_FORMAT_ISL)
990 return isl_basic_map_print_isl(bset, p, 0);
991 else if (p->output_format == ISL_FORMAT_POLYLIB)
992 return isl_basic_set_print_polylib(bset, p, 0);
993 else if (p->output_format == ISL_FORMAT_EXT_POLYLIB)
994 return isl_basic_set_print_polylib(bset, p, 1);
995 else if (p->output_format == ISL_FORMAT_POLYLIB_CONSTRAINTS)
996 return bset_print_constraints_polylib(bset, p);
997 else if (p->output_format == ISL_FORMAT_OMEGA)
998 return isl_basic_set_print_omega(bset, p);
999 isl_assert(p->ctx, 0, goto error);
1001 isl_printer_free(p);
1005 void isl_basic_set_print(struct isl_basic_set *bset, FILE *out, int indent,
1006 const char *prefix, const char *suffix, unsigned output_format)
1008 isl_printer *printer;
1013 printer = isl_printer_to_file(bset->ctx, out);
1014 printer = isl_printer_set_indent(printer, indent);
1015 printer = isl_printer_set_prefix(printer, prefix);
1016 printer = isl_printer_set_suffix(printer, suffix);
1017 printer = isl_printer_set_output_format(printer, output_format);
1018 isl_printer_print_basic_set(printer, bset);
1020 isl_printer_free(printer);
1023 __isl_give isl_printer *isl_printer_print_set(__isl_take isl_printer *p,
1024 __isl_keep isl_set *set)
1028 if (p->output_format == ISL_FORMAT_ISL)
1029 return isl_map_print_isl((isl_map *)set, p);
1030 else if (p->output_format == ISL_FORMAT_POLYLIB)
1031 return isl_set_print_polylib(set, p, 0);
1032 else if (p->output_format == ISL_FORMAT_EXT_POLYLIB)
1033 return isl_set_print_polylib(set, p, 1);
1034 else if (p->output_format == ISL_FORMAT_OMEGA)
1035 return isl_set_print_omega(set, p);
1036 else if (p->output_format == ISL_FORMAT_LATEX)
1037 return isl_map_print_latex((isl_map *)set, p);
1038 isl_assert(set->ctx, 0, goto error);
1040 isl_printer_free(p);
1044 void isl_set_print(struct isl_set *set, FILE *out, int indent,
1045 unsigned output_format)
1047 isl_printer *printer;
1052 printer = isl_printer_to_file(set->ctx, out);
1053 printer = isl_printer_set_indent(printer, indent);
1054 printer = isl_printer_set_output_format(printer, output_format);
1055 printer = isl_printer_print_set(printer, set);
1057 isl_printer_free(printer);
1060 __isl_give isl_printer *isl_printer_print_map(__isl_take isl_printer *p,
1061 __isl_keep isl_map *map)
1066 if (p->output_format == ISL_FORMAT_ISL)
1067 return isl_map_print_isl(map, p);
1068 else if (p->output_format == ISL_FORMAT_POLYLIB)
1069 return isl_map_print_polylib(map, p, 0);
1070 else if (p->output_format == ISL_FORMAT_EXT_POLYLIB)
1071 return isl_map_print_polylib(map, p, 1);
1072 else if (p->output_format == ISL_FORMAT_OMEGA)
1073 return isl_map_print_omega(map, p);
1074 else if (p->output_format == ISL_FORMAT_LATEX)
1075 return isl_map_print_latex(map, p);
1076 isl_assert(map->ctx, 0, goto error);
1078 isl_printer_free(p);
1082 struct isl_union_print_data {
1087 static int print_map_body(__isl_take isl_map *map, void *user)
1089 struct isl_union_print_data *data;
1090 data = (struct isl_union_print_data *)user;
1093 data->p = isl_printer_print_str(data->p, "; ");
1096 data->p = isl_map_print_isl_body(map, data->p);
1102 static __isl_give isl_printer *isl_union_map_print_isl(
1103 __isl_keep isl_union_map *umap, __isl_take isl_printer *p)
1105 struct isl_union_print_data data = { p, 1 };
1107 dim = isl_union_map_get_space(umap);
1108 if (isl_space_dim(dim, isl_dim_param) > 0) {
1109 p = print_tuple(dim, p, isl_dim_param, 0, NULL, NULL);
1110 p = isl_printer_print_str(p, s_to[0]);
1112 isl_space_free(dim);
1113 p = isl_printer_print_str(p, s_open_set[0]);
1114 isl_union_map_foreach_map(umap, &print_map_body, &data);
1116 p = isl_printer_print_str(p, s_close_set[0]);
1120 static int print_latex_map_body(__isl_take isl_map *map, void *user)
1122 struct isl_union_print_data *data;
1123 data = (struct isl_union_print_data *)user;
1126 data->p = isl_printer_print_str(data->p, " \\cup ");
1129 data->p = isl_map_print_latex(map, data->p);
1135 static __isl_give isl_printer *isl_union_map_print_latex(
1136 __isl_keep isl_union_map *umap, __isl_take isl_printer *p)
1138 struct isl_union_print_data data = { p, 1 };
1139 isl_union_map_foreach_map(umap, &print_latex_map_body, &data);
1144 __isl_give isl_printer *isl_printer_print_union_map(__isl_take isl_printer *p,
1145 __isl_keep isl_union_map *umap)
1150 if (p->output_format == ISL_FORMAT_ISL)
1151 return isl_union_map_print_isl(umap, p);
1152 if (p->output_format == ISL_FORMAT_LATEX)
1153 return isl_union_map_print_latex(umap, p);
1155 isl_die(p->ctx, isl_error_invalid,
1156 "invalid output format for isl_union_map", goto error);
1158 isl_printer_free(p);
1162 __isl_give isl_printer *isl_printer_print_union_set(__isl_take isl_printer *p,
1163 __isl_keep isl_union_set *uset)
1168 if (p->output_format == ISL_FORMAT_ISL)
1169 return isl_union_map_print_isl((isl_union_map *)uset, p);
1170 if (p->output_format == ISL_FORMAT_LATEX)
1171 return isl_union_map_print_latex((isl_union_map *)uset, p);
1173 isl_die(p->ctx, isl_error_invalid,
1174 "invalid output format for isl_union_set", goto error);
1176 isl_printer_free(p);
1180 void isl_map_print(__isl_keep isl_map *map, FILE *out, int indent,
1181 unsigned output_format)
1183 isl_printer *printer;
1188 printer = isl_printer_to_file(map->ctx, out);
1189 printer = isl_printer_set_indent(printer, indent);
1190 printer = isl_printer_set_output_format(printer, output_format);
1191 printer = isl_printer_print_map(printer, map);
1193 isl_printer_free(printer);
1196 static int upoly_rec_n_non_zero(__isl_keep struct isl_upoly_rec *rec)
1201 for (i = 0, n = 0; i < rec->n; ++i)
1202 if (!isl_upoly_is_zero(rec->p[i]))
1208 static __isl_give isl_printer *print_div(__isl_keep isl_space *dim,
1209 __isl_keep isl_mat *div, int pos, __isl_take isl_printer *p)
1211 int c = p->output_format == ISL_FORMAT_C;
1212 p = isl_printer_print_str(p, c ? "floord(" : "[(");
1213 p = print_affine_of_len(dim, div, p,
1214 div->row[pos] + 1, div->n_col - 1);
1215 p = isl_printer_print_str(p, c ? ", " : ")/");
1216 p = isl_printer_print_isl_int(p, div->row[pos][0]);
1217 p = isl_printer_print_str(p, c ? ")" : "]");
1221 static __isl_give isl_printer *upoly_print_cst(__isl_keep struct isl_upoly *up,
1222 __isl_take isl_printer *p, int first)
1224 struct isl_upoly_cst *cst;
1227 cst = isl_upoly_as_cst(up);
1230 neg = !first && isl_int_is_neg(cst->n);
1232 p = isl_printer_print_str(p, neg ? " - " : " + ");
1234 isl_int_neg(cst->n, cst->n);
1235 if (isl_int_is_zero(cst->d)) {
1236 int sgn = isl_int_sgn(cst->n);
1237 p = isl_printer_print_str(p, sgn < 0 ? "-infty" :
1238 sgn == 0 ? "NaN" : "infty");
1240 p = isl_printer_print_isl_int(p, cst->n);
1242 isl_int_neg(cst->n, cst->n);
1243 if (!isl_int_is_zero(cst->d) && !isl_int_is_one(cst->d)) {
1244 p = isl_printer_print_str(p, "/");
1245 p = isl_printer_print_isl_int(p, cst->d);
1249 isl_printer_free(p);
1253 static __isl_give isl_printer *print_base(__isl_take isl_printer *p,
1254 __isl_keep isl_space *dim, __isl_keep isl_mat *div, int var)
1258 total = isl_space_dim(dim, isl_dim_all);
1260 p = print_term(dim, NULL, dim->ctx->one, 1 + var, p, 0);
1262 p = print_div(dim, div, var - total, p);
1266 static __isl_give isl_printer *print_pow(__isl_take isl_printer *p,
1267 __isl_keep isl_space *dim, __isl_keep isl_mat *div, int var, int exp)
1269 p = print_base(p, dim, div, var);
1272 if (p->output_format == ISL_FORMAT_C) {
1274 for (i = 1; i < exp; ++i) {
1275 p = isl_printer_print_str(p, "*");
1276 p = print_base(p, dim, div, var);
1279 p = isl_printer_print_str(p, "^");
1280 p = isl_printer_print_int(p, exp);
1285 static __isl_give isl_printer *upoly_print(__isl_keep struct isl_upoly *up,
1286 __isl_keep isl_space *dim, __isl_keep isl_mat *div,
1287 __isl_take isl_printer *p, int outer)
1289 int i, n, first, print_parens;
1290 struct isl_upoly_rec *rec;
1292 if (!p || !up || !dim || !div)
1295 if (isl_upoly_is_cst(up))
1296 return upoly_print_cst(up, p, 1);
1298 rec = isl_upoly_as_rec(up);
1301 n = upoly_rec_n_non_zero(rec);
1302 print_parens = n > 1 ||
1303 (outer && rec->up.var >= isl_space_dim(dim, isl_dim_all));
1305 p = isl_printer_print_str(p, "(");
1306 for (i = 0, first = 1; i < rec->n; ++i) {
1307 if (isl_upoly_is_zero(rec->p[i]))
1309 if (isl_upoly_is_negone(rec->p[i])) {
1311 p = isl_printer_print_str(p, "-1");
1313 p = isl_printer_print_str(p, "-");
1315 p = isl_printer_print_str(p, " - ");
1316 } else if (isl_upoly_is_cst(rec->p[i]) &&
1317 !isl_upoly_is_one(rec->p[i]))
1318 p = upoly_print_cst(rec->p[i], p, first);
1321 p = isl_printer_print_str(p, " + ");
1322 if (i == 0 || !isl_upoly_is_one(rec->p[i]))
1323 p = upoly_print(rec->p[i], dim, div, p, 0);
1328 if (!isl_upoly_is_one(rec->p[i]) &&
1329 !isl_upoly_is_negone(rec->p[i]))
1330 p = isl_printer_print_str(p, " * ");
1331 p = print_pow(p, dim, div, rec->up.var, i);
1334 p = isl_printer_print_str(p, ")");
1337 isl_printer_free(p);
1341 static __isl_give isl_printer *print_qpolynomial(__isl_take isl_printer *p,
1342 __isl_keep isl_qpolynomial *qp)
1346 p = upoly_print(qp->upoly, qp->dim, qp->div, p, 1);
1349 isl_printer_free(p);
1353 static __isl_give isl_printer *print_qpolynomial_isl(__isl_take isl_printer *p,
1354 __isl_keep isl_qpolynomial *qp)
1359 if (isl_space_dim(qp->dim, isl_dim_param) > 0) {
1360 p = print_tuple(qp->dim, p, isl_dim_param, 0, NULL, NULL);
1361 p = isl_printer_print_str(p, " -> ");
1363 p = isl_printer_print_str(p, "{ ");
1364 if (!isl_space_is_params(qp->dim)) {
1365 p = print_space(qp->dim, p, 0, 0, NULL, NULL);
1366 p = isl_printer_print_str(p, " -> ");
1368 p = print_qpolynomial(p, qp);
1369 p = isl_printer_print_str(p, " }");
1372 isl_printer_free(p);
1376 static __isl_give isl_printer *print_qpolynomial_c(__isl_take isl_printer *p,
1377 __isl_keep isl_space *dim, __isl_keep isl_qpolynomial *qp)
1382 isl_qpolynomial_get_den(qp, &den);
1383 if (!isl_int_is_one(den)) {
1385 p = isl_printer_print_str(p, "(");
1386 qp = isl_qpolynomial_copy(qp);
1387 f = isl_qpolynomial_rat_cst_on_domain(isl_space_copy(qp->dim),
1388 den, qp->dim->ctx->one);
1389 qp = isl_qpolynomial_mul(qp, f);
1392 p = upoly_print(qp->upoly, dim, qp->div, p, 0);
1393 if (!isl_int_is_one(den)) {
1394 p = isl_printer_print_str(p, ")/");
1395 p = isl_printer_print_isl_int(p, den);
1396 isl_qpolynomial_free(qp);
1402 __isl_give isl_printer *isl_printer_print_qpolynomial(
1403 __isl_take isl_printer *p, __isl_keep isl_qpolynomial *qp)
1408 if (p->output_format == ISL_FORMAT_ISL)
1409 return print_qpolynomial_isl(p, qp);
1410 else if (p->output_format == ISL_FORMAT_C)
1411 return print_qpolynomial_c(p, qp->dim, qp);
1413 isl_die(qp->dim->ctx, isl_error_unsupported,
1414 "output format not supported for isl_qpolynomials",
1417 isl_printer_free(p);
1421 void isl_qpolynomial_print(__isl_keep isl_qpolynomial *qp, FILE *out,
1422 unsigned output_format)
1429 isl_assert(qp->dim->ctx, output_format == ISL_FORMAT_ISL, return);
1430 p = isl_printer_to_file(qp->dim->ctx, out);
1431 p = isl_printer_print_qpolynomial(p, qp);
1432 isl_printer_free(p);
1435 static __isl_give isl_printer *qpolynomial_fold_print(
1436 __isl_keep isl_qpolynomial_fold *fold, __isl_take isl_printer *p)
1440 if (fold->type == isl_fold_min)
1441 p = isl_printer_print_str(p, "min");
1442 else if (fold->type == isl_fold_max)
1443 p = isl_printer_print_str(p, "max");
1444 p = isl_printer_print_str(p, "(");
1445 for (i = 0; i < fold->n; ++i) {
1447 p = isl_printer_print_str(p, ", ");
1448 p = print_qpolynomial(p, fold->qp[i]);
1450 p = isl_printer_print_str(p, ")");
1454 void isl_qpolynomial_fold_print(__isl_keep isl_qpolynomial_fold *fold,
1455 FILE *out, unsigned output_format)
1462 isl_assert(fold->dim->ctx, output_format == ISL_FORMAT_ISL, return);
1464 p = isl_printer_to_file(fold->dim->ctx, out);
1465 p = isl_printer_print_qpolynomial_fold(p, fold);
1467 isl_printer_free(p);
1470 static __isl_give isl_printer *isl_pwqp_print_isl_body(
1471 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial *pwqp)
1475 for (i = 0; i < pwqp->n; ++i) {
1477 p = isl_printer_print_str(p, "; ");
1478 if (!isl_space_is_params(pwqp->p[i].set->dim)) {
1479 p = print_space(pwqp->p[i].set->dim, p, 0, 0, NULL, NULL);
1480 p = isl_printer_print_str(p, " -> ");
1482 p = print_qpolynomial(p, pwqp->p[i].qp);
1483 p = print_disjuncts((isl_map *)pwqp->p[i].set, p, 0);
1489 static __isl_give isl_printer *print_pw_qpolynomial_isl(
1490 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial *pwqp)
1495 if (isl_space_dim(pwqp->dim, isl_dim_param) > 0) {
1496 p = print_tuple(pwqp->dim, p, isl_dim_param, 0, NULL, NULL);
1497 p = isl_printer_print_str(p, " -> ");
1499 p = isl_printer_print_str(p, "{ ");
1501 if (!isl_space_is_set(pwqp->dim)) {
1502 p = print_tuple(pwqp->dim, p, isl_dim_in, 0, NULL, NULL);
1503 p = isl_printer_print_str(p, " -> ");
1505 p = isl_printer_print_str(p, "0");
1507 p = isl_pwqp_print_isl_body(p, pwqp);
1508 p = isl_printer_print_str(p, " }");
1511 isl_printer_free(p);
1515 void isl_pw_qpolynomial_print(__isl_keep isl_pw_qpolynomial *pwqp, FILE *out,
1516 unsigned output_format)
1523 p = isl_printer_to_file(pwqp->dim->ctx, out);
1524 p = isl_printer_set_output_format(p, output_format);
1525 p = isl_printer_print_pw_qpolynomial(p, pwqp);
1527 isl_printer_free(p);
1530 static __isl_give isl_printer *isl_pwf_print_isl_body(
1531 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial_fold *pwf)
1535 for (i = 0; i < pwf->n; ++i) {
1537 p = isl_printer_print_str(p, "; ");
1538 if (!isl_space_is_params(pwf->p[i].set->dim)) {
1539 p = print_space(pwf->p[i].set->dim, p, 0, 0, NULL, NULL);
1540 p = isl_printer_print_str(p, " -> ");
1542 p = qpolynomial_fold_print(pwf->p[i].fold, p);
1543 p = print_disjuncts((isl_map *)pwf->p[i].set, p, 0);
1549 static __isl_give isl_printer *print_pw_qpolynomial_fold_isl(
1550 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial_fold *pwf)
1552 if (isl_space_dim(pwf->dim, isl_dim_param) > 0) {
1553 p = print_tuple(pwf->dim, p, isl_dim_param, 0, NULL, NULL);
1554 p = isl_printer_print_str(p, " -> ");
1556 p = isl_printer_print_str(p, "{ ");
1558 if (!isl_space_is_set(pwf->dim)) {
1559 p = print_tuple(pwf->dim, p, isl_dim_in, 0, NULL, NULL);
1560 p = isl_printer_print_str(p, " -> ");
1562 p = isl_printer_print_str(p, "0");
1564 p = isl_pwf_print_isl_body(p, pwf);
1565 p = isl_printer_print_str(p, " }");
1569 static __isl_give isl_printer *print_affine_c(__isl_take isl_printer *p,
1570 __isl_keep isl_space *dim, __isl_keep isl_basic_set *bset, isl_int *c);
1572 static __isl_give isl_printer *print_name_c(__isl_take isl_printer *p,
1573 __isl_keep isl_space *dim,
1574 __isl_keep isl_basic_set *bset, enum isl_dim_type type, unsigned pos)
1576 if (type == isl_dim_div) {
1577 p = isl_printer_print_str(p, "floord(");
1578 p = print_affine_c(p, dim, bset, bset->div[pos] + 1);
1579 p = isl_printer_print_str(p, ", ");
1580 p = isl_printer_print_isl_int(p, bset->div[pos][0]);
1581 p = isl_printer_print_str(p, ")");
1585 name = isl_space_get_dim_name(dim, type, pos);
1588 p = isl_printer_print_str(p, name);
1593 static __isl_give isl_printer *print_term_c(__isl_take isl_printer *p,
1594 __isl_keep isl_space *dim,
1595 __isl_keep isl_basic_set *bset, isl_int c, unsigned pos)
1597 enum isl_dim_type type;
1600 return isl_printer_print_isl_int(p, c);
1602 if (isl_int_is_one(c))
1604 else if (isl_int_is_negone(c))
1605 p = isl_printer_print_str(p, "-");
1607 p = isl_printer_print_isl_int(p, c);
1608 p = isl_printer_print_str(p, "*");
1610 type = pos2type(dim, &pos);
1611 p = print_name_c(p, dim, bset, type, pos);
1615 static __isl_give isl_printer *print_partial_affine_c(__isl_take isl_printer *p,
1616 __isl_keep isl_space *dim,
1617 __isl_keep isl_basic_set *bset, isl_int *c, unsigned len)
1622 for (i = 0, first = 1; i < len; ++i) {
1624 if (isl_int_is_zero(c[i]))
1627 if (isl_int_is_neg(c[i])) {
1629 isl_int_neg(c[i], c[i]);
1630 p = isl_printer_print_str(p, " - ");
1632 p = isl_printer_print_str(p, " + ");
1635 p = print_term_c(p, dim, bset, c[i], i);
1637 isl_int_neg(c[i], c[i]);
1640 p = isl_printer_print_str(p, "0");
1644 static __isl_give isl_printer *print_affine_c(__isl_take isl_printer *p,
1645 __isl_keep isl_space *dim, __isl_keep isl_basic_set *bset, isl_int *c)
1647 unsigned len = 1 + isl_basic_set_total_dim(bset);
1648 return print_partial_affine_c(p, dim, bset, c, len);
1651 /* We skip the constraint if it is implied by the div expression.
1653 static __isl_give isl_printer *print_constraint_c(__isl_take isl_printer *p,
1654 __isl_keep isl_space *dim,
1655 __isl_keep isl_basic_set *bset, isl_int *c, const char *op, int first)
1661 o_div = isl_basic_set_offset(bset, isl_dim_div);
1662 n_div = isl_basic_set_dim(bset, isl_dim_div);
1663 div = isl_seq_last_non_zero(c + o_div, n_div);
1664 if (div >= 0 && isl_basic_set_is_div_constraint(bset, c, div))
1668 p = isl_printer_print_str(p, " && ");
1670 p = print_affine_c(p, dim, bset, c);
1671 p = isl_printer_print_str(p, " ");
1672 p = isl_printer_print_str(p, op);
1673 p = isl_printer_print_str(p, " 0");
1677 static __isl_give isl_printer *print_basic_set_c(__isl_take isl_printer *p,
1678 __isl_keep isl_space *dim, __isl_keep isl_basic_set *bset)
1681 unsigned n_div = isl_basic_set_dim(bset, isl_dim_div);
1682 unsigned total = isl_basic_set_total_dim(bset) - n_div;
1684 for (i = 0; i < bset->n_eq; ++i) {
1685 j = isl_seq_last_non_zero(bset->eq[i] + 1 + total, n_div);
1687 p = print_constraint_c(p, dim, bset,
1688 bset->eq[i], "==", !i);
1691 p = isl_printer_print_str(p, " && ");
1692 p = isl_printer_print_str(p, "(");
1693 p = print_partial_affine_c(p, dim, bset, bset->eq[i],
1695 p = isl_printer_print_str(p, ") % ");
1696 p = isl_printer_print_isl_int(p,
1697 bset->eq[i][1 + total + j]);
1698 p = isl_printer_print_str(p, " == 0");
1701 for (i = 0; i < bset->n_ineq; ++i)
1702 p = print_constraint_c(p, dim, bset, bset->ineq[i], ">=",
1707 static __isl_give isl_printer *print_set_c(__isl_take isl_printer *p,
1708 __isl_keep isl_space *dim, __isl_keep isl_set *set)
1713 p = isl_printer_print_str(p, "0");
1715 for (i = 0; i < set->n; ++i) {
1717 p = isl_printer_print_str(p, " || ");
1719 p = isl_printer_print_str(p, "(");
1720 p = print_basic_set_c(p, dim, set->p[i]);
1722 p = isl_printer_print_str(p, ")");
1727 static __isl_give isl_printer *print_pw_qpolynomial_c(
1728 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial *pwqp)
1732 if (pwqp->n == 1 && isl_set_plain_is_universe(pwqp->p[0].set))
1733 return print_qpolynomial_c(p, pwqp->dim, pwqp->p[0].qp);
1735 for (i = 0; i < pwqp->n; ++i) {
1736 p = isl_printer_print_str(p, "(");
1737 p = print_set_c(p, pwqp->dim, pwqp->p[i].set);
1738 p = isl_printer_print_str(p, ") ? (");
1739 p = print_qpolynomial_c(p, pwqp->dim, pwqp->p[i].qp);
1740 p = isl_printer_print_str(p, ") : ");
1743 p = isl_printer_print_str(p, "0");
1747 __isl_give isl_printer *isl_printer_print_pw_qpolynomial(
1748 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial *pwqp)
1753 if (p->output_format == ISL_FORMAT_ISL)
1754 return print_pw_qpolynomial_isl(p, pwqp);
1755 else if (p->output_format == ISL_FORMAT_C)
1756 return print_pw_qpolynomial_c(p, pwqp);
1757 isl_assert(p->ctx, 0, goto error);
1759 isl_printer_free(p);
1763 static int print_pwqp_body(__isl_take isl_pw_qpolynomial *pwqp, void *user)
1765 struct isl_union_print_data *data;
1766 data = (struct isl_union_print_data *)user;
1769 data->p = isl_printer_print_str(data->p, "; ");
1772 data->p = isl_pwqp_print_isl_body(data->p, pwqp);
1773 isl_pw_qpolynomial_free(pwqp);
1778 static __isl_give isl_printer *print_union_pw_qpolynomial_isl(
1779 __isl_take isl_printer *p, __isl_keep isl_union_pw_qpolynomial *upwqp)
1781 struct isl_union_print_data data = { p, 1 };
1783 dim = isl_union_pw_qpolynomial_get_space(upwqp);
1784 if (isl_space_dim(dim, isl_dim_param) > 0) {
1785 p = print_tuple(dim, p, isl_dim_param, 0, NULL, NULL);
1786 p = isl_printer_print_str(p, " -> ");
1788 isl_space_free(dim);
1789 p = isl_printer_print_str(p, "{ ");
1790 isl_union_pw_qpolynomial_foreach_pw_qpolynomial(upwqp, &print_pwqp_body,
1793 p = isl_printer_print_str(p, " }");
1797 __isl_give isl_printer *isl_printer_print_union_pw_qpolynomial(
1798 __isl_take isl_printer *p, __isl_keep isl_union_pw_qpolynomial *upwqp)
1803 if (p->output_format == ISL_FORMAT_ISL)
1804 return print_union_pw_qpolynomial_isl(p, upwqp);
1805 isl_die(p->ctx, isl_error_invalid,
1806 "invalid output format for isl_union_pw_qpolynomial",
1809 isl_printer_free(p);
1813 static __isl_give isl_printer *print_qpolynomial_fold_c(
1814 __isl_take isl_printer *p, __isl_keep isl_space *dim,
1815 __isl_keep isl_qpolynomial_fold *fold)
1819 for (i = 0; i < fold->n - 1; ++i)
1820 if (fold->type == isl_fold_min)
1821 p = isl_printer_print_str(p, "min(");
1822 else if (fold->type == isl_fold_max)
1823 p = isl_printer_print_str(p, "max(");
1825 for (i = 0; i < fold->n; ++i) {
1827 p = isl_printer_print_str(p, ", ");
1828 p = print_qpolynomial_c(p, dim, fold->qp[i]);
1830 p = isl_printer_print_str(p, ")");
1835 __isl_give isl_printer *isl_printer_print_qpolynomial_fold(
1836 __isl_take isl_printer *p, __isl_keep isl_qpolynomial_fold *fold)
1840 if (p->output_format == ISL_FORMAT_ISL)
1841 return qpolynomial_fold_print(fold, p);
1842 else if (p->output_format == ISL_FORMAT_C)
1843 return print_qpolynomial_fold_c(p, fold->dim, fold);
1844 isl_die(p->ctx, isl_error_unsupported, "unsupported output format",
1847 isl_printer_free(p);
1851 static __isl_give isl_printer *print_pw_qpolynomial_fold_c(
1852 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial_fold *pwf)
1856 if (pwf->n == 1 && isl_set_plain_is_universe(pwf->p[0].set))
1857 return print_qpolynomial_fold_c(p, pwf->dim, pwf->p[0].fold);
1859 for (i = 0; i < pwf->n; ++i) {
1860 p = isl_printer_print_str(p, "(");
1861 p = print_set_c(p, pwf->dim, pwf->p[i].set);
1862 p = isl_printer_print_str(p, ") ? (");
1863 p = print_qpolynomial_fold_c(p, pwf->dim, pwf->p[i].fold);
1864 p = isl_printer_print_str(p, ") : ");
1867 p = isl_printer_print_str(p, "0");
1871 __isl_give isl_printer *isl_printer_print_pw_qpolynomial_fold(
1872 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial_fold *pwf)
1877 if (p->output_format == ISL_FORMAT_ISL)
1878 return print_pw_qpolynomial_fold_isl(p, pwf);
1879 else if (p->output_format == ISL_FORMAT_C)
1880 return print_pw_qpolynomial_fold_c(p, pwf);
1881 isl_assert(p->ctx, 0, goto error);
1883 isl_printer_free(p);
1887 void isl_pw_qpolynomial_fold_print(__isl_keep isl_pw_qpolynomial_fold *pwf,
1888 FILE *out, unsigned output_format)
1895 p = isl_printer_to_file(pwf->dim->ctx, out);
1896 p = isl_printer_set_output_format(p, output_format);
1897 p = isl_printer_print_pw_qpolynomial_fold(p, pwf);
1899 isl_printer_free(p);
1902 static int print_pwf_body(__isl_take isl_pw_qpolynomial_fold *pwf, void *user)
1904 struct isl_union_print_data *data;
1905 data = (struct isl_union_print_data *)user;
1908 data->p = isl_printer_print_str(data->p, "; ");
1911 data->p = isl_pwf_print_isl_body(data->p, pwf);
1912 isl_pw_qpolynomial_fold_free(pwf);
1917 static __isl_give isl_printer *print_union_pw_qpolynomial_fold_isl(
1918 __isl_take isl_printer *p,
1919 __isl_keep isl_union_pw_qpolynomial_fold *upwf)
1921 struct isl_union_print_data data = { p, 1 };
1923 dim = isl_union_pw_qpolynomial_fold_get_space(upwf);
1924 if (isl_space_dim(dim, isl_dim_param) > 0) {
1925 p = print_tuple(dim, p, isl_dim_param, 0, NULL, NULL);
1926 p = isl_printer_print_str(p, " -> ");
1928 isl_space_free(dim);
1929 p = isl_printer_print_str(p, "{ ");
1930 isl_union_pw_qpolynomial_fold_foreach_pw_qpolynomial_fold(upwf,
1931 &print_pwf_body, &data);
1933 p = isl_printer_print_str(p, " }");
1937 __isl_give isl_printer *isl_printer_print_union_pw_qpolynomial_fold(
1938 __isl_take isl_printer *p,
1939 __isl_keep isl_union_pw_qpolynomial_fold *upwf)
1944 if (p->output_format == ISL_FORMAT_ISL)
1945 return print_union_pw_qpolynomial_fold_isl(p, upwf);
1946 isl_die(p->ctx, isl_error_invalid,
1947 "invalid output format for isl_union_pw_qpolynomial_fold",
1950 isl_printer_free(p);
1954 __isl_give isl_printer *isl_printer_print_constraint(__isl_take isl_printer *p,
1955 __isl_keep isl_constraint *c)
1957 isl_basic_map *bmap;
1962 bmap = isl_basic_map_from_constraint(isl_constraint_copy(c));
1963 p = isl_printer_print_basic_map(p, bmap);
1964 isl_basic_map_free(bmap);
1967 isl_printer_free(p);
1971 __isl_give isl_printer *isl_printer_print_space(__isl_take isl_printer *p,
1972 __isl_keep isl_space *dim)
1977 if (isl_space_dim(dim, isl_dim_param) > 0) {
1978 p = print_tuple(dim, p, isl_dim_param, 0, NULL, NULL);
1979 p = isl_printer_print_str(p, " -> ");
1982 p = isl_printer_print_str(p, "{ ");
1983 if (isl_space_is_params(dim))
1984 p = isl_printer_print_str(p, s_such_that[0]);
1986 p = print_space(dim, p, 0, 0, NULL, NULL);
1987 p = isl_printer_print_str(p, " }");
1991 isl_printer_free(p);
1995 __isl_give isl_printer *isl_printer_print_local_space(__isl_take isl_printer *p,
1996 __isl_keep isl_local_space *ls)
2004 total = isl_local_space_dim(ls, isl_dim_all);
2005 if (isl_local_space_dim(ls, isl_dim_param) > 0) {
2006 p = print_tuple(ls->dim, p, isl_dim_param, 0, NULL, NULL);
2007 p = isl_printer_print_str(p, " -> ");
2009 p = isl_printer_print_str(p, "{ ");
2010 p = print_space(ls->dim, p, 0, 0, NULL, NULL);
2011 n_div = isl_local_space_dim(ls, isl_dim_div);
2014 p = isl_printer_print_str(p, " : ");
2015 p = isl_printer_print_str(p, s_open_exists[0]);
2016 for (i = 0; i < n_div; ++i) {
2018 p = isl_printer_print_str(p, ", ");
2019 p = print_name(ls->dim, p, isl_dim_div, i, 0);
2020 if (isl_int_is_zero(ls->div->row[i][0]))
2022 p = isl_printer_print_str(p, " = [(");
2023 p = print_affine_of_len(ls->dim, ls->div, p,
2024 ls->div->row[i] + 1, 1 + total);
2025 p = isl_printer_print_str(p, ")/");
2026 p = isl_printer_print_isl_int(p, ls->div->row[i][0]);
2027 p = isl_printer_print_str(p, "]");
2029 } else if (isl_space_is_params(ls->dim))
2030 p = isl_printer_print_str(p, s_such_that[0]);
2031 p = isl_printer_print_str(p, " }");
2034 isl_printer_free(p);
2038 static __isl_give isl_printer *print_aff_body(__isl_take isl_printer *p,
2039 __isl_keep isl_aff *aff)
2043 total = isl_local_space_dim(aff->ls, isl_dim_all);
2044 p = isl_printer_print_str(p, "(");
2045 p = print_affine_of_len(aff->ls->dim, aff->ls->div, p,
2046 aff->v->el + 1, 1 + total);
2047 if (isl_int_is_one(aff->v->el[0]))
2048 p = isl_printer_print_str(p, ")");
2050 p = isl_printer_print_str(p, ")/");
2051 p = isl_printer_print_isl_int(p, aff->v->el[0]);
2057 static __isl_give isl_printer *print_aff(__isl_take isl_printer *p,
2058 __isl_keep isl_aff *aff)
2060 if (isl_space_is_params(aff->ls->dim))
2063 p = print_tuple(aff->ls->dim, p, isl_dim_set, 0, NULL, NULL);
2064 p = isl_printer_print_str(p, " -> ");
2066 p = isl_printer_print_str(p, "[");
2067 p = print_aff_body(p, aff);
2068 p = isl_printer_print_str(p, "]");
2073 static __isl_give isl_printer *print_aff_isl(__isl_take isl_printer *p,
2074 __isl_keep isl_aff *aff)
2079 if (isl_local_space_dim(aff->ls, isl_dim_param) > 0) {
2080 p = print_tuple(aff->ls->dim, p, isl_dim_param, 0, NULL, NULL);
2081 p = isl_printer_print_str(p, " -> ");
2083 p = isl_printer_print_str(p, "{ ");
2084 p = print_aff(p, aff);
2085 p = isl_printer_print_str(p, " }");
2088 isl_printer_free(p);
2092 static __isl_give isl_printer *print_pw_aff_isl(__isl_take isl_printer *p,
2093 __isl_keep isl_pw_aff *pwaff)
2100 if (isl_space_dim(pwaff->dim, isl_dim_param) > 0) {
2101 p = print_tuple(pwaff->dim, p, isl_dim_param, 0, NULL, NULL);
2102 p = isl_printer_print_str(p, " -> ");
2104 p = isl_printer_print_str(p, "{ ");
2105 for (i = 0; i < pwaff->n; ++i) {
2107 p = isl_printer_print_str(p, "; ");
2108 p = print_aff(p, pwaff->p[i].aff);
2109 p = print_disjuncts((isl_map *)pwaff->p[i].set, p, 0);
2111 p = isl_printer_print_str(p, " }");
2114 isl_printer_free(p);
2118 static __isl_give isl_printer *print_ls_affine_c(__isl_take isl_printer *p,
2119 __isl_keep isl_local_space *ls, isl_int *c);
2121 static __isl_give isl_printer *print_ls_name_c(__isl_take isl_printer *p,
2122 __isl_keep isl_local_space *ls, enum isl_dim_type type, unsigned pos)
2124 if (type == isl_dim_div) {
2125 p = isl_printer_print_str(p, "floord(");
2126 p = print_ls_affine_c(p, ls, ls->div->row[pos] + 1);
2127 p = isl_printer_print_str(p, ", ");
2128 p = isl_printer_print_isl_int(p, ls->div->row[pos][0]);
2129 p = isl_printer_print_str(p, ")");
2133 name = isl_space_get_dim_name(ls->dim, type, pos);
2136 p = isl_printer_print_str(p, name);
2141 static __isl_give isl_printer *print_ls_term_c(__isl_take isl_printer *p,
2142 __isl_keep isl_local_space *ls, isl_int c, unsigned pos)
2144 enum isl_dim_type type;
2147 return isl_printer_print_isl_int(p, c);
2149 if (isl_int_is_one(c))
2151 else if (isl_int_is_negone(c))
2152 p = isl_printer_print_str(p, "-");
2154 p = isl_printer_print_isl_int(p, c);
2155 p = isl_printer_print_str(p, "*");
2157 type = pos2type(ls->dim, &pos);
2158 p = print_ls_name_c(p, ls, type, pos);
2162 static __isl_give isl_printer *print_ls_partial_affine_c(
2163 __isl_take isl_printer *p, __isl_keep isl_local_space *ls,
2164 isl_int *c, unsigned len)
2169 for (i = 0, first = 1; i < len; ++i) {
2171 if (isl_int_is_zero(c[i]))
2174 if (isl_int_is_neg(c[i])) {
2176 isl_int_neg(c[i], c[i]);
2177 p = isl_printer_print_str(p, " - ");
2179 p = isl_printer_print_str(p, " + ");
2182 p = print_ls_term_c(p, ls, c[i], i);
2184 isl_int_neg(c[i], c[i]);
2187 p = isl_printer_print_str(p, "0");
2191 static __isl_give isl_printer *print_ls_affine_c(__isl_take isl_printer *p,
2192 __isl_keep isl_local_space *ls, isl_int *c)
2194 unsigned len = 1 + isl_local_space_dim(ls, isl_dim_all);
2195 return print_ls_partial_affine_c(p, ls, c, len);
2198 static __isl_give isl_printer *print_aff_c(__isl_take isl_printer *p,
2199 __isl_keep isl_aff *aff)
2203 total = isl_local_space_dim(aff->ls, isl_dim_all);
2204 if (!isl_int_is_one(aff->v->el[0]))
2205 p = isl_printer_print_str(p, "(");
2206 p = print_ls_partial_affine_c(p, aff->ls, aff->v->el + 1, 1 + total);
2207 if (!isl_int_is_one(aff->v->el[0])) {
2208 p = isl_printer_print_str(p, ")/");
2209 p = isl_printer_print_isl_int(p, aff->v->el[0]);
2214 /* In the C format, we cannot express that "pwaff" may be undefined
2215 * on parts of the domain space. We therefore assume that the expression
2216 * will only be evaluated on its definition domain and compute the gist
2217 * of each cell with respect to this domain.
2219 static __isl_give isl_printer *print_pw_aff_c(__isl_take isl_printer *p,
2220 __isl_keep isl_pw_aff *pwaff)
2227 isl_die(p->ctx, isl_error_unsupported,
2228 "cannot print empty isl_pw_aff in C format", goto error);
2229 space = isl_pw_aff_get_domain_space(pwaff);
2233 domain = isl_pw_aff_domain(isl_pw_aff_copy(pwaff));
2235 for (i = 0; i < pwaff->n - 1; ++i) {
2238 p = isl_printer_print_str(p, "(");
2240 set_i = isl_set_copy(pwaff->p[i].set);
2241 set_i = isl_set_gist(set_i, isl_set_copy(domain));
2242 p = print_set_c(p, space, set_i);
2243 isl_set_free(set_i);
2245 p = isl_printer_print_str(p, ") ? (");
2246 p = print_aff_c(p, pwaff->p[i].aff);
2247 p = isl_printer_print_str(p, ") : ");
2250 isl_set_free(domain);
2251 isl_space_free(space);
2253 return print_aff_c(p, pwaff->p[pwaff->n - 1].aff);
2255 isl_printer_free(p);
2259 __isl_give isl_printer *isl_printer_print_aff(__isl_take isl_printer *p,
2260 __isl_keep isl_aff *aff)
2265 if (p->output_format == ISL_FORMAT_ISL)
2266 return print_aff_isl(p, aff);
2267 else if (p->output_format == ISL_FORMAT_C)
2268 return print_aff_c(p, aff);
2269 isl_die(p->ctx, isl_error_unsupported, "unsupported output format",
2272 isl_printer_free(p);
2276 __isl_give isl_printer *isl_printer_print_pw_aff(__isl_take isl_printer *p,
2277 __isl_keep isl_pw_aff *pwaff)
2282 if (p->output_format == ISL_FORMAT_ISL)
2283 return print_pw_aff_isl(p, pwaff);
2284 else if (p->output_format == ISL_FORMAT_C)
2285 return print_pw_aff_c(p, pwaff);
2286 isl_die(p->ctx, isl_error_unsupported, "unsupported output format",
2289 isl_printer_free(p);
2293 static __isl_give isl_printer *print_multi_aff(__isl_take isl_printer *p,
2294 __isl_keep isl_multi_aff *maff)
2296 return print_space(maff->space, p, 0, 0, NULL, maff);
2299 static __isl_give isl_printer *print_multi_aff_isl(__isl_take isl_printer *p,
2300 __isl_keep isl_multi_aff *maff)
2305 if (isl_space_dim(maff->space, isl_dim_param) > 0) {
2306 p = print_tuple(maff->space, p, isl_dim_param, 0, NULL, NULL);
2307 p = isl_printer_print_str(p, " -> ");
2309 p = isl_printer_print_str(p, "{ ");
2310 p = print_multi_aff(p, maff);
2311 p = isl_printer_print_str(p, " }");
2314 isl_printer_free(p);
2318 __isl_give isl_printer *isl_printer_print_multi_aff(__isl_take isl_printer *p,
2319 __isl_keep isl_multi_aff *maff)
2324 if (p->output_format == ISL_FORMAT_ISL)
2325 return print_multi_aff_isl(p, maff);
2326 isl_die(p->ctx, isl_error_unsupported, "unsupported output format",
2329 isl_printer_free(p);
2333 static __isl_give isl_printer *print_pw_multi_aff_body(
2334 __isl_take isl_printer *p, __isl_keep isl_pw_multi_aff *pma)
2341 for (i = 0; i < pma->n; ++i) {
2343 p = isl_printer_print_str(p, "; ");
2344 p = print_multi_aff(p, pma->p[i].maff);
2345 p = print_disjuncts((isl_map *)pma->p[i].set, p, 0);
2349 isl_printer_free(p);
2353 static __isl_give isl_printer *print_pw_multi_aff_isl(__isl_take isl_printer *p,
2354 __isl_keep isl_pw_multi_aff *pma)
2359 if (isl_space_dim(pma->dim, isl_dim_param) > 0) {
2360 p = print_tuple(pma->dim, p, isl_dim_param, 0, NULL, NULL);
2361 p = isl_printer_print_str(p, " -> ");
2363 p = isl_printer_print_str(p, "{ ");
2364 p = print_pw_multi_aff_body(p, pma);
2365 p = isl_printer_print_str(p, " }");
2368 isl_printer_free(p);
2372 static __isl_give isl_printer *print_unnamed_pw_multi_aff_c(
2373 __isl_take isl_printer *p, __isl_keep isl_pw_multi_aff *pma)
2377 for (i = 0; i < pma->n - 1; ++i) {
2378 p = isl_printer_print_str(p, "(");
2379 p = print_set_c(p, pma->dim, pma->p[i].set);
2380 p = isl_printer_print_str(p, ") ? (");
2381 p = print_aff_c(p, pma->p[i].maff->p[0]);
2382 p = isl_printer_print_str(p, ") : ");
2385 return print_aff_c(p, pma->p[pma->n - 1].maff->p[0]);
2388 static __isl_give isl_printer *print_pw_multi_aff_c(__isl_take isl_printer *p,
2389 __isl_keep isl_pw_multi_aff *pma)
2397 isl_die(p->ctx, isl_error_unsupported,
2398 "cannot print empty isl_pw_multi_aff in C format",
2400 name = isl_pw_multi_aff_get_tuple_name(pma, isl_dim_out);
2401 if (!name && isl_pw_multi_aff_dim(pma, isl_dim_out) == 1)
2402 return print_unnamed_pw_multi_aff_c(p, pma);
2404 isl_die(p->ctx, isl_error_unsupported,
2405 "cannot print unnamed isl_pw_multi_aff in C format",
2408 p = isl_printer_print_str(p, name);
2409 n = isl_pw_multi_aff_dim(pma, isl_dim_out);
2411 isl_die(p->ctx, isl_error_unsupported,
2412 "not supported yet", goto error);
2416 isl_printer_free(p);
2420 __isl_give isl_printer *isl_printer_print_pw_multi_aff(
2421 __isl_take isl_printer *p, __isl_keep isl_pw_multi_aff *pma)
2426 if (p->output_format == ISL_FORMAT_ISL)
2427 return print_pw_multi_aff_isl(p, pma);
2428 if (p->output_format == ISL_FORMAT_C)
2429 return print_pw_multi_aff_c(p, pma);
2430 isl_die(p->ctx, isl_error_unsupported, "unsupported output format",
2433 isl_printer_free(p);
2437 static int print_pw_multi_aff_body_wrap(__isl_take isl_pw_multi_aff *pma,
2440 struct isl_union_print_data *data;
2441 data = (struct isl_union_print_data *) user;
2444 data->p = isl_printer_print_str(data->p, "; ");
2447 data->p = print_pw_multi_aff_body(data->p, pma);
2448 isl_pw_multi_aff_free(pma);
2453 static __isl_give isl_printer *print_union_pw_multi_aff_isl(
2454 __isl_take isl_printer *p, __isl_keep isl_union_pw_multi_aff *upma)
2456 struct isl_union_print_data data = { p, 1 };
2459 space = isl_union_pw_multi_aff_get_space(upma);
2460 if (isl_space_dim(space, isl_dim_param) > 0) {
2461 p = print_tuple(space, p, isl_dim_param, 0, NULL, NULL);
2462 p = isl_printer_print_str(p, s_to[0]);
2464 isl_space_free(space);
2465 p = isl_printer_print_str(p, s_open_set[0]);
2466 isl_union_pw_multi_aff_foreach_pw_multi_aff(upma,
2467 &print_pw_multi_aff_body_wrap, &data);
2469 p = isl_printer_print_str(p, s_close_set[0]);
2473 __isl_give isl_printer *isl_printer_print_union_pw_multi_aff(
2474 __isl_take isl_printer *p, __isl_keep isl_union_pw_multi_aff *upma)
2479 if (p->output_format == ISL_FORMAT_ISL)
2480 return print_union_pw_multi_aff_isl(p, upma);
2481 isl_die(p->ctx, isl_error_unsupported, "unsupported output format",
2484 isl_printer_free(p);