Merge branch 'maint'
[isl.git] / isl_output.c
blob8ebe10ef565cda4ca313f0ec22a1cba5fcc15673
1 /*
2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2012-2013 Ecole Normale Superieure
6 * Use of this software is governed by the MIT license
8 * Written by Sven Verdoolaege, K.U.Leuven, Departement
9 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
10 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
11 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
12 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
15 #include <stdlib.h>
16 #include <string.h>
17 #include <isl_ctx_private.h>
18 #include <isl_map_private.h>
19 #include <isl/set.h>
20 #include <isl_seq.h>
21 #include <isl_polynomial_private.h>
22 #include <isl_printer_private.h>
23 #include <isl_space_private.h>
24 #include <isl_mat_private.h>
25 #include <isl_vec_private.h>
26 #include <isl/union_map.h>
27 #include <isl/constraint.h>
28 #include <isl_local_space_private.h>
29 #include <isl_aff_private.h>
30 #include <isl_val_private.h>
31 #include <isl/ast_build.h>
32 #include <isl_sort.h>
34 static const char *s_to[2] = { " -> ", " \\to " };
35 static const char *s_and[2] = { " and ", " \\wedge " };
36 static const char *s_or[2] = { " or ", " \\vee " };
37 static const char *s_le[2] = { "<=", "\\le" };
38 static const char *s_ge[2] = { ">=", "\\ge" };
39 static const char *s_open_set[2] = { "{ ", "\\{\\, " };
40 static const char *s_close_set[2] = { " }", " \\,\\}" };
41 static const char *s_open_list[2] = { "[", "(" };
42 static const char *s_close_list[2] = { "]", ")" };
43 static const char *s_such_that[2] = { " : ", " \\mid " };
44 static const char *s_open_exists[2] = { "exists (", "\\exists \\, " };
45 static const char *s_close_exists[2] = { ")", "" };
46 static const char *s_div_prefix[2] = { "e", "\\alpha_" };
47 static const char *s_param_prefix[2] = { "p", "p_" };
48 static const char *s_input_prefix[2] = { "i", "i_" };
49 static const char *s_output_prefix[2] = { "o", "o_" };
51 static __isl_give isl_printer *print_constraint_polylib(
52 struct isl_basic_map *bmap, int ineq, int n, __isl_take isl_printer *p)
54 int i;
55 unsigned n_in = isl_basic_map_dim(bmap, isl_dim_in);
56 unsigned n_out = isl_basic_map_dim(bmap, isl_dim_out);
57 unsigned nparam = isl_basic_map_dim(bmap, isl_dim_param);
58 isl_int *c = ineq ? bmap->ineq[n] : bmap->eq[n];
60 p = isl_printer_start_line(p);
61 p = isl_printer_print_int(p, ineq);
62 for (i = 0; i < n_out; ++i) {
63 p = isl_printer_print_str(p, " ");
64 p = isl_printer_print_isl_int(p, c[1+nparam+n_in+i]);
66 for (i = 0; i < n_in; ++i) {
67 p = isl_printer_print_str(p, " ");
68 p = isl_printer_print_isl_int(p, c[1+nparam+i]);
70 for (i = 0; i < bmap->n_div; ++i) {
71 p = isl_printer_print_str(p, " ");
72 p = isl_printer_print_isl_int(p, c[1+nparam+n_in+n_out+i]);
74 for (i = 0; i < nparam; ++i) {
75 p = isl_printer_print_str(p, " ");
76 p = isl_printer_print_isl_int(p, c[1+i]);
78 p = isl_printer_print_str(p, " ");
79 p = isl_printer_print_isl_int(p, c[0]);
80 p = isl_printer_end_line(p);
81 return p;
84 static __isl_give isl_printer *print_constraints_polylib(
85 struct isl_basic_map *bmap, __isl_take isl_printer *p)
87 int i;
89 p = isl_printer_set_isl_int_width(p, 5);
91 for (i = 0; i < bmap->n_eq; ++i)
92 p = print_constraint_polylib(bmap, 0, i, p);
93 for (i = 0; i < bmap->n_ineq; ++i)
94 p = print_constraint_polylib(bmap, 1, i, p);
96 return p;
99 static __isl_give isl_printer *bset_print_constraints_polylib(
100 struct isl_basic_set *bset, __isl_take isl_printer *p)
102 return print_constraints_polylib((struct isl_basic_map *)bset, p);
105 static __isl_give isl_printer *isl_basic_map_print_polylib(
106 __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p, int ext)
108 unsigned total = isl_basic_map_total_dim(bmap);
109 p = isl_printer_start_line(p);
110 p = isl_printer_print_int(p, bmap->n_eq + bmap->n_ineq);
111 p = isl_printer_print_str(p, " ");
112 p = isl_printer_print_int(p, 1 + total + 1);
113 if (ext) {
114 p = isl_printer_print_str(p, " ");
115 p = isl_printer_print_int(p,
116 isl_basic_map_dim(bmap, isl_dim_out));
117 p = isl_printer_print_str(p, " ");
118 p = isl_printer_print_int(p,
119 isl_basic_map_dim(bmap, isl_dim_in));
120 p = isl_printer_print_str(p, " ");
121 p = isl_printer_print_int(p,
122 isl_basic_map_dim(bmap, isl_dim_div));
123 p = isl_printer_print_str(p, " ");
124 p = isl_printer_print_int(p,
125 isl_basic_map_dim(bmap, isl_dim_param));
127 p = isl_printer_end_line(p);
128 return print_constraints_polylib(bmap, p);
131 static __isl_give isl_printer *isl_basic_set_print_polylib(
132 __isl_keep isl_basic_set *bset, __isl_take isl_printer *p, int ext)
134 return isl_basic_map_print_polylib((struct isl_basic_map *)bset, p, ext);
137 static __isl_give isl_printer *isl_map_print_polylib(__isl_keep isl_map *map,
138 __isl_take isl_printer *p, int ext)
140 int i;
142 p = isl_printer_start_line(p);
143 p = isl_printer_print_int(p, map->n);
144 p = isl_printer_end_line(p);
145 for (i = 0; i < map->n; ++i) {
146 p = isl_printer_start_line(p);
147 p = isl_printer_end_line(p);
148 p = isl_basic_map_print_polylib(map->p[i], p, ext);
150 return p;
153 static __isl_give isl_printer *isl_set_print_polylib(__isl_keep isl_set *set,
154 __isl_take isl_printer *p, int ext)
156 return isl_map_print_polylib((struct isl_map *)set, p, ext);
159 static int count_same_name(__isl_keep isl_space *dim,
160 enum isl_dim_type type, unsigned pos, const char *name)
162 enum isl_dim_type t;
163 unsigned p, s;
164 int count = 0;
166 for (t = isl_dim_param; t <= type && t <= isl_dim_out; ++t) {
167 s = t == type ? pos : isl_space_dim(dim, t);
168 for (p = 0; p < s; ++p) {
169 const char *n = isl_space_get_dim_name(dim, t, p);
170 if (n && !strcmp(n, name))
171 count++;
174 return count;
177 static __isl_give isl_printer *print_name(__isl_keep isl_space *dim,
178 __isl_take isl_printer *p, enum isl_dim_type type, unsigned pos,
179 int latex)
181 const char *name;
182 char buffer[20];
183 int primes;
185 name = type == isl_dim_div ? NULL : isl_space_get_dim_name(dim, type, pos);
187 if (!name) {
188 const char *prefix;
189 if (type == isl_dim_param)
190 prefix = s_param_prefix[latex];
191 else if (type == isl_dim_div)
192 prefix = s_div_prefix[latex];
193 else if (isl_space_is_set(dim) || type == isl_dim_in)
194 prefix = s_input_prefix[latex];
195 else
196 prefix = s_output_prefix[latex];
197 snprintf(buffer, sizeof(buffer), "%s%d", prefix, pos);
198 name = buffer;
200 primes = count_same_name(dim, name == buffer ? isl_dim_div : type,
201 pos, name);
202 p = isl_printer_print_str(p, name);
203 while (primes-- > 0)
204 p = isl_printer_print_str(p, "'");
205 return p;
208 static enum isl_dim_type pos2type(__isl_keep isl_space *dim, unsigned *pos)
210 enum isl_dim_type type;
211 unsigned n_in = isl_space_dim(dim, isl_dim_in);
212 unsigned n_out = isl_space_dim(dim, isl_dim_out);
213 unsigned nparam = isl_space_dim(dim, isl_dim_param);
215 if (*pos < 1 + nparam) {
216 type = isl_dim_param;
217 *pos -= 1;
218 } else if (*pos < 1 + nparam + n_in) {
219 type = isl_dim_in;
220 *pos -= 1 + nparam;
221 } else if (*pos < 1 + nparam + n_in + n_out) {
222 type = isl_dim_out;
223 *pos -= 1 + nparam + n_in;
224 } else {
225 type = isl_dim_div;
226 *pos -= 1 + nparam + n_in + n_out;
229 return type;
232 static __isl_give isl_printer *print_div(__isl_keep isl_space *dim,
233 __isl_keep isl_mat *div, int pos, __isl_take isl_printer *p);
235 static __isl_give isl_printer *print_term(__isl_keep isl_space *dim,
236 __isl_keep isl_mat *div,
237 isl_int c, unsigned pos, __isl_take isl_printer *p, int latex)
239 enum isl_dim_type type;
240 int print_div_def;
242 if (pos == 0)
243 return isl_printer_print_isl_int(p, c);
245 type = pos2type(dim, &pos);
246 print_div_def = type == isl_dim_div && div &&
247 !isl_int_is_zero(div->row[pos][0]);
249 if (isl_int_is_one(c))
251 else if (isl_int_is_negone(c))
252 p = isl_printer_print_str(p, "-");
253 else {
254 p = isl_printer_print_isl_int(p, c);
255 if (p->output_format == ISL_FORMAT_C || print_div_def)
256 p = isl_printer_print_str(p, "*");
258 if (print_div_def)
259 p = print_div(dim, div, pos, p);
260 else
261 p = print_name(dim, p, type, pos, latex);
262 return p;
265 static __isl_give isl_printer *print_affine_of_len(__isl_keep isl_space *dim,
266 __isl_keep isl_mat *div,
267 __isl_take isl_printer *p, isl_int *c, int len)
269 int i;
270 int first;
272 for (i = 0, first = 1; i < len; ++i) {
273 int flip = 0;
274 if (isl_int_is_zero(c[i]))
275 continue;
276 if (!first) {
277 if (isl_int_is_neg(c[i])) {
278 flip = 1;
279 isl_int_neg(c[i], c[i]);
280 p = isl_printer_print_str(p, " - ");
281 } else
282 p = isl_printer_print_str(p, " + ");
284 first = 0;
285 p = print_term(dim, div, c[i], i, p, 0);
286 if (flip)
287 isl_int_neg(c[i], c[i]);
289 if (first)
290 p = isl_printer_print_str(p, "0");
291 return p;
294 static __isl_give isl_printer *print_affine(__isl_keep isl_basic_map *bmap,
295 __isl_keep isl_space *dim, __isl_take isl_printer *p, isl_int *c)
297 unsigned len = 1 + isl_basic_map_total_dim(bmap);
298 return print_affine_of_len(dim, NULL, p, c, len);
301 /* Internal data structure for print_space.
303 * latex is set if that is the output format.
304 * print_dim (if not NULL) is called on each dimension.
305 * user is set by the caller of print_space and may be used inside print_dim.
307 * space is the global space that is being printed. This field is set by
308 * print_space.
309 * type is the tuple of the global space that is currently being printed.
310 * This field is set by print_space.
312 struct isl_print_space_data {
313 int latex;
314 __isl_give isl_printer *(*print_dim)(__isl_take isl_printer *p,
315 struct isl_print_space_data *data, unsigned pos);
316 void *user;
318 isl_space *space;
319 enum isl_dim_type type;
322 /* offset is the offset of local_dim inside data->type of data->space.
324 static __isl_give isl_printer *print_nested_var_list(__isl_take isl_printer *p,
325 __isl_keep isl_space *local_dim, enum isl_dim_type local_type,
326 struct isl_print_space_data *data, int offset)
328 int i;
330 if (data->space != local_dim && local_type == isl_dim_out)
331 offset += local_dim->n_in;
333 for (i = 0; i < isl_space_dim(local_dim, local_type); ++i) {
334 if (i)
335 p = isl_printer_print_str(p, ", ");
336 if (data->print_dim)
337 p = data->print_dim(p, data, offset + i);
338 else
339 p = print_name(data->space, p, data->type, offset + i,
340 data->latex);
342 return p;
345 static __isl_give isl_printer *print_var_list(__isl_take isl_printer *p,
346 __isl_keep isl_space *space, enum isl_dim_type type)
348 struct isl_print_space_data data = { .space = space, .type = type };
350 return print_nested_var_list(p, space, type, &data, 0);
353 static __isl_give isl_printer *print_nested_map_dim(__isl_take isl_printer *p,
354 __isl_keep isl_space *local_dim,
355 struct isl_print_space_data *data, int offset);
357 static __isl_give isl_printer *print_nested_tuple(__isl_take isl_printer *p,
358 __isl_keep isl_space *local_dim, enum isl_dim_type local_type,
359 struct isl_print_space_data *data, int offset)
361 const char *name = NULL;
362 unsigned n = isl_space_dim(local_dim, local_type);
363 if ((local_type == isl_dim_in || local_type == isl_dim_out)) {
364 name = isl_space_get_tuple_name(local_dim, local_type);
365 if (name) {
366 if (data->latex)
367 p = isl_printer_print_str(p, "\\mathrm{");
368 p = isl_printer_print_str(p, name);
369 if (data->latex)
370 p = isl_printer_print_str(p, "}");
373 if (!data->latex || n != 1 || name)
374 p = isl_printer_print_str(p, s_open_list[data->latex]);
375 if ((local_type == isl_dim_in || local_type == isl_dim_out) &&
376 local_dim->nested[local_type - isl_dim_in]) {
377 if (data->space != local_dim && local_type == isl_dim_out)
378 offset += local_dim->n_in;
379 p = print_nested_map_dim(p,
380 local_dim->nested[local_type - isl_dim_in],
381 data, offset);
382 } else
383 p = print_nested_var_list(p, local_dim, local_type, data,
384 offset);
385 if (!data->latex || n != 1 || name)
386 p = isl_printer_print_str(p, s_close_list[data->latex]);
387 return p;
390 static __isl_give isl_printer *print_tuple(__isl_keep isl_space *dim,
391 __isl_take isl_printer *p, enum isl_dim_type type,
392 struct isl_print_space_data *data)
394 data->space = dim;
395 data->type = type;
396 return print_nested_tuple(p, dim, type, data, 0);
399 static __isl_give isl_printer *print_nested_map_dim(__isl_take isl_printer *p,
400 __isl_keep isl_space *local_dim,
401 struct isl_print_space_data *data, int offset)
403 p = print_nested_tuple(p, local_dim, isl_dim_in, data, offset);
404 p = isl_printer_print_str(p, s_to[data->latex]);
405 p = print_nested_tuple(p, local_dim, isl_dim_out, data, offset);
407 return p;
410 static __isl_give isl_printer *print_space(__isl_keep isl_space *dim,
411 __isl_take isl_printer *p, int rational,
412 struct isl_print_space_data *data)
414 if (rational && !data->latex)
415 p = isl_printer_print_str(p, "rat: ");
416 if (isl_space_is_params(dim))
418 else if (isl_space_is_set(dim))
419 p = print_tuple(dim, p, isl_dim_set, data);
420 else {
421 p = print_tuple(dim, p, isl_dim_in, data);
422 p = isl_printer_print_str(p, s_to[data->latex]);
423 p = print_tuple(dim, p, isl_dim_out, data);
426 return p;
429 static __isl_give isl_printer *print_omega_parameters(__isl_keep isl_space *dim,
430 __isl_take isl_printer *p)
432 if (isl_space_dim(dim, isl_dim_param) == 0)
433 return p;
435 p = isl_printer_start_line(p);
436 p = isl_printer_print_str(p, "symbolic ");
437 p = print_var_list(p, dim, isl_dim_param);
438 p = isl_printer_print_str(p, ";");
439 p = isl_printer_end_line(p);
440 return p;
443 static __isl_give isl_printer *print_constraint(struct isl_basic_map *bmap,
444 __isl_keep isl_space *dim, __isl_take isl_printer *p,
445 isl_int *c, int last, const char *op, int first_constraint, int latex)
447 if (!first_constraint)
448 p = isl_printer_print_str(p, s_and[latex]);
450 isl_int_abs(c[last], c[last]);
452 p = print_term(dim, NULL, c[last], last, p, latex);
454 p = isl_printer_print_str(p, " ");
455 p = isl_printer_print_str(p, op);
456 p = isl_printer_print_str(p, " ");
458 isl_int_set_si(c[last], 0);
459 p = print_affine(bmap, dim, p, c);
461 return p;
464 static __isl_give isl_printer *print_constraints(__isl_keep isl_basic_map *bmap,
465 __isl_keep isl_space *dim, __isl_take isl_printer *p, int latex)
467 int i;
468 struct isl_vec *c;
469 unsigned total = isl_basic_map_total_dim(bmap);
471 c = isl_vec_alloc(bmap->ctx, 1 + total);
472 if (!c)
473 goto error;
475 for (i = bmap->n_eq - 1; i >= 0; --i) {
476 int l = isl_seq_last_non_zero(bmap->eq[i], 1 + total);
477 if (l < 0) {
478 if (i != bmap->n_eq - 1)
479 p = isl_printer_print_str(p, s_and[latex]);
480 p = isl_printer_print_str(p, "0 = 0");
481 continue;
483 if (isl_int_is_neg(bmap->eq[i][l]))
484 isl_seq_cpy(c->el, bmap->eq[i], 1 + total);
485 else
486 isl_seq_neg(c->el, bmap->eq[i], 1 + total);
487 p = print_constraint(bmap, dim, p, c->el, l,
488 "=", i == bmap->n_eq - 1, latex);
490 for (i = 0; i < bmap->n_ineq; ++i) {
491 int l = isl_seq_last_non_zero(bmap->ineq[i], 1 + total);
492 int s;
493 const char *op;
494 if (l < 0)
495 continue;
496 s = isl_int_sgn(bmap->ineq[i][l]);
497 if (s < 0)
498 isl_seq_cpy(c->el, bmap->ineq[i], 1 + total);
499 else
500 isl_seq_neg(c->el, bmap->ineq[i], 1 + total);
501 op = s < 0 ? s_le[latex] : s_ge[latex];
502 p = print_constraint(bmap, dim, p, c->el, l,
503 op, !bmap->n_eq && !i, latex);
506 isl_vec_free(c);
508 return p;
509 error:
510 isl_vec_free(c);
511 isl_printer_free(p);
512 return NULL;
515 static __isl_give isl_printer *print_div(__isl_keep isl_space *dim,
516 __isl_keep isl_mat *div, int pos, __isl_take isl_printer *p)
518 int c = p->output_format == ISL_FORMAT_C;
519 p = isl_printer_print_str(p, c ? "floord(" : "floor((");
520 p = print_affine_of_len(dim, div, p,
521 div->row[pos] + 1, div->n_col - 1);
522 p = isl_printer_print_str(p, c ? ", " : ")/");
523 p = isl_printer_print_isl_int(p, div->row[pos][0]);
524 p = isl_printer_print_str(p, ")");
525 return p;
528 /* Print a comma separated list of div names, with their definitions
529 * (provided that they have a definition and we are printing in isl format).
531 static __isl_give isl_printer *print_div_list(__isl_take isl_printer *p,
532 __isl_keep isl_space *space, __isl_keep isl_mat *div, int latex)
534 int i;
535 unsigned n_div;
537 if (!p || !space || !div)
538 return isl_printer_free(p);
540 n_div = isl_mat_rows(div);
542 for (i = 0; i < n_div; ++i) {
543 if (i)
544 p = isl_printer_print_str(p, ", ");
545 p = print_name(space, p, isl_dim_div, i, latex);
546 if (p->output_format != ISL_FORMAT_ISL ||
547 isl_int_is_zero(div->row[i][0]))
548 continue;
549 p = isl_printer_print_str(p, " = ");
550 p = print_div(space, div, i, p);
553 return p;
556 static __isl_give isl_printer *print_disjunct(__isl_keep isl_basic_map *bmap,
557 __isl_keep isl_space *dim, __isl_take isl_printer *p, int latex)
559 if (bmap->n_div > 0) {
560 isl_space *space;
561 isl_mat *div;
563 space = isl_basic_map_get_space(bmap);
564 div = isl_basic_map_get_divs(bmap);
565 p = isl_printer_print_str(p, s_open_exists[latex]);
566 p = print_div_list(p, space, div, latex);
567 isl_space_free(space);
568 isl_mat_free(div);
569 p = isl_printer_print_str(p, ": ");
572 p = print_constraints(bmap, dim, p, latex);
574 if (bmap->n_div > 0)
575 p = isl_printer_print_str(p, s_close_exists[latex]);
576 return p;
579 /* Print a colon followed by the constraints of "bmap"
580 * to "p", provided there are any constraints.
581 * The names of the variables are taken from "space".
582 * "latex" is set if the constraints should be printed in LaTeX format.
584 static __isl_give isl_printer *print_optional_disjunct(
585 __isl_keep isl_basic_map *bmap, __isl_keep isl_space *space,
586 __isl_take isl_printer *p, int latex)
588 if (isl_basic_map_is_universe(bmap))
589 return p;
591 p = isl_printer_print_str(p, ": ");
592 p = print_disjunct(bmap, space, p, latex);
594 return p;
597 static __isl_give isl_printer *basic_map_print_omega(
598 __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p)
600 p = isl_printer_print_str(p, "{ [");
601 p = print_var_list(p, bmap->dim, isl_dim_in);
602 p = isl_printer_print_str(p, "] -> [");
603 p = print_var_list(p, bmap->dim, isl_dim_out);
604 p = isl_printer_print_str(p, "] ");
605 p = print_optional_disjunct(bmap, bmap->dim, p, 0);
606 p = isl_printer_print_str(p, " }");
607 return p;
610 static __isl_give isl_printer *basic_set_print_omega(
611 __isl_keep isl_basic_set *bset, __isl_take isl_printer *p)
613 p = isl_printer_print_str(p, "{ [");
614 p = print_var_list(p, bset->dim, isl_dim_set);
615 p = isl_printer_print_str(p, "] ");
616 p = print_optional_disjunct(bset, bset->dim, p, 0);
617 p = isl_printer_print_str(p, " }");
618 return p;
621 static __isl_give isl_printer *isl_map_print_omega(__isl_keep isl_map *map,
622 __isl_take isl_printer *p)
624 int i;
626 for (i = 0; i < map->n; ++i) {
627 if (i)
628 p = isl_printer_print_str(p, " union ");
629 p = basic_map_print_omega(map->p[i], p);
631 return p;
634 static __isl_give isl_printer *isl_set_print_omega(__isl_keep isl_set *set,
635 __isl_take isl_printer *p)
637 int i;
639 for (i = 0; i < set->n; ++i) {
640 if (i)
641 p = isl_printer_print_str(p, " union ");
642 p = basic_set_print_omega(set->p[i], p);
644 return p;
647 static __isl_give isl_printer *isl_basic_map_print_isl(
648 __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p,
649 int latex)
651 struct isl_print_space_data data = { .latex = latex };
652 int rational = ISL_F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL);
654 if (isl_basic_map_dim(bmap, isl_dim_param) > 0) {
655 p = print_tuple(bmap->dim, p, isl_dim_param, &data);
656 p = isl_printer_print_str(p, " -> ");
658 p = isl_printer_print_str(p, "{ ");
659 p = print_space(bmap->dim, p, rational, &data);
660 p = isl_printer_print_str(p, " : ");
661 p = print_disjunct(bmap, bmap->dim, p, latex);
662 p = isl_printer_print_str(p, " }");
663 return p;
666 static __isl_give isl_printer *print_disjuncts(__isl_keep isl_map *map,
667 __isl_take isl_printer *p, int latex)
669 int i;
671 if (isl_map_plain_is_universe(map))
672 return p;
674 p = isl_printer_print_str(p, s_such_that[latex]);
675 if (map->n == 0)
676 p = isl_printer_print_str(p, "1 = 0");
677 for (i = 0; i < map->n; ++i) {
678 if (i)
679 p = isl_printer_print_str(p, s_or[latex]);
680 if (map->n > 1 && map->p[i]->n_eq + map->p[i]->n_ineq > 1)
681 p = isl_printer_print_str(p, "(");
682 p = print_disjunct(map->p[i], map->dim, p, latex);
683 if (map->n > 1 && map->p[i]->n_eq + map->p[i]->n_ineq > 1)
684 p = isl_printer_print_str(p, ")");
686 return p;
689 /* Print the disjuncts of a map (or set).
690 * If the map turns out to be a universal parameter domain, then
691 * we need to print the colon. Otherwise, the output looks identical
692 * to the empty set.
694 static __isl_give isl_printer *print_disjuncts_map(__isl_keep isl_map *map,
695 __isl_take isl_printer *p, int latex)
697 if (isl_map_plain_is_universe(map) && isl_space_is_params(map->dim))
698 return isl_printer_print_str(p, s_such_that[latex]);
699 else
700 return print_disjuncts(map, p, latex);
703 struct isl_aff_split {
704 isl_basic_map *aff;
705 isl_map *map;
708 static void free_split(__isl_take struct isl_aff_split *split, int n)
710 int i;
712 if (!split)
713 return;
715 for (i = 0; i < n; ++i) {
716 isl_basic_map_free(split[i].aff);
717 isl_map_free(split[i].map);
720 free(split);
723 static __isl_give isl_basic_map *get_aff(__isl_take isl_basic_map *bmap)
725 int i, j;
726 unsigned nparam, n_in, n_out, total;
728 bmap = isl_basic_map_cow(bmap);
729 if (!bmap)
730 return NULL;
731 if (isl_basic_map_free_inequality(bmap, bmap->n_ineq) < 0)
732 goto error;
734 nparam = isl_basic_map_dim(bmap, isl_dim_param);
735 n_in = isl_basic_map_dim(bmap, isl_dim_in);
736 n_out = isl_basic_map_dim(bmap, isl_dim_out);
737 total = isl_basic_map_dim(bmap, isl_dim_all);
738 for (i = bmap->n_eq - 1; i >= 0; --i) {
739 j = isl_seq_last_non_zero(bmap->eq[i] + 1, total);
740 if (j >= nparam && j < nparam + n_in + n_out &&
741 (isl_int_is_one(bmap->eq[i][1 + j]) ||
742 isl_int_is_negone(bmap->eq[i][1 + j])))
743 continue;
744 if (isl_basic_map_drop_equality(bmap, i) < 0)
745 goto error;
748 bmap = isl_basic_map_finalize(bmap);
750 return bmap;
751 error:
752 isl_basic_map_free(bmap);
753 return NULL;
756 static int aff_split_cmp(const void *p1, const void *p2, void *user)
758 const struct isl_aff_split *s1, *s2;
759 s1 = (const struct isl_aff_split *) p1;
760 s2 = (const struct isl_aff_split *) p2;
762 return isl_basic_map_plain_cmp(s1->aff, s2->aff);
765 static __isl_give isl_basic_map *drop_aff(__isl_take isl_basic_map *bmap,
766 __isl_keep isl_basic_map *aff)
768 int i, j;
769 unsigned total;
771 if (!bmap || !aff)
772 goto error;
774 total = isl_space_dim(bmap->dim, isl_dim_all);
776 for (i = bmap->n_eq - 1; i >= 0; --i) {
777 if (isl_seq_first_non_zero(bmap->eq[i] + 1 + total,
778 bmap->n_div) != -1)
779 continue;
780 for (j = 0; j < aff->n_eq; ++j) {
781 if (!isl_seq_eq(bmap->eq[i], aff->eq[j], 1 + total) &&
782 !isl_seq_is_neg(bmap->eq[i], aff->eq[j], 1 + total))
783 continue;
784 if (isl_basic_map_drop_equality(bmap, i) < 0)
785 goto error;
786 break;
790 return bmap;
791 error:
792 isl_basic_map_free(bmap);
793 return NULL;
796 static __isl_give struct isl_aff_split *split_aff(__isl_keep isl_map *map)
798 int i, n;
799 struct isl_aff_split *split;
800 isl_ctx *ctx;
802 ctx = isl_map_get_ctx(map);
803 split = isl_calloc_array(ctx, struct isl_aff_split, map->n);
804 if (!split)
805 return NULL;
807 for (i = 0; i < map->n; ++i) {
808 isl_basic_map *bmap;
809 split[i].aff = get_aff(isl_basic_map_copy(map->p[i]));
810 bmap = isl_basic_map_copy(map->p[i]);
811 bmap = isl_basic_map_cow(bmap);
812 bmap = drop_aff(bmap, split[i].aff);
813 split[i].map = isl_map_from_basic_map(bmap);
814 if (!split[i].aff || !split[i].map)
815 goto error;
818 if (isl_sort(split, map->n, sizeof(struct isl_aff_split),
819 &aff_split_cmp, NULL) < 0)
820 goto error;
822 n = map->n;
823 for (i = n - 1; i >= 1; --i) {
824 if (!isl_basic_map_plain_is_equal(split[i - 1].aff,
825 split[i].aff))
826 continue;
827 isl_basic_map_free(split[i].aff);
828 split[i - 1].map = isl_map_union(split[i - 1].map,
829 split[i].map);
830 if (i != n - 1)
831 split[i] = split[n - 1];
832 split[n - 1].aff = NULL;
833 split[n - 1].map = NULL;
834 --n;
837 return split;
838 error:
839 free_split(split, map->n);
840 return NULL;
843 static int defining_equality(__isl_keep isl_basic_map *eq,
844 __isl_keep isl_space *dim, enum isl_dim_type type, int pos)
846 int i;
847 unsigned total;
849 if (!eq)
850 return -1;
852 pos += isl_space_offset(dim, type);
853 total = isl_basic_map_total_dim(eq);
855 for (i = 0; i < eq->n_eq; ++i) {
856 if (isl_seq_last_non_zero(eq->eq[i] + 1, total) != pos)
857 continue;
858 if (isl_int_is_one(eq->eq[i][1 + pos]))
859 isl_seq_neg(eq->eq[i], eq->eq[i], 1 + total);
860 return i;
863 return -1;
866 /* Print dimension "pos" of data->space to "p".
868 * data->user is assumed to be an isl_basic_map keeping track of equalities.
870 * If the current dimension is defined by these equalities, then print
871 * the corresponding expression. Otherwise, print the name of the dimension.
873 static __isl_give isl_printer *print_dim_eq(__isl_take isl_printer *p,
874 struct isl_print_space_data *data, unsigned pos)
876 isl_basic_map *eq = data->user;
877 int j;
879 j = defining_equality(eq, data->space, data->type, pos);
880 if (j >= 0) {
881 pos += 1 + isl_space_offset(data->space, data->type);
882 p = print_affine_of_len(eq->dim, NULL, p, eq->eq[j], pos);
883 } else {
884 p = print_name(data->space, p, data->type, pos, data->latex);
887 return p;
890 static __isl_give isl_printer *print_split_map(__isl_take isl_printer *p,
891 struct isl_aff_split *split, int n)
893 struct isl_print_space_data data = { 0 };
894 int i;
895 int rational;
897 data.print_dim = &print_dim_eq;
898 for (i = 0; i < n; ++i) {
899 isl_space *dim;
901 if (!split[i].map)
902 break;
903 dim = split[i].map->dim;
904 rational = split[i].map->n > 0 &&
905 ISL_F_ISSET(split[i].map->p[0], ISL_BASIC_MAP_RATIONAL);
906 if (i)
907 p = isl_printer_print_str(p, "; ");
908 data.user = split[i].aff;
909 p = print_space(dim, p, rational, &data);
910 p = print_disjuncts_map(split[i].map, p, 0);
913 return p;
916 static __isl_give isl_printer *isl_map_print_isl_body(__isl_keep isl_map *map,
917 __isl_take isl_printer *p)
919 struct isl_print_space_data data = { 0 };
920 struct isl_aff_split *split = NULL;
921 int rational;
923 if (map->n > 0)
924 split = split_aff(map);
925 if (split) {
926 p = print_split_map(p, split, map->n);
927 } else {
928 rational = map->n > 0 &&
929 ISL_F_ISSET(map->p[0], ISL_BASIC_MAP_RATIONAL);
930 p = print_space(map->dim, p, rational, &data);
931 p = print_disjuncts_map(map, p, 0);
933 free_split(split, map->n);
934 return p;
937 static __isl_give isl_printer *isl_map_print_isl(__isl_keep isl_map *map,
938 __isl_take isl_printer *p)
940 struct isl_print_space_data data = { 0 };
942 if (isl_map_dim(map, isl_dim_param) > 0) {
943 p = print_tuple(map->dim, p, isl_dim_param, &data);
944 p = isl_printer_print_str(p, s_to[0]);
946 p = isl_printer_print_str(p, s_open_set[0]);
947 p = isl_map_print_isl_body(map, p);
948 p = isl_printer_print_str(p, s_close_set[0]);
949 return p;
952 static __isl_give isl_printer *print_latex_map(__isl_keep isl_map *map,
953 __isl_take isl_printer *p, __isl_keep isl_basic_map *aff)
955 struct isl_print_space_data data = { 0 };
957 data.latex = 1;
958 if (isl_map_dim(map, isl_dim_param) > 0) {
959 p = print_tuple(map->dim, p, isl_dim_param, &data);
960 p = isl_printer_print_str(p, s_to[1]);
962 p = isl_printer_print_str(p, s_open_set[1]);
963 data.print_dim = &print_dim_eq;
964 data.user = aff;
965 p = print_space(map->dim, p, 0, &data);
966 p = print_disjuncts_map(map, p, 1);
967 p = isl_printer_print_str(p, s_close_set[1]);
969 return p;
972 static __isl_give isl_printer *isl_map_print_latex(__isl_keep isl_map *map,
973 __isl_take isl_printer *p)
975 int i;
976 struct isl_aff_split *split = NULL;
978 if (map->n > 0)
979 split = split_aff(map);
981 if (!split)
982 return print_latex_map(map, p, NULL);
984 for (i = 0; i < map->n; ++i) {
985 if (!split[i].map)
986 break;
987 if (i)
988 p = isl_printer_print_str(p, " \\cup ");
989 p = print_latex_map(split[i].map, p, split[i].aff);
992 free_split(split, map->n);
993 return p;
996 __isl_give isl_printer *isl_printer_print_basic_map(__isl_take isl_printer *p,
997 __isl_keep isl_basic_map *bmap)
999 if (!p || !bmap)
1000 goto error;
1001 if (p->output_format == ISL_FORMAT_ISL)
1002 return isl_basic_map_print_isl(bmap, p, 0);
1003 else if (p->output_format == ISL_FORMAT_OMEGA)
1004 return basic_map_print_omega(bmap, p);
1005 isl_assert(bmap->ctx, 0, goto error);
1006 error:
1007 isl_printer_free(p);
1008 return NULL;
1011 __isl_give isl_printer *isl_printer_print_basic_set(__isl_take isl_printer *p,
1012 __isl_keep isl_basic_set *bset)
1014 if (!p || !bset)
1015 goto error;
1017 if (p->output_format == ISL_FORMAT_ISL)
1018 return isl_basic_map_print_isl(bset, p, 0);
1019 else if (p->output_format == ISL_FORMAT_POLYLIB)
1020 return isl_basic_set_print_polylib(bset, p, 0);
1021 else if (p->output_format == ISL_FORMAT_EXT_POLYLIB)
1022 return isl_basic_set_print_polylib(bset, p, 1);
1023 else if (p->output_format == ISL_FORMAT_POLYLIB_CONSTRAINTS)
1024 return bset_print_constraints_polylib(bset, p);
1025 else if (p->output_format == ISL_FORMAT_OMEGA)
1026 return basic_set_print_omega(bset, p);
1027 isl_assert(p->ctx, 0, goto error);
1028 error:
1029 isl_printer_free(p);
1030 return NULL;
1033 __isl_give isl_printer *isl_printer_print_set(__isl_take isl_printer *p,
1034 __isl_keep isl_set *set)
1036 if (!p || !set)
1037 goto error;
1038 if (p->output_format == ISL_FORMAT_ISL)
1039 return isl_map_print_isl((isl_map *)set, p);
1040 else if (p->output_format == ISL_FORMAT_POLYLIB)
1041 return isl_set_print_polylib(set, p, 0);
1042 else if (p->output_format == ISL_FORMAT_EXT_POLYLIB)
1043 return isl_set_print_polylib(set, p, 1);
1044 else if (p->output_format == ISL_FORMAT_OMEGA)
1045 return isl_set_print_omega(set, p);
1046 else if (p->output_format == ISL_FORMAT_LATEX)
1047 return isl_map_print_latex((isl_map *)set, p);
1048 isl_assert(set->ctx, 0, goto error);
1049 error:
1050 isl_printer_free(p);
1051 return NULL;
1054 __isl_give isl_printer *isl_printer_print_map(__isl_take isl_printer *p,
1055 __isl_keep isl_map *map)
1057 if (!p || !map)
1058 goto error;
1060 if (p->output_format == ISL_FORMAT_ISL)
1061 return isl_map_print_isl(map, p);
1062 else if (p->output_format == ISL_FORMAT_POLYLIB)
1063 return isl_map_print_polylib(map, p, 0);
1064 else if (p->output_format == ISL_FORMAT_EXT_POLYLIB)
1065 return isl_map_print_polylib(map, p, 1);
1066 else if (p->output_format == ISL_FORMAT_OMEGA)
1067 return isl_map_print_omega(map, p);
1068 else if (p->output_format == ISL_FORMAT_LATEX)
1069 return isl_map_print_latex(map, p);
1070 isl_assert(map->ctx, 0, goto error);
1071 error:
1072 isl_printer_free(p);
1073 return NULL;
1076 struct isl_union_print_data {
1077 isl_printer *p;
1078 int first;
1081 static isl_stat print_map_body(__isl_take isl_map *map, void *user)
1083 struct isl_union_print_data *data;
1084 data = (struct isl_union_print_data *)user;
1086 if (!data->first)
1087 data->p = isl_printer_print_str(data->p, "; ");
1088 data->first = 0;
1090 data->p = isl_map_print_isl_body(map, data->p);
1091 isl_map_free(map);
1093 return isl_stat_ok;
1096 static __isl_give isl_printer *isl_union_map_print_isl(
1097 __isl_keep isl_union_map *umap, __isl_take isl_printer *p)
1099 struct isl_union_print_data data;
1100 struct isl_print_space_data space_data = { 0 };
1101 isl_space *dim;
1103 dim = isl_union_map_get_space(umap);
1104 if (isl_space_dim(dim, isl_dim_param) > 0) {
1105 p = print_tuple(dim, p, isl_dim_param, &space_data);
1106 p = isl_printer_print_str(p, s_to[0]);
1108 isl_space_free(dim);
1109 p = isl_printer_print_str(p, s_open_set[0]);
1110 data.p = p;
1111 data.first = 1;
1112 isl_union_map_foreach_map(umap, &print_map_body, &data);
1113 p = data.p;
1114 p = isl_printer_print_str(p, s_close_set[0]);
1115 return p;
1118 static isl_stat print_latex_map_body(__isl_take isl_map *map, void *user)
1120 struct isl_union_print_data *data;
1121 data = (struct isl_union_print_data *)user;
1123 if (!data->first)
1124 data->p = isl_printer_print_str(data->p, " \\cup ");
1125 data->first = 0;
1127 data->p = isl_map_print_latex(map, data->p);
1128 isl_map_free(map);
1130 return isl_stat_ok;
1133 static __isl_give isl_printer *isl_union_map_print_latex(
1134 __isl_keep isl_union_map *umap, __isl_take isl_printer *p)
1136 struct isl_union_print_data data = { p, 1 };
1137 isl_union_map_foreach_map(umap, &print_latex_map_body, &data);
1138 p = data.p;
1139 return p;
1142 __isl_give isl_printer *isl_printer_print_union_map(__isl_take isl_printer *p,
1143 __isl_keep isl_union_map *umap)
1145 if (!p || !umap)
1146 goto error;
1148 if (p->output_format == ISL_FORMAT_ISL)
1149 return isl_union_map_print_isl(umap, p);
1150 if (p->output_format == ISL_FORMAT_LATEX)
1151 return isl_union_map_print_latex(umap, p);
1153 isl_die(p->ctx, isl_error_invalid,
1154 "invalid output format for isl_union_map", goto error);
1155 error:
1156 isl_printer_free(p);
1157 return NULL;
1160 __isl_give isl_printer *isl_printer_print_union_set(__isl_take isl_printer *p,
1161 __isl_keep isl_union_set *uset)
1163 if (!p || !uset)
1164 goto error;
1166 if (p->output_format == ISL_FORMAT_ISL)
1167 return isl_union_map_print_isl((isl_union_map *)uset, p);
1168 if (p->output_format == ISL_FORMAT_LATEX)
1169 return isl_union_map_print_latex((isl_union_map *)uset, p);
1171 isl_die(p->ctx, isl_error_invalid,
1172 "invalid output format for isl_union_set", goto error);
1173 error:
1174 isl_printer_free(p);
1175 return NULL;
1178 static int upoly_rec_n_non_zero(__isl_keep struct isl_upoly_rec *rec)
1180 int i;
1181 int n;
1183 for (i = 0, n = 0; i < rec->n; ++i)
1184 if (!isl_upoly_is_zero(rec->p[i]))
1185 ++n;
1187 return n;
1190 static __isl_give isl_printer *upoly_print_cst(__isl_keep struct isl_upoly *up,
1191 __isl_take isl_printer *p, int first)
1193 struct isl_upoly_cst *cst;
1194 int neg;
1196 cst = isl_upoly_as_cst(up);
1197 if (!cst)
1198 goto error;
1199 neg = !first && isl_int_is_neg(cst->n);
1200 if (!first)
1201 p = isl_printer_print_str(p, neg ? " - " : " + ");
1202 if (neg)
1203 isl_int_neg(cst->n, cst->n);
1204 if (isl_int_is_zero(cst->d)) {
1205 int sgn = isl_int_sgn(cst->n);
1206 p = isl_printer_print_str(p, sgn < 0 ? "-infty" :
1207 sgn == 0 ? "NaN" : "infty");
1208 } else
1209 p = isl_printer_print_isl_int(p, cst->n);
1210 if (neg)
1211 isl_int_neg(cst->n, cst->n);
1212 if (!isl_int_is_zero(cst->d) && !isl_int_is_one(cst->d)) {
1213 p = isl_printer_print_str(p, "/");
1214 p = isl_printer_print_isl_int(p, cst->d);
1216 return p;
1217 error:
1218 isl_printer_free(p);
1219 return NULL;
1222 static __isl_give isl_printer *print_base(__isl_take isl_printer *p,
1223 __isl_keep isl_space *dim, __isl_keep isl_mat *div, int var)
1225 unsigned total;
1227 total = isl_space_dim(dim, isl_dim_all);
1228 if (var < total)
1229 p = print_term(dim, NULL, dim->ctx->one, 1 + var, p, 0);
1230 else
1231 p = print_div(dim, div, var - total, p);
1232 return p;
1235 static __isl_give isl_printer *print_pow(__isl_take isl_printer *p,
1236 __isl_keep isl_space *dim, __isl_keep isl_mat *div, int var, int exp)
1238 p = print_base(p, dim, div, var);
1239 if (exp == 1)
1240 return p;
1241 if (p->output_format == ISL_FORMAT_C) {
1242 int i;
1243 for (i = 1; i < exp; ++i) {
1244 p = isl_printer_print_str(p, "*");
1245 p = print_base(p, dim, div, var);
1247 } else {
1248 p = isl_printer_print_str(p, "^");
1249 p = isl_printer_print_int(p, exp);
1251 return p;
1254 static __isl_give isl_printer *upoly_print(__isl_keep struct isl_upoly *up,
1255 __isl_keep isl_space *dim, __isl_keep isl_mat *div,
1256 __isl_take isl_printer *p, int outer)
1258 int i, n, first, print_parens;
1259 struct isl_upoly_rec *rec;
1261 if (!p || !up || !dim || !div)
1262 goto error;
1264 if (isl_upoly_is_cst(up))
1265 return upoly_print_cst(up, p, 1);
1267 rec = isl_upoly_as_rec(up);
1268 if (!rec)
1269 goto error;
1270 n = upoly_rec_n_non_zero(rec);
1271 print_parens = n > 1 ||
1272 (outer && rec->up.var >= isl_space_dim(dim, isl_dim_all));
1273 if (print_parens)
1274 p = isl_printer_print_str(p, "(");
1275 for (i = 0, first = 1; i < rec->n; ++i) {
1276 if (isl_upoly_is_zero(rec->p[i]))
1277 continue;
1278 if (isl_upoly_is_negone(rec->p[i])) {
1279 if (!i)
1280 p = isl_printer_print_str(p, "-1");
1281 else if (first)
1282 p = isl_printer_print_str(p, "-");
1283 else
1284 p = isl_printer_print_str(p, " - ");
1285 } else if (isl_upoly_is_cst(rec->p[i]) &&
1286 !isl_upoly_is_one(rec->p[i]))
1287 p = upoly_print_cst(rec->p[i], p, first);
1288 else {
1289 if (!first)
1290 p = isl_printer_print_str(p, " + ");
1291 if (i == 0 || !isl_upoly_is_one(rec->p[i]))
1292 p = upoly_print(rec->p[i], dim, div, p, 0);
1294 first = 0;
1295 if (i == 0)
1296 continue;
1297 if (!isl_upoly_is_one(rec->p[i]) &&
1298 !isl_upoly_is_negone(rec->p[i]))
1299 p = isl_printer_print_str(p, " * ");
1300 p = print_pow(p, dim, div, rec->up.var, i);
1302 if (print_parens)
1303 p = isl_printer_print_str(p, ")");
1304 return p;
1305 error:
1306 isl_printer_free(p);
1307 return NULL;
1310 static __isl_give isl_printer *print_qpolynomial(__isl_take isl_printer *p,
1311 __isl_keep isl_qpolynomial *qp)
1313 if (!p || !qp)
1314 goto error;
1315 p = upoly_print(qp->upoly, qp->dim, qp->div, p, 1);
1316 return p;
1317 error:
1318 isl_printer_free(p);
1319 return NULL;
1322 static __isl_give isl_printer *print_qpolynomial_isl(__isl_take isl_printer *p,
1323 __isl_keep isl_qpolynomial *qp)
1325 struct isl_print_space_data data = { 0 };
1327 if (!p || !qp)
1328 goto error;
1330 if (isl_space_dim(qp->dim, isl_dim_param) > 0) {
1331 p = print_tuple(qp->dim, p, isl_dim_param, &data);
1332 p = isl_printer_print_str(p, " -> ");
1334 p = isl_printer_print_str(p, "{ ");
1335 if (!isl_space_is_params(qp->dim)) {
1336 p = print_space(qp->dim, p, 0, &data);
1337 p = isl_printer_print_str(p, " -> ");
1339 p = print_qpolynomial(p, qp);
1340 p = isl_printer_print_str(p, " }");
1341 return p;
1342 error:
1343 isl_printer_free(p);
1344 return NULL;
1347 static __isl_give isl_printer *print_qpolynomial_c(__isl_take isl_printer *p,
1348 __isl_keep isl_space *dim, __isl_keep isl_qpolynomial *qp)
1350 isl_int den;
1352 isl_int_init(den);
1353 isl_qpolynomial_get_den(qp, &den);
1354 if (!isl_int_is_one(den)) {
1355 isl_qpolynomial *f;
1356 p = isl_printer_print_str(p, "(");
1357 qp = isl_qpolynomial_copy(qp);
1358 f = isl_qpolynomial_rat_cst_on_domain(isl_space_copy(qp->dim),
1359 den, qp->dim->ctx->one);
1360 qp = isl_qpolynomial_mul(qp, f);
1362 if (qp)
1363 p = upoly_print(qp->upoly, dim, qp->div, p, 0);
1364 else
1365 p = isl_printer_free(p);
1366 if (!isl_int_is_one(den)) {
1367 p = isl_printer_print_str(p, ")/");
1368 p = isl_printer_print_isl_int(p, den);
1369 isl_qpolynomial_free(qp);
1371 isl_int_clear(den);
1372 return p;
1375 __isl_give isl_printer *isl_printer_print_qpolynomial(
1376 __isl_take isl_printer *p, __isl_keep isl_qpolynomial *qp)
1378 if (!p || !qp)
1379 goto error;
1381 if (p->output_format == ISL_FORMAT_ISL)
1382 return print_qpolynomial_isl(p, qp);
1383 else if (p->output_format == ISL_FORMAT_C)
1384 return print_qpolynomial_c(p, qp->dim, qp);
1385 else
1386 isl_die(qp->dim->ctx, isl_error_unsupported,
1387 "output format not supported for isl_qpolynomials",
1388 goto error);
1389 error:
1390 isl_printer_free(p);
1391 return NULL;
1394 void isl_qpolynomial_print(__isl_keep isl_qpolynomial *qp, FILE *out,
1395 unsigned output_format)
1397 isl_printer *p;
1399 if (!qp)
1400 return;
1402 isl_assert(qp->dim->ctx, output_format == ISL_FORMAT_ISL, return);
1403 p = isl_printer_to_file(qp->dim->ctx, out);
1404 p = isl_printer_print_qpolynomial(p, qp);
1405 isl_printer_free(p);
1408 static __isl_give isl_printer *qpolynomial_fold_print(
1409 __isl_keep isl_qpolynomial_fold *fold, __isl_take isl_printer *p)
1411 int i;
1413 if (fold->type == isl_fold_min)
1414 p = isl_printer_print_str(p, "min");
1415 else if (fold->type == isl_fold_max)
1416 p = isl_printer_print_str(p, "max");
1417 p = isl_printer_print_str(p, "(");
1418 for (i = 0; i < fold->n; ++i) {
1419 if (i)
1420 p = isl_printer_print_str(p, ", ");
1421 p = print_qpolynomial(p, fold->qp[i]);
1423 p = isl_printer_print_str(p, ")");
1424 return p;
1427 void isl_qpolynomial_fold_print(__isl_keep isl_qpolynomial_fold *fold,
1428 FILE *out, unsigned output_format)
1430 isl_printer *p;
1432 if (!fold)
1433 return;
1435 isl_assert(fold->dim->ctx, output_format == ISL_FORMAT_ISL, return);
1437 p = isl_printer_to_file(fold->dim->ctx, out);
1438 p = isl_printer_print_qpolynomial_fold(p, fold);
1440 isl_printer_free(p);
1443 static __isl_give isl_printer *isl_pwqp_print_isl_body(
1444 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial *pwqp)
1446 struct isl_print_space_data data = { 0 };
1447 int i = 0;
1449 for (i = 0; i < pwqp->n; ++i) {
1450 if (i)
1451 p = isl_printer_print_str(p, "; ");
1452 if (!isl_space_is_params(pwqp->p[i].set->dim)) {
1453 p = print_space(pwqp->p[i].set->dim, p, 0, &data);
1454 p = isl_printer_print_str(p, " -> ");
1456 p = print_qpolynomial(p, pwqp->p[i].qp);
1457 p = print_disjuncts((isl_map *)pwqp->p[i].set, p, 0);
1460 return p;
1463 static __isl_give isl_printer *print_pw_qpolynomial_isl(
1464 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial *pwqp)
1466 struct isl_print_space_data data = { 0 };
1468 if (!p || !pwqp)
1469 goto error;
1471 if (isl_space_dim(pwqp->dim, isl_dim_param) > 0) {
1472 p = print_tuple(pwqp->dim, p, isl_dim_param, &data);
1473 p = isl_printer_print_str(p, " -> ");
1475 p = isl_printer_print_str(p, "{ ");
1476 if (pwqp->n == 0) {
1477 if (!isl_space_is_set(pwqp->dim)) {
1478 p = print_tuple(pwqp->dim, p, isl_dim_in, &data);
1479 p = isl_printer_print_str(p, " -> ");
1481 p = isl_printer_print_str(p, "0");
1483 p = isl_pwqp_print_isl_body(p, pwqp);
1484 p = isl_printer_print_str(p, " }");
1485 return p;
1486 error:
1487 isl_printer_free(p);
1488 return NULL;
1491 void isl_pw_qpolynomial_print(__isl_keep isl_pw_qpolynomial *pwqp, FILE *out,
1492 unsigned output_format)
1494 isl_printer *p;
1496 if (!pwqp)
1497 return;
1499 p = isl_printer_to_file(pwqp->dim->ctx, out);
1500 p = isl_printer_set_output_format(p, output_format);
1501 p = isl_printer_print_pw_qpolynomial(p, pwqp);
1503 isl_printer_free(p);
1506 static __isl_give isl_printer *isl_pwf_print_isl_body(
1507 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial_fold *pwf)
1509 struct isl_print_space_data data = { 0 };
1510 int i = 0;
1512 for (i = 0; i < pwf->n; ++i) {
1513 if (i)
1514 p = isl_printer_print_str(p, "; ");
1515 if (!isl_space_is_params(pwf->p[i].set->dim)) {
1516 p = print_space(pwf->p[i].set->dim, p, 0, &data);
1517 p = isl_printer_print_str(p, " -> ");
1519 p = qpolynomial_fold_print(pwf->p[i].fold, p);
1520 p = print_disjuncts((isl_map *)pwf->p[i].set, p, 0);
1523 return p;
1526 static __isl_give isl_printer *print_pw_qpolynomial_fold_isl(
1527 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial_fold *pwf)
1529 struct isl_print_space_data data = { 0 };
1531 if (isl_space_dim(pwf->dim, isl_dim_param) > 0) {
1532 p = print_tuple(pwf->dim, p, isl_dim_param, &data);
1533 p = isl_printer_print_str(p, " -> ");
1535 p = isl_printer_print_str(p, "{ ");
1536 if (pwf->n == 0) {
1537 if (!isl_space_is_set(pwf->dim)) {
1538 p = print_tuple(pwf->dim, p, isl_dim_in, &data);
1539 p = isl_printer_print_str(p, " -> ");
1541 p = isl_printer_print_str(p, "0");
1543 p = isl_pwf_print_isl_body(p, pwf);
1544 p = isl_printer_print_str(p, " }");
1545 return p;
1548 static __isl_give isl_printer *print_affine_c(__isl_take isl_printer *p,
1549 __isl_keep isl_space *dim, __isl_keep isl_basic_set *bset, isl_int *c);
1551 static __isl_give isl_printer *print_name_c(__isl_take isl_printer *p,
1552 __isl_keep isl_space *dim,
1553 __isl_keep isl_basic_set *bset, enum isl_dim_type type, unsigned pos)
1555 if (type == isl_dim_div) {
1556 p = isl_printer_print_str(p, "floord(");
1557 p = print_affine_c(p, dim, bset, bset->div[pos] + 1);
1558 p = isl_printer_print_str(p, ", ");
1559 p = isl_printer_print_isl_int(p, bset->div[pos][0]);
1560 p = isl_printer_print_str(p, ")");
1561 } else {
1562 const char *name;
1564 name = isl_space_get_dim_name(dim, type, pos);
1565 if (!name)
1566 name = "UNNAMED";
1567 p = isl_printer_print_str(p, name);
1569 return p;
1572 static __isl_give isl_printer *print_term_c(__isl_take isl_printer *p,
1573 __isl_keep isl_space *dim,
1574 __isl_keep isl_basic_set *bset, isl_int c, unsigned pos)
1576 enum isl_dim_type type;
1578 if (pos == 0)
1579 return isl_printer_print_isl_int(p, c);
1581 if (isl_int_is_one(c))
1583 else if (isl_int_is_negone(c))
1584 p = isl_printer_print_str(p, "-");
1585 else {
1586 p = isl_printer_print_isl_int(p, c);
1587 p = isl_printer_print_str(p, "*");
1589 type = pos2type(dim, &pos);
1590 p = print_name_c(p, dim, bset, type, pos);
1591 return p;
1594 static __isl_give isl_printer *print_partial_affine_c(__isl_take isl_printer *p,
1595 __isl_keep isl_space *dim,
1596 __isl_keep isl_basic_set *bset, isl_int *c, unsigned len)
1598 int i;
1599 int first;
1601 for (i = 0, first = 1; i < len; ++i) {
1602 int flip = 0;
1603 if (isl_int_is_zero(c[i]))
1604 continue;
1605 if (!first) {
1606 if (isl_int_is_neg(c[i])) {
1607 flip = 1;
1608 isl_int_neg(c[i], c[i]);
1609 p = isl_printer_print_str(p, " - ");
1610 } else
1611 p = isl_printer_print_str(p, " + ");
1613 first = 0;
1614 p = print_term_c(p, dim, bset, c[i], i);
1615 if (flip)
1616 isl_int_neg(c[i], c[i]);
1618 if (first)
1619 p = isl_printer_print_str(p, "0");
1620 return p;
1623 static __isl_give isl_printer *print_affine_c(__isl_take isl_printer *p,
1624 __isl_keep isl_space *dim, __isl_keep isl_basic_set *bset, isl_int *c)
1626 unsigned len = 1 + isl_basic_set_total_dim(bset);
1627 return print_partial_affine_c(p, dim, bset, c, len);
1630 /* We skip the constraint if it is implied by the div expression.
1632 * *first indicates whether this is the first constraint in the conjunction and
1633 * is updated if the constraint is actually printed.
1635 static __isl_give isl_printer *print_constraint_c(__isl_take isl_printer *p,
1636 __isl_keep isl_space *dim,
1637 __isl_keep isl_basic_set *bset, isl_int *c, const char *op, int *first)
1639 unsigned o_div;
1640 unsigned n_div;
1641 int div;
1643 o_div = isl_basic_set_offset(bset, isl_dim_div);
1644 n_div = isl_basic_set_dim(bset, isl_dim_div);
1645 div = isl_seq_last_non_zero(c + o_div, n_div);
1646 if (div >= 0 && isl_basic_set_is_div_constraint(bset, c, div))
1647 return p;
1649 if (!*first)
1650 p = isl_printer_print_str(p, " && ");
1652 p = print_affine_c(p, dim, bset, c);
1653 p = isl_printer_print_str(p, " ");
1654 p = isl_printer_print_str(p, op);
1655 p = isl_printer_print_str(p, " 0");
1657 *first = 0;
1659 return p;
1662 static __isl_give isl_printer *print_basic_set_c(__isl_take isl_printer *p,
1663 __isl_keep isl_space *dim, __isl_keep isl_basic_set *bset)
1665 int i, j;
1666 int first = 1;
1667 unsigned n_div = isl_basic_set_dim(bset, isl_dim_div);
1668 unsigned total = isl_basic_set_total_dim(bset) - n_div;
1670 for (i = 0; i < bset->n_eq; ++i) {
1671 j = isl_seq_last_non_zero(bset->eq[i] + 1 + total, n_div);
1672 if (j < 0)
1673 p = print_constraint_c(p, dim, bset,
1674 bset->eq[i], "==", &first);
1675 else {
1676 if (i)
1677 p = isl_printer_print_str(p, " && ");
1678 p = isl_printer_print_str(p, "(");
1679 p = print_partial_affine_c(p, dim, bset, bset->eq[i],
1680 1 + total + j);
1681 p = isl_printer_print_str(p, ") % ");
1682 p = isl_printer_print_isl_int(p,
1683 bset->eq[i][1 + total + j]);
1684 p = isl_printer_print_str(p, " == 0");
1685 first = 0;
1688 for (i = 0; i < bset->n_ineq; ++i)
1689 p = print_constraint_c(p, dim, bset, bset->ineq[i], ">=",
1690 &first);
1691 return p;
1694 static __isl_give isl_printer *print_set_c(__isl_take isl_printer *p,
1695 __isl_keep isl_space *dim, __isl_keep isl_set *set)
1697 int i;
1699 if (!set)
1700 return isl_printer_free(p);
1702 if (set->n == 0)
1703 p = isl_printer_print_str(p, "0");
1705 for (i = 0; i < set->n; ++i) {
1706 if (i)
1707 p = isl_printer_print_str(p, " || ");
1708 if (set->n > 1)
1709 p = isl_printer_print_str(p, "(");
1710 p = print_basic_set_c(p, dim, set->p[i]);
1711 if (set->n > 1)
1712 p = isl_printer_print_str(p, ")");
1714 return p;
1717 static __isl_give isl_printer *print_pw_qpolynomial_c(
1718 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial *pwqp)
1720 int i;
1722 if (pwqp->n == 1 && isl_set_plain_is_universe(pwqp->p[0].set))
1723 return print_qpolynomial_c(p, pwqp->dim, pwqp->p[0].qp);
1725 for (i = 0; i < pwqp->n; ++i) {
1726 p = isl_printer_print_str(p, "(");
1727 p = print_set_c(p, pwqp->dim, pwqp->p[i].set);
1728 p = isl_printer_print_str(p, ") ? (");
1729 p = print_qpolynomial_c(p, pwqp->dim, pwqp->p[i].qp);
1730 p = isl_printer_print_str(p, ") : ");
1733 p = isl_printer_print_str(p, "0");
1734 return p;
1737 __isl_give isl_printer *isl_printer_print_pw_qpolynomial(
1738 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial *pwqp)
1740 if (!p || !pwqp)
1741 goto error;
1743 if (p->output_format == ISL_FORMAT_ISL)
1744 return print_pw_qpolynomial_isl(p, pwqp);
1745 else if (p->output_format == ISL_FORMAT_C)
1746 return print_pw_qpolynomial_c(p, pwqp);
1747 isl_assert(p->ctx, 0, goto error);
1748 error:
1749 isl_printer_free(p);
1750 return NULL;
1753 static isl_stat print_pwqp_body(__isl_take isl_pw_qpolynomial *pwqp, void *user)
1755 struct isl_union_print_data *data;
1756 data = (struct isl_union_print_data *)user;
1758 if (!data->first)
1759 data->p = isl_printer_print_str(data->p, "; ");
1760 data->first = 0;
1762 data->p = isl_pwqp_print_isl_body(data->p, pwqp);
1763 isl_pw_qpolynomial_free(pwqp);
1765 return isl_stat_ok;
1768 static __isl_give isl_printer *print_union_pw_qpolynomial_isl(
1769 __isl_take isl_printer *p, __isl_keep isl_union_pw_qpolynomial *upwqp)
1771 struct isl_union_print_data data;
1772 struct isl_print_space_data space_data = { 0 };
1773 isl_space *dim;
1775 dim = isl_union_pw_qpolynomial_get_space(upwqp);
1776 if (isl_space_dim(dim, isl_dim_param) > 0) {
1777 p = print_tuple(dim, p, isl_dim_param, &space_data);
1778 p = isl_printer_print_str(p, " -> ");
1780 isl_space_free(dim);
1781 p = isl_printer_print_str(p, "{ ");
1782 data.p = p;
1783 data.first = 1;
1784 isl_union_pw_qpolynomial_foreach_pw_qpolynomial(upwqp, &print_pwqp_body,
1785 &data);
1786 p = data.p;
1787 p = isl_printer_print_str(p, " }");
1788 return p;
1791 __isl_give isl_printer *isl_printer_print_union_pw_qpolynomial(
1792 __isl_take isl_printer *p, __isl_keep isl_union_pw_qpolynomial *upwqp)
1794 if (!p || !upwqp)
1795 goto error;
1797 if (p->output_format == ISL_FORMAT_ISL)
1798 return print_union_pw_qpolynomial_isl(p, upwqp);
1799 isl_die(p->ctx, isl_error_invalid,
1800 "invalid output format for isl_union_pw_qpolynomial",
1801 goto error);
1802 error:
1803 isl_printer_free(p);
1804 return NULL;
1807 static __isl_give isl_printer *print_qpolynomial_fold_c(
1808 __isl_take isl_printer *p, __isl_keep isl_space *dim,
1809 __isl_keep isl_qpolynomial_fold *fold)
1811 int i;
1813 for (i = 0; i < fold->n - 1; ++i)
1814 if (fold->type == isl_fold_min)
1815 p = isl_printer_print_str(p, "min(");
1816 else if (fold->type == isl_fold_max)
1817 p = isl_printer_print_str(p, "max(");
1819 for (i = 0; i < fold->n; ++i) {
1820 if (i)
1821 p = isl_printer_print_str(p, ", ");
1822 p = print_qpolynomial_c(p, dim, fold->qp[i]);
1823 if (i)
1824 p = isl_printer_print_str(p, ")");
1826 return p;
1829 __isl_give isl_printer *isl_printer_print_qpolynomial_fold(
1830 __isl_take isl_printer *p, __isl_keep isl_qpolynomial_fold *fold)
1832 if (!p || !fold)
1833 goto error;
1834 if (p->output_format == ISL_FORMAT_ISL)
1835 return qpolynomial_fold_print(fold, p);
1836 else if (p->output_format == ISL_FORMAT_C)
1837 return print_qpolynomial_fold_c(p, fold->dim, fold);
1838 isl_die(p->ctx, isl_error_unsupported, "unsupported output format",
1839 goto error);
1840 error:
1841 isl_printer_free(p);
1842 return NULL;
1845 static __isl_give isl_printer *print_pw_qpolynomial_fold_c(
1846 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial_fold *pwf)
1848 int i;
1850 if (pwf->n == 1 && isl_set_plain_is_universe(pwf->p[0].set))
1851 return print_qpolynomial_fold_c(p, pwf->dim, pwf->p[0].fold);
1853 for (i = 0; i < pwf->n; ++i) {
1854 p = isl_printer_print_str(p, "(");
1855 p = print_set_c(p, pwf->dim, pwf->p[i].set);
1856 p = isl_printer_print_str(p, ") ? (");
1857 p = print_qpolynomial_fold_c(p, pwf->dim, pwf->p[i].fold);
1858 p = isl_printer_print_str(p, ") : ");
1861 p = isl_printer_print_str(p, "0");
1862 return p;
1865 __isl_give isl_printer *isl_printer_print_pw_qpolynomial_fold(
1866 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial_fold *pwf)
1868 if (!p || !pwf)
1869 goto error;
1871 if (p->output_format == ISL_FORMAT_ISL)
1872 return print_pw_qpolynomial_fold_isl(p, pwf);
1873 else if (p->output_format == ISL_FORMAT_C)
1874 return print_pw_qpolynomial_fold_c(p, pwf);
1875 isl_assert(p->ctx, 0, goto error);
1876 error:
1877 isl_printer_free(p);
1878 return NULL;
1881 void isl_pw_qpolynomial_fold_print(__isl_keep isl_pw_qpolynomial_fold *pwf,
1882 FILE *out, unsigned output_format)
1884 isl_printer *p;
1886 if (!pwf)
1887 return;
1889 p = isl_printer_to_file(pwf->dim->ctx, out);
1890 p = isl_printer_set_output_format(p, output_format);
1891 p = isl_printer_print_pw_qpolynomial_fold(p, pwf);
1893 isl_printer_free(p);
1896 static isl_stat print_pwf_body(__isl_take isl_pw_qpolynomial_fold *pwf,
1897 void *user)
1899 struct isl_union_print_data *data;
1900 data = (struct isl_union_print_data *)user;
1902 if (!data->first)
1903 data->p = isl_printer_print_str(data->p, "; ");
1904 data->first = 0;
1906 data->p = isl_pwf_print_isl_body(data->p, pwf);
1907 isl_pw_qpolynomial_fold_free(pwf);
1909 return isl_stat_ok;
1912 static __isl_give isl_printer *print_union_pw_qpolynomial_fold_isl(
1913 __isl_take isl_printer *p,
1914 __isl_keep isl_union_pw_qpolynomial_fold *upwf)
1916 struct isl_union_print_data data;
1917 struct isl_print_space_data space_data = { 0 };
1918 isl_space *dim;
1920 dim = isl_union_pw_qpolynomial_fold_get_space(upwf);
1921 if (isl_space_dim(dim, isl_dim_param) > 0) {
1922 p = print_tuple(dim, p, isl_dim_param, &space_data);
1923 p = isl_printer_print_str(p, " -> ");
1925 isl_space_free(dim);
1926 p = isl_printer_print_str(p, "{ ");
1927 data.p = p;
1928 data.first = 1;
1929 isl_union_pw_qpolynomial_fold_foreach_pw_qpolynomial_fold(upwf,
1930 &print_pwf_body, &data);
1931 p = data.p;
1932 p = isl_printer_print_str(p, " }");
1933 return p;
1936 __isl_give isl_printer *isl_printer_print_union_pw_qpolynomial_fold(
1937 __isl_take isl_printer *p,
1938 __isl_keep isl_union_pw_qpolynomial_fold *upwf)
1940 if (!p || !upwf)
1941 goto error;
1943 if (p->output_format == ISL_FORMAT_ISL)
1944 return print_union_pw_qpolynomial_fold_isl(p, upwf);
1945 isl_die(p->ctx, isl_error_invalid,
1946 "invalid output format for isl_union_pw_qpolynomial_fold",
1947 goto error);
1948 error:
1949 isl_printer_free(p);
1950 return NULL;
1953 __isl_give isl_printer *isl_printer_print_constraint(__isl_take isl_printer *p,
1954 __isl_keep isl_constraint *c)
1956 isl_basic_map *bmap;
1958 if (!p || !c)
1959 goto error;
1961 bmap = isl_basic_map_from_constraint(isl_constraint_copy(c));
1962 p = isl_printer_print_basic_map(p, bmap);
1963 isl_basic_map_free(bmap);
1964 return p;
1965 error:
1966 isl_printer_free(p);
1967 return NULL;
1970 static __isl_give isl_printer *isl_printer_print_space_isl(
1971 __isl_take isl_printer *p, __isl_keep isl_space *dim)
1973 struct isl_print_space_data data = { 0 };
1975 if (!dim)
1976 goto error;
1978 if (isl_space_dim(dim, isl_dim_param) > 0) {
1979 p = print_tuple(dim, p, isl_dim_param, &data);
1980 p = isl_printer_print_str(p, " -> ");
1983 p = isl_printer_print_str(p, "{ ");
1984 if (isl_space_is_params(dim))
1985 p = isl_printer_print_str(p, s_such_that[0]);
1986 else
1987 p = print_space(dim, p, 0, &data);
1988 p = isl_printer_print_str(p, " }");
1990 return p;
1991 error:
1992 isl_printer_free(p);
1993 return NULL;
1996 __isl_give isl_printer *isl_printer_print_space(__isl_take isl_printer *p,
1997 __isl_keep isl_space *space)
1999 if (!p || !space)
2000 return isl_printer_free(p);
2001 if (p->output_format == ISL_FORMAT_ISL)
2002 return isl_printer_print_space_isl(p, space);
2003 else if (p->output_format == ISL_FORMAT_OMEGA)
2004 return print_omega_parameters(space, p);
2006 isl_die(isl_space_get_ctx(space), isl_error_unsupported,
2007 "output format not supported for space",
2008 return isl_printer_free(p));
2011 __isl_give isl_printer *isl_printer_print_local_space(__isl_take isl_printer *p,
2012 __isl_keep isl_local_space *ls)
2014 struct isl_print_space_data data = { 0 };
2015 unsigned n_div;
2017 if (!ls)
2018 goto error;
2020 if (isl_local_space_dim(ls, isl_dim_param) > 0) {
2021 p = print_tuple(ls->dim, p, isl_dim_param, &data);
2022 p = isl_printer_print_str(p, " -> ");
2024 p = isl_printer_print_str(p, "{ ");
2025 p = print_space(ls->dim, p, 0, &data);
2026 n_div = isl_local_space_dim(ls, isl_dim_div);
2027 if (n_div > 0) {
2028 p = isl_printer_print_str(p, " : ");
2029 p = isl_printer_print_str(p, s_open_exists[0]);
2030 p = print_div_list(p, ls->dim, ls->div, 0);
2031 } else if (isl_space_is_params(ls->dim))
2032 p = isl_printer_print_str(p, s_such_that[0]);
2033 p = isl_printer_print_str(p, " }");
2034 return p;
2035 error:
2036 isl_printer_free(p);
2037 return NULL;
2040 static __isl_give isl_printer *print_aff_body(__isl_take isl_printer *p,
2041 __isl_keep isl_aff *aff)
2043 unsigned total;
2045 if (isl_aff_is_nan(aff))
2046 return isl_printer_print_str(p, "NaN");
2048 total = isl_local_space_dim(aff->ls, isl_dim_all);
2049 p = isl_printer_print_str(p, "(");
2050 p = print_affine_of_len(aff->ls->dim, aff->ls->div, p,
2051 aff->v->el + 1, 1 + total);
2052 if (isl_int_is_one(aff->v->el[0]))
2053 p = isl_printer_print_str(p, ")");
2054 else {
2055 p = isl_printer_print_str(p, ")/");
2056 p = isl_printer_print_isl_int(p, aff->v->el[0]);
2059 return p;
2062 static __isl_give isl_printer *print_aff(__isl_take isl_printer *p,
2063 __isl_keep isl_aff *aff)
2065 struct isl_print_space_data data = { 0 };
2067 if (isl_space_is_params(aff->ls->dim))
2069 else {
2070 p = print_tuple(aff->ls->dim, p, isl_dim_set, &data);
2071 p = isl_printer_print_str(p, " -> ");
2073 p = isl_printer_print_str(p, "[");
2074 p = print_aff_body(p, aff);
2075 p = isl_printer_print_str(p, "]");
2077 return p;
2080 static __isl_give isl_printer *print_aff_isl(__isl_take isl_printer *p,
2081 __isl_keep isl_aff *aff)
2083 struct isl_print_space_data data = { 0 };
2085 if (!aff)
2086 goto error;
2088 if (isl_local_space_dim(aff->ls, isl_dim_param) > 0) {
2089 p = print_tuple(aff->ls->dim, p, isl_dim_param, &data);
2090 p = isl_printer_print_str(p, " -> ");
2092 p = isl_printer_print_str(p, "{ ");
2093 p = print_aff(p, aff);
2094 p = isl_printer_print_str(p, " }");
2095 return p;
2096 error:
2097 isl_printer_free(p);
2098 return NULL;
2101 /* Print the body of an isl_pw_aff, i.e., a semicolon delimited
2102 * sequence of affine expressions, each followed by constraints.
2104 static __isl_give isl_printer *print_pw_aff_body(
2105 __isl_take isl_printer *p, __isl_keep isl_pw_aff *pa)
2107 int i;
2109 if (!pa)
2110 return isl_printer_free(p);
2112 for (i = 0; i < pa->n; ++i) {
2113 if (i)
2114 p = isl_printer_print_str(p, "; ");
2115 p = print_aff(p, pa->p[i].aff);
2116 p = print_disjuncts((isl_map *)pa->p[i].set, p, 0);
2119 return p;
2122 static __isl_give isl_printer *print_pw_aff_isl(__isl_take isl_printer *p,
2123 __isl_keep isl_pw_aff *pwaff)
2125 struct isl_print_space_data data = { 0 };
2127 if (!pwaff)
2128 goto error;
2130 if (isl_space_dim(pwaff->dim, isl_dim_param) > 0) {
2131 p = print_tuple(pwaff->dim, p, isl_dim_param, &data);
2132 p = isl_printer_print_str(p, " -> ");
2134 p = isl_printer_print_str(p, "{ ");
2135 p = print_pw_aff_body(p, pwaff);
2136 p = isl_printer_print_str(p, " }");
2137 return p;
2138 error:
2139 isl_printer_free(p);
2140 return NULL;
2143 static __isl_give isl_printer *print_ls_affine_c(__isl_take isl_printer *p,
2144 __isl_keep isl_local_space *ls, isl_int *c);
2146 static __isl_give isl_printer *print_ls_name_c(__isl_take isl_printer *p,
2147 __isl_keep isl_local_space *ls, enum isl_dim_type type, unsigned pos)
2149 if (type == isl_dim_div) {
2150 p = isl_printer_print_str(p, "floord(");
2151 p = print_ls_affine_c(p, ls, ls->div->row[pos] + 1);
2152 p = isl_printer_print_str(p, ", ");
2153 p = isl_printer_print_isl_int(p, ls->div->row[pos][0]);
2154 p = isl_printer_print_str(p, ")");
2155 } else {
2156 const char *name;
2158 name = isl_space_get_dim_name(ls->dim, type, pos);
2159 if (!name)
2160 name = "UNNAMED";
2161 p = isl_printer_print_str(p, name);
2163 return p;
2166 static __isl_give isl_printer *print_ls_term_c(__isl_take isl_printer *p,
2167 __isl_keep isl_local_space *ls, isl_int c, unsigned pos)
2169 enum isl_dim_type type;
2171 if (pos == 0)
2172 return isl_printer_print_isl_int(p, c);
2174 if (isl_int_is_one(c))
2176 else if (isl_int_is_negone(c))
2177 p = isl_printer_print_str(p, "-");
2178 else {
2179 p = isl_printer_print_isl_int(p, c);
2180 p = isl_printer_print_str(p, "*");
2182 type = pos2type(ls->dim, &pos);
2183 p = print_ls_name_c(p, ls, type, pos);
2184 return p;
2187 static __isl_give isl_printer *print_ls_partial_affine_c(
2188 __isl_take isl_printer *p, __isl_keep isl_local_space *ls,
2189 isl_int *c, unsigned len)
2191 int i;
2192 int first;
2194 for (i = 0, first = 1; i < len; ++i) {
2195 int flip = 0;
2196 if (isl_int_is_zero(c[i]))
2197 continue;
2198 if (!first) {
2199 if (isl_int_is_neg(c[i])) {
2200 flip = 1;
2201 isl_int_neg(c[i], c[i]);
2202 p = isl_printer_print_str(p, " - ");
2203 } else
2204 p = isl_printer_print_str(p, " + ");
2206 first = 0;
2207 p = print_ls_term_c(p, ls, c[i], i);
2208 if (flip)
2209 isl_int_neg(c[i], c[i]);
2211 if (first)
2212 p = isl_printer_print_str(p, "0");
2213 return p;
2216 static __isl_give isl_printer *print_ls_affine_c(__isl_take isl_printer *p,
2217 __isl_keep isl_local_space *ls, isl_int *c)
2219 unsigned len = 1 + isl_local_space_dim(ls, isl_dim_all);
2220 return print_ls_partial_affine_c(p, ls, c, len);
2223 static __isl_give isl_printer *print_aff_c(__isl_take isl_printer *p,
2224 __isl_keep isl_aff *aff)
2226 unsigned total;
2228 total = isl_local_space_dim(aff->ls, isl_dim_all);
2229 if (!isl_int_is_one(aff->v->el[0]))
2230 p = isl_printer_print_str(p, "(");
2231 p = print_ls_partial_affine_c(p, aff->ls, aff->v->el + 1, 1 + total);
2232 if (!isl_int_is_one(aff->v->el[0])) {
2233 p = isl_printer_print_str(p, ")/");
2234 p = isl_printer_print_isl_int(p, aff->v->el[0]);
2236 return p;
2239 /* In the C format, we cannot express that "pwaff" may be undefined
2240 * on parts of the domain space. We therefore assume that the expression
2241 * will only be evaluated on its definition domain and compute the gist
2242 * of each cell with respect to this domain.
2244 static __isl_give isl_printer *print_pw_aff_c(__isl_take isl_printer *p,
2245 __isl_keep isl_pw_aff *pwaff)
2247 isl_set *domain;
2248 isl_ast_build *build;
2249 isl_ast_expr *expr;
2251 if (pwaff->n < 1)
2252 isl_die(p->ctx, isl_error_unsupported,
2253 "cannot print empty isl_pw_aff in C format",
2254 return isl_printer_free(p));
2256 domain = isl_pw_aff_domain(isl_pw_aff_copy(pwaff));
2257 build = isl_ast_build_from_context(domain);
2258 expr = isl_ast_build_expr_from_pw_aff(build, isl_pw_aff_copy(pwaff));
2259 p = isl_printer_print_ast_expr(p, expr);
2260 isl_ast_expr_free(expr);
2261 isl_ast_build_free(build);
2263 return p;
2266 __isl_give isl_printer *isl_printer_print_aff(__isl_take isl_printer *p,
2267 __isl_keep isl_aff *aff)
2269 if (!p || !aff)
2270 goto error;
2272 if (p->output_format == ISL_FORMAT_ISL)
2273 return print_aff_isl(p, aff);
2274 else if (p->output_format == ISL_FORMAT_C)
2275 return print_aff_c(p, aff);
2276 isl_die(p->ctx, isl_error_unsupported, "unsupported output format",
2277 goto error);
2278 error:
2279 isl_printer_free(p);
2280 return NULL;
2283 __isl_give isl_printer *isl_printer_print_pw_aff(__isl_take isl_printer *p,
2284 __isl_keep isl_pw_aff *pwaff)
2286 if (!p || !pwaff)
2287 goto error;
2289 if (p->output_format == ISL_FORMAT_ISL)
2290 return print_pw_aff_isl(p, pwaff);
2291 else if (p->output_format == ISL_FORMAT_C)
2292 return print_pw_aff_c(p, pwaff);
2293 isl_die(p->ctx, isl_error_unsupported, "unsupported output format",
2294 goto error);
2295 error:
2296 isl_printer_free(p);
2297 return NULL;
2300 /* Print "pa" in a sequence of isl_pw_affs delimited by semicolons.
2301 * Each isl_pw_aff itself is also printed as semicolon delimited
2302 * sequence of pieces.
2303 * If data->first = 1, then this is the first in the sequence.
2304 * Update data->first to tell the next element that it is not the first.
2306 static isl_stat print_pw_aff_body_wrap(__isl_take isl_pw_aff *pa,
2307 void *user)
2309 struct isl_union_print_data *data;
2310 data = (struct isl_union_print_data *) user;
2312 if (!data->first)
2313 data->p = isl_printer_print_str(data->p, "; ");
2314 data->first = 0;
2316 data->p = print_pw_aff_body(data->p, pa);
2317 isl_pw_aff_free(pa);
2319 return data->p ? isl_stat_ok : isl_stat_error;
2322 /* Print the body of an isl_union_pw_aff, i.e., a semicolon delimited
2323 * sequence of affine expressions, each followed by constraints,
2324 * with the sequence enclosed in braces.
2326 static __isl_give isl_printer *print_union_pw_aff_body(
2327 __isl_take isl_printer *p, __isl_keep isl_union_pw_aff *upa)
2329 struct isl_union_print_data data = { p, 1 };
2331 p = isl_printer_print_str(p, s_open_set[0]);
2332 data.p = p;
2333 if (isl_union_pw_aff_foreach_pw_aff(upa,
2334 &print_pw_aff_body_wrap, &data) < 0)
2335 data.p = isl_printer_free(p);
2336 p = data.p;
2337 p = isl_printer_print_str(p, s_close_set[0]);
2339 return p;
2342 /* Print the isl_union_pw_aff "upa" to "p" in isl format.
2344 * The individual isl_pw_affs are delimited by a semicolon.
2346 static __isl_give isl_printer *print_union_pw_aff_isl(
2347 __isl_take isl_printer *p, __isl_keep isl_union_pw_aff *upa)
2349 struct isl_print_space_data data = { 0 };
2350 isl_space *space;
2352 space = isl_union_pw_aff_get_space(upa);
2353 if (isl_space_dim(space, isl_dim_param) > 0) {
2354 p = print_tuple(space, p, isl_dim_param, &data);
2355 p = isl_printer_print_str(p, s_to[0]);
2357 isl_space_free(space);
2358 p = print_union_pw_aff_body(p, upa);
2359 return p;
2362 /* Print the isl_union_pw_aff "upa" to "p".
2364 * We currently only support an isl format.
2366 __isl_give isl_printer *isl_printer_print_union_pw_aff(
2367 __isl_take isl_printer *p, __isl_keep isl_union_pw_aff *upa)
2369 if (!p || !upa)
2370 return isl_printer_free(p);
2372 if (p->output_format == ISL_FORMAT_ISL)
2373 return print_union_pw_aff_isl(p, upa);
2374 isl_die(isl_printer_get_ctx(p), isl_error_unsupported,
2375 "unsupported output format", return isl_printer_free(p));
2378 /* Print dimension "pos" of data->space to "p".
2380 * data->user is assumed to be an isl_multi_aff.
2382 * If the current dimension is an output dimension, then print
2383 * the corresponding expression. Otherwise, print the name of the dimension.
2385 static __isl_give isl_printer *print_dim_ma(__isl_take isl_printer *p,
2386 struct isl_print_space_data *data, unsigned pos)
2388 isl_multi_aff *ma = data->user;
2390 if (data->type == isl_dim_out)
2391 p = print_aff_body(p, ma->p[pos]);
2392 else
2393 p = print_name(data->space, p, data->type, pos, data->latex);
2395 return p;
2398 static __isl_give isl_printer *print_multi_aff(__isl_take isl_printer *p,
2399 __isl_keep isl_multi_aff *maff)
2401 struct isl_print_space_data data = { 0 };
2403 data.print_dim = &print_dim_ma;
2404 data.user = maff;
2405 return print_space(maff->space, p, 0, &data);
2408 static __isl_give isl_printer *print_multi_aff_isl(__isl_take isl_printer *p,
2409 __isl_keep isl_multi_aff *maff)
2411 struct isl_print_space_data data = { 0 };
2413 if (!maff)
2414 goto error;
2416 if (isl_space_dim(maff->space, isl_dim_param) > 0) {
2417 p = print_tuple(maff->space, p, isl_dim_param, &data);
2418 p = isl_printer_print_str(p, " -> ");
2420 p = isl_printer_print_str(p, "{ ");
2421 p = print_multi_aff(p, maff);
2422 p = isl_printer_print_str(p, " }");
2423 return p;
2424 error:
2425 isl_printer_free(p);
2426 return NULL;
2429 __isl_give isl_printer *isl_printer_print_multi_aff(__isl_take isl_printer *p,
2430 __isl_keep isl_multi_aff *maff)
2432 if (!p || !maff)
2433 goto error;
2435 if (p->output_format == ISL_FORMAT_ISL)
2436 return print_multi_aff_isl(p, maff);
2437 isl_die(p->ctx, isl_error_unsupported, "unsupported output format",
2438 goto error);
2439 error:
2440 isl_printer_free(p);
2441 return NULL;
2444 static __isl_give isl_printer *print_pw_multi_aff_body(
2445 __isl_take isl_printer *p, __isl_keep isl_pw_multi_aff *pma)
2447 int i;
2449 if (!pma)
2450 goto error;
2452 for (i = 0; i < pma->n; ++i) {
2453 if (i)
2454 p = isl_printer_print_str(p, "; ");
2455 p = print_multi_aff(p, pma->p[i].maff);
2456 p = print_disjuncts((isl_map *)pma->p[i].set, p, 0);
2458 return p;
2459 error:
2460 isl_printer_free(p);
2461 return NULL;
2464 static __isl_give isl_printer *print_pw_multi_aff_isl(__isl_take isl_printer *p,
2465 __isl_keep isl_pw_multi_aff *pma)
2467 struct isl_print_space_data data = { 0 };
2469 if (!pma)
2470 goto error;
2472 if (isl_space_dim(pma->dim, isl_dim_param) > 0) {
2473 p = print_tuple(pma->dim, p, isl_dim_param, &data);
2474 p = isl_printer_print_str(p, " -> ");
2476 p = isl_printer_print_str(p, "{ ");
2477 p = print_pw_multi_aff_body(p, pma);
2478 p = isl_printer_print_str(p, " }");
2479 return p;
2480 error:
2481 isl_printer_free(p);
2482 return NULL;
2485 static __isl_give isl_printer *print_unnamed_pw_multi_aff_c(
2486 __isl_take isl_printer *p, __isl_keep isl_pw_multi_aff *pma)
2488 int i;
2490 for (i = 0; i < pma->n - 1; ++i) {
2491 p = isl_printer_print_str(p, "(");
2492 p = print_set_c(p, pma->dim, pma->p[i].set);
2493 p = isl_printer_print_str(p, ") ? (");
2494 p = print_aff_c(p, pma->p[i].maff->p[0]);
2495 p = isl_printer_print_str(p, ") : ");
2498 return print_aff_c(p, pma->p[pma->n - 1].maff->p[0]);
2501 static __isl_give isl_printer *print_pw_multi_aff_c(__isl_take isl_printer *p,
2502 __isl_keep isl_pw_multi_aff *pma)
2504 int n;
2505 const char *name;
2507 if (!pma)
2508 goto error;
2509 if (pma->n < 1)
2510 isl_die(p->ctx, isl_error_unsupported,
2511 "cannot print empty isl_pw_multi_aff in C format",
2512 goto error);
2513 name = isl_pw_multi_aff_get_tuple_name(pma, isl_dim_out);
2514 if (!name && isl_pw_multi_aff_dim(pma, isl_dim_out) == 1)
2515 return print_unnamed_pw_multi_aff_c(p, pma);
2516 if (!name)
2517 isl_die(p->ctx, isl_error_unsupported,
2518 "cannot print unnamed isl_pw_multi_aff in C format",
2519 goto error);
2521 p = isl_printer_print_str(p, name);
2522 n = isl_pw_multi_aff_dim(pma, isl_dim_out);
2523 if (n != 0)
2524 isl_die(p->ctx, isl_error_unsupported,
2525 "not supported yet", goto error);
2527 return p;
2528 error:
2529 isl_printer_free(p);
2530 return NULL;
2533 __isl_give isl_printer *isl_printer_print_pw_multi_aff(
2534 __isl_take isl_printer *p, __isl_keep isl_pw_multi_aff *pma)
2536 if (!p || !pma)
2537 goto error;
2539 if (p->output_format == ISL_FORMAT_ISL)
2540 return print_pw_multi_aff_isl(p, pma);
2541 if (p->output_format == ISL_FORMAT_C)
2542 return print_pw_multi_aff_c(p, pma);
2543 isl_die(p->ctx, isl_error_unsupported, "unsupported output format",
2544 goto error);
2545 error:
2546 isl_printer_free(p);
2547 return NULL;
2550 static isl_stat print_pw_multi_aff_body_wrap(__isl_take isl_pw_multi_aff *pma,
2551 void *user)
2553 struct isl_union_print_data *data;
2554 data = (struct isl_union_print_data *) user;
2556 if (!data->first)
2557 data->p = isl_printer_print_str(data->p, "; ");
2558 data->first = 0;
2560 data->p = print_pw_multi_aff_body(data->p, pma);
2561 isl_pw_multi_aff_free(pma);
2563 return isl_stat_ok;
2566 static __isl_give isl_printer *print_union_pw_multi_aff_isl(
2567 __isl_take isl_printer *p, __isl_keep isl_union_pw_multi_aff *upma)
2569 struct isl_union_print_data data;
2570 struct isl_print_space_data space_data = { 0 };
2571 isl_space *space;
2573 space = isl_union_pw_multi_aff_get_space(upma);
2574 if (isl_space_dim(space, isl_dim_param) > 0) {
2575 p = print_tuple(space, p, isl_dim_param, &space_data);
2576 p = isl_printer_print_str(p, s_to[0]);
2578 isl_space_free(space);
2579 p = isl_printer_print_str(p, s_open_set[0]);
2580 data.p = p;
2581 data.first = 1;
2582 isl_union_pw_multi_aff_foreach_pw_multi_aff(upma,
2583 &print_pw_multi_aff_body_wrap, &data);
2584 p = data.p;
2585 p = isl_printer_print_str(p, s_close_set[0]);
2586 return p;
2589 __isl_give isl_printer *isl_printer_print_union_pw_multi_aff(
2590 __isl_take isl_printer *p, __isl_keep isl_union_pw_multi_aff *upma)
2592 if (!p || !upma)
2593 goto error;
2595 if (p->output_format == ISL_FORMAT_ISL)
2596 return print_union_pw_multi_aff_isl(p, upma);
2597 isl_die(p->ctx, isl_error_unsupported, "unsupported output format",
2598 goto error);
2599 error:
2600 isl_printer_free(p);
2601 return NULL;
2604 /* Print dimension "pos" of data->space to "p".
2606 * data->user is assumed to be an isl_multi_pw_aff.
2608 * If the current dimension is an output dimension, then print
2609 * the corresponding piecewise affine expression.
2610 * Otherwise, print the name of the dimension.
2612 static __isl_give isl_printer *print_dim_mpa(__isl_take isl_printer *p,
2613 struct isl_print_space_data *data, unsigned pos)
2615 int i;
2616 int need_parens;
2617 isl_multi_pw_aff *mpa = data->user;
2618 isl_pw_aff *pa;
2620 if (data->type != isl_dim_out)
2621 return print_name(data->space, p, data->type, pos, data->latex);
2623 pa = mpa->p[pos];
2624 if (pa->n == 0)
2625 return isl_printer_print_str(p, "(0 : 1 = 0)");
2627 need_parens = pa->n != 1 || !isl_set_plain_is_universe(pa->p[0].set);
2628 if (need_parens)
2629 p = isl_printer_print_str(p, "(");
2630 for (i = 0; i < pa->n; ++i) {
2631 if (i)
2632 p = isl_printer_print_str(p, "; ");
2633 p = print_aff_body(p, pa->p[i].aff);
2634 p = print_disjuncts(pa->p[i].set, p, 0);
2636 if (need_parens)
2637 p = isl_printer_print_str(p, ")");
2639 return p;
2642 /* Print "mpa" to "p" in isl format.
2644 static __isl_give isl_printer *print_multi_pw_aff_isl(__isl_take isl_printer *p,
2645 __isl_keep isl_multi_pw_aff *mpa)
2647 struct isl_print_space_data data = { 0 };
2649 if (!mpa)
2650 return isl_printer_free(p);
2652 if (isl_space_dim(mpa->space, isl_dim_param) > 0) {
2653 p = print_tuple(mpa->space, p, isl_dim_param, &data);
2654 p = isl_printer_print_str(p, " -> ");
2656 p = isl_printer_print_str(p, "{ ");
2657 data.print_dim = &print_dim_mpa;
2658 data.user = mpa;
2659 p = print_space(mpa->space, p, 0, &data);
2660 p = isl_printer_print_str(p, " }");
2661 return p;
2664 __isl_give isl_printer *isl_printer_print_multi_pw_aff(
2665 __isl_take isl_printer *p, __isl_keep isl_multi_pw_aff *mpa)
2667 if (!p || !mpa)
2668 return isl_printer_free(p);
2670 if (p->output_format == ISL_FORMAT_ISL)
2671 return print_multi_pw_aff_isl(p, mpa);
2672 isl_die(p->ctx, isl_error_unsupported, "unsupported output format",
2673 return isl_printer_free(p));
2676 /* Print dimension "pos" of data->space to "p".
2678 * data->user is assumed to be an isl_multi_val.
2680 * If the current dimension is an output dimension, then print
2681 * the corresponding value. Otherwise, print the name of the dimension.
2683 static __isl_give isl_printer *print_dim_mv(__isl_take isl_printer *p,
2684 struct isl_print_space_data *data, unsigned pos)
2686 isl_multi_val *mv = data->user;
2688 if (data->type == isl_dim_out)
2689 return isl_printer_print_val(p, mv->p[pos]);
2690 else
2691 return print_name(data->space, p, data->type, pos, data->latex);
2694 /* Print the isl_multi_val "mv" to "p" in isl format.
2696 static __isl_give isl_printer *print_multi_val_isl(__isl_take isl_printer *p,
2697 __isl_keep isl_multi_val *mv)
2699 struct isl_print_space_data data = { 0 };
2701 if (!mv)
2702 return isl_printer_free(p);
2704 if (isl_space_dim(mv->space, isl_dim_param) > 0) {
2705 p = print_tuple(mv->space, p, isl_dim_param, &data);
2706 p = isl_printer_print_str(p, " -> ");
2708 p = isl_printer_print_str(p, "{ ");
2709 data.print_dim = &print_dim_mv;
2710 data.user = mv;
2711 p = print_space(mv->space, p, 0, &data);
2712 p = isl_printer_print_str(p, " }");
2713 return p;
2716 /* Print the isl_multi_val "mv" to "p".
2718 * Currently only supported in isl format.
2720 __isl_give isl_printer *isl_printer_print_multi_val(
2721 __isl_take isl_printer *p, __isl_keep isl_multi_val *mv)
2723 if (!p || !mv)
2724 return isl_printer_free(p);
2726 if (p->output_format == ISL_FORMAT_ISL)
2727 return print_multi_val_isl(p, mv);
2728 isl_die(p->ctx, isl_error_unsupported, "unsupported output format",
2729 return isl_printer_free(p));
2732 /* Print dimension "pos" of data->space to "p".
2734 * data->user is assumed to be an isl_multi_union_pw_aff.
2736 * The current dimension is necessarily a set dimension, so
2737 * we print the corresponding isl_union_pw_aff, including
2738 * the braces.
2740 static __isl_give isl_printer *print_union_pw_aff_dim(__isl_take isl_printer *p,
2741 struct isl_print_space_data *data, unsigned pos)
2743 isl_multi_union_pw_aff *mupa = data->user;
2744 isl_union_pw_aff *upa;
2746 upa = isl_multi_union_pw_aff_get_union_pw_aff(mupa, pos);
2747 p = print_union_pw_aff_body(p, upa);
2748 isl_union_pw_aff_free(upa);
2750 return p;
2753 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
2755 static __isl_give isl_printer *print_multi_union_pw_aff_isl(
2756 __isl_take isl_printer *p, __isl_keep isl_multi_union_pw_aff *mupa)
2758 struct isl_print_space_data data = { 0 };
2759 isl_space *space;
2761 space = isl_multi_union_pw_aff_get_space(mupa);
2762 if (isl_space_dim(space, isl_dim_param) > 0) {
2763 struct isl_print_space_data space_data = { 0 };
2764 p = print_tuple(space, p, isl_dim_param, &space_data);
2765 p = isl_printer_print_str(p, s_to[0]);
2768 data.print_dim = &print_union_pw_aff_dim;
2769 data.user = mupa;
2771 p = print_space(space, p, 0, &data);
2772 isl_space_free(space);
2774 return p;
2777 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
2779 * We currently only support an isl format.
2781 __isl_give isl_printer *isl_printer_print_multi_union_pw_aff(
2782 __isl_take isl_printer *p, __isl_keep isl_multi_union_pw_aff *mupa)
2784 if (!p || !mupa)
2785 return isl_printer_free(p);
2787 if (p->output_format == ISL_FORMAT_ISL)
2788 return print_multi_union_pw_aff_isl(p, mupa);
2789 isl_die(isl_printer_get_ctx(p), isl_error_unsupported,
2790 "unsupported output format", return isl_printer_free(p));