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 any 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
)
756 div
= isl_basic_map_get_divs(bmap
);
758 exists
= bmap
->n_div
> 0;
760 exists
= need_exists(p
, bmap
, div
);
761 if (exists
>= 0 && exists
) {
762 p
= isl_printer_print_str(p
, s_open_exists
[latex
]);
763 p
= print_div_list(p
, space
, div
, latex
, p
->dump
);
764 p
= isl_printer_print_str(p
, ": ");
768 div
= isl_mat_free(div
);
769 p
= print_constraints(bmap
, space
, div
, p
, latex
);
772 if (exists
>= 0 && exists
)
773 p
= isl_printer_print_str(p
, s_close_exists
[latex
]);
777 /* Print a colon followed by the constraints of "bmap"
778 * to "p", provided there are any constraints.
779 * The names of the variables are taken from "space".
780 * "latex" is set if the constraints should be printed in LaTeX format.
782 static __isl_give isl_printer
*print_optional_disjunct(
783 __isl_keep isl_basic_map
*bmap
, __isl_keep isl_space
*space
,
784 __isl_take isl_printer
*p
, int latex
)
786 if (isl_basic_map_plain_is_universe(bmap
))
789 p
= isl_printer_print_str(p
, ": ");
790 p
= print_disjunct(bmap
, space
, p
, latex
);
795 static __isl_give isl_printer
*basic_map_print_omega(
796 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
)
798 p
= isl_printer_print_str(p
, "{ [");
799 p
= print_var_list(p
, bmap
->dim
, isl_dim_in
);
800 p
= isl_printer_print_str(p
, "] -> [");
801 p
= print_var_list(p
, bmap
->dim
, isl_dim_out
);
802 p
= isl_printer_print_str(p
, "] ");
803 p
= print_optional_disjunct(bmap
, bmap
->dim
, p
, 0);
804 p
= isl_printer_print_str(p
, " }");
808 static __isl_give isl_printer
*basic_set_print_omega(
809 __isl_keep isl_basic_set
*bset
, __isl_take isl_printer
*p
)
811 p
= isl_printer_print_str(p
, "{ [");
812 p
= print_var_list(p
, bset
->dim
, isl_dim_set
);
813 p
= isl_printer_print_str(p
, "] ");
814 p
= print_optional_disjunct(bset
, bset
->dim
, p
, 0);
815 p
= isl_printer_print_str(p
, " }");
819 static __isl_give isl_printer
*isl_map_print_omega(__isl_keep isl_map
*map
,
820 __isl_take isl_printer
*p
)
824 for (i
= 0; i
< map
->n
; ++i
) {
826 p
= isl_printer_print_str(p
, " union ");
827 p
= basic_map_print_omega(map
->p
[i
], p
);
832 static __isl_give isl_printer
*isl_set_print_omega(__isl_keep isl_set
*set
,
833 __isl_take isl_printer
*p
)
837 for (i
= 0; i
< set
->n
; ++i
) {
839 p
= isl_printer_print_str(p
, " union ");
840 p
= basic_set_print_omega(set
->p
[i
], p
);
845 static __isl_give isl_printer
*isl_basic_map_print_isl(
846 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
,
849 struct isl_print_space_data data
= { .latex
= latex
};
850 int rational
= ISL_F_ISSET(bmap
, ISL_BASIC_MAP_RATIONAL
);
852 if (isl_basic_map_dim(bmap
, isl_dim_param
) > 0) {
853 p
= print_tuple(bmap
->dim
, p
, isl_dim_param
, &data
);
854 p
= isl_printer_print_str(p
, " -> ");
856 p
= isl_printer_print_str(p
, "{ ");
857 p
= isl_print_space(bmap
->dim
, p
, rational
, &data
);
858 p
= isl_printer_print_str(p
, " : ");
859 p
= print_disjunct(bmap
, bmap
->dim
, p
, latex
);
860 p
= isl_printer_print_str(p
, " }");
864 /* Print the disjuncts of a map (or set) "map" to "p".
865 * The names of the variables are taken from "space".
866 * "latex" is set if the constraints should be printed in LaTeX format.
868 static __isl_give isl_printer
*print_disjuncts_core(__isl_keep isl_map
*map
,
869 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
874 p
= isl_printer_print_str(p
, "1 = 0");
875 for (i
= 0; i
< map
->n
; ++i
) {
877 p
= isl_printer_print_str(p
, s_or
[latex
]);
878 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
879 p
= isl_printer_print_str(p
, "(");
880 p
= print_disjunct(map
->p
[i
], space
, p
, latex
);
881 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
882 p
= isl_printer_print_str(p
, ")");
887 /* Print the disjuncts of a map (or set) "map" to "p".
888 * The names of the variables are taken from "space".
889 * "hull" describes constraints shared by all disjuncts of "map".
890 * "latex" is set if the constraints should be printed in LaTeX format.
892 * Print the disjuncts as a conjunction of "hull" and
893 * the result of removing the constraints of "hull" from "map".
894 * If this result turns out to be the universe, then simply print "hull".
896 static __isl_give isl_printer
*print_disjuncts_in_hull(__isl_keep isl_map
*map
,
897 __isl_keep isl_space
*space
, __isl_take isl_basic_map
*hull
,
898 __isl_take isl_printer
*p
, int latex
)
900 isl_bool is_universe
;
902 p
= print_disjunct(hull
, space
, p
, latex
);
903 map
= isl_map_plain_gist_basic_map(isl_map_copy(map
), hull
);
904 is_universe
= isl_map_plain_is_universe(map
);
908 p
= isl_printer_print_str(p
, s_and
[latex
]);
909 p
= isl_printer_print_str(p
, "(");
910 p
= print_disjuncts_core(map
, space
, p
, latex
);
911 p
= isl_printer_print_str(p
, ")");
922 /* Print the disjuncts of a map (or set) "map" to "p".
923 * The names of the variables are taken from "space".
924 * "latex" is set if the constraints should be printed in LaTeX format.
926 * If there are at least two disjuncts and "dump" mode is not turned out,
927 * check for any shared constraints among all disjuncts.
928 * If there are any, then print them separately in print_disjuncts_in_hull.
930 static __isl_give isl_printer
*print_disjuncts(__isl_keep isl_map
*map
,
931 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
933 if (isl_map_plain_is_universe(map
))
936 p
= isl_printer_print_str(p
, s_such_that
[latex
]);
940 if (!p
->dump
&& map
->n
>= 2) {
942 isl_bool is_universe
;
944 hull
= isl_map_plain_unshifted_simple_hull(isl_map_copy(map
));
945 is_universe
= isl_basic_map_plain_is_universe(hull
);
947 p
= isl_printer_free(p
);
948 else if (!is_universe
)
949 return print_disjuncts_in_hull(map
, space
, hull
,
951 isl_basic_map_free(hull
);
954 return print_disjuncts_core(map
, space
, p
, latex
);
957 /* Print the disjuncts of a map (or set).
958 * The names of the variables are taken from "space".
959 * "latex" is set if the constraints should be printed in LaTeX format.
961 * If the map turns out to be a universal parameter domain, then
962 * we need to print the colon. Otherwise, the output looks identical
965 static __isl_give isl_printer
*print_disjuncts_map(__isl_keep isl_map
*map
,
966 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
968 if (isl_map_plain_is_universe(map
) && isl_space_is_params(map
->dim
))
969 return isl_printer_print_str(p
, s_such_that
[latex
]);
971 return print_disjuncts(map
, space
, p
, latex
);
974 struct isl_aff_split
{
979 static void free_split(__isl_take
struct isl_aff_split
*split
, int n
)
986 for (i
= 0; i
< n
; ++i
) {
987 isl_basic_map_free(split
[i
].aff
);
988 isl_map_free(split
[i
].map
);
994 static __isl_give isl_basic_map
*get_aff(__isl_take isl_basic_map
*bmap
)
997 unsigned nparam
, n_in
, n_out
, total
;
999 bmap
= isl_basic_map_cow(bmap
);
1002 if (isl_basic_map_free_inequality(bmap
, bmap
->n_ineq
) < 0)
1005 nparam
= isl_basic_map_dim(bmap
, isl_dim_param
);
1006 n_in
= isl_basic_map_dim(bmap
, isl_dim_in
);
1007 n_out
= isl_basic_map_dim(bmap
, isl_dim_out
);
1008 total
= isl_basic_map_dim(bmap
, isl_dim_all
);
1009 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
1010 j
= isl_seq_last_non_zero(bmap
->eq
[i
] + 1, total
);
1011 if (j
>= nparam
&& j
< nparam
+ n_in
+ n_out
&&
1012 (isl_int_is_one(bmap
->eq
[i
][1 + j
]) ||
1013 isl_int_is_negone(bmap
->eq
[i
][1 + j
])))
1015 if (isl_basic_map_drop_equality(bmap
, i
) < 0)
1019 bmap
= isl_basic_map_finalize(bmap
);
1023 isl_basic_map_free(bmap
);
1027 static int aff_split_cmp(const void *p1
, const void *p2
, void *user
)
1029 const struct isl_aff_split
*s1
, *s2
;
1030 s1
= (const struct isl_aff_split
*) p1
;
1031 s2
= (const struct isl_aff_split
*) p2
;
1033 return isl_basic_map_plain_cmp(s1
->aff
, s2
->aff
);
1036 static __isl_give isl_basic_map
*drop_aff(__isl_take isl_basic_map
*bmap
,
1037 __isl_keep isl_basic_map
*aff
)
1045 total
= isl_space_dim(bmap
->dim
, isl_dim_all
);
1047 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
1048 if (isl_seq_first_non_zero(bmap
->eq
[i
] + 1 + total
,
1051 for (j
= 0; j
< aff
->n_eq
; ++j
) {
1052 if (!isl_seq_eq(bmap
->eq
[i
], aff
->eq
[j
], 1 + total
) &&
1053 !isl_seq_is_neg(bmap
->eq
[i
], aff
->eq
[j
], 1 + total
))
1055 if (isl_basic_map_drop_equality(bmap
, i
) < 0)
1063 isl_basic_map_free(bmap
);
1067 static __isl_give
struct isl_aff_split
*split_aff(__isl_keep isl_map
*map
)
1070 struct isl_aff_split
*split
;
1073 ctx
= isl_map_get_ctx(map
);
1074 split
= isl_calloc_array(ctx
, struct isl_aff_split
, map
->n
);
1078 for (i
= 0; i
< map
->n
; ++i
) {
1079 isl_basic_map
*bmap
;
1080 split
[i
].aff
= get_aff(isl_basic_map_copy(map
->p
[i
]));
1081 bmap
= isl_basic_map_copy(map
->p
[i
]);
1082 bmap
= isl_basic_map_cow(bmap
);
1083 bmap
= drop_aff(bmap
, split
[i
].aff
);
1084 split
[i
].map
= isl_map_from_basic_map(bmap
);
1085 if (!split
[i
].aff
|| !split
[i
].map
)
1089 if (isl_sort(split
, map
->n
, sizeof(struct isl_aff_split
),
1090 &aff_split_cmp
, NULL
) < 0)
1094 for (i
= n
- 1; i
>= 1; --i
) {
1095 if (!isl_basic_map_plain_is_equal(split
[i
- 1].aff
,
1098 isl_basic_map_free(split
[i
].aff
);
1099 split
[i
- 1].map
= isl_map_union(split
[i
- 1].map
,
1102 split
[i
] = split
[n
- 1];
1103 split
[n
- 1].aff
= NULL
;
1104 split
[n
- 1].map
= NULL
;
1110 free_split(split
, map
->n
);
1114 static int defining_equality(__isl_keep isl_basic_map
*eq
,
1115 __isl_keep isl_space
*dim
, enum isl_dim_type type
, int pos
)
1123 pos
+= isl_space_offset(dim
, type
);
1124 total
= isl_basic_map_total_dim(eq
);
1126 for (i
= 0; i
< eq
->n_eq
; ++i
) {
1127 if (isl_seq_last_non_zero(eq
->eq
[i
] + 1, total
) != pos
)
1129 if (isl_int_is_one(eq
->eq
[i
][1 + pos
]))
1130 isl_seq_neg(eq
->eq
[i
], eq
->eq
[i
], 1 + total
);
1137 /* Print dimension "pos" of data->space to "p".
1139 * data->user is assumed to be an isl_basic_map keeping track of equalities.
1141 * If the current dimension is defined by these equalities, then print
1142 * the corresponding expression, assigned to the name of the dimension
1143 * if there is any. Otherwise, print the name of the dimension.
1145 static __isl_give isl_printer
*print_dim_eq(__isl_take isl_printer
*p
,
1146 struct isl_print_space_data
*data
, unsigned pos
)
1148 isl_basic_map
*eq
= data
->user
;
1151 j
= defining_equality(eq
, data
->space
, data
->type
, pos
);
1153 if (isl_space_has_dim_name(data
->space
, data
->type
, pos
)) {
1154 p
= print_name(data
->space
, p
, data
->type
, pos
,
1156 p
= isl_printer_print_str(p
, " = ");
1158 pos
+= 1 + isl_space_offset(data
->space
, data
->type
);
1159 p
= print_affine_of_len(data
->space
, NULL
, p
, eq
->eq
[j
], pos
);
1161 p
= print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
1167 static __isl_give isl_printer
*print_split_map(__isl_take isl_printer
*p
,
1168 struct isl_aff_split
*split
, int n
, __isl_keep isl_space
*space
)
1170 struct isl_print_space_data data
= { 0 };
1174 data
.print_dim
= &print_dim_eq
;
1175 for (i
= 0; i
< n
; ++i
) {
1178 rational
= split
[i
].map
->n
> 0 &&
1179 ISL_F_ISSET(split
[i
].map
->p
[0], ISL_BASIC_MAP_RATIONAL
);
1181 p
= isl_printer_print_str(p
, "; ");
1182 data
.user
= split
[i
].aff
;
1183 p
= isl_print_space(space
, p
, rational
, &data
);
1184 p
= print_disjuncts_map(split
[i
].map
, space
, p
, 0);
1190 static __isl_give isl_printer
*isl_map_print_isl_body(__isl_keep isl_map
*map
,
1191 __isl_take isl_printer
*p
)
1193 struct isl_print_space_data data
= { 0 };
1194 struct isl_aff_split
*split
= NULL
;
1197 if (!p
->dump
&& map
->n
> 0)
1198 split
= split_aff(map
);
1200 p
= print_split_map(p
, split
, map
->n
, map
->dim
);
1202 rational
= map
->n
> 0 &&
1203 ISL_F_ISSET(map
->p
[0], ISL_BASIC_MAP_RATIONAL
);
1204 p
= isl_print_space(map
->dim
, p
, rational
, &data
);
1205 p
= print_disjuncts_map(map
, map
->dim
, p
, 0);
1207 free_split(split
, map
->n
);
1211 static __isl_give isl_printer
*isl_map_print_isl(__isl_keep isl_map
*map
,
1212 __isl_take isl_printer
*p
)
1214 struct isl_print_space_data data
= { 0 };
1216 if (isl_map_dim(map
, isl_dim_param
) > 0) {
1217 p
= print_tuple(map
->dim
, p
, isl_dim_param
, &data
);
1218 p
= isl_printer_print_str(p
, s_to
[0]);
1220 p
= isl_printer_print_str(p
, s_open_set
[0]);
1221 p
= isl_map_print_isl_body(map
, p
);
1222 p
= isl_printer_print_str(p
, s_close_set
[0]);
1226 static __isl_give isl_printer
*print_latex_map(__isl_keep isl_map
*map
,
1227 __isl_take isl_printer
*p
, __isl_keep isl_basic_map
*aff
)
1229 struct isl_print_space_data data
= { 0 };
1232 if (isl_map_dim(map
, isl_dim_param
) > 0) {
1233 p
= print_tuple(map
->dim
, p
, isl_dim_param
, &data
);
1234 p
= isl_printer_print_str(p
, s_to
[1]);
1236 p
= isl_printer_print_str(p
, s_open_set
[1]);
1237 data
.print_dim
= &print_dim_eq
;
1239 p
= isl_print_space(map
->dim
, p
, 0, &data
);
1240 p
= print_disjuncts_map(map
, map
->dim
, p
, 1);
1241 p
= isl_printer_print_str(p
, s_close_set
[1]);
1246 static __isl_give isl_printer
*isl_map_print_latex(__isl_keep isl_map
*map
,
1247 __isl_take isl_printer
*p
)
1250 struct isl_aff_split
*split
= NULL
;
1253 split
= split_aff(map
);
1256 return print_latex_map(map
, p
, NULL
);
1258 for (i
= 0; i
< map
->n
; ++i
) {
1262 p
= isl_printer_print_str(p
, " \\cup ");
1263 p
= print_latex_map(split
[i
].map
, p
, split
[i
].aff
);
1266 free_split(split
, map
->n
);
1270 __isl_give isl_printer
*isl_printer_print_basic_map(__isl_take isl_printer
*p
,
1271 __isl_keep isl_basic_map
*bmap
)
1275 if (p
->output_format
== ISL_FORMAT_ISL
)
1276 return isl_basic_map_print_isl(bmap
, p
, 0);
1277 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1278 return basic_map_print_omega(bmap
, p
);
1279 isl_assert(bmap
->ctx
, 0, goto error
);
1281 isl_printer_free(p
);
1285 __isl_give isl_printer
*isl_printer_print_basic_set(__isl_take isl_printer
*p
,
1286 __isl_keep isl_basic_set
*bset
)
1291 if (p
->output_format
== ISL_FORMAT_ISL
)
1292 return isl_basic_map_print_isl(bset
, p
, 0);
1293 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1294 return isl_basic_set_print_polylib(bset
, p
, 0);
1295 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1296 return isl_basic_set_print_polylib(bset
, p
, 1);
1297 else if (p
->output_format
== ISL_FORMAT_POLYLIB_CONSTRAINTS
)
1298 return bset_print_constraints_polylib(bset
, p
);
1299 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1300 return basic_set_print_omega(bset
, p
);
1301 isl_assert(p
->ctx
, 0, goto error
);
1303 isl_printer_free(p
);
1307 __isl_give isl_printer
*isl_printer_print_set(__isl_take isl_printer
*p
,
1308 __isl_keep isl_set
*set
)
1312 if (p
->output_format
== ISL_FORMAT_ISL
)
1313 return isl_map_print_isl((isl_map
*)set
, p
);
1314 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1315 return isl_set_print_polylib(set
, p
, 0);
1316 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1317 return isl_set_print_polylib(set
, p
, 1);
1318 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1319 return isl_set_print_omega(set
, p
);
1320 else if (p
->output_format
== ISL_FORMAT_LATEX
)
1321 return isl_map_print_latex((isl_map
*)set
, p
);
1322 isl_assert(set
->ctx
, 0, goto error
);
1324 isl_printer_free(p
);
1328 __isl_give isl_printer
*isl_printer_print_map(__isl_take isl_printer
*p
,
1329 __isl_keep isl_map
*map
)
1334 if (p
->output_format
== ISL_FORMAT_ISL
)
1335 return isl_map_print_isl(map
, p
);
1336 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1337 return isl_map_print_polylib(map
, p
, 0);
1338 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1339 return isl_map_print_polylib(map
, p
, 1);
1340 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1341 return isl_map_print_omega(map
, p
);
1342 else if (p
->output_format
== ISL_FORMAT_LATEX
)
1343 return isl_map_print_latex(map
, p
);
1344 isl_assert(map
->ctx
, 0, goto error
);
1346 isl_printer_free(p
);
1350 struct isl_union_print_data
{
1355 static isl_stat
print_map_body(__isl_take isl_map
*map
, void *user
)
1357 struct isl_union_print_data
*data
;
1358 data
= (struct isl_union_print_data
*)user
;
1361 data
->p
= isl_printer_print_str(data
->p
, "; ");
1364 data
->p
= isl_map_print_isl_body(map
, data
->p
);
1370 static __isl_give isl_printer
*isl_union_map_print_isl(
1371 __isl_keep isl_union_map
*umap
, __isl_take isl_printer
*p
)
1373 struct isl_union_print_data data
;
1374 struct isl_print_space_data space_data
= { 0 };
1377 dim
= isl_union_map_get_space(umap
);
1378 if (isl_space_dim(dim
, isl_dim_param
) > 0) {
1379 p
= print_tuple(dim
, p
, isl_dim_param
, &space_data
);
1380 p
= isl_printer_print_str(p
, s_to
[0]);
1382 isl_space_free(dim
);
1383 p
= isl_printer_print_str(p
, s_open_set
[0]);
1386 isl_union_map_foreach_map(umap
, &print_map_body
, &data
);
1388 p
= isl_printer_print_str(p
, s_close_set
[0]);
1392 static isl_stat
print_latex_map_body(__isl_take isl_map
*map
, void *user
)
1394 struct isl_union_print_data
*data
;
1395 data
= (struct isl_union_print_data
*)user
;
1398 data
->p
= isl_printer_print_str(data
->p
, " \\cup ");
1401 data
->p
= isl_map_print_latex(map
, data
->p
);
1407 static __isl_give isl_printer
*isl_union_map_print_latex(
1408 __isl_keep isl_union_map
*umap
, __isl_take isl_printer
*p
)
1410 struct isl_union_print_data data
= { p
, 1 };
1411 isl_union_map_foreach_map(umap
, &print_latex_map_body
, &data
);
1416 __isl_give isl_printer
*isl_printer_print_union_map(__isl_take isl_printer
*p
,
1417 __isl_keep isl_union_map
*umap
)
1422 if (p
->output_format
== ISL_FORMAT_ISL
)
1423 return isl_union_map_print_isl(umap
, p
);
1424 if (p
->output_format
== ISL_FORMAT_LATEX
)
1425 return isl_union_map_print_latex(umap
, p
);
1427 isl_die(p
->ctx
, isl_error_invalid
,
1428 "invalid output format for isl_union_map", goto error
);
1430 isl_printer_free(p
);
1434 __isl_give isl_printer
*isl_printer_print_union_set(__isl_take isl_printer
*p
,
1435 __isl_keep isl_union_set
*uset
)
1440 if (p
->output_format
== ISL_FORMAT_ISL
)
1441 return isl_union_map_print_isl((isl_union_map
*)uset
, p
);
1442 if (p
->output_format
== ISL_FORMAT_LATEX
)
1443 return isl_union_map_print_latex((isl_union_map
*)uset
, p
);
1445 isl_die(p
->ctx
, isl_error_invalid
,
1446 "invalid output format for isl_union_set", goto error
);
1448 isl_printer_free(p
);
1452 static int upoly_rec_n_non_zero(__isl_keep
struct isl_upoly_rec
*rec
)
1457 for (i
= 0, n
= 0; i
< rec
->n
; ++i
)
1458 if (!isl_upoly_is_zero(rec
->p
[i
]))
1464 static __isl_give isl_printer
*upoly_print_cst(__isl_keep
struct isl_upoly
*up
,
1465 __isl_take isl_printer
*p
, int first
)
1467 struct isl_upoly_cst
*cst
;
1470 cst
= isl_upoly_as_cst(up
);
1473 neg
= !first
&& isl_int_is_neg(cst
->n
);
1475 p
= isl_printer_print_str(p
, neg
? " - " : " + ");
1477 isl_int_neg(cst
->n
, cst
->n
);
1478 if (isl_int_is_zero(cst
->d
)) {
1479 int sgn
= isl_int_sgn(cst
->n
);
1480 p
= isl_printer_print_str(p
, sgn
< 0 ? "-infty" :
1481 sgn
== 0 ? "NaN" : "infty");
1483 p
= isl_printer_print_isl_int(p
, cst
->n
);
1485 isl_int_neg(cst
->n
, cst
->n
);
1486 if (!isl_int_is_zero(cst
->d
) && !isl_int_is_one(cst
->d
)) {
1487 p
= isl_printer_print_str(p
, "/");
1488 p
= isl_printer_print_isl_int(p
, cst
->d
);
1492 isl_printer_free(p
);
1496 static __isl_give isl_printer
*print_base(__isl_take isl_printer
*p
,
1497 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
, int var
)
1501 total
= isl_space_dim(dim
, isl_dim_all
);
1503 p
= print_term(dim
, NULL
, dim
->ctx
->one
, 1 + var
, p
, 0);
1505 p
= print_div(dim
, div
, var
- total
, p
);
1509 static __isl_give isl_printer
*print_pow(__isl_take isl_printer
*p
,
1510 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
, int var
, int exp
)
1512 p
= print_base(p
, dim
, div
, var
);
1515 if (p
->output_format
== ISL_FORMAT_C
) {
1517 for (i
= 1; i
< exp
; ++i
) {
1518 p
= isl_printer_print_str(p
, "*");
1519 p
= print_base(p
, dim
, div
, var
);
1522 p
= isl_printer_print_str(p
, "^");
1523 p
= isl_printer_print_int(p
, exp
);
1528 static __isl_give isl_printer
*upoly_print(__isl_keep
struct isl_upoly
*up
,
1529 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
,
1530 __isl_take isl_printer
*p
, int outer
)
1532 int i
, n
, first
, print_parens
;
1533 struct isl_upoly_rec
*rec
;
1535 if (!p
|| !up
|| !dim
|| !div
)
1538 if (isl_upoly_is_cst(up
))
1539 return upoly_print_cst(up
, p
, 1);
1541 rec
= isl_upoly_as_rec(up
);
1544 n
= upoly_rec_n_non_zero(rec
);
1545 print_parens
= n
> 1 ||
1546 (outer
&& rec
->up
.var
>= isl_space_dim(dim
, isl_dim_all
));
1548 p
= isl_printer_print_str(p
, "(");
1549 for (i
= 0, first
= 1; i
< rec
->n
; ++i
) {
1550 if (isl_upoly_is_zero(rec
->p
[i
]))
1552 if (isl_upoly_is_negone(rec
->p
[i
])) {
1554 p
= isl_printer_print_str(p
, "-1");
1556 p
= isl_printer_print_str(p
, "-");
1558 p
= isl_printer_print_str(p
, " - ");
1559 } else if (isl_upoly_is_cst(rec
->p
[i
]) &&
1560 !isl_upoly_is_one(rec
->p
[i
]))
1561 p
= upoly_print_cst(rec
->p
[i
], p
, first
);
1564 p
= isl_printer_print_str(p
, " + ");
1565 if (i
== 0 || !isl_upoly_is_one(rec
->p
[i
]))
1566 p
= upoly_print(rec
->p
[i
], dim
, div
, p
, 0);
1571 if (!isl_upoly_is_one(rec
->p
[i
]) &&
1572 !isl_upoly_is_negone(rec
->p
[i
]))
1573 p
= isl_printer_print_str(p
, " * ");
1574 p
= print_pow(p
, dim
, div
, rec
->up
.var
, i
);
1577 p
= isl_printer_print_str(p
, ")");
1580 isl_printer_free(p
);
1584 static __isl_give isl_printer
*print_qpolynomial(__isl_take isl_printer
*p
,
1585 __isl_keep isl_qpolynomial
*qp
)
1589 p
= upoly_print(qp
->upoly
, qp
->dim
, qp
->div
, p
, 1);
1592 isl_printer_free(p
);
1596 static __isl_give isl_printer
*print_qpolynomial_isl(__isl_take isl_printer
*p
,
1597 __isl_keep isl_qpolynomial
*qp
)
1599 struct isl_print_space_data data
= { 0 };
1604 if (isl_space_dim(qp
->dim
, isl_dim_param
) > 0) {
1605 p
= print_tuple(qp
->dim
, p
, isl_dim_param
, &data
);
1606 p
= isl_printer_print_str(p
, " -> ");
1608 p
= isl_printer_print_str(p
, "{ ");
1609 if (!isl_space_is_params(qp
->dim
)) {
1610 p
= isl_print_space(qp
->dim
, p
, 0, &data
);
1611 p
= isl_printer_print_str(p
, " -> ");
1613 p
= print_qpolynomial(p
, qp
);
1614 p
= isl_printer_print_str(p
, " }");
1617 isl_printer_free(p
);
1621 static __isl_give isl_printer
*print_qpolynomial_c(__isl_take isl_printer
*p
,
1622 __isl_keep isl_space
*dim
, __isl_keep isl_qpolynomial
*qp
)
1627 isl_qpolynomial_get_den(qp
, &den
);
1628 if (!isl_int_is_one(den
)) {
1630 p
= isl_printer_print_str(p
, "(");
1631 qp
= isl_qpolynomial_copy(qp
);
1632 f
= isl_qpolynomial_rat_cst_on_domain(isl_space_copy(qp
->dim
),
1633 den
, qp
->dim
->ctx
->one
);
1634 qp
= isl_qpolynomial_mul(qp
, f
);
1637 p
= upoly_print(qp
->upoly
, dim
, qp
->div
, p
, 0);
1639 p
= isl_printer_free(p
);
1640 if (!isl_int_is_one(den
)) {
1641 p
= isl_printer_print_str(p
, ")/");
1642 p
= isl_printer_print_isl_int(p
, den
);
1643 isl_qpolynomial_free(qp
);
1649 __isl_give isl_printer
*isl_printer_print_qpolynomial(
1650 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial
*qp
)
1655 if (p
->output_format
== ISL_FORMAT_ISL
)
1656 return print_qpolynomial_isl(p
, qp
);
1657 else if (p
->output_format
== ISL_FORMAT_C
)
1658 return print_qpolynomial_c(p
, qp
->dim
, qp
);
1660 isl_die(qp
->dim
->ctx
, isl_error_unsupported
,
1661 "output format not supported for isl_qpolynomials",
1664 isl_printer_free(p
);
1668 void isl_qpolynomial_print(__isl_keep isl_qpolynomial
*qp
, FILE *out
,
1669 unsigned output_format
)
1676 isl_assert(qp
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
1677 p
= isl_printer_to_file(qp
->dim
->ctx
, out
);
1678 p
= isl_printer_print_qpolynomial(p
, qp
);
1679 isl_printer_free(p
);
1682 static __isl_give isl_printer
*qpolynomial_fold_print(
1683 __isl_keep isl_qpolynomial_fold
*fold
, __isl_take isl_printer
*p
)
1687 if (fold
->type
== isl_fold_min
)
1688 p
= isl_printer_print_str(p
, "min");
1689 else if (fold
->type
== isl_fold_max
)
1690 p
= isl_printer_print_str(p
, "max");
1691 p
= isl_printer_print_str(p
, "(");
1692 for (i
= 0; i
< fold
->n
; ++i
) {
1694 p
= isl_printer_print_str(p
, ", ");
1695 p
= print_qpolynomial(p
, fold
->qp
[i
]);
1697 p
= isl_printer_print_str(p
, ")");
1701 void isl_qpolynomial_fold_print(__isl_keep isl_qpolynomial_fold
*fold
,
1702 FILE *out
, unsigned output_format
)
1709 isl_assert(fold
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
1711 p
= isl_printer_to_file(fold
->dim
->ctx
, out
);
1712 p
= isl_printer_print_qpolynomial_fold(p
, fold
);
1714 isl_printer_free(p
);
1717 static __isl_give isl_printer
*isl_pwqp_print_isl_body(
1718 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
1720 struct isl_print_space_data data
= { 0 };
1723 for (i
= 0; i
< pwqp
->n
; ++i
) {
1727 p
= isl_printer_print_str(p
, "; ");
1728 space
= isl_qpolynomial_get_domain_space(pwqp
->p
[i
].qp
);
1729 if (!isl_space_is_params(space
)) {
1730 p
= isl_print_space(space
, p
, 0, &data
);
1731 p
= isl_printer_print_str(p
, " -> ");
1733 p
= print_qpolynomial(p
, pwqp
->p
[i
].qp
);
1734 p
= print_disjuncts((isl_map
*)pwqp
->p
[i
].set
, space
, p
, 0);
1735 isl_space_free(space
);
1741 static __isl_give isl_printer
*print_pw_qpolynomial_isl(
1742 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
1744 struct isl_print_space_data data
= { 0 };
1749 if (isl_space_dim(pwqp
->dim
, isl_dim_param
) > 0) {
1750 p
= print_tuple(pwqp
->dim
, p
, isl_dim_param
, &data
);
1751 p
= isl_printer_print_str(p
, " -> ");
1753 p
= isl_printer_print_str(p
, "{ ");
1755 if (!isl_space_is_set(pwqp
->dim
)) {
1756 p
= print_tuple(pwqp
->dim
, p
, isl_dim_in
, &data
);
1757 p
= isl_printer_print_str(p
, " -> ");
1759 p
= isl_printer_print_str(p
, "0");
1761 p
= isl_pwqp_print_isl_body(p
, pwqp
);
1762 p
= isl_printer_print_str(p
, " }");
1765 isl_printer_free(p
);
1769 void isl_pw_qpolynomial_print(__isl_keep isl_pw_qpolynomial
*pwqp
, FILE *out
,
1770 unsigned output_format
)
1777 p
= isl_printer_to_file(pwqp
->dim
->ctx
, out
);
1778 p
= isl_printer_set_output_format(p
, output_format
);
1779 p
= isl_printer_print_pw_qpolynomial(p
, pwqp
);
1781 isl_printer_free(p
);
1784 static __isl_give isl_printer
*isl_pwf_print_isl_body(
1785 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
1787 struct isl_print_space_data data
= { 0 };
1790 for (i
= 0; i
< pwf
->n
; ++i
) {
1794 p
= isl_printer_print_str(p
, "; ");
1795 space
= isl_qpolynomial_fold_get_domain_space(pwf
->p
[i
].fold
);
1796 if (!isl_space_is_params(space
)) {
1797 p
= isl_print_space(space
, p
, 0, &data
);
1798 p
= isl_printer_print_str(p
, " -> ");
1800 p
= qpolynomial_fold_print(pwf
->p
[i
].fold
, p
);
1801 p
= print_disjuncts((isl_map
*)pwf
->p
[i
].set
, space
, p
, 0);
1802 isl_space_free(space
);
1808 static __isl_give isl_printer
*print_pw_qpolynomial_fold_isl(
1809 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
1811 struct isl_print_space_data data
= { 0 };
1813 if (isl_space_dim(pwf
->dim
, isl_dim_param
) > 0) {
1814 p
= print_tuple(pwf
->dim
, p
, isl_dim_param
, &data
);
1815 p
= isl_printer_print_str(p
, " -> ");
1817 p
= isl_printer_print_str(p
, "{ ");
1819 if (!isl_space_is_set(pwf
->dim
)) {
1820 p
= print_tuple(pwf
->dim
, p
, isl_dim_in
, &data
);
1821 p
= isl_printer_print_str(p
, " -> ");
1823 p
= isl_printer_print_str(p
, "0");
1825 p
= isl_pwf_print_isl_body(p
, pwf
);
1826 p
= isl_printer_print_str(p
, " }");
1830 static __isl_give isl_printer
*print_affine_c(__isl_take isl_printer
*p
,
1831 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
, isl_int
*c
);
1833 static __isl_give isl_printer
*print_name_c(__isl_take isl_printer
*p
,
1834 __isl_keep isl_space
*dim
,
1835 __isl_keep isl_basic_set
*bset
, enum isl_dim_type type
, unsigned pos
)
1837 if (type
== isl_dim_div
) {
1838 p
= isl_printer_print_str(p
, "floord(");
1839 p
= print_affine_c(p
, dim
, bset
, bset
->div
[pos
] + 1);
1840 p
= isl_printer_print_str(p
, ", ");
1841 p
= isl_printer_print_isl_int(p
, bset
->div
[pos
][0]);
1842 p
= isl_printer_print_str(p
, ")");
1846 name
= isl_space_get_dim_name(dim
, type
, pos
);
1849 p
= isl_printer_print_str(p
, name
);
1854 static __isl_give isl_printer
*print_term_c(__isl_take isl_printer
*p
,
1855 __isl_keep isl_space
*dim
,
1856 __isl_keep isl_basic_set
*bset
, isl_int c
, unsigned pos
)
1858 enum isl_dim_type type
;
1861 return isl_printer_print_isl_int(p
, c
);
1863 if (isl_int_is_one(c
))
1865 else if (isl_int_is_negone(c
))
1866 p
= isl_printer_print_str(p
, "-");
1868 p
= isl_printer_print_isl_int(p
, c
);
1869 p
= isl_printer_print_str(p
, "*");
1871 type
= pos2type(dim
, &pos
);
1872 p
= print_name_c(p
, dim
, bset
, type
, pos
);
1876 static __isl_give isl_printer
*print_partial_affine_c(__isl_take isl_printer
*p
,
1877 __isl_keep isl_space
*dim
,
1878 __isl_keep isl_basic_set
*bset
, isl_int
*c
, unsigned len
)
1883 for (i
= 0, first
= 1; i
< len
; ++i
) {
1885 if (isl_int_is_zero(c
[i
]))
1888 if (isl_int_is_neg(c
[i
])) {
1890 isl_int_neg(c
[i
], c
[i
]);
1891 p
= isl_printer_print_str(p
, " - ");
1893 p
= isl_printer_print_str(p
, " + ");
1896 p
= print_term_c(p
, dim
, bset
, c
[i
], i
);
1898 isl_int_neg(c
[i
], c
[i
]);
1901 p
= isl_printer_print_str(p
, "0");
1905 static __isl_give isl_printer
*print_affine_c(__isl_take isl_printer
*p
,
1906 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
, isl_int
*c
)
1908 unsigned len
= 1 + isl_basic_set_total_dim(bset
);
1909 return print_partial_affine_c(p
, dim
, bset
, c
, len
);
1912 /* We skip the constraint if it is implied by the div expression.
1914 * *first indicates whether this is the first constraint in the conjunction and
1915 * is updated if the constraint is actually printed.
1917 static __isl_give isl_printer
*print_constraint_c(__isl_take isl_printer
*p
,
1918 __isl_keep isl_space
*dim
,
1919 __isl_keep isl_basic_set
*bset
, isl_int
*c
, const char *op
, int *first
)
1925 o_div
= isl_basic_set_offset(bset
, isl_dim_div
);
1926 n_div
= isl_basic_set_dim(bset
, isl_dim_div
);
1927 div
= isl_seq_last_non_zero(c
+ o_div
, n_div
);
1928 if (div
>= 0 && isl_basic_set_is_div_constraint(bset
, c
, div
))
1932 p
= isl_printer_print_str(p
, " && ");
1934 p
= print_affine_c(p
, dim
, bset
, c
);
1935 p
= isl_printer_print_str(p
, " ");
1936 p
= isl_printer_print_str(p
, op
);
1937 p
= isl_printer_print_str(p
, " 0");
1944 static __isl_give isl_printer
*print_basic_set_c(__isl_take isl_printer
*p
,
1945 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
)
1949 unsigned n_div
= isl_basic_set_dim(bset
, isl_dim_div
);
1950 unsigned total
= isl_basic_set_total_dim(bset
) - n_div
;
1952 for (i
= 0; i
< bset
->n_eq
; ++i
) {
1953 j
= isl_seq_last_non_zero(bset
->eq
[i
] + 1 + total
, n_div
);
1955 p
= print_constraint_c(p
, dim
, bset
,
1956 bset
->eq
[i
], "==", &first
);
1959 p
= isl_printer_print_str(p
, " && ");
1960 p
= isl_printer_print_str(p
, "(");
1961 p
= print_partial_affine_c(p
, dim
, bset
, bset
->eq
[i
],
1963 p
= isl_printer_print_str(p
, ") % ");
1964 p
= isl_printer_print_isl_int(p
,
1965 bset
->eq
[i
][1 + total
+ j
]);
1966 p
= isl_printer_print_str(p
, " == 0");
1970 for (i
= 0; i
< bset
->n_ineq
; ++i
)
1971 p
= print_constraint_c(p
, dim
, bset
, bset
->ineq
[i
], ">=",
1976 static __isl_give isl_printer
*print_set_c(__isl_take isl_printer
*p
,
1977 __isl_keep isl_space
*dim
, __isl_keep isl_set
*set
)
1982 return isl_printer_free(p
);
1985 p
= isl_printer_print_str(p
, "0");
1987 for (i
= 0; i
< set
->n
; ++i
) {
1989 p
= isl_printer_print_str(p
, " || ");
1991 p
= isl_printer_print_str(p
, "(");
1992 p
= print_basic_set_c(p
, dim
, set
->p
[i
]);
1994 p
= isl_printer_print_str(p
, ")");
1999 static __isl_give isl_printer
*print_pw_qpolynomial_c(
2000 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2004 if (pwqp
->n
== 1 && isl_set_plain_is_universe(pwqp
->p
[0].set
))
2005 return print_qpolynomial_c(p
, pwqp
->dim
, pwqp
->p
[0].qp
);
2007 for (i
= 0; i
< pwqp
->n
; ++i
) {
2008 p
= isl_printer_print_str(p
, "(");
2009 p
= print_set_c(p
, pwqp
->dim
, pwqp
->p
[i
].set
);
2010 p
= isl_printer_print_str(p
, ") ? (");
2011 p
= print_qpolynomial_c(p
, pwqp
->dim
, pwqp
->p
[i
].qp
);
2012 p
= isl_printer_print_str(p
, ") : ");
2015 p
= isl_printer_print_str(p
, "0");
2019 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial(
2020 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2025 if (p
->output_format
== ISL_FORMAT_ISL
)
2026 return print_pw_qpolynomial_isl(p
, pwqp
);
2027 else if (p
->output_format
== ISL_FORMAT_C
)
2028 return print_pw_qpolynomial_c(p
, pwqp
);
2029 isl_assert(p
->ctx
, 0, goto error
);
2031 isl_printer_free(p
);
2035 static isl_stat
print_pwqp_body(__isl_take isl_pw_qpolynomial
*pwqp
, void *user
)
2037 struct isl_union_print_data
*data
;
2038 data
= (struct isl_union_print_data
*)user
;
2041 data
->p
= isl_printer_print_str(data
->p
, "; ");
2044 data
->p
= isl_pwqp_print_isl_body(data
->p
, pwqp
);
2045 isl_pw_qpolynomial_free(pwqp
);
2050 static __isl_give isl_printer
*print_union_pw_qpolynomial_isl(
2051 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2053 struct isl_union_print_data data
;
2054 struct isl_print_space_data space_data
= { 0 };
2057 dim
= isl_union_pw_qpolynomial_get_space(upwqp
);
2058 if (isl_space_dim(dim
, isl_dim_param
) > 0) {
2059 p
= print_tuple(dim
, p
, isl_dim_param
, &space_data
);
2060 p
= isl_printer_print_str(p
, " -> ");
2062 isl_space_free(dim
);
2063 p
= isl_printer_print_str(p
, "{ ");
2066 isl_union_pw_qpolynomial_foreach_pw_qpolynomial(upwqp
, &print_pwqp_body
,
2069 p
= isl_printer_print_str(p
, " }");
2073 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial(
2074 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2079 if (p
->output_format
== ISL_FORMAT_ISL
)
2080 return print_union_pw_qpolynomial_isl(p
, upwqp
);
2081 isl_die(p
->ctx
, isl_error_invalid
,
2082 "invalid output format for isl_union_pw_qpolynomial",
2085 isl_printer_free(p
);
2089 static __isl_give isl_printer
*print_qpolynomial_fold_c(
2090 __isl_take isl_printer
*p
, __isl_keep isl_space
*dim
,
2091 __isl_keep isl_qpolynomial_fold
*fold
)
2095 for (i
= 0; i
< fold
->n
- 1; ++i
)
2096 if (fold
->type
== isl_fold_min
)
2097 p
= isl_printer_print_str(p
, "min(");
2098 else if (fold
->type
== isl_fold_max
)
2099 p
= isl_printer_print_str(p
, "max(");
2101 for (i
= 0; i
< fold
->n
; ++i
) {
2103 p
= isl_printer_print_str(p
, ", ");
2104 p
= print_qpolynomial_c(p
, dim
, fold
->qp
[i
]);
2106 p
= isl_printer_print_str(p
, ")");
2111 __isl_give isl_printer
*isl_printer_print_qpolynomial_fold(
2112 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial_fold
*fold
)
2116 if (p
->output_format
== ISL_FORMAT_ISL
)
2117 return qpolynomial_fold_print(fold
, p
);
2118 else if (p
->output_format
== ISL_FORMAT_C
)
2119 return print_qpolynomial_fold_c(p
, fold
->dim
, fold
);
2120 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2123 isl_printer_free(p
);
2127 static __isl_give isl_printer
*print_pw_qpolynomial_fold_c(
2128 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2132 if (pwf
->n
== 1 && isl_set_plain_is_universe(pwf
->p
[0].set
))
2133 return print_qpolynomial_fold_c(p
, pwf
->dim
, pwf
->p
[0].fold
);
2135 for (i
= 0; i
< pwf
->n
; ++i
) {
2136 p
= isl_printer_print_str(p
, "(");
2137 p
= print_set_c(p
, pwf
->dim
, pwf
->p
[i
].set
);
2138 p
= isl_printer_print_str(p
, ") ? (");
2139 p
= print_qpolynomial_fold_c(p
, pwf
->dim
, pwf
->p
[i
].fold
);
2140 p
= isl_printer_print_str(p
, ") : ");
2143 p
= isl_printer_print_str(p
, "0");
2147 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial_fold(
2148 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2153 if (p
->output_format
== ISL_FORMAT_ISL
)
2154 return print_pw_qpolynomial_fold_isl(p
, pwf
);
2155 else if (p
->output_format
== ISL_FORMAT_C
)
2156 return print_pw_qpolynomial_fold_c(p
, pwf
);
2157 isl_assert(p
->ctx
, 0, goto error
);
2159 isl_printer_free(p
);
2163 void isl_pw_qpolynomial_fold_print(__isl_keep isl_pw_qpolynomial_fold
*pwf
,
2164 FILE *out
, unsigned output_format
)
2171 p
= isl_printer_to_file(pwf
->dim
->ctx
, out
);
2172 p
= isl_printer_set_output_format(p
, output_format
);
2173 p
= isl_printer_print_pw_qpolynomial_fold(p
, pwf
);
2175 isl_printer_free(p
);
2178 static isl_stat
print_pwf_body(__isl_take isl_pw_qpolynomial_fold
*pwf
,
2181 struct isl_union_print_data
*data
;
2182 data
= (struct isl_union_print_data
*)user
;
2185 data
->p
= isl_printer_print_str(data
->p
, "; ");
2188 data
->p
= isl_pwf_print_isl_body(data
->p
, pwf
);
2189 isl_pw_qpolynomial_fold_free(pwf
);
2194 static __isl_give isl_printer
*print_union_pw_qpolynomial_fold_isl(
2195 __isl_take isl_printer
*p
,
2196 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2198 struct isl_union_print_data data
;
2199 struct isl_print_space_data space_data
= { 0 };
2202 dim
= isl_union_pw_qpolynomial_fold_get_space(upwf
);
2203 if (isl_space_dim(dim
, isl_dim_param
) > 0) {
2204 p
= print_tuple(dim
, p
, isl_dim_param
, &space_data
);
2205 p
= isl_printer_print_str(p
, " -> ");
2207 isl_space_free(dim
);
2208 p
= isl_printer_print_str(p
, "{ ");
2211 isl_union_pw_qpolynomial_fold_foreach_pw_qpolynomial_fold(upwf
,
2212 &print_pwf_body
, &data
);
2214 p
= isl_printer_print_str(p
, " }");
2218 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial_fold(
2219 __isl_take isl_printer
*p
,
2220 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2225 if (p
->output_format
== ISL_FORMAT_ISL
)
2226 return print_union_pw_qpolynomial_fold_isl(p
, upwf
);
2227 isl_die(p
->ctx
, isl_error_invalid
,
2228 "invalid output format for isl_union_pw_qpolynomial_fold",
2231 isl_printer_free(p
);
2235 __isl_give isl_printer
*isl_printer_print_constraint(__isl_take isl_printer
*p
,
2236 __isl_keep isl_constraint
*c
)
2238 isl_basic_map
*bmap
;
2243 bmap
= isl_basic_map_from_constraint(isl_constraint_copy(c
));
2244 p
= isl_printer_print_basic_map(p
, bmap
);
2245 isl_basic_map_free(bmap
);
2248 isl_printer_free(p
);
2252 static __isl_give isl_printer
*isl_printer_print_space_isl(
2253 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
)
2255 struct isl_print_space_data data
= { 0 };
2260 if (isl_space_dim(space
, isl_dim_param
) > 0) {
2261 p
= print_tuple(space
, p
, isl_dim_param
, &data
);
2262 p
= isl_printer_print_str(p
, " -> ");
2265 p
= isl_printer_print_str(p
, "{ ");
2266 if (isl_space_is_params(space
))
2267 p
= isl_printer_print_str(p
, s_such_that
[0]);
2269 p
= isl_print_space(space
, p
, 0, &data
);
2270 p
= isl_printer_print_str(p
, " }");
2274 isl_printer_free(p
);
2278 __isl_give isl_printer
*isl_printer_print_space(__isl_take isl_printer
*p
,
2279 __isl_keep isl_space
*space
)
2282 return isl_printer_free(p
);
2283 if (p
->output_format
== ISL_FORMAT_ISL
)
2284 return isl_printer_print_space_isl(p
, space
);
2285 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
2286 return print_omega_parameters(space
, p
);
2288 isl_die(isl_space_get_ctx(space
), isl_error_unsupported
,
2289 "output format not supported for space",
2290 return isl_printer_free(p
));
2293 __isl_give isl_printer
*isl_printer_print_local_space(__isl_take isl_printer
*p
,
2294 __isl_keep isl_local_space
*ls
)
2296 struct isl_print_space_data data
= { 0 };
2302 if (isl_local_space_dim(ls
, isl_dim_param
) > 0) {
2303 p
= print_tuple(ls
->dim
, p
, isl_dim_param
, &data
);
2304 p
= isl_printer_print_str(p
, " -> ");
2306 p
= isl_printer_print_str(p
, "{ ");
2307 p
= isl_print_space(ls
->dim
, p
, 0, &data
);
2308 n_div
= isl_local_space_dim(ls
, isl_dim_div
);
2310 p
= isl_printer_print_str(p
, " : ");
2311 p
= isl_printer_print_str(p
, s_open_exists
[0]);
2312 p
= print_div_list(p
, ls
->dim
, ls
->div
, 0, 1);
2313 p
= isl_printer_print_str(p
, s_close_exists
[0]);
2314 } else if (isl_space_is_params(ls
->dim
))
2315 p
= isl_printer_print_str(p
, s_such_that
[0]);
2316 p
= isl_printer_print_str(p
, " }");
2319 isl_printer_free(p
);
2323 static __isl_give isl_printer
*print_aff_body(__isl_take isl_printer
*p
,
2324 __isl_keep isl_aff
*aff
)
2328 if (isl_aff_is_nan(aff
))
2329 return isl_printer_print_str(p
, "NaN");
2331 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2332 p
= isl_printer_print_str(p
, "(");
2333 p
= print_affine_of_len(aff
->ls
->dim
, aff
->ls
->div
, p
,
2334 aff
->v
->el
+ 1, 1 + total
);
2335 if (isl_int_is_one(aff
->v
->el
[0]))
2336 p
= isl_printer_print_str(p
, ")");
2338 p
= isl_printer_print_str(p
, ")/");
2339 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2345 static __isl_give isl_printer
*print_aff(__isl_take isl_printer
*p
,
2346 __isl_keep isl_aff
*aff
)
2348 struct isl_print_space_data data
= { 0 };
2350 if (isl_space_is_params(aff
->ls
->dim
))
2353 p
= print_tuple(aff
->ls
->dim
, p
, isl_dim_set
, &data
);
2354 p
= isl_printer_print_str(p
, " -> ");
2356 p
= isl_printer_print_str(p
, "[");
2357 p
= print_aff_body(p
, aff
);
2358 p
= isl_printer_print_str(p
, "]");
2363 static __isl_give isl_printer
*print_aff_isl(__isl_take isl_printer
*p
,
2364 __isl_keep isl_aff
*aff
)
2366 struct isl_print_space_data data
= { 0 };
2371 if (isl_local_space_dim(aff
->ls
, isl_dim_param
) > 0) {
2372 p
= print_tuple(aff
->ls
->dim
, p
, isl_dim_param
, &data
);
2373 p
= isl_printer_print_str(p
, " -> ");
2375 p
= isl_printer_print_str(p
, "{ ");
2376 p
= print_aff(p
, aff
);
2377 p
= isl_printer_print_str(p
, " }");
2380 isl_printer_free(p
);
2384 /* Print the body of an isl_pw_aff, i.e., a semicolon delimited
2385 * sequence of affine expressions, each followed by constraints.
2387 static __isl_give isl_printer
*print_pw_aff_body(
2388 __isl_take isl_printer
*p
, __isl_keep isl_pw_aff
*pa
)
2393 return isl_printer_free(p
);
2395 for (i
= 0; i
< pa
->n
; ++i
) {
2399 p
= isl_printer_print_str(p
, "; ");
2400 p
= print_aff(p
, pa
->p
[i
].aff
);
2401 space
= isl_aff_get_domain_space(pa
->p
[i
].aff
);
2402 p
= print_disjuncts((isl_map
*)pa
->p
[i
].set
, space
, p
, 0);
2403 isl_space_free(space
);
2409 static __isl_give isl_printer
*print_pw_aff_isl(__isl_take isl_printer
*p
,
2410 __isl_keep isl_pw_aff
*pwaff
)
2412 struct isl_print_space_data data
= { 0 };
2417 if (isl_space_dim(pwaff
->dim
, isl_dim_param
) > 0) {
2418 p
= print_tuple(pwaff
->dim
, p
, isl_dim_param
, &data
);
2419 p
= isl_printer_print_str(p
, " -> ");
2421 p
= isl_printer_print_str(p
, "{ ");
2422 p
= print_pw_aff_body(p
, pwaff
);
2423 p
= isl_printer_print_str(p
, " }");
2426 isl_printer_free(p
);
2430 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2431 __isl_keep isl_local_space
*ls
, isl_int
*c
);
2433 static __isl_give isl_printer
*print_ls_name_c(__isl_take isl_printer
*p
,
2434 __isl_keep isl_local_space
*ls
, enum isl_dim_type type
, unsigned pos
)
2436 if (type
== isl_dim_div
) {
2437 p
= isl_printer_print_str(p
, "floord(");
2438 p
= print_ls_affine_c(p
, ls
, ls
->div
->row
[pos
] + 1);
2439 p
= isl_printer_print_str(p
, ", ");
2440 p
= isl_printer_print_isl_int(p
, ls
->div
->row
[pos
][0]);
2441 p
= isl_printer_print_str(p
, ")");
2445 name
= isl_space_get_dim_name(ls
->dim
, type
, pos
);
2448 p
= isl_printer_print_str(p
, name
);
2453 static __isl_give isl_printer
*print_ls_term_c(__isl_take isl_printer
*p
,
2454 __isl_keep isl_local_space
*ls
, isl_int c
, unsigned pos
)
2456 enum isl_dim_type type
;
2459 return isl_printer_print_isl_int(p
, c
);
2461 if (isl_int_is_one(c
))
2463 else if (isl_int_is_negone(c
))
2464 p
= isl_printer_print_str(p
, "-");
2466 p
= isl_printer_print_isl_int(p
, c
);
2467 p
= isl_printer_print_str(p
, "*");
2469 type
= pos2type(ls
->dim
, &pos
);
2470 p
= print_ls_name_c(p
, ls
, type
, pos
);
2474 static __isl_give isl_printer
*print_ls_partial_affine_c(
2475 __isl_take isl_printer
*p
, __isl_keep isl_local_space
*ls
,
2476 isl_int
*c
, unsigned len
)
2481 for (i
= 0, first
= 1; i
< len
; ++i
) {
2483 if (isl_int_is_zero(c
[i
]))
2486 if (isl_int_is_neg(c
[i
])) {
2488 isl_int_neg(c
[i
], c
[i
]);
2489 p
= isl_printer_print_str(p
, " - ");
2491 p
= isl_printer_print_str(p
, " + ");
2494 p
= print_ls_term_c(p
, ls
, c
[i
], i
);
2496 isl_int_neg(c
[i
], c
[i
]);
2499 p
= isl_printer_print_str(p
, "0");
2503 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2504 __isl_keep isl_local_space
*ls
, isl_int
*c
)
2506 unsigned len
= 1 + isl_local_space_dim(ls
, isl_dim_all
);
2507 return print_ls_partial_affine_c(p
, ls
, c
, len
);
2510 static __isl_give isl_printer
*print_aff_c(__isl_take isl_printer
*p
,
2511 __isl_keep isl_aff
*aff
)
2515 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2516 if (!isl_int_is_one(aff
->v
->el
[0]))
2517 p
= isl_printer_print_str(p
, "(");
2518 p
= print_ls_partial_affine_c(p
, aff
->ls
, aff
->v
->el
+ 1, 1 + total
);
2519 if (!isl_int_is_one(aff
->v
->el
[0])) {
2520 p
= isl_printer_print_str(p
, ")/");
2521 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2526 /* In the C format, we cannot express that "pwaff" may be undefined
2527 * on parts of the domain space. We therefore assume that the expression
2528 * will only be evaluated on its definition domain and compute the gist
2529 * of each cell with respect to this domain.
2531 static __isl_give isl_printer
*print_pw_aff_c(__isl_take isl_printer
*p
,
2532 __isl_keep isl_pw_aff
*pwaff
)
2535 isl_ast_build
*build
;
2539 isl_die(p
->ctx
, isl_error_unsupported
,
2540 "cannot print empty isl_pw_aff in C format",
2541 return isl_printer_free(p
));
2543 domain
= isl_pw_aff_domain(isl_pw_aff_copy(pwaff
));
2544 build
= isl_ast_build_from_context(domain
);
2545 expr
= isl_ast_build_expr_from_pw_aff(build
, isl_pw_aff_copy(pwaff
));
2546 p
= isl_printer_print_ast_expr(p
, expr
);
2547 isl_ast_expr_free(expr
);
2548 isl_ast_build_free(build
);
2553 __isl_give isl_printer
*isl_printer_print_aff(__isl_take isl_printer
*p
,
2554 __isl_keep isl_aff
*aff
)
2559 if (p
->output_format
== ISL_FORMAT_ISL
)
2560 return print_aff_isl(p
, aff
);
2561 else if (p
->output_format
== ISL_FORMAT_C
)
2562 return print_aff_c(p
, aff
);
2563 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2566 isl_printer_free(p
);
2570 __isl_give isl_printer
*isl_printer_print_pw_aff(__isl_take isl_printer
*p
,
2571 __isl_keep isl_pw_aff
*pwaff
)
2576 if (p
->output_format
== ISL_FORMAT_ISL
)
2577 return print_pw_aff_isl(p
, pwaff
);
2578 else if (p
->output_format
== ISL_FORMAT_C
)
2579 return print_pw_aff_c(p
, pwaff
);
2580 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2583 isl_printer_free(p
);
2587 /* Print "pa" in a sequence of isl_pw_affs delimited by semicolons.
2588 * Each isl_pw_aff itself is also printed as semicolon delimited
2589 * sequence of pieces.
2590 * If data->first = 1, then this is the first in the sequence.
2591 * Update data->first to tell the next element that it is not the first.
2593 static isl_stat
print_pw_aff_body_wrap(__isl_take isl_pw_aff
*pa
,
2596 struct isl_union_print_data
*data
;
2597 data
= (struct isl_union_print_data
*) user
;
2600 data
->p
= isl_printer_print_str(data
->p
, "; ");
2603 data
->p
= print_pw_aff_body(data
->p
, pa
);
2604 isl_pw_aff_free(pa
);
2606 return data
->p
? isl_stat_ok
: isl_stat_error
;
2609 /* Print the body of an isl_union_pw_aff, i.e., a semicolon delimited
2610 * sequence of affine expressions, each followed by constraints,
2611 * with the sequence enclosed in braces.
2613 static __isl_give isl_printer
*print_union_pw_aff_body(
2614 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2616 struct isl_union_print_data data
= { p
, 1 };
2618 p
= isl_printer_print_str(p
, s_open_set
[0]);
2620 if (isl_union_pw_aff_foreach_pw_aff(upa
,
2621 &print_pw_aff_body_wrap
, &data
) < 0)
2622 data
.p
= isl_printer_free(p
);
2624 p
= isl_printer_print_str(p
, s_close_set
[0]);
2629 /* Print the isl_union_pw_aff "upa" to "p" in isl format.
2631 * The individual isl_pw_affs are delimited by a semicolon.
2633 static __isl_give isl_printer
*print_union_pw_aff_isl(
2634 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2636 struct isl_print_space_data data
= { 0 };
2639 space
= isl_union_pw_aff_get_space(upa
);
2640 if (isl_space_dim(space
, isl_dim_param
) > 0) {
2641 p
= print_tuple(space
, p
, isl_dim_param
, &data
);
2642 p
= isl_printer_print_str(p
, s_to
[0]);
2644 isl_space_free(space
);
2645 p
= print_union_pw_aff_body(p
, upa
);
2649 /* Print the isl_union_pw_aff "upa" to "p".
2651 * We currently only support an isl format.
2653 __isl_give isl_printer
*isl_printer_print_union_pw_aff(
2654 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2657 return isl_printer_free(p
);
2659 if (p
->output_format
== ISL_FORMAT_ISL
)
2660 return print_union_pw_aff_isl(p
, upa
);
2661 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
2662 "unsupported output format", return isl_printer_free(p
));
2665 /* Print dimension "pos" of data->space to "p".
2667 * data->user is assumed to be an isl_multi_aff.
2669 * If the current dimension is an output dimension, then print
2670 * the corresponding expression. Otherwise, print the name of the dimension.
2672 static __isl_give isl_printer
*print_dim_ma(__isl_take isl_printer
*p
,
2673 struct isl_print_space_data
*data
, unsigned pos
)
2675 isl_multi_aff
*ma
= data
->user
;
2677 if (data
->type
== isl_dim_out
)
2678 p
= print_aff_body(p
, ma
->p
[pos
]);
2680 p
= print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
2685 static __isl_give isl_printer
*print_multi_aff(__isl_take isl_printer
*p
,
2686 __isl_keep isl_multi_aff
*maff
)
2688 struct isl_print_space_data data
= { 0 };
2690 data
.print_dim
= &print_dim_ma
;
2692 return isl_print_space(maff
->space
, p
, 0, &data
);
2695 static __isl_give isl_printer
*print_multi_aff_isl(__isl_take isl_printer
*p
,
2696 __isl_keep isl_multi_aff
*maff
)
2698 struct isl_print_space_data data
= { 0 };
2703 if (isl_space_dim(maff
->space
, isl_dim_param
) > 0) {
2704 p
= print_tuple(maff
->space
, p
, isl_dim_param
, &data
);
2705 p
= isl_printer_print_str(p
, " -> ");
2707 p
= isl_printer_print_str(p
, "{ ");
2708 p
= print_multi_aff(p
, maff
);
2709 p
= isl_printer_print_str(p
, " }");
2712 isl_printer_free(p
);
2716 __isl_give isl_printer
*isl_printer_print_multi_aff(__isl_take isl_printer
*p
,
2717 __isl_keep isl_multi_aff
*maff
)
2722 if (p
->output_format
== ISL_FORMAT_ISL
)
2723 return print_multi_aff_isl(p
, maff
);
2724 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2727 isl_printer_free(p
);
2731 static __isl_give isl_printer
*print_pw_multi_aff_body(
2732 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2739 for (i
= 0; i
< pma
->n
; ++i
) {
2743 p
= isl_printer_print_str(p
, "; ");
2744 p
= print_multi_aff(p
, pma
->p
[i
].maff
);
2745 space
= isl_multi_aff_get_domain_space(pma
->p
[i
].maff
);
2746 p
= print_disjuncts((isl_map
*)pma
->p
[i
].set
, space
, p
, 0);
2747 isl_space_free(space
);
2751 isl_printer_free(p
);
2755 static __isl_give isl_printer
*print_pw_multi_aff_isl(__isl_take isl_printer
*p
,
2756 __isl_keep isl_pw_multi_aff
*pma
)
2758 struct isl_print_space_data data
= { 0 };
2763 if (isl_space_dim(pma
->dim
, isl_dim_param
) > 0) {
2764 p
= print_tuple(pma
->dim
, p
, isl_dim_param
, &data
);
2765 p
= isl_printer_print_str(p
, " -> ");
2767 p
= isl_printer_print_str(p
, "{ ");
2768 p
= print_pw_multi_aff_body(p
, pma
);
2769 p
= isl_printer_print_str(p
, " }");
2772 isl_printer_free(p
);
2776 static __isl_give isl_printer
*print_unnamed_pw_multi_aff_c(
2777 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2781 for (i
= 0; i
< pma
->n
- 1; ++i
) {
2782 p
= isl_printer_print_str(p
, "(");
2783 p
= print_set_c(p
, pma
->dim
, pma
->p
[i
].set
);
2784 p
= isl_printer_print_str(p
, ") ? (");
2785 p
= print_aff_c(p
, pma
->p
[i
].maff
->p
[0]);
2786 p
= isl_printer_print_str(p
, ") : ");
2789 return print_aff_c(p
, pma
->p
[pma
->n
- 1].maff
->p
[0]);
2792 static __isl_give isl_printer
*print_pw_multi_aff_c(__isl_take isl_printer
*p
,
2793 __isl_keep isl_pw_multi_aff
*pma
)
2801 isl_die(p
->ctx
, isl_error_unsupported
,
2802 "cannot print empty isl_pw_multi_aff in C format",
2804 name
= isl_pw_multi_aff_get_tuple_name(pma
, isl_dim_out
);
2805 if (!name
&& isl_pw_multi_aff_dim(pma
, isl_dim_out
) == 1)
2806 return print_unnamed_pw_multi_aff_c(p
, pma
);
2808 isl_die(p
->ctx
, isl_error_unsupported
,
2809 "cannot print unnamed isl_pw_multi_aff in C format",
2812 p
= isl_printer_print_str(p
, name
);
2813 n
= isl_pw_multi_aff_dim(pma
, isl_dim_out
);
2815 isl_die(p
->ctx
, isl_error_unsupported
,
2816 "not supported yet", goto error
);
2820 isl_printer_free(p
);
2824 __isl_give isl_printer
*isl_printer_print_pw_multi_aff(
2825 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2830 if (p
->output_format
== ISL_FORMAT_ISL
)
2831 return print_pw_multi_aff_isl(p
, pma
);
2832 if (p
->output_format
== ISL_FORMAT_C
)
2833 return print_pw_multi_aff_c(p
, pma
);
2834 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2837 isl_printer_free(p
);
2841 static isl_stat
print_pw_multi_aff_body_wrap(__isl_take isl_pw_multi_aff
*pma
,
2844 struct isl_union_print_data
*data
;
2845 data
= (struct isl_union_print_data
*) user
;
2848 data
->p
= isl_printer_print_str(data
->p
, "; ");
2851 data
->p
= print_pw_multi_aff_body(data
->p
, pma
);
2852 isl_pw_multi_aff_free(pma
);
2857 static __isl_give isl_printer
*print_union_pw_multi_aff_isl(
2858 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
2860 struct isl_union_print_data data
;
2861 struct isl_print_space_data space_data
= { 0 };
2864 space
= isl_union_pw_multi_aff_get_space(upma
);
2865 if (isl_space_dim(space
, isl_dim_param
) > 0) {
2866 p
= print_tuple(space
, p
, isl_dim_param
, &space_data
);
2867 p
= isl_printer_print_str(p
, s_to
[0]);
2869 isl_space_free(space
);
2870 p
= isl_printer_print_str(p
, s_open_set
[0]);
2873 isl_union_pw_multi_aff_foreach_pw_multi_aff(upma
,
2874 &print_pw_multi_aff_body_wrap
, &data
);
2876 p
= isl_printer_print_str(p
, s_close_set
[0]);
2880 __isl_give isl_printer
*isl_printer_print_union_pw_multi_aff(
2881 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
2886 if (p
->output_format
== ISL_FORMAT_ISL
)
2887 return print_union_pw_multi_aff_isl(p
, upma
);
2888 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2891 isl_printer_free(p
);
2895 /* Print dimension "pos" of data->space to "p".
2897 * data->user is assumed to be an isl_multi_pw_aff.
2899 * If the current dimension is an output dimension, then print
2900 * the corresponding piecewise affine expression.
2901 * Otherwise, print the name of the dimension.
2903 static __isl_give isl_printer
*print_dim_mpa(__isl_take isl_printer
*p
,
2904 struct isl_print_space_data
*data
, unsigned pos
)
2908 isl_multi_pw_aff
*mpa
= data
->user
;
2911 if (data
->type
!= isl_dim_out
)
2912 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
2916 return isl_printer_print_str(p
, "(0 : 1 = 0)");
2918 need_parens
= pa
->n
!= 1 || !isl_set_plain_is_universe(pa
->p
[0].set
);
2920 p
= isl_printer_print_str(p
, "(");
2921 for (i
= 0; i
< pa
->n
; ++i
) {
2925 p
= isl_printer_print_str(p
, "; ");
2926 p
= print_aff_body(p
, pa
->p
[i
].aff
);
2927 space
= isl_aff_get_domain_space(pa
->p
[i
].aff
);
2928 p
= print_disjuncts(pa
->p
[i
].set
, space
, p
, 0);
2929 isl_space_free(space
);
2932 p
= isl_printer_print_str(p
, ")");
2937 /* Print "mpa" to "p" in isl format.
2939 static __isl_give isl_printer
*print_multi_pw_aff_isl(__isl_take isl_printer
*p
,
2940 __isl_keep isl_multi_pw_aff
*mpa
)
2942 struct isl_print_space_data data
= { 0 };
2945 return isl_printer_free(p
);
2947 if (isl_space_dim(mpa
->space
, isl_dim_param
) > 0) {
2948 p
= print_tuple(mpa
->space
, p
, isl_dim_param
, &data
);
2949 p
= isl_printer_print_str(p
, " -> ");
2951 p
= isl_printer_print_str(p
, "{ ");
2952 data
.print_dim
= &print_dim_mpa
;
2954 p
= isl_print_space(mpa
->space
, p
, 0, &data
);
2955 p
= isl_printer_print_str(p
, " }");
2959 __isl_give isl_printer
*isl_printer_print_multi_pw_aff(
2960 __isl_take isl_printer
*p
, __isl_keep isl_multi_pw_aff
*mpa
)
2963 return isl_printer_free(p
);
2965 if (p
->output_format
== ISL_FORMAT_ISL
)
2966 return print_multi_pw_aff_isl(p
, mpa
);
2967 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2968 return isl_printer_free(p
));
2971 /* Print dimension "pos" of data->space to "p".
2973 * data->user is assumed to be an isl_multi_val.
2975 * If the current dimension is an output dimension, then print
2976 * the corresponding value. Otherwise, print the name of the dimension.
2978 static __isl_give isl_printer
*print_dim_mv(__isl_take isl_printer
*p
,
2979 struct isl_print_space_data
*data
, unsigned pos
)
2981 isl_multi_val
*mv
= data
->user
;
2983 if (data
->type
== isl_dim_out
)
2984 return isl_printer_print_val(p
, mv
->p
[pos
]);
2986 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
2989 /* Print the isl_multi_val "mv" to "p" in isl format.
2991 static __isl_give isl_printer
*print_multi_val_isl(__isl_take isl_printer
*p
,
2992 __isl_keep isl_multi_val
*mv
)
2994 struct isl_print_space_data data
= { 0 };
2997 return isl_printer_free(p
);
2999 if (isl_space_dim(mv
->space
, isl_dim_param
) > 0) {
3000 p
= print_tuple(mv
->space
, p
, isl_dim_param
, &data
);
3001 p
= isl_printer_print_str(p
, " -> ");
3003 p
= isl_printer_print_str(p
, "{ ");
3004 data
.print_dim
= &print_dim_mv
;
3006 p
= isl_print_space(mv
->space
, p
, 0, &data
);
3007 p
= isl_printer_print_str(p
, " }");
3011 /* Print the isl_multi_val "mv" to "p".
3013 * Currently only supported in isl format.
3015 __isl_give isl_printer
*isl_printer_print_multi_val(
3016 __isl_take isl_printer
*p
, __isl_keep isl_multi_val
*mv
)
3019 return isl_printer_free(p
);
3021 if (p
->output_format
== ISL_FORMAT_ISL
)
3022 return print_multi_val_isl(p
, mv
);
3023 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3024 return isl_printer_free(p
));
3027 /* Print dimension "pos" of data->space to "p".
3029 * data->user is assumed to be an isl_multi_union_pw_aff.
3031 * The current dimension is necessarily a set dimension, so
3032 * we print the corresponding isl_union_pw_aff, including
3035 static __isl_give isl_printer
*print_union_pw_aff_dim(__isl_take isl_printer
*p
,
3036 struct isl_print_space_data
*data
, unsigned pos
)
3038 isl_multi_union_pw_aff
*mupa
= data
->user
;
3039 isl_union_pw_aff
*upa
;
3041 upa
= isl_multi_union_pw_aff_get_union_pw_aff(mupa
, pos
);
3042 p
= print_union_pw_aff_body(p
, upa
);
3043 isl_union_pw_aff_free(upa
);
3048 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3050 static __isl_give isl_printer
*print_multi_union_pw_aff_isl(
3051 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3053 struct isl_print_space_data data
= { 0 };
3056 space
= isl_multi_union_pw_aff_get_space(mupa
);
3057 if (isl_space_dim(space
, isl_dim_param
) > 0) {
3058 struct isl_print_space_data space_data
= { 0 };
3059 p
= print_tuple(space
, p
, isl_dim_param
, &space_data
);
3060 p
= isl_printer_print_str(p
, s_to
[0]);
3063 data
.print_dim
= &print_union_pw_aff_dim
;
3066 p
= isl_print_space(space
, p
, 0, &data
);
3067 isl_space_free(space
);
3072 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3074 * We currently only support an isl format.
3076 __isl_give isl_printer
*isl_printer_print_multi_union_pw_aff(
3077 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3080 return isl_printer_free(p
);
3082 if (p
->output_format
== ISL_FORMAT_ISL
)
3083 return print_multi_union_pw_aff_isl(p
, mupa
);
3084 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
3085 "unsupported output format", return isl_printer_free(p
));