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
17 #include <isl_ctx_private.h>
18 #include <isl_map_private.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>
33 #include <isl_output_private.h>
35 static const char *s_to
[2] = { " -> ", " \\to " };
36 static const char *s_and
[2] = { " and ", " \\wedge " };
37 static const char *s_or
[2] = { " or ", " \\vee " };
38 static const char *s_le
[2] = { "<=", "\\le" };
39 static const char *s_ge
[2] = { ">=", "\\ge" };
40 static const char *s_open_set
[2] = { "{ ", "\\{\\, " };
41 static const char *s_close_set
[2] = { " }", " \\,\\}" };
42 static const char *s_open_list
[2] = { "[", "(" };
43 static const char *s_close_list
[2] = { "]", ")" };
44 static const char *s_such_that
[2] = { " : ", " \\mid " };
45 static const char *s_open_exists
[2] = { "exists (", "\\exists \\, " };
46 static const char *s_close_exists
[2] = { ")", "" };
47 static const char *s_div_prefix
[2] = { "e", "\\alpha_" };
48 static const char *s_param_prefix
[2] = { "p", "p_" };
49 static const char *s_input_prefix
[2] = { "i", "i_" };
50 static const char *s_output_prefix
[2] = { "o", "o_" };
52 static __isl_give isl_printer
*print_constraint_polylib(
53 struct isl_basic_map
*bmap
, int ineq
, int n
, __isl_take isl_printer
*p
)
56 unsigned n_in
= isl_basic_map_dim(bmap
, isl_dim_in
);
57 unsigned n_out
= isl_basic_map_dim(bmap
, isl_dim_out
);
58 unsigned nparam
= isl_basic_map_dim(bmap
, isl_dim_param
);
59 isl_int
*c
= ineq
? bmap
->ineq
[n
] : bmap
->eq
[n
];
61 p
= isl_printer_start_line(p
);
62 p
= isl_printer_print_int(p
, ineq
);
63 for (i
= 0; i
< n_out
; ++i
) {
64 p
= isl_printer_print_str(p
, " ");
65 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+n_in
+i
]);
67 for (i
= 0; i
< n_in
; ++i
) {
68 p
= isl_printer_print_str(p
, " ");
69 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+i
]);
71 for (i
= 0; i
< bmap
->n_div
; ++i
) {
72 p
= isl_printer_print_str(p
, " ");
73 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+n_in
+n_out
+i
]);
75 for (i
= 0; i
< nparam
; ++i
) {
76 p
= isl_printer_print_str(p
, " ");
77 p
= isl_printer_print_isl_int(p
, c
[1+i
]);
79 p
= isl_printer_print_str(p
, " ");
80 p
= isl_printer_print_isl_int(p
, c
[0]);
81 p
= isl_printer_end_line(p
);
85 static __isl_give isl_printer
*print_constraints_polylib(
86 struct isl_basic_map
*bmap
, __isl_take isl_printer
*p
)
90 p
= isl_printer_set_isl_int_width(p
, 5);
92 for (i
= 0; i
< bmap
->n_eq
; ++i
)
93 p
= print_constraint_polylib(bmap
, 0, i
, p
);
94 for (i
= 0; i
< bmap
->n_ineq
; ++i
)
95 p
= print_constraint_polylib(bmap
, 1, i
, p
);
100 static __isl_give isl_printer
*bset_print_constraints_polylib(
101 struct isl_basic_set
*bset
, __isl_take isl_printer
*p
)
103 return print_constraints_polylib((struct isl_basic_map
*)bset
, p
);
106 static __isl_give isl_printer
*isl_basic_map_print_polylib(
107 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
, int ext
)
109 unsigned total
= isl_basic_map_total_dim(bmap
);
110 p
= isl_printer_start_line(p
);
111 p
= isl_printer_print_int(p
, bmap
->n_eq
+ bmap
->n_ineq
);
112 p
= isl_printer_print_str(p
, " ");
113 p
= isl_printer_print_int(p
, 1 + total
+ 1);
115 p
= isl_printer_print_str(p
, " ");
116 p
= isl_printer_print_int(p
,
117 isl_basic_map_dim(bmap
, isl_dim_out
));
118 p
= isl_printer_print_str(p
, " ");
119 p
= isl_printer_print_int(p
,
120 isl_basic_map_dim(bmap
, isl_dim_in
));
121 p
= isl_printer_print_str(p
, " ");
122 p
= isl_printer_print_int(p
,
123 isl_basic_map_dim(bmap
, isl_dim_div
));
124 p
= isl_printer_print_str(p
, " ");
125 p
= isl_printer_print_int(p
,
126 isl_basic_map_dim(bmap
, isl_dim_param
));
128 p
= isl_printer_end_line(p
);
129 return print_constraints_polylib(bmap
, p
);
132 static __isl_give isl_printer
*isl_basic_set_print_polylib(
133 __isl_keep isl_basic_set
*bset
, __isl_take isl_printer
*p
, int ext
)
135 return isl_basic_map_print_polylib((struct isl_basic_map
*)bset
, p
, ext
);
138 static __isl_give isl_printer
*isl_map_print_polylib(__isl_keep isl_map
*map
,
139 __isl_take isl_printer
*p
, int ext
)
143 p
= isl_printer_start_line(p
);
144 p
= isl_printer_print_int(p
, map
->n
);
145 p
= isl_printer_end_line(p
);
146 for (i
= 0; i
< map
->n
; ++i
) {
147 p
= isl_printer_start_line(p
);
148 p
= isl_printer_end_line(p
);
149 p
= isl_basic_map_print_polylib(map
->p
[i
], p
, ext
);
154 static __isl_give isl_printer
*isl_set_print_polylib(__isl_keep isl_set
*set
,
155 __isl_take isl_printer
*p
, int ext
)
157 return isl_map_print_polylib((struct isl_map
*)set
, p
, ext
);
160 static int count_same_name(__isl_keep isl_space
*dim
,
161 enum isl_dim_type type
, unsigned pos
, const char *name
)
167 for (t
= isl_dim_param
; t
<= type
&& t
<= isl_dim_out
; ++t
) {
168 s
= t
== type
? pos
: isl_space_dim(dim
, t
);
169 for (p
= 0; p
< s
; ++p
) {
170 const char *n
= isl_space_get_dim_name(dim
, t
, p
);
171 if (n
&& !strcmp(n
, name
))
178 /* Print the name of the variable of type "type" and position "pos"
181 static __isl_give isl_printer
*print_name(__isl_keep isl_space
*space
,
182 __isl_take isl_printer
*p
, enum isl_dim_type type
, unsigned pos
,
189 name
= type
== isl_dim_div
? NULL
190 : isl_space_get_dim_name(space
, type
, pos
);
194 if (type
== isl_dim_param
)
195 prefix
= s_param_prefix
[latex
];
196 else if (type
== isl_dim_div
)
197 prefix
= s_div_prefix
[latex
];
198 else if (isl_space_is_set(space
) || type
== isl_dim_in
)
199 prefix
= s_input_prefix
[latex
];
201 prefix
= s_output_prefix
[latex
];
202 snprintf(buffer
, sizeof(buffer
), "%s%d", prefix
, pos
);
205 primes
= count_same_name(space
, name
== buffer
? isl_dim_div
: type
,
207 p
= isl_printer_print_str(p
, name
);
209 p
= isl_printer_print_str(p
, "'");
213 static enum isl_dim_type
pos2type(__isl_keep isl_space
*dim
, unsigned *pos
)
215 enum isl_dim_type type
;
216 unsigned n_in
= isl_space_dim(dim
, isl_dim_in
);
217 unsigned n_out
= isl_space_dim(dim
, isl_dim_out
);
218 unsigned nparam
= isl_space_dim(dim
, isl_dim_param
);
220 if (*pos
< 1 + nparam
) {
221 type
= isl_dim_param
;
223 } else if (*pos
< 1 + nparam
+ n_in
) {
226 } else if (*pos
< 1 + nparam
+ n_in
+ n_out
) {
228 *pos
-= 1 + nparam
+ n_in
;
231 *pos
-= 1 + nparam
+ n_in
+ n_out
;
237 /* Can the div expression of the integer division at position "row" of "div"
239 * In particular, are the div expressions available and does the selected
240 * variable have a known explicit representation?
241 * Furthermore, the Omega format does not allow and div expressions
244 static isl_bool
can_print_div_expr(__isl_keep isl_printer
*p
,
245 __isl_keep isl_mat
*div
, int pos
)
247 if (p
->output_format
== ISL_FORMAT_OMEGA
)
248 return isl_bool_false
;
250 return isl_bool_false
;
251 return !isl_int_is_zero(div
->row
[pos
][0]);
254 static __isl_give isl_printer
*print_div(__isl_keep isl_space
*dim
,
255 __isl_keep isl_mat
*div
, int pos
, __isl_take isl_printer
*p
);
257 static __isl_give isl_printer
*print_term(__isl_keep isl_space
*space
,
258 __isl_keep isl_mat
*div
,
259 isl_int c
, unsigned pos
, __isl_take isl_printer
*p
, int latex
)
261 enum isl_dim_type type
;
265 return isl_printer_print_isl_int(p
, c
);
267 type
= pos2type(space
, &pos
);
268 print_div_def
= type
== isl_dim_div
&& can_print_div_expr(p
, div
, pos
);
270 if (isl_int_is_one(c
))
272 else if (isl_int_is_negone(c
))
273 p
= isl_printer_print_str(p
, "-");
275 p
= isl_printer_print_isl_int(p
, c
);
276 if (p
->output_format
== ISL_FORMAT_C
|| print_div_def
)
277 p
= isl_printer_print_str(p
, "*");
280 p
= print_div(space
, div
, pos
, p
);
282 p
= print_name(space
, p
, type
, pos
, latex
);
286 static __isl_give isl_printer
*print_affine_of_len(__isl_keep isl_space
*dim
,
287 __isl_keep isl_mat
*div
,
288 __isl_take isl_printer
*p
, isl_int
*c
, int len
)
293 for (i
= 0, first
= 1; i
< len
; ++i
) {
295 if (isl_int_is_zero(c
[i
]))
298 if (isl_int_is_neg(c
[i
])) {
300 isl_int_neg(c
[i
], c
[i
]);
301 p
= isl_printer_print_str(p
, " - ");
303 p
= isl_printer_print_str(p
, " + ");
306 p
= print_term(dim
, div
, c
[i
], i
, p
, 0);
308 isl_int_neg(c
[i
], c
[i
]);
311 p
= isl_printer_print_str(p
, "0");
315 /* Print an affine expression "c" corresponding to a constraint in "bmap"
316 * to "p", with the variable names taken from "space" and
317 * the integer division definitions taken from "div".
319 static __isl_give isl_printer
*print_affine(__isl_keep isl_basic_map
*bmap
,
320 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
321 __isl_take isl_printer
*p
, isl_int
*c
)
323 unsigned len
= 1 + isl_basic_map_total_dim(bmap
);
324 return print_affine_of_len(space
, div
, p
, c
, len
);
327 /* offset is the offset of local_dim inside data->type of data->space.
329 static __isl_give isl_printer
*print_nested_var_list(__isl_take isl_printer
*p
,
330 __isl_keep isl_space
*local_dim
, enum isl_dim_type local_type
,
331 struct isl_print_space_data
*data
, int offset
)
335 if (data
->space
!= local_dim
&& local_type
== isl_dim_out
)
336 offset
+= local_dim
->n_in
;
338 for (i
= 0; i
< isl_space_dim(local_dim
, local_type
); ++i
) {
340 p
= isl_printer_print_str(p
, ", ");
342 p
= data
->print_dim(p
, data
, offset
+ i
);
344 p
= print_name(data
->space
, p
, data
->type
, offset
+ i
,
350 static __isl_give isl_printer
*print_var_list(__isl_take isl_printer
*p
,
351 __isl_keep isl_space
*space
, enum isl_dim_type type
)
353 struct isl_print_space_data data
= { .space
= space
, .type
= type
};
355 return print_nested_var_list(p
, space
, type
, &data
, 0);
358 static __isl_give isl_printer
*print_nested_map_dim(__isl_take isl_printer
*p
,
359 __isl_keep isl_space
*local_dim
,
360 struct isl_print_space_data
*data
, int offset
);
362 static __isl_give isl_printer
*print_nested_tuple(__isl_take isl_printer
*p
,
363 __isl_keep isl_space
*local_dim
, enum isl_dim_type local_type
,
364 struct isl_print_space_data
*data
, int offset
)
366 const char *name
= NULL
;
367 unsigned n
= isl_space_dim(local_dim
, local_type
);
368 if ((local_type
== isl_dim_in
|| local_type
== isl_dim_out
)) {
369 name
= isl_space_get_tuple_name(local_dim
, local_type
);
372 p
= isl_printer_print_str(p
, "\\mathrm{");
373 p
= isl_printer_print_str(p
, name
);
375 p
= isl_printer_print_str(p
, "}");
378 if (!data
->latex
|| n
!= 1 || name
)
379 p
= isl_printer_print_str(p
, s_open_list
[data
->latex
]);
380 if ((local_type
== isl_dim_in
|| local_type
== isl_dim_out
) &&
381 local_dim
->nested
[local_type
- isl_dim_in
]) {
382 if (data
->space
!= local_dim
&& local_type
== isl_dim_out
)
383 offset
+= local_dim
->n_in
;
384 p
= print_nested_map_dim(p
,
385 local_dim
->nested
[local_type
- isl_dim_in
],
388 p
= print_nested_var_list(p
, local_dim
, local_type
, data
,
390 if (!data
->latex
|| n
!= 1 || name
)
391 p
= isl_printer_print_str(p
, s_close_list
[data
->latex
]);
395 static __isl_give isl_printer
*print_tuple(__isl_keep isl_space
*dim
,
396 __isl_take isl_printer
*p
, enum isl_dim_type type
,
397 struct isl_print_space_data
*data
)
401 return print_nested_tuple(p
, dim
, type
, data
, 0);
404 static __isl_give isl_printer
*print_nested_map_dim(__isl_take isl_printer
*p
,
405 __isl_keep isl_space
*local_dim
,
406 struct isl_print_space_data
*data
, int offset
)
408 p
= print_nested_tuple(p
, local_dim
, isl_dim_in
, data
, offset
);
409 p
= isl_printer_print_str(p
, s_to
[data
->latex
]);
410 p
= print_nested_tuple(p
, local_dim
, isl_dim_out
, data
, offset
);
415 __isl_give isl_printer
*isl_print_space(__isl_keep isl_space
*space
,
416 __isl_take isl_printer
*p
, int rational
,
417 struct isl_print_space_data
*data
)
419 if (rational
&& !data
->latex
)
420 p
= isl_printer_print_str(p
, "rat: ");
421 if (isl_space_is_params(space
))
423 else if (isl_space_is_set(space
))
424 p
= print_tuple(space
, p
, isl_dim_set
, data
);
426 p
= print_tuple(space
, p
, isl_dim_in
, data
);
427 p
= isl_printer_print_str(p
, s_to
[data
->latex
]);
428 p
= print_tuple(space
, p
, isl_dim_out
, data
);
434 static __isl_give isl_printer
*print_omega_parameters(__isl_keep isl_space
*dim
,
435 __isl_take isl_printer
*p
)
437 if (isl_space_dim(dim
, isl_dim_param
) == 0)
440 p
= isl_printer_start_line(p
);
441 p
= isl_printer_print_str(p
, "symbolic ");
442 p
= print_var_list(p
, dim
, isl_dim_param
);
443 p
= isl_printer_print_str(p
, ";");
444 p
= isl_printer_end_line(p
);
448 /* Does the inequality constraint following "i" in "bmap"
449 * have an opposite value for the same last coefficient?
450 * "last" is the position of the last coefficient of inequality "i".
451 * If the next constraint is a div constraint, then it is ignored
452 * since div constraints are not printed.
454 static int next_is_opposite(__isl_keep isl_basic_map
*bmap
, int i
, int last
)
456 unsigned total
= isl_basic_map_total_dim(bmap
);
457 unsigned o_div
= isl_basic_map_offset(bmap
, isl_dim_div
);
459 if (i
+ 1 >= bmap
->n_ineq
)
461 if (isl_seq_last_non_zero(bmap
->ineq
[i
+ 1], 1 + total
) != last
)
464 isl_basic_map_is_div_constraint(bmap
, bmap
->ineq
[i
+ 1],
467 return isl_int_abs_eq(bmap
->ineq
[i
][last
], bmap
->ineq
[i
+ 1][last
]) &&
468 !isl_int_eq(bmap
->ineq
[i
][last
], bmap
->ineq
[i
+ 1][last
]);
471 /* Return a string representation of the operator used when
472 * printing a constraint where the LHS is greater than or equal to the LHS
473 * (sign > 0) or smaller than or equal to the LHS (sign < 0).
474 * If "strict" is set, then return the strict version of the comparison
477 static const char *constraint_op(int sign
, int strict
, int latex
)
480 return sign
< 0 ? "<" : ">";
487 /* Print one side of a constraint "c" from "bmap" to "p", with
488 * the variable names taken from "space" and the integer division definitions
490 * "last" is the position of the last non-zero coefficient.
491 * Let c' be the result of zeroing out this coefficient, then
492 * the partial constraint
497 * "first_constraint" is set if this is the first constraint
498 * in the conjunction.
500 static __isl_give isl_printer
*print_half_constraint(struct isl_basic_map
*bmap
,
501 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
502 __isl_take isl_printer
*p
, isl_int
*c
, int last
, const char *op
,
503 int first_constraint
, int latex
)
505 if (!first_constraint
)
506 p
= isl_printer_print_str(p
, s_and
[latex
]);
508 isl_int_set_si(c
[last
], 0);
509 p
= print_affine(bmap
, space
, div
, p
, c
);
511 p
= isl_printer_print_str(p
, " ");
512 p
= isl_printer_print_str(p
, op
);
513 p
= isl_printer_print_str(p
, " ");
518 /* Print a constraint "c" from "bmap" to "p", with the variable names
519 * taken from "space" and the integer division definitions taken from "div".
520 * "last" is the position of the last non-zero coefficient, which is
521 * moreover assumed to be negative.
522 * Let c' be the result of zeroing out this coefficient, then
523 * the constraint is printed in the form
527 * "first_constraint" is set if this is the first constraint
528 * in the conjunction.
530 static __isl_give isl_printer
*print_constraint(struct isl_basic_map
*bmap
,
531 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
532 __isl_take isl_printer
*p
,
533 isl_int
*c
, int last
, const char *op
, int first_constraint
, int latex
)
535 if (!first_constraint
)
536 p
= isl_printer_print_str(p
, s_and
[latex
]);
538 isl_int_abs(c
[last
], c
[last
]);
540 p
= print_term(space
, div
, c
[last
], last
, p
, latex
);
542 p
= isl_printer_print_str(p
, " ");
543 p
= isl_printer_print_str(p
, op
);
544 p
= isl_printer_print_str(p
, " ");
546 isl_int_set_si(c
[last
], 0);
547 p
= print_affine(bmap
, space
, div
, p
, c
);
552 /* Print the constraints of "bmap" to "p".
553 * The names of the variables are taken from "space" and
554 * the integer division definitions are taken from "div".
555 * Div constraints are only printed in "dump" mode.
556 * The constraints are sorted prior to printing (except in "dump" mode).
558 * If x is the last variable with a non-zero coefficient,
567 * while an upper bound
575 * If the next constraint has an opposite sign for the same last coefficient,
576 * then it is printed as
584 * instead. In fact, the "a x" part is not printed explicitly, but
585 * reused from the next constraint, which is therefore treated as
586 * a first constraint in the conjunction.
588 * If the constant term of "f" is -1, then "f" is replaced by "f + 1" and
589 * the comparison operator is replaced by the strict variant.
590 * Essentially, ">= 1" is replaced by "> 0".
592 static __isl_give isl_printer
*print_constraints(__isl_keep isl_basic_map
*bmap
,
593 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
594 __isl_take isl_printer
*p
, int latex
)
598 int rational
= ISL_F_ISSET(bmap
, ISL_BASIC_MAP_RATIONAL
);
599 unsigned total
= isl_basic_map_total_dim(bmap
);
600 unsigned o_div
= isl_basic_map_offset(bmap
, isl_dim_div
);
603 bmap
= isl_basic_map_copy(bmap
);
605 bmap
= isl_basic_map_sort_constraints(bmap
);
609 c
= isl_vec_alloc(bmap
->ctx
, 1 + total
);
613 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
614 int l
= isl_seq_last_non_zero(bmap
->eq
[i
], 1 + total
);
616 if (i
!= bmap
->n_eq
- 1)
617 p
= isl_printer_print_str(p
, s_and
[latex
]);
618 p
= isl_printer_print_str(p
, "0 = 0");
621 if (isl_int_is_neg(bmap
->eq
[i
][l
]))
622 isl_seq_cpy(c
->el
, bmap
->eq
[i
], 1 + total
);
624 isl_seq_neg(c
->el
, bmap
->eq
[i
], 1 + total
);
625 p
= print_constraint(bmap
, space
, div
, p
, c
->el
, l
,
629 for (i
= 0; i
< bmap
->n_ineq
; ++i
) {
630 int l
= isl_seq_last_non_zero(bmap
->ineq
[i
], 1 + total
);
636 if (!p
->dump
&& l
>= o_div
&&
637 can_print_div_expr(p
, div
, l
- o_div
) &&
638 isl_basic_map_is_div_constraint(bmap
, bmap
->ineq
[i
],
641 s
= isl_int_sgn(bmap
->ineq
[i
][l
]);
642 strict
= !rational
&& isl_int_is_negone(bmap
->ineq
[i
][0]);
644 isl_seq_cpy(c
->el
, bmap
->ineq
[i
], 1 + total
);
646 isl_seq_neg(c
->el
, bmap
->ineq
[i
], 1 + total
);
648 isl_int_set_si(c
->el
[0], 0);
649 if (!p
->dump
&& next_is_opposite(bmap
, i
, l
)) {
650 op
= constraint_op(-s
, strict
, latex
);
651 p
= print_half_constraint(bmap
, space
, div
, p
, c
->el
, l
,
655 op
= constraint_op(s
, strict
, latex
);
656 p
= print_constraint(bmap
, space
, div
, p
, c
->el
, l
,
662 isl_basic_map_free(bmap
);
667 isl_basic_map_free(bmap
);
673 static __isl_give isl_printer
*print_div(__isl_keep isl_space
*dim
,
674 __isl_keep isl_mat
*div
, int pos
, __isl_take isl_printer
*p
)
679 return isl_printer_free(p
);
681 c
= p
->output_format
== ISL_FORMAT_C
;
682 p
= isl_printer_print_str(p
, c
? "floord(" : "floor((");
683 p
= print_affine_of_len(dim
, div
, p
,
684 div
->row
[pos
] + 1, div
->n_col
- 1);
685 p
= isl_printer_print_str(p
, c
? ", " : ")/");
686 p
= isl_printer_print_isl_int(p
, div
->row
[pos
][0]);
687 p
= isl_printer_print_str(p
, ")");
691 /* Print a comma separated list of div names, except those that have
692 * a definition that can be printed.
693 * If "print_defined_divs" is set, then those div names are printed
694 * as well, along with their definitions.
696 static __isl_give isl_printer
*print_div_list(__isl_take isl_printer
*p
,
697 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, int latex
,
698 int print_defined_divs
)
704 if (!p
|| !space
|| !div
)
705 return isl_printer_free(p
);
707 n_div
= isl_mat_rows(div
);
709 for (i
= 0; i
< n_div
; ++i
) {
710 if (!print_defined_divs
&& can_print_div_expr(p
, div
, i
))
713 p
= isl_printer_print_str(p
, ", ");
714 p
= print_name(space
, p
, isl_dim_div
, i
, latex
);
716 if (!can_print_div_expr(p
, div
, i
))
718 p
= isl_printer_print_str(p
, " = ");
719 p
= print_div(space
, div
, i
, p
);
725 /* Does printing "bmap" require an "exists" clause?
726 * That is, are there any local variables without an explicit representation?
728 static isl_bool
need_exists(__isl_keep isl_printer
*p
,
729 __isl_keep isl_basic_map
*bmap
, __isl_keep isl_mat
*div
)
734 return isl_bool_error
;
735 if (bmap
->n_div
== 0)
736 return isl_bool_false
;
737 for (i
= 0; i
< bmap
->n_div
; ++i
)
738 if (!can_print_div_expr(p
, div
, i
))
739 return isl_bool_true
;
740 return isl_bool_false
;
743 /* Print the constraints of "bmap" to "p".
744 * The names of the variables are taken from "space".
745 * "latex" is set if the constraints should be printed in LaTeX format.
746 * Do not print inline explicit div representations in "dump" mode.
748 static __isl_give isl_printer
*print_disjunct(__isl_keep isl_basic_map
*bmap
,
749 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
758 div
= isl_basic_map_get_divs(bmap
);
760 exists
= bmap
->n_div
> 0;
762 exists
= need_exists(p
, bmap
, div
);
763 if (exists
>= 0 && exists
) {
764 p
= isl_printer_print_str(p
, s_open_exists
[latex
]);
765 p
= print_div_list(p
, space
, div
, latex
, dump
);
766 p
= isl_printer_print_str(p
, ": ");
770 div
= isl_mat_free(div
);
771 p
= print_constraints(bmap
, space
, div
, p
, latex
);
774 if (exists
>= 0 && exists
)
775 p
= isl_printer_print_str(p
, s_close_exists
[latex
]);
779 /* Print a colon followed by the constraints of "bmap"
780 * to "p", provided there are any constraints.
781 * The names of the variables are taken from "space".
782 * "latex" is set if the constraints should be printed in LaTeX format.
784 static __isl_give isl_printer
*print_optional_disjunct(
785 __isl_keep isl_basic_map
*bmap
, __isl_keep isl_space
*space
,
786 __isl_take isl_printer
*p
, int latex
)
788 if (isl_basic_map_plain_is_universe(bmap
))
791 p
= isl_printer_print_str(p
, ": ");
792 p
= print_disjunct(bmap
, space
, p
, latex
);
797 static __isl_give isl_printer
*basic_map_print_omega(
798 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
)
800 p
= isl_printer_print_str(p
, "{ [");
801 p
= print_var_list(p
, bmap
->dim
, isl_dim_in
);
802 p
= isl_printer_print_str(p
, "] -> [");
803 p
= print_var_list(p
, bmap
->dim
, isl_dim_out
);
804 p
= isl_printer_print_str(p
, "] ");
805 p
= print_optional_disjunct(bmap
, bmap
->dim
, p
, 0);
806 p
= isl_printer_print_str(p
, " }");
810 static __isl_give isl_printer
*basic_set_print_omega(
811 __isl_keep isl_basic_set
*bset
, __isl_take isl_printer
*p
)
813 p
= isl_printer_print_str(p
, "{ [");
814 p
= print_var_list(p
, bset
->dim
, isl_dim_set
);
815 p
= isl_printer_print_str(p
, "] ");
816 p
= print_optional_disjunct(bset
, bset
->dim
, p
, 0);
817 p
= isl_printer_print_str(p
, " }");
821 static __isl_give isl_printer
*isl_map_print_omega(__isl_keep isl_map
*map
,
822 __isl_take isl_printer
*p
)
826 for (i
= 0; i
< map
->n
; ++i
) {
828 p
= isl_printer_print_str(p
, " union ");
829 p
= basic_map_print_omega(map
->p
[i
], p
);
834 static __isl_give isl_printer
*isl_set_print_omega(__isl_keep isl_set
*set
,
835 __isl_take isl_printer
*p
)
839 for (i
= 0; i
< set
->n
; ++i
) {
841 p
= isl_printer_print_str(p
, " union ");
842 p
= basic_set_print_omega(set
->p
[i
], p
);
847 static __isl_give isl_printer
*isl_basic_map_print_isl(
848 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
,
851 struct isl_print_space_data data
= { .latex
= latex
};
852 int rational
= ISL_F_ISSET(bmap
, ISL_BASIC_MAP_RATIONAL
);
854 if (isl_basic_map_dim(bmap
, isl_dim_param
) > 0) {
855 p
= print_tuple(bmap
->dim
, p
, isl_dim_param
, &data
);
856 p
= isl_printer_print_str(p
, " -> ");
858 p
= isl_printer_print_str(p
, "{ ");
859 p
= isl_print_space(bmap
->dim
, p
, rational
, &data
);
860 p
= isl_printer_print_str(p
, " : ");
861 p
= print_disjunct(bmap
, bmap
->dim
, p
, latex
);
862 p
= isl_printer_print_str(p
, " }");
866 /* Print the disjuncts of a map (or set) "map" to "p".
867 * The names of the variables are taken from "space".
868 * "latex" is set if the constraints should be printed in LaTeX format.
870 static __isl_give isl_printer
*print_disjuncts_core(__isl_keep isl_map
*map
,
871 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
876 p
= isl_printer_print_str(p
, "1 = 0");
877 for (i
= 0; i
< map
->n
; ++i
) {
879 p
= isl_printer_print_str(p
, s_or
[latex
]);
880 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
881 p
= isl_printer_print_str(p
, "(");
882 p
= print_disjunct(map
->p
[i
], space
, p
, latex
);
883 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
884 p
= isl_printer_print_str(p
, ")");
889 /* Print the disjuncts of a map (or set) "map" to "p".
890 * The names of the variables are taken from "space".
891 * "hull" describes constraints shared by all disjuncts of "map".
892 * "latex" is set if the constraints should be printed in LaTeX format.
894 * Print the disjuncts as a conjunction of "hull" and
895 * the result of removing the constraints of "hull" from "map".
896 * If this result turns out to be the universe, then simply print "hull".
898 static __isl_give isl_printer
*print_disjuncts_in_hull(__isl_keep isl_map
*map
,
899 __isl_keep isl_space
*space
, __isl_take isl_basic_map
*hull
,
900 __isl_take isl_printer
*p
, int latex
)
902 isl_bool is_universe
;
904 p
= print_disjunct(hull
, space
, p
, latex
);
905 map
= isl_map_plain_gist_basic_map(isl_map_copy(map
), hull
);
906 is_universe
= isl_map_plain_is_universe(map
);
910 p
= isl_printer_print_str(p
, s_and
[latex
]);
911 p
= isl_printer_print_str(p
, "(");
912 p
= print_disjuncts_core(map
, space
, p
, latex
);
913 p
= isl_printer_print_str(p
, ")");
924 /* Print the disjuncts of a map (or set) "map" to "p".
925 * The names of the variables are taken from "space".
926 * "latex" is set if the constraints should be printed in LaTeX format.
928 * If there are at least two disjuncts and "dump" mode is not turned out,
929 * check for any shared constraints among all disjuncts.
930 * If there are any, then print them separately in print_disjuncts_in_hull.
932 static __isl_give isl_printer
*print_disjuncts(__isl_keep isl_map
*map
,
933 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
935 if (isl_map_plain_is_universe(map
))
938 p
= isl_printer_print_str(p
, s_such_that
[latex
]);
942 if (!p
->dump
&& map
->n
>= 2) {
944 isl_bool is_universe
;
946 hull
= isl_map_plain_unshifted_simple_hull(isl_map_copy(map
));
947 is_universe
= isl_basic_map_plain_is_universe(hull
);
949 p
= isl_printer_free(p
);
950 else if (!is_universe
)
951 return print_disjuncts_in_hull(map
, space
, hull
,
953 isl_basic_map_free(hull
);
956 return print_disjuncts_core(map
, space
, p
, latex
);
959 /* Print the disjuncts of a map (or set).
960 * The names of the variables are taken from "space".
961 * "latex" is set if the constraints should be printed in LaTeX format.
963 * If the map turns out to be a universal parameter domain, then
964 * we need to print the colon. Otherwise, the output looks identical
967 static __isl_give isl_printer
*print_disjuncts_map(__isl_keep isl_map
*map
,
968 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
970 if (isl_map_plain_is_universe(map
) && isl_space_is_params(map
->dim
))
971 return isl_printer_print_str(p
, s_such_that
[latex
]);
973 return print_disjuncts(map
, space
, p
, latex
);
976 struct isl_aff_split
{
981 static void free_split(__isl_take
struct isl_aff_split
*split
, int n
)
988 for (i
= 0; i
< n
; ++i
) {
989 isl_basic_map_free(split
[i
].aff
);
990 isl_map_free(split
[i
].map
);
996 static __isl_give isl_basic_map
*get_aff(__isl_take isl_basic_map
*bmap
)
999 unsigned nparam
, n_in
, n_out
, total
;
1001 bmap
= isl_basic_map_cow(bmap
);
1004 if (isl_basic_map_free_inequality(bmap
, bmap
->n_ineq
) < 0)
1007 nparam
= isl_basic_map_dim(bmap
, isl_dim_param
);
1008 n_in
= isl_basic_map_dim(bmap
, isl_dim_in
);
1009 n_out
= isl_basic_map_dim(bmap
, isl_dim_out
);
1010 total
= isl_basic_map_dim(bmap
, isl_dim_all
);
1011 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
1012 j
= isl_seq_last_non_zero(bmap
->eq
[i
] + 1, total
);
1013 if (j
>= nparam
&& j
< nparam
+ n_in
+ n_out
&&
1014 (isl_int_is_one(bmap
->eq
[i
][1 + j
]) ||
1015 isl_int_is_negone(bmap
->eq
[i
][1 + j
])))
1017 if (isl_basic_map_drop_equality(bmap
, i
) < 0)
1021 bmap
= isl_basic_map_finalize(bmap
);
1025 isl_basic_map_free(bmap
);
1029 static int aff_split_cmp(const void *p1
, const void *p2
, void *user
)
1031 const struct isl_aff_split
*s1
, *s2
;
1032 s1
= (const struct isl_aff_split
*) p1
;
1033 s2
= (const struct isl_aff_split
*) p2
;
1035 return isl_basic_map_plain_cmp(s1
->aff
, s2
->aff
);
1038 static __isl_give isl_basic_map
*drop_aff(__isl_take isl_basic_map
*bmap
,
1039 __isl_keep isl_basic_map
*aff
)
1047 total
= isl_space_dim(bmap
->dim
, isl_dim_all
);
1049 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
1050 if (isl_seq_first_non_zero(bmap
->eq
[i
] + 1 + total
,
1053 for (j
= 0; j
< aff
->n_eq
; ++j
) {
1054 if (!isl_seq_eq(bmap
->eq
[i
], aff
->eq
[j
], 1 + total
) &&
1055 !isl_seq_is_neg(bmap
->eq
[i
], aff
->eq
[j
], 1 + total
))
1057 if (isl_basic_map_drop_equality(bmap
, i
) < 0)
1065 isl_basic_map_free(bmap
);
1069 static __isl_give
struct isl_aff_split
*split_aff(__isl_keep isl_map
*map
)
1072 struct isl_aff_split
*split
;
1075 ctx
= isl_map_get_ctx(map
);
1076 split
= isl_calloc_array(ctx
, struct isl_aff_split
, map
->n
);
1080 for (i
= 0; i
< map
->n
; ++i
) {
1081 isl_basic_map
*bmap
;
1082 split
[i
].aff
= get_aff(isl_basic_map_copy(map
->p
[i
]));
1083 bmap
= isl_basic_map_copy(map
->p
[i
]);
1084 bmap
= isl_basic_map_cow(bmap
);
1085 bmap
= drop_aff(bmap
, split
[i
].aff
);
1086 split
[i
].map
= isl_map_from_basic_map(bmap
);
1087 if (!split
[i
].aff
|| !split
[i
].map
)
1091 if (isl_sort(split
, map
->n
, sizeof(struct isl_aff_split
),
1092 &aff_split_cmp
, NULL
) < 0)
1096 for (i
= n
- 1; i
>= 1; --i
) {
1097 if (!isl_basic_map_plain_is_equal(split
[i
- 1].aff
,
1100 isl_basic_map_free(split
[i
].aff
);
1101 split
[i
- 1].map
= isl_map_union(split
[i
- 1].map
,
1104 split
[i
] = split
[n
- 1];
1105 split
[n
- 1].aff
= NULL
;
1106 split
[n
- 1].map
= NULL
;
1112 free_split(split
, map
->n
);
1116 static int defining_equality(__isl_keep isl_basic_map
*eq
,
1117 __isl_keep isl_space
*dim
, enum isl_dim_type type
, int pos
)
1125 pos
+= isl_space_offset(dim
, type
);
1126 total
= isl_basic_map_total_dim(eq
);
1128 for (i
= 0; i
< eq
->n_eq
; ++i
) {
1129 if (isl_seq_last_non_zero(eq
->eq
[i
] + 1, total
) != pos
)
1131 if (isl_int_is_one(eq
->eq
[i
][1 + pos
]))
1132 isl_seq_neg(eq
->eq
[i
], eq
->eq
[i
], 1 + total
);
1139 /* Print dimension "pos" of data->space to "p".
1141 * data->user is assumed to be an isl_basic_map keeping track of equalities.
1143 * If the current dimension is defined by these equalities, then print
1144 * the corresponding expression, assigned to the name of the dimension
1145 * if there is any. Otherwise, print the name of the dimension.
1147 static __isl_give isl_printer
*print_dim_eq(__isl_take isl_printer
*p
,
1148 struct isl_print_space_data
*data
, unsigned pos
)
1150 isl_basic_map
*eq
= data
->user
;
1153 j
= defining_equality(eq
, data
->space
, data
->type
, pos
);
1155 if (isl_space_has_dim_name(data
->space
, data
->type
, pos
)) {
1156 p
= print_name(data
->space
, p
, data
->type
, pos
,
1158 p
= isl_printer_print_str(p
, " = ");
1160 pos
+= 1 + isl_space_offset(data
->space
, data
->type
);
1161 p
= print_affine_of_len(data
->space
, NULL
, p
, eq
->eq
[j
], pos
);
1163 p
= print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
1169 static __isl_give isl_printer
*print_split_map(__isl_take isl_printer
*p
,
1170 struct isl_aff_split
*split
, int n
, __isl_keep isl_space
*space
)
1172 struct isl_print_space_data data
= { 0 };
1176 data
.print_dim
= &print_dim_eq
;
1177 for (i
= 0; i
< n
; ++i
) {
1180 rational
= split
[i
].map
->n
> 0 &&
1181 ISL_F_ISSET(split
[i
].map
->p
[0], ISL_BASIC_MAP_RATIONAL
);
1183 p
= isl_printer_print_str(p
, "; ");
1184 data
.user
= split
[i
].aff
;
1185 p
= isl_print_space(space
, p
, rational
, &data
);
1186 p
= print_disjuncts_map(split
[i
].map
, space
, p
, 0);
1192 static __isl_give isl_printer
*isl_map_print_isl_body(__isl_keep isl_map
*map
,
1193 __isl_take isl_printer
*p
)
1195 struct isl_print_space_data data
= { 0 };
1196 struct isl_aff_split
*split
= NULL
;
1200 return isl_printer_free(p
);
1201 if (!p
->dump
&& map
->n
> 0)
1202 split
= split_aff(map
);
1204 p
= print_split_map(p
, split
, map
->n
, map
->dim
);
1206 rational
= map
->n
> 0 &&
1207 ISL_F_ISSET(map
->p
[0], ISL_BASIC_MAP_RATIONAL
);
1208 p
= isl_print_space(map
->dim
, p
, rational
, &data
);
1209 p
= print_disjuncts_map(map
, map
->dim
, p
, 0);
1211 free_split(split
, map
->n
);
1215 static __isl_give isl_printer
*isl_map_print_isl(__isl_keep isl_map
*map
,
1216 __isl_take isl_printer
*p
)
1218 struct isl_print_space_data data
= { 0 };
1220 if (isl_map_dim(map
, isl_dim_param
) > 0) {
1221 p
= print_tuple(map
->dim
, p
, isl_dim_param
, &data
);
1222 p
= isl_printer_print_str(p
, s_to
[0]);
1224 p
= isl_printer_print_str(p
, s_open_set
[0]);
1225 p
= isl_map_print_isl_body(map
, p
);
1226 p
= isl_printer_print_str(p
, s_close_set
[0]);
1230 static __isl_give isl_printer
*print_latex_map(__isl_keep isl_map
*map
,
1231 __isl_take isl_printer
*p
, __isl_keep isl_basic_map
*aff
)
1233 struct isl_print_space_data data
= { 0 };
1236 if (isl_map_dim(map
, isl_dim_param
) > 0) {
1237 p
= print_tuple(map
->dim
, p
, isl_dim_param
, &data
);
1238 p
= isl_printer_print_str(p
, s_to
[1]);
1240 p
= isl_printer_print_str(p
, s_open_set
[1]);
1241 data
.print_dim
= &print_dim_eq
;
1243 p
= isl_print_space(map
->dim
, p
, 0, &data
);
1244 p
= print_disjuncts_map(map
, map
->dim
, p
, 1);
1245 p
= isl_printer_print_str(p
, s_close_set
[1]);
1250 static __isl_give isl_printer
*isl_map_print_latex(__isl_keep isl_map
*map
,
1251 __isl_take isl_printer
*p
)
1254 struct isl_aff_split
*split
= NULL
;
1257 split
= split_aff(map
);
1260 return print_latex_map(map
, p
, NULL
);
1262 for (i
= 0; i
< map
->n
; ++i
) {
1266 p
= isl_printer_print_str(p
, " \\cup ");
1267 p
= print_latex_map(split
[i
].map
, p
, split
[i
].aff
);
1270 free_split(split
, map
->n
);
1274 __isl_give isl_printer
*isl_printer_print_basic_map(__isl_take isl_printer
*p
,
1275 __isl_keep isl_basic_map
*bmap
)
1279 if (p
->output_format
== ISL_FORMAT_ISL
)
1280 return isl_basic_map_print_isl(bmap
, p
, 0);
1281 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1282 return basic_map_print_omega(bmap
, p
);
1283 isl_assert(bmap
->ctx
, 0, goto error
);
1285 isl_printer_free(p
);
1289 __isl_give isl_printer
*isl_printer_print_basic_set(__isl_take isl_printer
*p
,
1290 __isl_keep isl_basic_set
*bset
)
1295 if (p
->output_format
== ISL_FORMAT_ISL
)
1296 return isl_basic_map_print_isl(bset
, p
, 0);
1297 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1298 return isl_basic_set_print_polylib(bset
, p
, 0);
1299 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1300 return isl_basic_set_print_polylib(bset
, p
, 1);
1301 else if (p
->output_format
== ISL_FORMAT_POLYLIB_CONSTRAINTS
)
1302 return bset_print_constraints_polylib(bset
, p
);
1303 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1304 return basic_set_print_omega(bset
, p
);
1305 isl_assert(p
->ctx
, 0, goto error
);
1307 isl_printer_free(p
);
1311 __isl_give isl_printer
*isl_printer_print_set(__isl_take isl_printer
*p
,
1312 __isl_keep isl_set
*set
)
1316 if (p
->output_format
== ISL_FORMAT_ISL
)
1317 return isl_map_print_isl((isl_map
*)set
, p
);
1318 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1319 return isl_set_print_polylib(set
, p
, 0);
1320 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1321 return isl_set_print_polylib(set
, p
, 1);
1322 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1323 return isl_set_print_omega(set
, p
);
1324 else if (p
->output_format
== ISL_FORMAT_LATEX
)
1325 return isl_map_print_latex((isl_map
*)set
, p
);
1326 isl_assert(set
->ctx
, 0, goto error
);
1328 isl_printer_free(p
);
1332 __isl_give isl_printer
*isl_printer_print_map(__isl_take isl_printer
*p
,
1333 __isl_keep isl_map
*map
)
1338 if (p
->output_format
== ISL_FORMAT_ISL
)
1339 return isl_map_print_isl(map
, p
);
1340 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1341 return isl_map_print_polylib(map
, p
, 0);
1342 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1343 return isl_map_print_polylib(map
, p
, 1);
1344 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1345 return isl_map_print_omega(map
, p
);
1346 else if (p
->output_format
== ISL_FORMAT_LATEX
)
1347 return isl_map_print_latex(map
, p
);
1348 isl_assert(map
->ctx
, 0, goto error
);
1350 isl_printer_free(p
);
1354 struct isl_union_print_data
{
1359 static isl_stat
print_map_body(__isl_take isl_map
*map
, void *user
)
1361 struct isl_union_print_data
*data
;
1362 data
= (struct isl_union_print_data
*)user
;
1365 data
->p
= isl_printer_print_str(data
->p
, "; ");
1368 data
->p
= isl_map_print_isl_body(map
, data
->p
);
1374 static __isl_give isl_printer
*isl_union_map_print_isl(
1375 __isl_keep isl_union_map
*umap
, __isl_take isl_printer
*p
)
1377 struct isl_union_print_data data
;
1378 struct isl_print_space_data space_data
= { 0 };
1381 dim
= isl_union_map_get_space(umap
);
1382 if (isl_space_dim(dim
, isl_dim_param
) > 0) {
1383 p
= print_tuple(dim
, p
, isl_dim_param
, &space_data
);
1384 p
= isl_printer_print_str(p
, s_to
[0]);
1386 isl_space_free(dim
);
1387 p
= isl_printer_print_str(p
, s_open_set
[0]);
1390 isl_union_map_foreach_map(umap
, &print_map_body
, &data
);
1392 p
= isl_printer_print_str(p
, s_close_set
[0]);
1396 static isl_stat
print_latex_map_body(__isl_take isl_map
*map
, void *user
)
1398 struct isl_union_print_data
*data
;
1399 data
= (struct isl_union_print_data
*)user
;
1402 data
->p
= isl_printer_print_str(data
->p
, " \\cup ");
1405 data
->p
= isl_map_print_latex(map
, data
->p
);
1411 static __isl_give isl_printer
*isl_union_map_print_latex(
1412 __isl_keep isl_union_map
*umap
, __isl_take isl_printer
*p
)
1414 struct isl_union_print_data data
= { p
, 1 };
1415 isl_union_map_foreach_map(umap
, &print_latex_map_body
, &data
);
1420 __isl_give isl_printer
*isl_printer_print_union_map(__isl_take isl_printer
*p
,
1421 __isl_keep isl_union_map
*umap
)
1426 if (p
->output_format
== ISL_FORMAT_ISL
)
1427 return isl_union_map_print_isl(umap
, p
);
1428 if (p
->output_format
== ISL_FORMAT_LATEX
)
1429 return isl_union_map_print_latex(umap
, p
);
1431 isl_die(p
->ctx
, isl_error_invalid
,
1432 "invalid output format for isl_union_map", goto error
);
1434 isl_printer_free(p
);
1438 __isl_give isl_printer
*isl_printer_print_union_set(__isl_take isl_printer
*p
,
1439 __isl_keep isl_union_set
*uset
)
1444 if (p
->output_format
== ISL_FORMAT_ISL
)
1445 return isl_union_map_print_isl((isl_union_map
*)uset
, p
);
1446 if (p
->output_format
== ISL_FORMAT_LATEX
)
1447 return isl_union_map_print_latex((isl_union_map
*)uset
, p
);
1449 isl_die(p
->ctx
, isl_error_invalid
,
1450 "invalid output format for isl_union_set", goto error
);
1452 isl_printer_free(p
);
1456 static int upoly_rec_n_non_zero(__isl_keep
struct isl_upoly_rec
*rec
)
1461 for (i
= 0, n
= 0; i
< rec
->n
; ++i
)
1462 if (!isl_upoly_is_zero(rec
->p
[i
]))
1468 static __isl_give isl_printer
*upoly_print_cst(__isl_keep
struct isl_upoly
*up
,
1469 __isl_take isl_printer
*p
, int first
)
1471 struct isl_upoly_cst
*cst
;
1474 cst
= isl_upoly_as_cst(up
);
1477 neg
= !first
&& isl_int_is_neg(cst
->n
);
1479 p
= isl_printer_print_str(p
, neg
? " - " : " + ");
1481 isl_int_neg(cst
->n
, cst
->n
);
1482 if (isl_int_is_zero(cst
->d
)) {
1483 int sgn
= isl_int_sgn(cst
->n
);
1484 p
= isl_printer_print_str(p
, sgn
< 0 ? "-infty" :
1485 sgn
== 0 ? "NaN" : "infty");
1487 p
= isl_printer_print_isl_int(p
, cst
->n
);
1489 isl_int_neg(cst
->n
, cst
->n
);
1490 if (!isl_int_is_zero(cst
->d
) && !isl_int_is_one(cst
->d
)) {
1491 p
= isl_printer_print_str(p
, "/");
1492 p
= isl_printer_print_isl_int(p
, cst
->d
);
1496 isl_printer_free(p
);
1500 static __isl_give isl_printer
*print_base(__isl_take isl_printer
*p
,
1501 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
, int var
)
1505 total
= isl_space_dim(dim
, isl_dim_all
);
1507 p
= print_term(dim
, NULL
, dim
->ctx
->one
, 1 + var
, p
, 0);
1509 p
= print_div(dim
, div
, var
- total
, p
);
1513 static __isl_give isl_printer
*print_pow(__isl_take isl_printer
*p
,
1514 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
, int var
, int exp
)
1516 p
= print_base(p
, dim
, div
, var
);
1519 if (p
->output_format
== ISL_FORMAT_C
) {
1521 for (i
= 1; i
< exp
; ++i
) {
1522 p
= isl_printer_print_str(p
, "*");
1523 p
= print_base(p
, dim
, div
, var
);
1526 p
= isl_printer_print_str(p
, "^");
1527 p
= isl_printer_print_int(p
, exp
);
1532 static __isl_give isl_printer
*upoly_print(__isl_keep
struct isl_upoly
*up
,
1533 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
,
1534 __isl_take isl_printer
*p
, int outer
)
1536 int i
, n
, first
, print_parens
;
1537 struct isl_upoly_rec
*rec
;
1539 if (!p
|| !up
|| !dim
|| !div
)
1542 if (isl_upoly_is_cst(up
))
1543 return upoly_print_cst(up
, p
, 1);
1545 rec
= isl_upoly_as_rec(up
);
1548 n
= upoly_rec_n_non_zero(rec
);
1549 print_parens
= n
> 1 ||
1550 (outer
&& rec
->up
.var
>= isl_space_dim(dim
, isl_dim_all
));
1552 p
= isl_printer_print_str(p
, "(");
1553 for (i
= 0, first
= 1; i
< rec
->n
; ++i
) {
1554 if (isl_upoly_is_zero(rec
->p
[i
]))
1556 if (isl_upoly_is_negone(rec
->p
[i
])) {
1558 p
= isl_printer_print_str(p
, "-1");
1560 p
= isl_printer_print_str(p
, "-");
1562 p
= isl_printer_print_str(p
, " - ");
1563 } else if (isl_upoly_is_cst(rec
->p
[i
]) &&
1564 !isl_upoly_is_one(rec
->p
[i
]))
1565 p
= upoly_print_cst(rec
->p
[i
], p
, first
);
1568 p
= isl_printer_print_str(p
, " + ");
1569 if (i
== 0 || !isl_upoly_is_one(rec
->p
[i
]))
1570 p
= upoly_print(rec
->p
[i
], dim
, div
, p
, 0);
1575 if (!isl_upoly_is_one(rec
->p
[i
]) &&
1576 !isl_upoly_is_negone(rec
->p
[i
]))
1577 p
= isl_printer_print_str(p
, " * ");
1578 p
= print_pow(p
, dim
, div
, rec
->up
.var
, i
);
1581 p
= isl_printer_print_str(p
, ")");
1584 isl_printer_free(p
);
1588 static __isl_give isl_printer
*print_qpolynomial(__isl_take isl_printer
*p
,
1589 __isl_keep isl_qpolynomial
*qp
)
1593 p
= upoly_print(qp
->upoly
, qp
->dim
, qp
->div
, p
, 1);
1596 isl_printer_free(p
);
1600 static __isl_give isl_printer
*print_qpolynomial_isl(__isl_take isl_printer
*p
,
1601 __isl_keep isl_qpolynomial
*qp
)
1603 struct isl_print_space_data data
= { 0 };
1608 if (isl_space_dim(qp
->dim
, isl_dim_param
) > 0) {
1609 p
= print_tuple(qp
->dim
, p
, isl_dim_param
, &data
);
1610 p
= isl_printer_print_str(p
, " -> ");
1612 p
= isl_printer_print_str(p
, "{ ");
1613 if (!isl_space_is_params(qp
->dim
)) {
1614 p
= isl_print_space(qp
->dim
, p
, 0, &data
);
1615 p
= isl_printer_print_str(p
, " -> ");
1617 p
= print_qpolynomial(p
, qp
);
1618 p
= isl_printer_print_str(p
, " }");
1621 isl_printer_free(p
);
1625 static __isl_give isl_printer
*print_qpolynomial_c(__isl_take isl_printer
*p
,
1626 __isl_keep isl_space
*dim
, __isl_keep isl_qpolynomial
*qp
)
1631 isl_qpolynomial_get_den(qp
, &den
);
1632 if (!isl_int_is_one(den
)) {
1634 p
= isl_printer_print_str(p
, "(");
1635 qp
= isl_qpolynomial_copy(qp
);
1636 f
= isl_qpolynomial_rat_cst_on_domain(isl_space_copy(qp
->dim
),
1637 den
, qp
->dim
->ctx
->one
);
1638 qp
= isl_qpolynomial_mul(qp
, f
);
1641 p
= upoly_print(qp
->upoly
, dim
, qp
->div
, p
, 0);
1643 p
= isl_printer_free(p
);
1644 if (!isl_int_is_one(den
)) {
1645 p
= isl_printer_print_str(p
, ")/");
1646 p
= isl_printer_print_isl_int(p
, den
);
1647 isl_qpolynomial_free(qp
);
1653 __isl_give isl_printer
*isl_printer_print_qpolynomial(
1654 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial
*qp
)
1659 if (p
->output_format
== ISL_FORMAT_ISL
)
1660 return print_qpolynomial_isl(p
, qp
);
1661 else if (p
->output_format
== ISL_FORMAT_C
)
1662 return print_qpolynomial_c(p
, qp
->dim
, qp
);
1664 isl_die(qp
->dim
->ctx
, isl_error_unsupported
,
1665 "output format not supported for isl_qpolynomials",
1668 isl_printer_free(p
);
1672 void isl_qpolynomial_print(__isl_keep isl_qpolynomial
*qp
, FILE *out
,
1673 unsigned output_format
)
1680 isl_assert(qp
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
1681 p
= isl_printer_to_file(qp
->dim
->ctx
, out
);
1682 p
= isl_printer_print_qpolynomial(p
, qp
);
1683 isl_printer_free(p
);
1686 static __isl_give isl_printer
*qpolynomial_fold_print(
1687 __isl_keep isl_qpolynomial_fold
*fold
, __isl_take isl_printer
*p
)
1691 if (fold
->type
== isl_fold_min
)
1692 p
= isl_printer_print_str(p
, "min");
1693 else if (fold
->type
== isl_fold_max
)
1694 p
= isl_printer_print_str(p
, "max");
1695 p
= isl_printer_print_str(p
, "(");
1696 for (i
= 0; i
< fold
->n
; ++i
) {
1698 p
= isl_printer_print_str(p
, ", ");
1699 p
= print_qpolynomial(p
, fold
->qp
[i
]);
1701 p
= isl_printer_print_str(p
, ")");
1705 void isl_qpolynomial_fold_print(__isl_keep isl_qpolynomial_fold
*fold
,
1706 FILE *out
, unsigned output_format
)
1713 isl_assert(fold
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
1715 p
= isl_printer_to_file(fold
->dim
->ctx
, out
);
1716 p
= isl_printer_print_qpolynomial_fold(p
, fold
);
1718 isl_printer_free(p
);
1721 static __isl_give isl_printer
*isl_pwqp_print_isl_body(
1722 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
1724 struct isl_print_space_data data
= { 0 };
1727 for (i
= 0; i
< pwqp
->n
; ++i
) {
1731 p
= isl_printer_print_str(p
, "; ");
1732 space
= isl_qpolynomial_get_domain_space(pwqp
->p
[i
].qp
);
1733 if (!isl_space_is_params(space
)) {
1734 p
= isl_print_space(space
, p
, 0, &data
);
1735 p
= isl_printer_print_str(p
, " -> ");
1737 p
= print_qpolynomial(p
, pwqp
->p
[i
].qp
);
1738 p
= print_disjuncts((isl_map
*)pwqp
->p
[i
].set
, space
, p
, 0);
1739 isl_space_free(space
);
1745 static __isl_give isl_printer
*print_pw_qpolynomial_isl(
1746 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
1748 struct isl_print_space_data data
= { 0 };
1753 if (isl_space_dim(pwqp
->dim
, isl_dim_param
) > 0) {
1754 p
= print_tuple(pwqp
->dim
, p
, isl_dim_param
, &data
);
1755 p
= isl_printer_print_str(p
, " -> ");
1757 p
= isl_printer_print_str(p
, "{ ");
1759 if (!isl_space_is_set(pwqp
->dim
)) {
1760 p
= print_tuple(pwqp
->dim
, p
, isl_dim_in
, &data
);
1761 p
= isl_printer_print_str(p
, " -> ");
1763 p
= isl_printer_print_str(p
, "0");
1765 p
= isl_pwqp_print_isl_body(p
, pwqp
);
1766 p
= isl_printer_print_str(p
, " }");
1769 isl_printer_free(p
);
1773 void isl_pw_qpolynomial_print(__isl_keep isl_pw_qpolynomial
*pwqp
, FILE *out
,
1774 unsigned output_format
)
1781 p
= isl_printer_to_file(pwqp
->dim
->ctx
, out
);
1782 p
= isl_printer_set_output_format(p
, output_format
);
1783 p
= isl_printer_print_pw_qpolynomial(p
, pwqp
);
1785 isl_printer_free(p
);
1788 static __isl_give isl_printer
*isl_pwf_print_isl_body(
1789 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
1791 struct isl_print_space_data data
= { 0 };
1794 for (i
= 0; i
< pwf
->n
; ++i
) {
1798 p
= isl_printer_print_str(p
, "; ");
1799 space
= isl_qpolynomial_fold_get_domain_space(pwf
->p
[i
].fold
);
1800 if (!isl_space_is_params(space
)) {
1801 p
= isl_print_space(space
, p
, 0, &data
);
1802 p
= isl_printer_print_str(p
, " -> ");
1804 p
= qpolynomial_fold_print(pwf
->p
[i
].fold
, p
);
1805 p
= print_disjuncts((isl_map
*)pwf
->p
[i
].set
, space
, p
, 0);
1806 isl_space_free(space
);
1812 static __isl_give isl_printer
*print_pw_qpolynomial_fold_isl(
1813 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
1815 struct isl_print_space_data data
= { 0 };
1817 if (isl_space_dim(pwf
->dim
, isl_dim_param
) > 0) {
1818 p
= print_tuple(pwf
->dim
, p
, isl_dim_param
, &data
);
1819 p
= isl_printer_print_str(p
, " -> ");
1821 p
= isl_printer_print_str(p
, "{ ");
1823 if (!isl_space_is_set(pwf
->dim
)) {
1824 p
= print_tuple(pwf
->dim
, p
, isl_dim_in
, &data
);
1825 p
= isl_printer_print_str(p
, " -> ");
1827 p
= isl_printer_print_str(p
, "0");
1829 p
= isl_pwf_print_isl_body(p
, pwf
);
1830 p
= isl_printer_print_str(p
, " }");
1834 static __isl_give isl_printer
*print_affine_c(__isl_take isl_printer
*p
,
1835 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
, isl_int
*c
);
1837 static __isl_give isl_printer
*print_name_c(__isl_take isl_printer
*p
,
1838 __isl_keep isl_space
*dim
,
1839 __isl_keep isl_basic_set
*bset
, enum isl_dim_type type
, unsigned pos
)
1841 if (type
== isl_dim_div
) {
1842 p
= isl_printer_print_str(p
, "floord(");
1843 p
= print_affine_c(p
, dim
, bset
, bset
->div
[pos
] + 1);
1844 p
= isl_printer_print_str(p
, ", ");
1845 p
= isl_printer_print_isl_int(p
, bset
->div
[pos
][0]);
1846 p
= isl_printer_print_str(p
, ")");
1850 name
= isl_space_get_dim_name(dim
, type
, pos
);
1853 p
= isl_printer_print_str(p
, name
);
1858 static __isl_give isl_printer
*print_term_c(__isl_take isl_printer
*p
,
1859 __isl_keep isl_space
*dim
,
1860 __isl_keep isl_basic_set
*bset
, isl_int c
, unsigned pos
)
1862 enum isl_dim_type type
;
1865 return isl_printer_print_isl_int(p
, c
);
1867 if (isl_int_is_one(c
))
1869 else if (isl_int_is_negone(c
))
1870 p
= isl_printer_print_str(p
, "-");
1872 p
= isl_printer_print_isl_int(p
, c
);
1873 p
= isl_printer_print_str(p
, "*");
1875 type
= pos2type(dim
, &pos
);
1876 p
= print_name_c(p
, dim
, bset
, type
, pos
);
1880 static __isl_give isl_printer
*print_partial_affine_c(__isl_take isl_printer
*p
,
1881 __isl_keep isl_space
*dim
,
1882 __isl_keep isl_basic_set
*bset
, isl_int
*c
, unsigned len
)
1887 for (i
= 0, first
= 1; i
< len
; ++i
) {
1889 if (isl_int_is_zero(c
[i
]))
1892 if (isl_int_is_neg(c
[i
])) {
1894 isl_int_neg(c
[i
], c
[i
]);
1895 p
= isl_printer_print_str(p
, " - ");
1897 p
= isl_printer_print_str(p
, " + ");
1900 p
= print_term_c(p
, dim
, bset
, c
[i
], i
);
1902 isl_int_neg(c
[i
], c
[i
]);
1905 p
= isl_printer_print_str(p
, "0");
1909 static __isl_give isl_printer
*print_affine_c(__isl_take isl_printer
*p
,
1910 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
, isl_int
*c
)
1912 unsigned len
= 1 + isl_basic_set_total_dim(bset
);
1913 return print_partial_affine_c(p
, dim
, bset
, c
, len
);
1916 /* We skip the constraint if it is implied by the div expression.
1918 * *first indicates whether this is the first constraint in the conjunction and
1919 * is updated if the constraint is actually printed.
1921 static __isl_give isl_printer
*print_constraint_c(__isl_take isl_printer
*p
,
1922 __isl_keep isl_space
*dim
,
1923 __isl_keep isl_basic_set
*bset
, isl_int
*c
, const char *op
, int *first
)
1929 o_div
= isl_basic_set_offset(bset
, isl_dim_div
);
1930 n_div
= isl_basic_set_dim(bset
, isl_dim_div
);
1931 div
= isl_seq_last_non_zero(c
+ o_div
, n_div
);
1932 if (div
>= 0 && isl_basic_set_is_div_constraint(bset
, c
, div
))
1936 p
= isl_printer_print_str(p
, " && ");
1938 p
= print_affine_c(p
, dim
, bset
, c
);
1939 p
= isl_printer_print_str(p
, " ");
1940 p
= isl_printer_print_str(p
, op
);
1941 p
= isl_printer_print_str(p
, " 0");
1948 static __isl_give isl_printer
*print_basic_set_c(__isl_take isl_printer
*p
,
1949 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
)
1953 unsigned n_div
= isl_basic_set_dim(bset
, isl_dim_div
);
1954 unsigned total
= isl_basic_set_total_dim(bset
) - n_div
;
1956 for (i
= 0; i
< bset
->n_eq
; ++i
) {
1957 j
= isl_seq_last_non_zero(bset
->eq
[i
] + 1 + total
, n_div
);
1959 p
= print_constraint_c(p
, dim
, bset
,
1960 bset
->eq
[i
], "==", &first
);
1963 p
= isl_printer_print_str(p
, " && ");
1964 p
= isl_printer_print_str(p
, "(");
1965 p
= print_partial_affine_c(p
, dim
, bset
, bset
->eq
[i
],
1967 p
= isl_printer_print_str(p
, ") % ");
1968 p
= isl_printer_print_isl_int(p
,
1969 bset
->eq
[i
][1 + total
+ j
]);
1970 p
= isl_printer_print_str(p
, " == 0");
1974 for (i
= 0; i
< bset
->n_ineq
; ++i
)
1975 p
= print_constraint_c(p
, dim
, bset
, bset
->ineq
[i
], ">=",
1980 static __isl_give isl_printer
*print_set_c(__isl_take isl_printer
*p
,
1981 __isl_keep isl_space
*dim
, __isl_keep isl_set
*set
)
1986 return isl_printer_free(p
);
1989 p
= isl_printer_print_str(p
, "0");
1991 for (i
= 0; i
< set
->n
; ++i
) {
1993 p
= isl_printer_print_str(p
, " || ");
1995 p
= isl_printer_print_str(p
, "(");
1996 p
= print_basic_set_c(p
, dim
, set
->p
[i
]);
1998 p
= isl_printer_print_str(p
, ")");
2003 static __isl_give isl_printer
*print_pw_qpolynomial_c(
2004 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2008 if (pwqp
->n
== 1 && isl_set_plain_is_universe(pwqp
->p
[0].set
))
2009 return print_qpolynomial_c(p
, pwqp
->dim
, pwqp
->p
[0].qp
);
2011 for (i
= 0; i
< pwqp
->n
; ++i
) {
2012 p
= isl_printer_print_str(p
, "(");
2013 p
= print_set_c(p
, pwqp
->dim
, pwqp
->p
[i
].set
);
2014 p
= isl_printer_print_str(p
, ") ? (");
2015 p
= print_qpolynomial_c(p
, pwqp
->dim
, pwqp
->p
[i
].qp
);
2016 p
= isl_printer_print_str(p
, ") : ");
2019 p
= isl_printer_print_str(p
, "0");
2023 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial(
2024 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2029 if (p
->output_format
== ISL_FORMAT_ISL
)
2030 return print_pw_qpolynomial_isl(p
, pwqp
);
2031 else if (p
->output_format
== ISL_FORMAT_C
)
2032 return print_pw_qpolynomial_c(p
, pwqp
);
2033 isl_assert(p
->ctx
, 0, goto error
);
2035 isl_printer_free(p
);
2039 static isl_stat
print_pwqp_body(__isl_take isl_pw_qpolynomial
*pwqp
, void *user
)
2041 struct isl_union_print_data
*data
;
2042 data
= (struct isl_union_print_data
*)user
;
2045 data
->p
= isl_printer_print_str(data
->p
, "; ");
2048 data
->p
= isl_pwqp_print_isl_body(data
->p
, pwqp
);
2049 isl_pw_qpolynomial_free(pwqp
);
2054 static __isl_give isl_printer
*print_union_pw_qpolynomial_isl(
2055 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2057 struct isl_union_print_data data
;
2058 struct isl_print_space_data space_data
= { 0 };
2061 dim
= isl_union_pw_qpolynomial_get_space(upwqp
);
2062 if (isl_space_dim(dim
, isl_dim_param
) > 0) {
2063 p
= print_tuple(dim
, p
, isl_dim_param
, &space_data
);
2064 p
= isl_printer_print_str(p
, " -> ");
2066 isl_space_free(dim
);
2067 p
= isl_printer_print_str(p
, "{ ");
2070 isl_union_pw_qpolynomial_foreach_pw_qpolynomial(upwqp
, &print_pwqp_body
,
2073 p
= isl_printer_print_str(p
, " }");
2077 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial(
2078 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2083 if (p
->output_format
== ISL_FORMAT_ISL
)
2084 return print_union_pw_qpolynomial_isl(p
, upwqp
);
2085 isl_die(p
->ctx
, isl_error_invalid
,
2086 "invalid output format for isl_union_pw_qpolynomial",
2089 isl_printer_free(p
);
2093 static __isl_give isl_printer
*print_qpolynomial_fold_c(
2094 __isl_take isl_printer
*p
, __isl_keep isl_space
*dim
,
2095 __isl_keep isl_qpolynomial_fold
*fold
)
2099 for (i
= 0; i
< fold
->n
- 1; ++i
)
2100 if (fold
->type
== isl_fold_min
)
2101 p
= isl_printer_print_str(p
, "min(");
2102 else if (fold
->type
== isl_fold_max
)
2103 p
= isl_printer_print_str(p
, "max(");
2105 for (i
= 0; i
< fold
->n
; ++i
) {
2107 p
= isl_printer_print_str(p
, ", ");
2108 p
= print_qpolynomial_c(p
, dim
, fold
->qp
[i
]);
2110 p
= isl_printer_print_str(p
, ")");
2115 __isl_give isl_printer
*isl_printer_print_qpolynomial_fold(
2116 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial_fold
*fold
)
2120 if (p
->output_format
== ISL_FORMAT_ISL
)
2121 return qpolynomial_fold_print(fold
, p
);
2122 else if (p
->output_format
== ISL_FORMAT_C
)
2123 return print_qpolynomial_fold_c(p
, fold
->dim
, fold
);
2124 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2127 isl_printer_free(p
);
2131 static __isl_give isl_printer
*print_pw_qpolynomial_fold_c(
2132 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2136 if (pwf
->n
== 1 && isl_set_plain_is_universe(pwf
->p
[0].set
))
2137 return print_qpolynomial_fold_c(p
, pwf
->dim
, pwf
->p
[0].fold
);
2139 for (i
= 0; i
< pwf
->n
; ++i
) {
2140 p
= isl_printer_print_str(p
, "(");
2141 p
= print_set_c(p
, pwf
->dim
, pwf
->p
[i
].set
);
2142 p
= isl_printer_print_str(p
, ") ? (");
2143 p
= print_qpolynomial_fold_c(p
, pwf
->dim
, pwf
->p
[i
].fold
);
2144 p
= isl_printer_print_str(p
, ") : ");
2147 p
= isl_printer_print_str(p
, "0");
2151 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial_fold(
2152 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2157 if (p
->output_format
== ISL_FORMAT_ISL
)
2158 return print_pw_qpolynomial_fold_isl(p
, pwf
);
2159 else if (p
->output_format
== ISL_FORMAT_C
)
2160 return print_pw_qpolynomial_fold_c(p
, pwf
);
2161 isl_assert(p
->ctx
, 0, goto error
);
2163 isl_printer_free(p
);
2167 void isl_pw_qpolynomial_fold_print(__isl_keep isl_pw_qpolynomial_fold
*pwf
,
2168 FILE *out
, unsigned output_format
)
2175 p
= isl_printer_to_file(pwf
->dim
->ctx
, out
);
2176 p
= isl_printer_set_output_format(p
, output_format
);
2177 p
= isl_printer_print_pw_qpolynomial_fold(p
, pwf
);
2179 isl_printer_free(p
);
2182 static isl_stat
print_pwf_body(__isl_take isl_pw_qpolynomial_fold
*pwf
,
2185 struct isl_union_print_data
*data
;
2186 data
= (struct isl_union_print_data
*)user
;
2189 data
->p
= isl_printer_print_str(data
->p
, "; ");
2192 data
->p
= isl_pwf_print_isl_body(data
->p
, pwf
);
2193 isl_pw_qpolynomial_fold_free(pwf
);
2198 static __isl_give isl_printer
*print_union_pw_qpolynomial_fold_isl(
2199 __isl_take isl_printer
*p
,
2200 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2202 struct isl_union_print_data data
;
2203 struct isl_print_space_data space_data
= { 0 };
2206 dim
= isl_union_pw_qpolynomial_fold_get_space(upwf
);
2207 if (isl_space_dim(dim
, isl_dim_param
) > 0) {
2208 p
= print_tuple(dim
, p
, isl_dim_param
, &space_data
);
2209 p
= isl_printer_print_str(p
, " -> ");
2211 isl_space_free(dim
);
2212 p
= isl_printer_print_str(p
, "{ ");
2215 isl_union_pw_qpolynomial_fold_foreach_pw_qpolynomial_fold(upwf
,
2216 &print_pwf_body
, &data
);
2218 p
= isl_printer_print_str(p
, " }");
2222 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial_fold(
2223 __isl_take isl_printer
*p
,
2224 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2229 if (p
->output_format
== ISL_FORMAT_ISL
)
2230 return print_union_pw_qpolynomial_fold_isl(p
, upwf
);
2231 isl_die(p
->ctx
, isl_error_invalid
,
2232 "invalid output format for isl_union_pw_qpolynomial_fold",
2235 isl_printer_free(p
);
2239 __isl_give isl_printer
*isl_printer_print_constraint(__isl_take isl_printer
*p
,
2240 __isl_keep isl_constraint
*c
)
2242 isl_basic_map
*bmap
;
2247 bmap
= isl_basic_map_from_constraint(isl_constraint_copy(c
));
2248 p
= isl_printer_print_basic_map(p
, bmap
);
2249 isl_basic_map_free(bmap
);
2252 isl_printer_free(p
);
2256 static __isl_give isl_printer
*isl_printer_print_space_isl(
2257 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
)
2259 struct isl_print_space_data data
= { 0 };
2264 if (isl_space_dim(space
, isl_dim_param
) > 0) {
2265 p
= print_tuple(space
, p
, isl_dim_param
, &data
);
2266 p
= isl_printer_print_str(p
, " -> ");
2269 p
= isl_printer_print_str(p
, "{ ");
2270 if (isl_space_is_params(space
))
2271 p
= isl_printer_print_str(p
, s_such_that
[0]);
2273 p
= isl_print_space(space
, p
, 0, &data
);
2274 p
= isl_printer_print_str(p
, " }");
2278 isl_printer_free(p
);
2282 __isl_give isl_printer
*isl_printer_print_space(__isl_take isl_printer
*p
,
2283 __isl_keep isl_space
*space
)
2286 return isl_printer_free(p
);
2287 if (p
->output_format
== ISL_FORMAT_ISL
)
2288 return isl_printer_print_space_isl(p
, space
);
2289 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
2290 return print_omega_parameters(space
, p
);
2292 isl_die(isl_space_get_ctx(space
), isl_error_unsupported
,
2293 "output format not supported for space",
2294 return isl_printer_free(p
));
2297 __isl_give isl_printer
*isl_printer_print_local_space(__isl_take isl_printer
*p
,
2298 __isl_keep isl_local_space
*ls
)
2300 struct isl_print_space_data data
= { 0 };
2306 if (isl_local_space_dim(ls
, isl_dim_param
) > 0) {
2307 p
= print_tuple(ls
->dim
, p
, isl_dim_param
, &data
);
2308 p
= isl_printer_print_str(p
, " -> ");
2310 p
= isl_printer_print_str(p
, "{ ");
2311 p
= isl_print_space(ls
->dim
, p
, 0, &data
);
2312 n_div
= isl_local_space_dim(ls
, isl_dim_div
);
2314 p
= isl_printer_print_str(p
, " : ");
2315 p
= isl_printer_print_str(p
, s_open_exists
[0]);
2316 p
= print_div_list(p
, ls
->dim
, ls
->div
, 0, 1);
2317 p
= isl_printer_print_str(p
, s_close_exists
[0]);
2318 } else if (isl_space_is_params(ls
->dim
))
2319 p
= isl_printer_print_str(p
, s_such_that
[0]);
2320 p
= isl_printer_print_str(p
, " }");
2323 isl_printer_free(p
);
2327 static __isl_give isl_printer
*print_aff_body(__isl_take isl_printer
*p
,
2328 __isl_keep isl_aff
*aff
)
2332 if (isl_aff_is_nan(aff
))
2333 return isl_printer_print_str(p
, "NaN");
2335 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2336 p
= isl_printer_print_str(p
, "(");
2337 p
= print_affine_of_len(aff
->ls
->dim
, aff
->ls
->div
, p
,
2338 aff
->v
->el
+ 1, 1 + total
);
2339 if (isl_int_is_one(aff
->v
->el
[0]))
2340 p
= isl_printer_print_str(p
, ")");
2342 p
= isl_printer_print_str(p
, ")/");
2343 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2349 static __isl_give isl_printer
*print_aff(__isl_take isl_printer
*p
,
2350 __isl_keep isl_aff
*aff
)
2352 struct isl_print_space_data data
= { 0 };
2354 if (isl_space_is_params(aff
->ls
->dim
))
2357 p
= print_tuple(aff
->ls
->dim
, p
, isl_dim_set
, &data
);
2358 p
= isl_printer_print_str(p
, " -> ");
2360 p
= isl_printer_print_str(p
, "[");
2361 p
= print_aff_body(p
, aff
);
2362 p
= isl_printer_print_str(p
, "]");
2367 static __isl_give isl_printer
*print_aff_isl(__isl_take isl_printer
*p
,
2368 __isl_keep isl_aff
*aff
)
2370 struct isl_print_space_data data
= { 0 };
2375 if (isl_local_space_dim(aff
->ls
, isl_dim_param
) > 0) {
2376 p
= print_tuple(aff
->ls
->dim
, p
, isl_dim_param
, &data
);
2377 p
= isl_printer_print_str(p
, " -> ");
2379 p
= isl_printer_print_str(p
, "{ ");
2380 p
= print_aff(p
, aff
);
2381 p
= isl_printer_print_str(p
, " }");
2384 isl_printer_free(p
);
2388 /* Print the body of an isl_pw_aff, i.e., a semicolon delimited
2389 * sequence of affine expressions, each followed by constraints.
2391 static __isl_give isl_printer
*print_pw_aff_body(
2392 __isl_take isl_printer
*p
, __isl_keep isl_pw_aff
*pa
)
2397 return isl_printer_free(p
);
2399 for (i
= 0; i
< pa
->n
; ++i
) {
2403 p
= isl_printer_print_str(p
, "; ");
2404 p
= print_aff(p
, pa
->p
[i
].aff
);
2405 space
= isl_aff_get_domain_space(pa
->p
[i
].aff
);
2406 p
= print_disjuncts((isl_map
*)pa
->p
[i
].set
, space
, p
, 0);
2407 isl_space_free(space
);
2413 static __isl_give isl_printer
*print_pw_aff_isl(__isl_take isl_printer
*p
,
2414 __isl_keep isl_pw_aff
*pwaff
)
2416 struct isl_print_space_data data
= { 0 };
2421 if (isl_space_dim(pwaff
->dim
, isl_dim_param
) > 0) {
2422 p
= print_tuple(pwaff
->dim
, p
, isl_dim_param
, &data
);
2423 p
= isl_printer_print_str(p
, " -> ");
2425 p
= isl_printer_print_str(p
, "{ ");
2426 p
= print_pw_aff_body(p
, pwaff
);
2427 p
= isl_printer_print_str(p
, " }");
2430 isl_printer_free(p
);
2434 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2435 __isl_keep isl_local_space
*ls
, isl_int
*c
);
2437 static __isl_give isl_printer
*print_ls_name_c(__isl_take isl_printer
*p
,
2438 __isl_keep isl_local_space
*ls
, enum isl_dim_type type
, unsigned pos
)
2440 if (type
== isl_dim_div
) {
2441 p
= isl_printer_print_str(p
, "floord(");
2442 p
= print_ls_affine_c(p
, ls
, ls
->div
->row
[pos
] + 1);
2443 p
= isl_printer_print_str(p
, ", ");
2444 p
= isl_printer_print_isl_int(p
, ls
->div
->row
[pos
][0]);
2445 p
= isl_printer_print_str(p
, ")");
2449 name
= isl_space_get_dim_name(ls
->dim
, type
, pos
);
2452 p
= isl_printer_print_str(p
, name
);
2457 static __isl_give isl_printer
*print_ls_term_c(__isl_take isl_printer
*p
,
2458 __isl_keep isl_local_space
*ls
, isl_int c
, unsigned pos
)
2460 enum isl_dim_type type
;
2463 return isl_printer_print_isl_int(p
, c
);
2465 if (isl_int_is_one(c
))
2467 else if (isl_int_is_negone(c
))
2468 p
= isl_printer_print_str(p
, "-");
2470 p
= isl_printer_print_isl_int(p
, c
);
2471 p
= isl_printer_print_str(p
, "*");
2473 type
= pos2type(ls
->dim
, &pos
);
2474 p
= print_ls_name_c(p
, ls
, type
, pos
);
2478 static __isl_give isl_printer
*print_ls_partial_affine_c(
2479 __isl_take isl_printer
*p
, __isl_keep isl_local_space
*ls
,
2480 isl_int
*c
, unsigned len
)
2485 for (i
= 0, first
= 1; i
< len
; ++i
) {
2487 if (isl_int_is_zero(c
[i
]))
2490 if (isl_int_is_neg(c
[i
])) {
2492 isl_int_neg(c
[i
], c
[i
]);
2493 p
= isl_printer_print_str(p
, " - ");
2495 p
= isl_printer_print_str(p
, " + ");
2498 p
= print_ls_term_c(p
, ls
, c
[i
], i
);
2500 isl_int_neg(c
[i
], c
[i
]);
2503 p
= isl_printer_print_str(p
, "0");
2507 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2508 __isl_keep isl_local_space
*ls
, isl_int
*c
)
2510 unsigned len
= 1 + isl_local_space_dim(ls
, isl_dim_all
);
2511 return print_ls_partial_affine_c(p
, ls
, c
, len
);
2514 static __isl_give isl_printer
*print_aff_c(__isl_take isl_printer
*p
,
2515 __isl_keep isl_aff
*aff
)
2519 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2520 if (!isl_int_is_one(aff
->v
->el
[0]))
2521 p
= isl_printer_print_str(p
, "(");
2522 p
= print_ls_partial_affine_c(p
, aff
->ls
, aff
->v
->el
+ 1, 1 + total
);
2523 if (!isl_int_is_one(aff
->v
->el
[0])) {
2524 p
= isl_printer_print_str(p
, ")/");
2525 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2530 /* In the C format, we cannot express that "pwaff" may be undefined
2531 * on parts of the domain space. We therefore assume that the expression
2532 * will only be evaluated on its definition domain and compute the gist
2533 * of each cell with respect to this domain.
2535 static __isl_give isl_printer
*print_pw_aff_c(__isl_take isl_printer
*p
,
2536 __isl_keep isl_pw_aff
*pwaff
)
2539 isl_ast_build
*build
;
2543 isl_die(p
->ctx
, isl_error_unsupported
,
2544 "cannot print empty isl_pw_aff in C format",
2545 return isl_printer_free(p
));
2547 domain
= isl_pw_aff_domain(isl_pw_aff_copy(pwaff
));
2548 build
= isl_ast_build_from_context(domain
);
2549 expr
= isl_ast_build_expr_from_pw_aff(build
, isl_pw_aff_copy(pwaff
));
2550 p
= isl_printer_print_ast_expr(p
, expr
);
2551 isl_ast_expr_free(expr
);
2552 isl_ast_build_free(build
);
2557 __isl_give isl_printer
*isl_printer_print_aff(__isl_take isl_printer
*p
,
2558 __isl_keep isl_aff
*aff
)
2563 if (p
->output_format
== ISL_FORMAT_ISL
)
2564 return print_aff_isl(p
, aff
);
2565 else if (p
->output_format
== ISL_FORMAT_C
)
2566 return print_aff_c(p
, aff
);
2567 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2570 isl_printer_free(p
);
2574 __isl_give isl_printer
*isl_printer_print_pw_aff(__isl_take isl_printer
*p
,
2575 __isl_keep isl_pw_aff
*pwaff
)
2580 if (p
->output_format
== ISL_FORMAT_ISL
)
2581 return print_pw_aff_isl(p
, pwaff
);
2582 else if (p
->output_format
== ISL_FORMAT_C
)
2583 return print_pw_aff_c(p
, pwaff
);
2584 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2587 isl_printer_free(p
);
2591 /* Print "pa" in a sequence of isl_pw_affs delimited by semicolons.
2592 * Each isl_pw_aff itself is also printed as semicolon delimited
2593 * sequence of pieces.
2594 * If data->first = 1, then this is the first in the sequence.
2595 * Update data->first to tell the next element that it is not the first.
2597 static isl_stat
print_pw_aff_body_wrap(__isl_take isl_pw_aff
*pa
,
2600 struct isl_union_print_data
*data
;
2601 data
= (struct isl_union_print_data
*) user
;
2604 data
->p
= isl_printer_print_str(data
->p
, "; ");
2607 data
->p
= print_pw_aff_body(data
->p
, pa
);
2608 isl_pw_aff_free(pa
);
2610 return data
->p
? isl_stat_ok
: isl_stat_error
;
2613 /* Print the body of an isl_union_pw_aff, i.e., a semicolon delimited
2614 * sequence of affine expressions, each followed by constraints,
2615 * with the sequence enclosed in braces.
2617 static __isl_give isl_printer
*print_union_pw_aff_body(
2618 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2620 struct isl_union_print_data data
= { p
, 1 };
2622 p
= isl_printer_print_str(p
, s_open_set
[0]);
2624 if (isl_union_pw_aff_foreach_pw_aff(upa
,
2625 &print_pw_aff_body_wrap
, &data
) < 0)
2626 data
.p
= isl_printer_free(p
);
2628 p
= isl_printer_print_str(p
, s_close_set
[0]);
2633 /* Print the isl_union_pw_aff "upa" to "p" in isl format.
2635 * The individual isl_pw_affs are delimited by a semicolon.
2637 static __isl_give isl_printer
*print_union_pw_aff_isl(
2638 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2640 struct isl_print_space_data data
= { 0 };
2643 space
= isl_union_pw_aff_get_space(upa
);
2644 if (isl_space_dim(space
, isl_dim_param
) > 0) {
2645 p
= print_tuple(space
, p
, isl_dim_param
, &data
);
2646 p
= isl_printer_print_str(p
, s_to
[0]);
2648 isl_space_free(space
);
2649 p
= print_union_pw_aff_body(p
, upa
);
2653 /* Print the isl_union_pw_aff "upa" to "p".
2655 * We currently only support an isl format.
2657 __isl_give isl_printer
*isl_printer_print_union_pw_aff(
2658 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2661 return isl_printer_free(p
);
2663 if (p
->output_format
== ISL_FORMAT_ISL
)
2664 return print_union_pw_aff_isl(p
, upa
);
2665 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
2666 "unsupported output format", return isl_printer_free(p
));
2669 /* Print dimension "pos" of data->space to "p".
2671 * data->user is assumed to be an isl_multi_aff.
2673 * If the current dimension is an output dimension, then print
2674 * the corresponding expression. Otherwise, print the name of the dimension.
2676 static __isl_give isl_printer
*print_dim_ma(__isl_take isl_printer
*p
,
2677 struct isl_print_space_data
*data
, unsigned pos
)
2679 isl_multi_aff
*ma
= data
->user
;
2681 if (data
->type
== isl_dim_out
)
2682 p
= print_aff_body(p
, ma
->p
[pos
]);
2684 p
= print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
2689 static __isl_give isl_printer
*print_multi_aff(__isl_take isl_printer
*p
,
2690 __isl_keep isl_multi_aff
*maff
)
2692 struct isl_print_space_data data
= { 0 };
2694 data
.print_dim
= &print_dim_ma
;
2696 return isl_print_space(maff
->space
, p
, 0, &data
);
2699 static __isl_give isl_printer
*print_multi_aff_isl(__isl_take isl_printer
*p
,
2700 __isl_keep isl_multi_aff
*maff
)
2702 struct isl_print_space_data data
= { 0 };
2707 if (isl_space_dim(maff
->space
, isl_dim_param
) > 0) {
2708 p
= print_tuple(maff
->space
, p
, isl_dim_param
, &data
);
2709 p
= isl_printer_print_str(p
, " -> ");
2711 p
= isl_printer_print_str(p
, "{ ");
2712 p
= print_multi_aff(p
, maff
);
2713 p
= isl_printer_print_str(p
, " }");
2716 isl_printer_free(p
);
2720 __isl_give isl_printer
*isl_printer_print_multi_aff(__isl_take isl_printer
*p
,
2721 __isl_keep isl_multi_aff
*maff
)
2726 if (p
->output_format
== ISL_FORMAT_ISL
)
2727 return print_multi_aff_isl(p
, maff
);
2728 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2731 isl_printer_free(p
);
2735 static __isl_give isl_printer
*print_pw_multi_aff_body(
2736 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2743 for (i
= 0; i
< pma
->n
; ++i
) {
2747 p
= isl_printer_print_str(p
, "; ");
2748 p
= print_multi_aff(p
, pma
->p
[i
].maff
);
2749 space
= isl_multi_aff_get_domain_space(pma
->p
[i
].maff
);
2750 p
= print_disjuncts((isl_map
*)pma
->p
[i
].set
, space
, p
, 0);
2751 isl_space_free(space
);
2755 isl_printer_free(p
);
2759 static __isl_give isl_printer
*print_pw_multi_aff_isl(__isl_take isl_printer
*p
,
2760 __isl_keep isl_pw_multi_aff
*pma
)
2762 struct isl_print_space_data data
= { 0 };
2767 if (isl_space_dim(pma
->dim
, isl_dim_param
) > 0) {
2768 p
= print_tuple(pma
->dim
, p
, isl_dim_param
, &data
);
2769 p
= isl_printer_print_str(p
, " -> ");
2771 p
= isl_printer_print_str(p
, "{ ");
2772 p
= print_pw_multi_aff_body(p
, pma
);
2773 p
= isl_printer_print_str(p
, " }");
2776 isl_printer_free(p
);
2780 static __isl_give isl_printer
*print_unnamed_pw_multi_aff_c(
2781 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2785 for (i
= 0; i
< pma
->n
- 1; ++i
) {
2786 p
= isl_printer_print_str(p
, "(");
2787 p
= print_set_c(p
, pma
->dim
, pma
->p
[i
].set
);
2788 p
= isl_printer_print_str(p
, ") ? (");
2789 p
= print_aff_c(p
, pma
->p
[i
].maff
->p
[0]);
2790 p
= isl_printer_print_str(p
, ") : ");
2793 return print_aff_c(p
, pma
->p
[pma
->n
- 1].maff
->p
[0]);
2796 static __isl_give isl_printer
*print_pw_multi_aff_c(__isl_take isl_printer
*p
,
2797 __isl_keep isl_pw_multi_aff
*pma
)
2805 isl_die(p
->ctx
, isl_error_unsupported
,
2806 "cannot print empty isl_pw_multi_aff in C format",
2808 name
= isl_pw_multi_aff_get_tuple_name(pma
, isl_dim_out
);
2809 if (!name
&& isl_pw_multi_aff_dim(pma
, isl_dim_out
) == 1)
2810 return print_unnamed_pw_multi_aff_c(p
, pma
);
2812 isl_die(p
->ctx
, isl_error_unsupported
,
2813 "cannot print unnamed isl_pw_multi_aff in C format",
2816 p
= isl_printer_print_str(p
, name
);
2817 n
= isl_pw_multi_aff_dim(pma
, isl_dim_out
);
2819 isl_die(p
->ctx
, isl_error_unsupported
,
2820 "not supported yet", goto error
);
2824 isl_printer_free(p
);
2828 __isl_give isl_printer
*isl_printer_print_pw_multi_aff(
2829 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2834 if (p
->output_format
== ISL_FORMAT_ISL
)
2835 return print_pw_multi_aff_isl(p
, pma
);
2836 if (p
->output_format
== ISL_FORMAT_C
)
2837 return print_pw_multi_aff_c(p
, pma
);
2838 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2841 isl_printer_free(p
);
2845 static isl_stat
print_pw_multi_aff_body_wrap(__isl_take isl_pw_multi_aff
*pma
,
2848 struct isl_union_print_data
*data
;
2849 data
= (struct isl_union_print_data
*) user
;
2852 data
->p
= isl_printer_print_str(data
->p
, "; ");
2855 data
->p
= print_pw_multi_aff_body(data
->p
, pma
);
2856 isl_pw_multi_aff_free(pma
);
2861 static __isl_give isl_printer
*print_union_pw_multi_aff_isl(
2862 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
2864 struct isl_union_print_data data
;
2865 struct isl_print_space_data space_data
= { 0 };
2868 space
= isl_union_pw_multi_aff_get_space(upma
);
2869 if (isl_space_dim(space
, isl_dim_param
) > 0) {
2870 p
= print_tuple(space
, p
, isl_dim_param
, &space_data
);
2871 p
= isl_printer_print_str(p
, s_to
[0]);
2873 isl_space_free(space
);
2874 p
= isl_printer_print_str(p
, s_open_set
[0]);
2877 isl_union_pw_multi_aff_foreach_pw_multi_aff(upma
,
2878 &print_pw_multi_aff_body_wrap
, &data
);
2880 p
= isl_printer_print_str(p
, s_close_set
[0]);
2884 __isl_give isl_printer
*isl_printer_print_union_pw_multi_aff(
2885 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
2890 if (p
->output_format
== ISL_FORMAT_ISL
)
2891 return print_union_pw_multi_aff_isl(p
, upma
);
2892 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2895 isl_printer_free(p
);
2899 /* Print dimension "pos" of data->space to "p".
2901 * data->user is assumed to be an isl_multi_pw_aff.
2903 * If the current dimension is an output dimension, then print
2904 * the corresponding piecewise affine expression.
2905 * Otherwise, print the name of the dimension.
2907 static __isl_give isl_printer
*print_dim_mpa(__isl_take isl_printer
*p
,
2908 struct isl_print_space_data
*data
, unsigned pos
)
2912 isl_multi_pw_aff
*mpa
= data
->user
;
2915 if (data
->type
!= isl_dim_out
)
2916 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
2920 return isl_printer_print_str(p
, "(0 : 1 = 0)");
2922 need_parens
= pa
->n
!= 1 || !isl_set_plain_is_universe(pa
->p
[0].set
);
2924 p
= isl_printer_print_str(p
, "(");
2925 for (i
= 0; i
< pa
->n
; ++i
) {
2929 p
= isl_printer_print_str(p
, "; ");
2930 p
= print_aff_body(p
, pa
->p
[i
].aff
);
2931 space
= isl_aff_get_domain_space(pa
->p
[i
].aff
);
2932 p
= print_disjuncts(pa
->p
[i
].set
, space
, p
, 0);
2933 isl_space_free(space
);
2936 p
= isl_printer_print_str(p
, ")");
2941 /* Print "mpa" to "p" in isl format.
2943 static __isl_give isl_printer
*print_multi_pw_aff_isl(__isl_take isl_printer
*p
,
2944 __isl_keep isl_multi_pw_aff
*mpa
)
2946 struct isl_print_space_data data
= { 0 };
2949 return isl_printer_free(p
);
2951 if (isl_space_dim(mpa
->space
, isl_dim_param
) > 0) {
2952 p
= print_tuple(mpa
->space
, p
, isl_dim_param
, &data
);
2953 p
= isl_printer_print_str(p
, " -> ");
2955 p
= isl_printer_print_str(p
, "{ ");
2956 data
.print_dim
= &print_dim_mpa
;
2958 p
= isl_print_space(mpa
->space
, p
, 0, &data
);
2959 p
= isl_printer_print_str(p
, " }");
2963 __isl_give isl_printer
*isl_printer_print_multi_pw_aff(
2964 __isl_take isl_printer
*p
, __isl_keep isl_multi_pw_aff
*mpa
)
2967 return isl_printer_free(p
);
2969 if (p
->output_format
== ISL_FORMAT_ISL
)
2970 return print_multi_pw_aff_isl(p
, mpa
);
2971 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2972 return isl_printer_free(p
));
2975 /* Print dimension "pos" of data->space to "p".
2977 * data->user is assumed to be an isl_multi_val.
2979 * If the current dimension is an output dimension, then print
2980 * the corresponding value. Otherwise, print the name of the dimension.
2982 static __isl_give isl_printer
*print_dim_mv(__isl_take isl_printer
*p
,
2983 struct isl_print_space_data
*data
, unsigned pos
)
2985 isl_multi_val
*mv
= data
->user
;
2987 if (data
->type
== isl_dim_out
)
2988 return isl_printer_print_val(p
, mv
->p
[pos
]);
2990 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
2993 /* Print the isl_multi_val "mv" to "p" in isl format.
2995 static __isl_give isl_printer
*print_multi_val_isl(__isl_take isl_printer
*p
,
2996 __isl_keep isl_multi_val
*mv
)
2998 struct isl_print_space_data data
= { 0 };
3001 return isl_printer_free(p
);
3003 if (isl_space_dim(mv
->space
, isl_dim_param
) > 0) {
3004 p
= print_tuple(mv
->space
, p
, isl_dim_param
, &data
);
3005 p
= isl_printer_print_str(p
, " -> ");
3007 p
= isl_printer_print_str(p
, "{ ");
3008 data
.print_dim
= &print_dim_mv
;
3010 p
= isl_print_space(mv
->space
, p
, 0, &data
);
3011 p
= isl_printer_print_str(p
, " }");
3015 /* Print the isl_multi_val "mv" to "p".
3017 * Currently only supported in isl format.
3019 __isl_give isl_printer
*isl_printer_print_multi_val(
3020 __isl_take isl_printer
*p
, __isl_keep isl_multi_val
*mv
)
3023 return isl_printer_free(p
);
3025 if (p
->output_format
== ISL_FORMAT_ISL
)
3026 return print_multi_val_isl(p
, mv
);
3027 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3028 return isl_printer_free(p
));
3031 /* Print dimension "pos" of data->space to "p".
3033 * data->user is assumed to be an isl_multi_union_pw_aff.
3035 * The current dimension is necessarily a set dimension, so
3036 * we print the corresponding isl_union_pw_aff, including
3039 static __isl_give isl_printer
*print_union_pw_aff_dim(__isl_take isl_printer
*p
,
3040 struct isl_print_space_data
*data
, unsigned pos
)
3042 isl_multi_union_pw_aff
*mupa
= data
->user
;
3043 isl_union_pw_aff
*upa
;
3045 upa
= isl_multi_union_pw_aff_get_union_pw_aff(mupa
, pos
);
3046 p
= print_union_pw_aff_body(p
, upa
);
3047 isl_union_pw_aff_free(upa
);
3052 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3054 static __isl_give isl_printer
*print_multi_union_pw_aff_isl(
3055 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3057 struct isl_print_space_data data
= { 0 };
3060 space
= isl_multi_union_pw_aff_get_space(mupa
);
3061 if (isl_space_dim(space
, isl_dim_param
) > 0) {
3062 struct isl_print_space_data space_data
= { 0 };
3063 p
= print_tuple(space
, p
, isl_dim_param
, &space_data
);
3064 p
= isl_printer_print_str(p
, s_to
[0]);
3067 data
.print_dim
= &print_union_pw_aff_dim
;
3070 p
= isl_print_space(space
, p
, 0, &data
);
3071 isl_space_free(space
);
3076 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3078 * We currently only support an isl format.
3080 __isl_give isl_printer
*isl_printer_print_multi_union_pw_aff(
3081 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3084 return isl_printer_free(p
);
3086 if (p
->output_format
== ISL_FORMAT_ISL
)
3087 return print_multi_union_pw_aff_isl(p
, mupa
);
3088 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
3089 "unsupported output format", return isl_printer_free(p
));