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_constraint_private.h>
32 #include <isl/ast_build.h>
34 #include <isl_output_private.h>
36 #include <bset_to_bmap.c>
37 #include <set_to_map.c>
39 static const char *s_to
[2] = { " -> ", " \\to " };
40 static const char *s_and
[2] = { " and ", " \\wedge " };
41 static const char *s_or
[2] = { " or ", " \\vee " };
42 static const char *s_le
[2] = { "<=", "\\le" };
43 static const char *s_ge
[2] = { ">=", "\\ge" };
44 static const char *s_open_set
[2] = { "{ ", "\\{\\, " };
45 static const char *s_close_set
[2] = { " }", " \\,\\}" };
46 static const char *s_open_list
[2] = { "[", "(" };
47 static const char *s_close_list
[2] = { "]", ")" };
48 static const char *s_such_that
[2] = { " : ", " \\mid " };
49 static const char *s_open_exists
[2] = { "exists (", "\\exists \\, " };
50 static const char *s_close_exists
[2] = { ")", "" };
51 static const char *s_div_prefix
[2] = { "e", "\\alpha_" };
52 static const char *s_param_prefix
[2] = { "p", "p_" };
53 static const char *s_input_prefix
[2] = { "i", "i_" };
54 static const char *s_output_prefix
[2] = { "o", "o_" };
56 static __isl_give isl_printer
*print_constraint_polylib(
57 struct isl_basic_map
*bmap
, int ineq
, int n
, __isl_take isl_printer
*p
)
60 unsigned n_in
= isl_basic_map_dim(bmap
, isl_dim_in
);
61 unsigned n_out
= isl_basic_map_dim(bmap
, isl_dim_out
);
62 unsigned nparam
= isl_basic_map_dim(bmap
, isl_dim_param
);
63 isl_int
*c
= ineq
? bmap
->ineq
[n
] : bmap
->eq
[n
];
65 p
= isl_printer_start_line(p
);
66 p
= isl_printer_print_int(p
, ineq
);
67 for (i
= 0; i
< n_out
; ++i
) {
68 p
= isl_printer_print_str(p
, " ");
69 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+n_in
+i
]);
71 for (i
= 0; i
< n_in
; ++i
) {
72 p
= isl_printer_print_str(p
, " ");
73 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+i
]);
75 for (i
= 0; i
< bmap
->n_div
; ++i
) {
76 p
= isl_printer_print_str(p
, " ");
77 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+n_in
+n_out
+i
]);
79 for (i
= 0; i
< nparam
; ++i
) {
80 p
= isl_printer_print_str(p
, " ");
81 p
= isl_printer_print_isl_int(p
, c
[1+i
]);
83 p
= isl_printer_print_str(p
, " ");
84 p
= isl_printer_print_isl_int(p
, c
[0]);
85 p
= isl_printer_end_line(p
);
89 static __isl_give isl_printer
*print_constraints_polylib(
90 struct isl_basic_map
*bmap
, __isl_take isl_printer
*p
)
94 p
= isl_printer_set_isl_int_width(p
, 5);
96 for (i
= 0; i
< bmap
->n_eq
; ++i
)
97 p
= print_constraint_polylib(bmap
, 0, i
, p
);
98 for (i
= 0; i
< bmap
->n_ineq
; ++i
)
99 p
= print_constraint_polylib(bmap
, 1, i
, p
);
104 static __isl_give isl_printer
*bset_print_constraints_polylib(
105 struct isl_basic_set
*bset
, __isl_take isl_printer
*p
)
107 return print_constraints_polylib(bset_to_bmap(bset
), p
);
110 static __isl_give isl_printer
*isl_basic_map_print_polylib(
111 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
, int ext
)
113 unsigned total
= isl_basic_map_total_dim(bmap
);
114 p
= isl_printer_start_line(p
);
115 p
= isl_printer_print_int(p
, bmap
->n_eq
+ bmap
->n_ineq
);
116 p
= isl_printer_print_str(p
, " ");
117 p
= isl_printer_print_int(p
, 1 + total
+ 1);
119 p
= isl_printer_print_str(p
, " ");
120 p
= isl_printer_print_int(p
,
121 isl_basic_map_dim(bmap
, isl_dim_out
));
122 p
= isl_printer_print_str(p
, " ");
123 p
= isl_printer_print_int(p
,
124 isl_basic_map_dim(bmap
, isl_dim_in
));
125 p
= isl_printer_print_str(p
, " ");
126 p
= isl_printer_print_int(p
,
127 isl_basic_map_dim(bmap
, isl_dim_div
));
128 p
= isl_printer_print_str(p
, " ");
129 p
= isl_printer_print_int(p
,
130 isl_basic_map_dim(bmap
, isl_dim_param
));
132 p
= isl_printer_end_line(p
);
133 return print_constraints_polylib(bmap
, p
);
136 static __isl_give isl_printer
*isl_basic_set_print_polylib(
137 __isl_keep isl_basic_set
*bset
, __isl_take isl_printer
*p
, int ext
)
139 return isl_basic_map_print_polylib(bset_to_bmap(bset
), p
, ext
);
142 static __isl_give isl_printer
*isl_map_print_polylib(__isl_keep isl_map
*map
,
143 __isl_take isl_printer
*p
, int ext
)
147 p
= isl_printer_start_line(p
);
148 p
= isl_printer_print_int(p
, map
->n
);
149 p
= isl_printer_end_line(p
);
150 for (i
= 0; i
< map
->n
; ++i
) {
151 p
= isl_printer_start_line(p
);
152 p
= isl_printer_end_line(p
);
153 p
= isl_basic_map_print_polylib(map
->p
[i
], p
, ext
);
158 static __isl_give isl_printer
*isl_set_print_polylib(__isl_keep isl_set
*set
,
159 __isl_take isl_printer
*p
, int ext
)
161 return isl_map_print_polylib(set_to_map(set
), p
, ext
);
164 static int count_same_name(__isl_keep isl_space
*dim
,
165 enum isl_dim_type type
, unsigned pos
, const char *name
)
171 for (t
= isl_dim_param
; t
<= type
&& t
<= isl_dim_out
; ++t
) {
172 s
= t
== type
? pos
: isl_space_dim(dim
, t
);
173 for (p
= 0; p
< s
; ++p
) {
174 const char *n
= isl_space_get_dim_name(dim
, t
, p
);
175 if (n
&& !strcmp(n
, name
))
182 /* Print the name of the variable of type "type" and position "pos"
185 static __isl_give isl_printer
*print_name(__isl_keep isl_space
*space
,
186 __isl_take isl_printer
*p
, enum isl_dim_type type
, unsigned pos
,
193 name
= type
== isl_dim_div
? NULL
194 : isl_space_get_dim_name(space
, type
, pos
);
198 if (type
== isl_dim_param
)
199 prefix
= s_param_prefix
[latex
];
200 else if (type
== isl_dim_div
)
201 prefix
= s_div_prefix
[latex
];
202 else if (isl_space_is_set(space
) || type
== isl_dim_in
)
203 prefix
= s_input_prefix
[latex
];
205 prefix
= s_output_prefix
[latex
];
206 snprintf(buffer
, sizeof(buffer
), "%s%d", prefix
, pos
);
209 primes
= count_same_name(space
, name
== buffer
? isl_dim_div
: type
,
211 p
= isl_printer_print_str(p
, name
);
213 p
= isl_printer_print_str(p
, "'");
217 static enum isl_dim_type
pos2type(__isl_keep isl_space
*dim
, unsigned *pos
)
219 enum isl_dim_type type
;
220 unsigned n_in
= isl_space_dim(dim
, isl_dim_in
);
221 unsigned n_out
= isl_space_dim(dim
, isl_dim_out
);
222 unsigned nparam
= isl_space_dim(dim
, isl_dim_param
);
224 if (*pos
< 1 + nparam
) {
225 type
= isl_dim_param
;
227 } else if (*pos
< 1 + nparam
+ n_in
) {
230 } else if (*pos
< 1 + nparam
+ n_in
+ n_out
) {
232 *pos
-= 1 + nparam
+ n_in
;
235 *pos
-= 1 + nparam
+ n_in
+ n_out
;
241 /* Can the div expression of the integer division at position "row" of "div"
243 * In particular, are the div expressions available and does the selected
244 * variable have a known explicit representation?
245 * Furthermore, the Omega format does not allow any div expressions
248 static isl_bool
can_print_div_expr(__isl_keep isl_printer
*p
,
249 __isl_keep isl_mat
*div
, int pos
)
251 if (p
->output_format
== ISL_FORMAT_OMEGA
)
252 return isl_bool_false
;
254 return isl_bool_false
;
255 return !isl_int_is_zero(div
->row
[pos
][0]);
258 static __isl_give isl_printer
*print_div(__isl_keep isl_space
*dim
,
259 __isl_keep isl_mat
*div
, int pos
, __isl_take isl_printer
*p
);
261 static __isl_give isl_printer
*print_term(__isl_keep isl_space
*space
,
262 __isl_keep isl_mat
*div
,
263 isl_int c
, unsigned pos
, __isl_take isl_printer
*p
, int latex
)
265 enum isl_dim_type type
;
269 return isl_printer_print_isl_int(p
, c
);
271 type
= pos2type(space
, &pos
);
272 print_div_def
= type
== isl_dim_div
&& can_print_div_expr(p
, div
, pos
);
274 if (isl_int_is_one(c
))
276 else if (isl_int_is_negone(c
))
277 p
= isl_printer_print_str(p
, "-");
279 p
= isl_printer_print_isl_int(p
, c
);
280 if (p
->output_format
== ISL_FORMAT_C
|| print_div_def
)
281 p
= isl_printer_print_str(p
, "*");
284 p
= print_div(space
, div
, pos
, p
);
286 p
= print_name(space
, p
, type
, pos
, latex
);
290 static __isl_give isl_printer
*print_affine_of_len(__isl_keep isl_space
*dim
,
291 __isl_keep isl_mat
*div
,
292 __isl_take isl_printer
*p
, isl_int
*c
, int len
)
297 for (i
= 0, first
= 1; i
< len
; ++i
) {
299 if (isl_int_is_zero(c
[i
]))
302 if (isl_int_is_neg(c
[i
])) {
304 isl_int_neg(c
[i
], c
[i
]);
305 p
= isl_printer_print_str(p
, " - ");
307 p
= isl_printer_print_str(p
, " + ");
310 p
= print_term(dim
, div
, c
[i
], i
, p
, 0);
312 isl_int_neg(c
[i
], c
[i
]);
315 p
= isl_printer_print_str(p
, "0");
319 /* Print an affine expression "c" corresponding to a constraint in "bmap"
320 * to "p", with the variable names taken from "space" and
321 * the integer division definitions taken from "div".
323 static __isl_give isl_printer
*print_affine(__isl_keep isl_basic_map
*bmap
,
324 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
325 __isl_take isl_printer
*p
, isl_int
*c
)
327 unsigned len
= 1 + isl_basic_map_total_dim(bmap
);
328 return print_affine_of_len(space
, div
, p
, c
, len
);
331 /* offset is the offset of local_dim inside data->type of data->space.
333 static __isl_give isl_printer
*print_nested_var_list(__isl_take isl_printer
*p
,
334 __isl_keep isl_space
*local_dim
, enum isl_dim_type local_type
,
335 struct isl_print_space_data
*data
, int offset
)
339 if (data
->space
!= local_dim
&& local_type
== isl_dim_out
)
340 offset
+= local_dim
->n_in
;
342 for (i
= 0; i
< isl_space_dim(local_dim
, local_type
); ++i
) {
344 p
= isl_printer_print_str(p
, ", ");
346 p
= data
->print_dim(p
, data
, offset
+ i
);
348 p
= print_name(data
->space
, p
, data
->type
, offset
+ i
,
354 static __isl_give isl_printer
*print_var_list(__isl_take isl_printer
*p
,
355 __isl_keep isl_space
*space
, enum isl_dim_type type
)
357 struct isl_print_space_data data
= { .space
= space
, .type
= type
};
359 return print_nested_var_list(p
, space
, type
, &data
, 0);
362 static __isl_give isl_printer
*print_nested_map_dim(__isl_take isl_printer
*p
,
363 __isl_keep isl_space
*local_dim
,
364 struct isl_print_space_data
*data
, int offset
);
366 static __isl_give isl_printer
*print_nested_tuple(__isl_take isl_printer
*p
,
367 __isl_keep isl_space
*local_dim
, enum isl_dim_type local_type
,
368 struct isl_print_space_data
*data
, int offset
)
370 const char *name
= NULL
;
371 unsigned n
= isl_space_dim(local_dim
, local_type
);
372 if ((local_type
== isl_dim_in
|| local_type
== isl_dim_out
)) {
373 name
= isl_space_get_tuple_name(local_dim
, local_type
);
376 p
= isl_printer_print_str(p
, "\\mathrm{");
377 p
= isl_printer_print_str(p
, name
);
379 p
= isl_printer_print_str(p
, "}");
382 if (!data
->latex
|| n
!= 1 || name
)
383 p
= isl_printer_print_str(p
, s_open_list
[data
->latex
]);
384 if ((local_type
== isl_dim_in
|| local_type
== isl_dim_out
) &&
385 local_dim
->nested
[local_type
- isl_dim_in
]) {
386 if (data
->space
!= local_dim
&& local_type
== isl_dim_out
)
387 offset
+= local_dim
->n_in
;
388 p
= print_nested_map_dim(p
,
389 local_dim
->nested
[local_type
- isl_dim_in
],
392 p
= print_nested_var_list(p
, local_dim
, local_type
, data
,
394 if (!data
->latex
|| n
!= 1 || name
)
395 p
= isl_printer_print_str(p
, s_close_list
[data
->latex
]);
399 static __isl_give isl_printer
*print_tuple(__isl_keep isl_space
*dim
,
400 __isl_take isl_printer
*p
, enum isl_dim_type type
,
401 struct isl_print_space_data
*data
)
405 return print_nested_tuple(p
, dim
, type
, data
, 0);
408 static __isl_give isl_printer
*print_nested_map_dim(__isl_take isl_printer
*p
,
409 __isl_keep isl_space
*local_dim
,
410 struct isl_print_space_data
*data
, int offset
)
412 p
= print_nested_tuple(p
, local_dim
, isl_dim_in
, data
, offset
);
413 p
= isl_printer_print_str(p
, s_to
[data
->latex
]);
414 p
= print_nested_tuple(p
, local_dim
, isl_dim_out
, data
, offset
);
419 __isl_give isl_printer
*isl_print_space(__isl_keep isl_space
*space
,
420 __isl_take isl_printer
*p
, int rational
,
421 struct isl_print_space_data
*data
)
423 if (rational
&& !data
->latex
)
424 p
= isl_printer_print_str(p
, "rat: ");
425 if (isl_space_is_params(space
))
427 else if (isl_space_is_set(space
))
428 p
= print_tuple(space
, p
, isl_dim_set
, data
);
430 p
= print_tuple(space
, p
, isl_dim_in
, data
);
431 p
= isl_printer_print_str(p
, s_to
[data
->latex
]);
432 p
= print_tuple(space
, p
, isl_dim_out
, data
);
438 static __isl_give isl_printer
*print_omega_parameters(__isl_keep isl_space
*dim
,
439 __isl_take isl_printer
*p
)
441 if (isl_space_dim(dim
, isl_dim_param
) == 0)
444 p
= isl_printer_start_line(p
);
445 p
= isl_printer_print_str(p
, "symbolic ");
446 p
= print_var_list(p
, dim
, isl_dim_param
);
447 p
= isl_printer_print_str(p
, ";");
448 p
= isl_printer_end_line(p
);
452 /* Does the inequality constraint following "i" in "bmap"
453 * have an opposite value for the same last coefficient?
454 * "last" is the position of the last coefficient of inequality "i".
455 * If the next constraint is a div constraint, then it is ignored
456 * since div constraints are not printed.
458 static int next_is_opposite(__isl_keep isl_basic_map
*bmap
, int i
, int last
)
460 unsigned total
= isl_basic_map_total_dim(bmap
);
461 unsigned o_div
= isl_basic_map_offset(bmap
, isl_dim_div
);
463 if (i
+ 1 >= bmap
->n_ineq
)
465 if (isl_seq_last_non_zero(bmap
->ineq
[i
+ 1], 1 + total
) != last
)
469 is_div
= isl_basic_map_is_div_constraint(bmap
,
470 bmap
->ineq
[i
+ 1], last
- o_div
);
476 return isl_int_abs_eq(bmap
->ineq
[i
][last
], bmap
->ineq
[i
+ 1][last
]) &&
477 !isl_int_eq(bmap
->ineq
[i
][last
], bmap
->ineq
[i
+ 1][last
]);
480 /* Return a string representation of the operator used when
481 * printing a constraint where the LHS is greater than or equal to the LHS
482 * (sign > 0) or smaller than or equal to the LHS (sign < 0).
483 * If "strict" is set, then return the strict version of the comparison
486 static const char *constraint_op(int sign
, int strict
, int latex
)
489 return sign
< 0 ? "<" : ">";
496 /* Print one side of a constraint "c" from "bmap" to "p", with
497 * the variable names taken from "space" and the integer division definitions
499 * "last" is the position of the last non-zero coefficient.
500 * Let c' be the result of zeroing out this coefficient, then
501 * the partial constraint
506 * "first_constraint" is set if this is the first constraint
507 * in the conjunction.
509 static __isl_give isl_printer
*print_half_constraint(struct isl_basic_map
*bmap
,
510 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
511 __isl_take isl_printer
*p
, isl_int
*c
, int last
, const char *op
,
512 int first_constraint
, int latex
)
514 if (!first_constraint
)
515 p
= isl_printer_print_str(p
, s_and
[latex
]);
517 isl_int_set_si(c
[last
], 0);
518 p
= print_affine(bmap
, space
, div
, p
, c
);
520 p
= isl_printer_print_str(p
, " ");
521 p
= isl_printer_print_str(p
, op
);
522 p
= isl_printer_print_str(p
, " ");
527 /* Print a constraint "c" from "bmap" to "p", with the variable names
528 * taken from "space" and the integer division definitions taken from "div".
529 * "last" is the position of the last non-zero coefficient, which is
530 * moreover assumed to be negative.
531 * Let c' be the result of zeroing out this coefficient, then
532 * the constraint is printed in the form
536 * "first_constraint" is set if this is the first constraint
537 * in the conjunction.
539 static __isl_give isl_printer
*print_constraint(struct isl_basic_map
*bmap
,
540 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
541 __isl_take isl_printer
*p
,
542 isl_int
*c
, int last
, const char *op
, int first_constraint
, int latex
)
544 if (!first_constraint
)
545 p
= isl_printer_print_str(p
, s_and
[latex
]);
547 isl_int_abs(c
[last
], c
[last
]);
549 p
= print_term(space
, div
, c
[last
], last
, p
, latex
);
551 p
= isl_printer_print_str(p
, " ");
552 p
= isl_printer_print_str(p
, op
);
553 p
= isl_printer_print_str(p
, " ");
555 isl_int_set_si(c
[last
], 0);
556 p
= print_affine(bmap
, space
, div
, p
, c
);
561 /* Print the constraints of "bmap" to "p".
562 * The names of the variables are taken from "space" and
563 * the integer division definitions are taken from "div".
564 * Div constraints are only printed in "dump" mode.
565 * The constraints are sorted prior to printing (except in "dump" mode).
567 * If x is the last variable with a non-zero coefficient,
576 * while an upper bound
584 * If the next constraint has an opposite sign for the same last coefficient,
585 * then it is printed as
593 * instead. In fact, the "a x" part is not printed explicitly, but
594 * reused from the next constraint, which is therefore treated as
595 * a first constraint in the conjunction.
597 * If the constant term of "f" is -1, then "f" is replaced by "f + 1" and
598 * the comparison operator is replaced by the strict variant.
599 * Essentially, ">= 1" is replaced by "> 0".
601 static __isl_give isl_printer
*print_constraints(__isl_keep isl_basic_map
*bmap
,
602 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
603 __isl_take isl_printer
*p
, int latex
)
607 int rational
= ISL_F_ISSET(bmap
, ISL_BASIC_MAP_RATIONAL
);
608 unsigned total
= isl_basic_map_total_dim(bmap
);
609 unsigned o_div
= isl_basic_map_offset(bmap
, isl_dim_div
);
615 bmap
= isl_basic_map_copy(bmap
);
618 bmap
= isl_basic_map_sort_constraints(bmap
);
622 c
= isl_vec_alloc(bmap
->ctx
, 1 + total
);
626 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
627 int l
= isl_seq_last_non_zero(bmap
->eq
[i
], 1 + total
);
629 if (i
!= bmap
->n_eq
- 1)
630 p
= isl_printer_print_str(p
, s_and
[latex
]);
631 p
= isl_printer_print_str(p
, "0 = 0");
634 if (isl_int_is_neg(bmap
->eq
[i
][l
]))
635 isl_seq_cpy(c
->el
, bmap
->eq
[i
], 1 + total
);
637 isl_seq_neg(c
->el
, bmap
->eq
[i
], 1 + total
);
638 p
= print_constraint(bmap
, space
, div
, p
, c
->el
, l
,
642 for (i
= 0; i
< bmap
->n_ineq
; ++i
) {
643 int l
= isl_seq_last_non_zero(bmap
->ineq
[i
], 1 + total
);
649 if (!dump
&& l
>= o_div
&&
650 can_print_div_expr(p
, div
, l
- o_div
)) {
652 is_div
= isl_basic_map_is_div_constraint(bmap
,
653 bmap
->ineq
[i
], l
- o_div
);
659 s
= isl_int_sgn(bmap
->ineq
[i
][l
]);
660 strict
= !rational
&& isl_int_is_negone(bmap
->ineq
[i
][0]);
662 isl_seq_cpy(c
->el
, bmap
->ineq
[i
], 1 + total
);
664 isl_seq_neg(c
->el
, bmap
->ineq
[i
], 1 + total
);
666 isl_int_set_si(c
->el
[0], 0);
667 if (!dump
&& next_is_opposite(bmap
, i
, l
)) {
668 op
= constraint_op(-s
, strict
, latex
);
669 p
= print_half_constraint(bmap
, space
, div
, p
, c
->el
, l
,
673 op
= constraint_op(s
, strict
, latex
);
674 p
= print_constraint(bmap
, space
, div
, p
, c
->el
, l
,
680 isl_basic_map_free(bmap
);
685 isl_basic_map_free(bmap
);
691 static __isl_give isl_printer
*print_div(__isl_keep isl_space
*dim
,
692 __isl_keep isl_mat
*div
, int pos
, __isl_take isl_printer
*p
)
697 return isl_printer_free(p
);
699 c
= p
->output_format
== ISL_FORMAT_C
;
700 p
= isl_printer_print_str(p
, c
? "floord(" : "floor((");
701 p
= print_affine_of_len(dim
, div
, p
,
702 div
->row
[pos
] + 1, div
->n_col
- 1);
703 p
= isl_printer_print_str(p
, c
? ", " : ")/");
704 p
= isl_printer_print_isl_int(p
, div
->row
[pos
][0]);
705 p
= isl_printer_print_str(p
, ")");
709 /* Print a comma separated list of div names, except those that have
710 * a definition that can be printed.
711 * If "print_defined_divs" is set, then those div names are printed
712 * as well, along with their definitions.
714 static __isl_give isl_printer
*print_div_list(__isl_take isl_printer
*p
,
715 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, int latex
,
716 int print_defined_divs
)
722 if (!p
|| !space
|| !div
)
723 return isl_printer_free(p
);
725 n_div
= isl_mat_rows(div
);
727 for (i
= 0; i
< n_div
; ++i
) {
728 if (!print_defined_divs
&& can_print_div_expr(p
, div
, i
))
731 p
= isl_printer_print_str(p
, ", ");
732 p
= print_name(space
, p
, isl_dim_div
, i
, latex
);
734 if (!can_print_div_expr(p
, div
, i
))
736 p
= isl_printer_print_str(p
, " = ");
737 p
= print_div(space
, div
, i
, p
);
743 /* Does printing an object with local variables described by "div"
744 * require an "exists" clause?
745 * That is, are there any local variables without an explicit representation?
746 * An exists clause is also needed in "dump" mode because
747 * explicit div representations are not printed inline in that case.
749 static isl_bool
need_exists(__isl_keep isl_printer
*p
, __isl_keep isl_mat
*div
)
754 return isl_bool_error
;
755 n
= isl_mat_rows(div
);
757 return isl_bool_false
;
759 return isl_bool_true
;
760 for (i
= 0; i
< n
; ++i
)
761 if (!can_print_div_expr(p
, div
, i
))
762 return isl_bool_true
;
763 return isl_bool_false
;
766 /* Print the start of an exists clause, i.e.,
770 * In dump mode, local variables with an explicit definition are printed
771 * as well because they will not be printed inline.
773 static __isl_give isl_printer
*open_exists(__isl_take isl_printer
*p
,
774 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, int latex
)
782 p
= isl_printer_print_str(p
, s_open_exists
[latex
]);
783 p
= print_div_list(p
, space
, div
, latex
, dump
);
784 p
= isl_printer_print_str(p
, ": ");
789 /* Print the constraints of "bmap" to "p".
790 * The names of the variables are taken from "space".
791 * "latex" is set if the constraints should be printed in LaTeX format.
792 * Do not print inline explicit div representations in "dump" mode.
794 static __isl_give isl_printer
*print_disjunct(__isl_keep isl_basic_map
*bmap
,
795 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
804 div
= isl_basic_map_get_divs(bmap
);
805 exists
= need_exists(p
, div
);
806 if (exists
>= 0 && exists
)
807 p
= open_exists(p
, space
, div
, latex
);
810 div
= isl_mat_free(div
);
811 p
= print_constraints(bmap
, space
, div
, p
, latex
);
814 if (exists
>= 0 && exists
)
815 p
= isl_printer_print_str(p
, s_close_exists
[latex
]);
819 /* Print a colon followed by the constraints of "bmap"
820 * to "p", provided there are any constraints.
821 * The names of the variables are taken from "space".
822 * "latex" is set if the constraints should be printed in LaTeX format.
824 static __isl_give isl_printer
*print_optional_disjunct(
825 __isl_keep isl_basic_map
*bmap
, __isl_keep isl_space
*space
,
826 __isl_take isl_printer
*p
, int latex
)
828 if (isl_basic_map_plain_is_universe(bmap
))
831 p
= isl_printer_print_str(p
, ": ");
832 p
= print_disjunct(bmap
, space
, p
, latex
);
837 static __isl_give isl_printer
*basic_map_print_omega(
838 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
)
840 p
= isl_printer_print_str(p
, "{ [");
841 p
= print_var_list(p
, bmap
->dim
, isl_dim_in
);
842 p
= isl_printer_print_str(p
, "] -> [");
843 p
= print_var_list(p
, bmap
->dim
, isl_dim_out
);
844 p
= isl_printer_print_str(p
, "] ");
845 p
= print_optional_disjunct(bmap
, bmap
->dim
, p
, 0);
846 p
= isl_printer_print_str(p
, " }");
850 static __isl_give isl_printer
*basic_set_print_omega(
851 __isl_keep isl_basic_set
*bset
, __isl_take isl_printer
*p
)
853 p
= isl_printer_print_str(p
, "{ [");
854 p
= print_var_list(p
, bset
->dim
, isl_dim_set
);
855 p
= isl_printer_print_str(p
, "] ");
856 p
= print_optional_disjunct(bset
, bset
->dim
, p
, 0);
857 p
= isl_printer_print_str(p
, " }");
861 static __isl_give isl_printer
*isl_map_print_omega(__isl_keep isl_map
*map
,
862 __isl_take isl_printer
*p
)
866 for (i
= 0; i
< map
->n
; ++i
) {
868 p
= isl_printer_print_str(p
, " union ");
869 p
= basic_map_print_omega(map
->p
[i
], p
);
874 static __isl_give isl_printer
*isl_set_print_omega(__isl_keep isl_set
*set
,
875 __isl_take isl_printer
*p
)
879 for (i
= 0; i
< set
->n
; ++i
) {
881 p
= isl_printer_print_str(p
, " union ");
882 p
= basic_set_print_omega(set
->p
[i
], p
);
887 /* Print the list of parameters in "space", followed by an arrow, to "p",
888 * if there are any parameters.
890 static __isl_give isl_printer
*print_param_tuple(__isl_take isl_printer
*p
,
891 __isl_keep isl_space
*space
, struct isl_print_space_data
*data
)
894 return isl_printer_free(p
);
895 if (isl_space_dim(space
, isl_dim_param
) == 0)
898 p
= print_tuple(space
, p
, isl_dim_param
, data
);
899 p
= isl_printer_print_str(p
, s_to
[data
->latex
]);
904 static __isl_give isl_printer
*isl_basic_map_print_isl(
905 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
,
908 struct isl_print_space_data data
= { .latex
= latex
};
909 int rational
= ISL_F_ISSET(bmap
, ISL_BASIC_MAP_RATIONAL
);
911 p
= print_param_tuple(p
, bmap
->dim
, &data
);
912 p
= isl_printer_print_str(p
, "{ ");
913 p
= isl_print_space(bmap
->dim
, p
, rational
, &data
);
914 p
= isl_printer_print_str(p
, " : ");
915 p
= print_disjunct(bmap
, bmap
->dim
, p
, latex
);
916 p
= isl_printer_print_str(p
, " }");
920 /* Print the disjuncts of a map (or set) "map" to "p".
921 * The names of the variables are taken from "space".
922 * "latex" is set if the constraints should be printed in LaTeX format.
924 static __isl_give isl_printer
*print_disjuncts_core(__isl_keep isl_map
*map
,
925 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
930 p
= isl_printer_print_str(p
, "1 = 0");
931 for (i
= 0; i
< map
->n
; ++i
) {
933 p
= isl_printer_print_str(p
, s_or
[latex
]);
934 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
935 p
= isl_printer_print_str(p
, "(");
936 p
= print_disjunct(map
->p
[i
], space
, p
, latex
);
937 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
938 p
= isl_printer_print_str(p
, ")");
943 /* Print the disjuncts of a map (or set) "map" to "p".
944 * The names of the variables are taken from "space".
945 * "hull" describes constraints shared by all disjuncts of "map".
946 * "latex" is set if the constraints should be printed in LaTeX format.
948 * Print the disjuncts as a conjunction of "hull" and
949 * the result of removing the constraints of "hull" from "map".
950 * If this result turns out to be the universe, then simply print "hull".
952 static __isl_give isl_printer
*print_disjuncts_in_hull(__isl_keep isl_map
*map
,
953 __isl_keep isl_space
*space
, __isl_take isl_basic_map
*hull
,
954 __isl_take isl_printer
*p
, int latex
)
956 isl_bool is_universe
;
958 p
= print_disjunct(hull
, space
, p
, latex
);
959 map
= isl_map_plain_gist_basic_map(isl_map_copy(map
), hull
);
960 is_universe
= isl_map_plain_is_universe(map
);
964 p
= isl_printer_print_str(p
, s_and
[latex
]);
965 p
= isl_printer_print_str(p
, "(");
966 p
= print_disjuncts_core(map
, space
, p
, latex
);
967 p
= isl_printer_print_str(p
, ")");
978 /* Print the disjuncts of a map (or set) "map" to "p".
979 * The names of the variables are taken from "space".
980 * "latex" is set if the constraints should be printed in LaTeX format.
982 * If there are at least two disjuncts and "dump" mode is not turned out,
983 * check for any shared constraints among all disjuncts.
984 * If there are any, then print them separately in print_disjuncts_in_hull.
986 static __isl_give isl_printer
*print_disjuncts(__isl_keep isl_map
*map
,
987 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
989 if (isl_map_plain_is_universe(map
))
992 p
= isl_printer_print_str(p
, s_such_that
[latex
]);
996 if (!p
->dump
&& map
->n
>= 2) {
998 isl_bool is_universe
;
1000 hull
= isl_map_plain_unshifted_simple_hull(isl_map_copy(map
));
1001 is_universe
= isl_basic_map_plain_is_universe(hull
);
1002 if (is_universe
< 0)
1003 p
= isl_printer_free(p
);
1004 else if (!is_universe
)
1005 return print_disjuncts_in_hull(map
, space
, hull
,
1007 isl_basic_map_free(hull
);
1010 return print_disjuncts_core(map
, space
, p
, latex
);
1013 /* Print the disjuncts of a map (or set).
1014 * The names of the variables are taken from "space".
1015 * "latex" is set if the constraints should be printed in LaTeX format.
1017 * If the map turns out to be a universal parameter domain, then
1018 * we need to print the colon. Otherwise, the output looks identical
1021 static __isl_give isl_printer
*print_disjuncts_map(__isl_keep isl_map
*map
,
1022 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
1024 if (isl_map_plain_is_universe(map
) && isl_space_is_params(map
->dim
))
1025 return isl_printer_print_str(p
, s_such_that
[latex
]);
1027 return print_disjuncts(map
, space
, p
, latex
);
1030 struct isl_aff_split
{
1035 static void free_split(__isl_take
struct isl_aff_split
*split
, int n
)
1042 for (i
= 0; i
< n
; ++i
) {
1043 isl_basic_map_free(split
[i
].aff
);
1044 isl_map_free(split
[i
].map
);
1050 static __isl_give isl_basic_map
*get_aff(__isl_take isl_basic_map
*bmap
)
1053 unsigned nparam
, n_in
, n_out
, total
;
1055 bmap
= isl_basic_map_cow(bmap
);
1058 if (isl_basic_map_free_inequality(bmap
, bmap
->n_ineq
) < 0)
1061 nparam
= isl_basic_map_dim(bmap
, isl_dim_param
);
1062 n_in
= isl_basic_map_dim(bmap
, isl_dim_in
);
1063 n_out
= isl_basic_map_dim(bmap
, isl_dim_out
);
1064 total
= isl_basic_map_dim(bmap
, isl_dim_all
);
1065 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
1066 j
= isl_seq_last_non_zero(bmap
->eq
[i
] + 1, total
);
1067 if (j
>= nparam
&& j
< nparam
+ n_in
+ n_out
&&
1068 (isl_int_is_one(bmap
->eq
[i
][1 + j
]) ||
1069 isl_int_is_negone(bmap
->eq
[i
][1 + j
])))
1071 if (isl_basic_map_drop_equality(bmap
, i
) < 0)
1075 bmap
= isl_basic_map_finalize(bmap
);
1079 isl_basic_map_free(bmap
);
1083 static int aff_split_cmp(const void *p1
, const void *p2
, void *user
)
1085 const struct isl_aff_split
*s1
, *s2
;
1086 s1
= (const struct isl_aff_split
*) p1
;
1087 s2
= (const struct isl_aff_split
*) p2
;
1089 return isl_basic_map_plain_cmp(s1
->aff
, s2
->aff
);
1092 static __isl_give isl_basic_map
*drop_aff(__isl_take isl_basic_map
*bmap
,
1093 __isl_keep isl_basic_map
*aff
)
1101 total
= isl_space_dim(bmap
->dim
, isl_dim_all
);
1103 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
1104 if (isl_seq_first_non_zero(bmap
->eq
[i
] + 1 + total
,
1107 for (j
= 0; j
< aff
->n_eq
; ++j
) {
1108 if (!isl_seq_eq(bmap
->eq
[i
], aff
->eq
[j
], 1 + total
) &&
1109 !isl_seq_is_neg(bmap
->eq
[i
], aff
->eq
[j
], 1 + total
))
1111 if (isl_basic_map_drop_equality(bmap
, i
) < 0)
1119 isl_basic_map_free(bmap
);
1123 static __isl_give
struct isl_aff_split
*split_aff(__isl_keep isl_map
*map
)
1126 struct isl_aff_split
*split
;
1129 ctx
= isl_map_get_ctx(map
);
1130 split
= isl_calloc_array(ctx
, struct isl_aff_split
, map
->n
);
1134 for (i
= 0; i
< map
->n
; ++i
) {
1135 isl_basic_map
*bmap
;
1136 split
[i
].aff
= get_aff(isl_basic_map_copy(map
->p
[i
]));
1137 bmap
= isl_basic_map_copy(map
->p
[i
]);
1138 bmap
= isl_basic_map_cow(bmap
);
1139 bmap
= drop_aff(bmap
, split
[i
].aff
);
1140 split
[i
].map
= isl_map_from_basic_map(bmap
);
1141 if (!split
[i
].aff
|| !split
[i
].map
)
1145 if (isl_sort(split
, map
->n
, sizeof(struct isl_aff_split
),
1146 &aff_split_cmp
, NULL
) < 0)
1150 for (i
= n
- 1; i
>= 1; --i
) {
1151 if (!isl_basic_map_plain_is_equal(split
[i
- 1].aff
,
1154 isl_basic_map_free(split
[i
].aff
);
1155 split
[i
- 1].map
= isl_map_union(split
[i
- 1].map
,
1158 split
[i
] = split
[n
- 1];
1159 split
[n
- 1].aff
= NULL
;
1160 split
[n
- 1].map
= NULL
;
1166 free_split(split
, map
->n
);
1170 static int defining_equality(__isl_keep isl_basic_map
*eq
,
1171 __isl_keep isl_space
*dim
, enum isl_dim_type type
, int pos
)
1179 pos
+= isl_space_offset(dim
, type
);
1180 total
= isl_basic_map_total_dim(eq
);
1182 for (i
= 0; i
< eq
->n_eq
; ++i
) {
1183 if (isl_seq_last_non_zero(eq
->eq
[i
] + 1, total
) != pos
)
1185 if (isl_int_is_one(eq
->eq
[i
][1 + pos
]))
1186 isl_seq_neg(eq
->eq
[i
], eq
->eq
[i
], 1 + total
);
1193 /* Print dimension "pos" of data->space to "p".
1195 * data->user is assumed to be an isl_basic_map keeping track of equalities.
1197 * If the current dimension is defined by these equalities, then print
1198 * the corresponding expression, assigned to the name of the dimension
1199 * if there is any. Otherwise, print the name of the dimension.
1201 static __isl_give isl_printer
*print_dim_eq(__isl_take isl_printer
*p
,
1202 struct isl_print_space_data
*data
, unsigned pos
)
1204 isl_basic_map
*eq
= data
->user
;
1207 j
= defining_equality(eq
, data
->space
, data
->type
, pos
);
1209 if (isl_space_has_dim_name(data
->space
, data
->type
, pos
)) {
1210 p
= print_name(data
->space
, p
, data
->type
, pos
,
1212 p
= isl_printer_print_str(p
, " = ");
1214 pos
+= 1 + isl_space_offset(data
->space
, data
->type
);
1215 p
= print_affine_of_len(data
->space
, NULL
, p
, eq
->eq
[j
], pos
);
1217 p
= print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
1223 static __isl_give isl_printer
*print_split_map(__isl_take isl_printer
*p
,
1224 struct isl_aff_split
*split
, int n
, __isl_keep isl_space
*space
)
1226 struct isl_print_space_data data
= { 0 };
1230 data
.print_dim
= &print_dim_eq
;
1231 for (i
= 0; i
< n
; ++i
) {
1234 rational
= split
[i
].map
->n
> 0 &&
1235 ISL_F_ISSET(split
[i
].map
->p
[0], ISL_BASIC_MAP_RATIONAL
);
1237 p
= isl_printer_print_str(p
, "; ");
1238 data
.user
= split
[i
].aff
;
1239 p
= isl_print_space(space
, p
, rational
, &data
);
1240 p
= print_disjuncts_map(split
[i
].map
, space
, p
, 0);
1246 static __isl_give isl_printer
*isl_map_print_isl_body(__isl_keep isl_map
*map
,
1247 __isl_take isl_printer
*p
)
1249 struct isl_print_space_data data
= { 0 };
1250 struct isl_aff_split
*split
= NULL
;
1254 return isl_printer_free(p
);
1255 if (!p
->dump
&& map
->n
> 0)
1256 split
= split_aff(map
);
1258 p
= print_split_map(p
, split
, map
->n
, map
->dim
);
1260 rational
= map
->n
> 0 &&
1261 ISL_F_ISSET(map
->p
[0], ISL_BASIC_MAP_RATIONAL
);
1262 p
= isl_print_space(map
->dim
, p
, rational
, &data
);
1263 p
= print_disjuncts_map(map
, map
->dim
, p
, 0);
1265 free_split(split
, map
->n
);
1269 static __isl_give isl_printer
*isl_map_print_isl(__isl_keep isl_map
*map
,
1270 __isl_take isl_printer
*p
)
1272 struct isl_print_space_data data
= { 0 };
1274 p
= print_param_tuple(p
, map
->dim
, &data
);
1275 p
= isl_printer_print_str(p
, s_open_set
[0]);
1276 p
= isl_map_print_isl_body(map
, p
);
1277 p
= isl_printer_print_str(p
, s_close_set
[0]);
1281 static __isl_give isl_printer
*print_latex_map(__isl_keep isl_map
*map
,
1282 __isl_take isl_printer
*p
, __isl_keep isl_basic_map
*aff
)
1284 struct isl_print_space_data data
= { 0 };
1287 p
= print_param_tuple(p
, map
->dim
, &data
);
1288 p
= isl_printer_print_str(p
, s_open_set
[1]);
1289 data
.print_dim
= &print_dim_eq
;
1291 p
= isl_print_space(map
->dim
, p
, 0, &data
);
1292 p
= print_disjuncts_map(map
, map
->dim
, p
, 1);
1293 p
= isl_printer_print_str(p
, s_close_set
[1]);
1298 static __isl_give isl_printer
*isl_map_print_latex(__isl_keep isl_map
*map
,
1299 __isl_take isl_printer
*p
)
1302 struct isl_aff_split
*split
= NULL
;
1305 split
= split_aff(map
);
1308 return print_latex_map(map
, p
, NULL
);
1310 for (i
= 0; i
< map
->n
; ++i
) {
1314 p
= isl_printer_print_str(p
, " \\cup ");
1315 p
= print_latex_map(split
[i
].map
, p
, split
[i
].aff
);
1318 free_split(split
, map
->n
);
1322 __isl_give isl_printer
*isl_printer_print_basic_map(__isl_take isl_printer
*p
,
1323 __isl_keep isl_basic_map
*bmap
)
1327 if (p
->output_format
== ISL_FORMAT_ISL
)
1328 return isl_basic_map_print_isl(bmap
, p
, 0);
1329 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1330 return basic_map_print_omega(bmap
, p
);
1331 isl_assert(bmap
->ctx
, 0, goto error
);
1333 isl_printer_free(p
);
1337 __isl_give isl_printer
*isl_printer_print_basic_set(__isl_take isl_printer
*p
,
1338 __isl_keep isl_basic_set
*bset
)
1343 if (p
->output_format
== ISL_FORMAT_ISL
)
1344 return isl_basic_map_print_isl(bset
, p
, 0);
1345 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1346 return isl_basic_set_print_polylib(bset
, p
, 0);
1347 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1348 return isl_basic_set_print_polylib(bset
, p
, 1);
1349 else if (p
->output_format
== ISL_FORMAT_POLYLIB_CONSTRAINTS
)
1350 return bset_print_constraints_polylib(bset
, p
);
1351 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1352 return basic_set_print_omega(bset
, p
);
1353 isl_assert(p
->ctx
, 0, goto error
);
1355 isl_printer_free(p
);
1359 __isl_give isl_printer
*isl_printer_print_set(__isl_take isl_printer
*p
,
1360 __isl_keep isl_set
*set
)
1364 if (p
->output_format
== ISL_FORMAT_ISL
)
1365 return isl_map_print_isl(set_to_map(set
), p
);
1366 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1367 return isl_set_print_polylib(set
, p
, 0);
1368 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1369 return isl_set_print_polylib(set
, p
, 1);
1370 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1371 return isl_set_print_omega(set
, p
);
1372 else if (p
->output_format
== ISL_FORMAT_LATEX
)
1373 return isl_map_print_latex(set_to_map(set
), p
);
1374 isl_assert(set
->ctx
, 0, goto error
);
1376 isl_printer_free(p
);
1380 __isl_give isl_printer
*isl_printer_print_map(__isl_take isl_printer
*p
,
1381 __isl_keep isl_map
*map
)
1386 if (p
->output_format
== ISL_FORMAT_ISL
)
1387 return isl_map_print_isl(map
, p
);
1388 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1389 return isl_map_print_polylib(map
, p
, 0);
1390 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1391 return isl_map_print_polylib(map
, p
, 1);
1392 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1393 return isl_map_print_omega(map
, p
);
1394 else if (p
->output_format
== ISL_FORMAT_LATEX
)
1395 return isl_map_print_latex(map
, p
);
1396 isl_assert(map
->ctx
, 0, goto error
);
1398 isl_printer_free(p
);
1402 struct isl_union_print_data
{
1407 static isl_stat
print_map_body(__isl_take isl_map
*map
, void *user
)
1409 struct isl_union_print_data
*data
;
1410 data
= (struct isl_union_print_data
*)user
;
1413 data
->p
= isl_printer_print_str(data
->p
, "; ");
1416 data
->p
= isl_map_print_isl_body(map
, data
->p
);
1422 static __isl_give isl_printer
*isl_union_map_print_isl(
1423 __isl_keep isl_union_map
*umap
, __isl_take isl_printer
*p
)
1425 struct isl_union_print_data data
;
1426 struct isl_print_space_data space_data
= { 0 };
1429 space
= isl_union_map_get_space(umap
);
1430 p
= print_param_tuple(p
, space
, &space_data
);
1431 isl_space_free(space
);
1432 p
= isl_printer_print_str(p
, s_open_set
[0]);
1435 isl_union_map_foreach_map(umap
, &print_map_body
, &data
);
1437 p
= isl_printer_print_str(p
, s_close_set
[0]);
1441 static isl_stat
print_latex_map_body(__isl_take isl_map
*map
, void *user
)
1443 struct isl_union_print_data
*data
;
1444 data
= (struct isl_union_print_data
*)user
;
1447 data
->p
= isl_printer_print_str(data
->p
, " \\cup ");
1450 data
->p
= isl_map_print_latex(map
, data
->p
);
1456 static __isl_give isl_printer
*isl_union_map_print_latex(
1457 __isl_keep isl_union_map
*umap
, __isl_take isl_printer
*p
)
1459 struct isl_union_print_data data
= { p
, 1 };
1460 isl_union_map_foreach_map(umap
, &print_latex_map_body
, &data
);
1465 __isl_give isl_printer
*isl_printer_print_union_map(__isl_take isl_printer
*p
,
1466 __isl_keep isl_union_map
*umap
)
1471 if (p
->output_format
== ISL_FORMAT_ISL
)
1472 return isl_union_map_print_isl(umap
, p
);
1473 if (p
->output_format
== ISL_FORMAT_LATEX
)
1474 return isl_union_map_print_latex(umap
, p
);
1476 isl_die(p
->ctx
, isl_error_invalid
,
1477 "invalid output format for isl_union_map", goto error
);
1479 isl_printer_free(p
);
1483 __isl_give isl_printer
*isl_printer_print_union_set(__isl_take isl_printer
*p
,
1484 __isl_keep isl_union_set
*uset
)
1489 if (p
->output_format
== ISL_FORMAT_ISL
)
1490 return isl_union_map_print_isl((isl_union_map
*)uset
, p
);
1491 if (p
->output_format
== ISL_FORMAT_LATEX
)
1492 return isl_union_map_print_latex((isl_union_map
*)uset
, p
);
1494 isl_die(p
->ctx
, isl_error_invalid
,
1495 "invalid output format for isl_union_set", goto error
);
1497 isl_printer_free(p
);
1501 static int upoly_rec_n_non_zero(__isl_keep
struct isl_upoly_rec
*rec
)
1506 for (i
= 0, n
= 0; i
< rec
->n
; ++i
)
1507 if (!isl_upoly_is_zero(rec
->p
[i
]))
1513 static __isl_give isl_printer
*upoly_print_cst(__isl_keep
struct isl_upoly
*up
,
1514 __isl_take isl_printer
*p
, int first
)
1516 struct isl_upoly_cst
*cst
;
1519 cst
= isl_upoly_as_cst(up
);
1522 neg
= !first
&& isl_int_is_neg(cst
->n
);
1524 p
= isl_printer_print_str(p
, neg
? " - " : " + ");
1526 isl_int_neg(cst
->n
, cst
->n
);
1527 if (isl_int_is_zero(cst
->d
)) {
1528 int sgn
= isl_int_sgn(cst
->n
);
1529 p
= isl_printer_print_str(p
, sgn
< 0 ? "-infty" :
1530 sgn
== 0 ? "NaN" : "infty");
1532 p
= isl_printer_print_isl_int(p
, cst
->n
);
1534 isl_int_neg(cst
->n
, cst
->n
);
1535 if (!isl_int_is_zero(cst
->d
) && !isl_int_is_one(cst
->d
)) {
1536 p
= isl_printer_print_str(p
, "/");
1537 p
= isl_printer_print_isl_int(p
, cst
->d
);
1541 isl_printer_free(p
);
1545 static __isl_give isl_printer
*print_base(__isl_take isl_printer
*p
,
1546 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
, int var
)
1550 total
= isl_space_dim(dim
, isl_dim_all
);
1552 p
= print_term(dim
, NULL
, dim
->ctx
->one
, 1 + var
, p
, 0);
1554 p
= print_div(dim
, div
, var
- total
, p
);
1558 static __isl_give isl_printer
*print_pow(__isl_take isl_printer
*p
,
1559 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
, int var
, int exp
)
1561 p
= print_base(p
, dim
, div
, var
);
1564 if (p
->output_format
== ISL_FORMAT_C
) {
1566 for (i
= 1; i
< exp
; ++i
) {
1567 p
= isl_printer_print_str(p
, "*");
1568 p
= print_base(p
, dim
, div
, var
);
1571 p
= isl_printer_print_str(p
, "^");
1572 p
= isl_printer_print_int(p
, exp
);
1577 static __isl_give isl_printer
*upoly_print(__isl_keep
struct isl_upoly
*up
,
1578 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
,
1579 __isl_take isl_printer
*p
, int outer
)
1581 int i
, n
, first
, print_parens
;
1582 struct isl_upoly_rec
*rec
;
1584 if (!p
|| !up
|| !dim
|| !div
)
1587 if (isl_upoly_is_cst(up
))
1588 return upoly_print_cst(up
, p
, 1);
1590 rec
= isl_upoly_as_rec(up
);
1593 n
= upoly_rec_n_non_zero(rec
);
1594 print_parens
= n
> 1 ||
1595 (outer
&& rec
->up
.var
>= isl_space_dim(dim
, isl_dim_all
));
1597 p
= isl_printer_print_str(p
, "(");
1598 for (i
= 0, first
= 1; i
< rec
->n
; ++i
) {
1599 if (isl_upoly_is_zero(rec
->p
[i
]))
1601 if (isl_upoly_is_negone(rec
->p
[i
])) {
1603 p
= isl_printer_print_str(p
, "-1");
1605 p
= isl_printer_print_str(p
, "-");
1607 p
= isl_printer_print_str(p
, " - ");
1608 } else if (isl_upoly_is_cst(rec
->p
[i
]) &&
1609 !isl_upoly_is_one(rec
->p
[i
]))
1610 p
= upoly_print_cst(rec
->p
[i
], p
, first
);
1613 p
= isl_printer_print_str(p
, " + ");
1614 if (i
== 0 || !isl_upoly_is_one(rec
->p
[i
]))
1615 p
= upoly_print(rec
->p
[i
], dim
, div
, p
, 0);
1620 if (!isl_upoly_is_one(rec
->p
[i
]) &&
1621 !isl_upoly_is_negone(rec
->p
[i
]))
1622 p
= isl_printer_print_str(p
, " * ");
1623 p
= print_pow(p
, dim
, div
, rec
->up
.var
, i
);
1626 p
= isl_printer_print_str(p
, ")");
1629 isl_printer_free(p
);
1633 static __isl_give isl_printer
*print_qpolynomial(__isl_take isl_printer
*p
,
1634 __isl_keep isl_qpolynomial
*qp
)
1638 p
= upoly_print(qp
->upoly
, qp
->dim
, qp
->div
, p
, 1);
1641 isl_printer_free(p
);
1645 static __isl_give isl_printer
*print_qpolynomial_isl(__isl_take isl_printer
*p
,
1646 __isl_keep isl_qpolynomial
*qp
)
1648 struct isl_print_space_data data
= { 0 };
1653 p
= print_param_tuple(p
, qp
->dim
, &data
);
1654 p
= isl_printer_print_str(p
, "{ ");
1655 if (!isl_space_is_params(qp
->dim
)) {
1656 p
= isl_print_space(qp
->dim
, p
, 0, &data
);
1657 p
= isl_printer_print_str(p
, " -> ");
1659 p
= print_qpolynomial(p
, qp
);
1660 p
= isl_printer_print_str(p
, " }");
1663 isl_printer_free(p
);
1667 static __isl_give isl_printer
*print_qpolynomial_c(__isl_take isl_printer
*p
,
1668 __isl_keep isl_space
*dim
, __isl_keep isl_qpolynomial
*qp
)
1673 isl_qpolynomial_get_den(qp
, &den
);
1674 if (!isl_int_is_one(den
)) {
1676 p
= isl_printer_print_str(p
, "(");
1677 qp
= isl_qpolynomial_copy(qp
);
1678 f
= isl_qpolynomial_rat_cst_on_domain(isl_space_copy(qp
->dim
),
1679 den
, qp
->dim
->ctx
->one
);
1680 qp
= isl_qpolynomial_mul(qp
, f
);
1683 p
= upoly_print(qp
->upoly
, dim
, qp
->div
, p
, 0);
1685 p
= isl_printer_free(p
);
1686 if (!isl_int_is_one(den
)) {
1687 p
= isl_printer_print_str(p
, ")/");
1688 p
= isl_printer_print_isl_int(p
, den
);
1689 isl_qpolynomial_free(qp
);
1695 __isl_give isl_printer
*isl_printer_print_qpolynomial(
1696 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial
*qp
)
1701 if (p
->output_format
== ISL_FORMAT_ISL
)
1702 return print_qpolynomial_isl(p
, qp
);
1703 else if (p
->output_format
== ISL_FORMAT_C
)
1704 return print_qpolynomial_c(p
, qp
->dim
, qp
);
1706 isl_die(qp
->dim
->ctx
, isl_error_unsupported
,
1707 "output format not supported for isl_qpolynomials",
1710 isl_printer_free(p
);
1714 void isl_qpolynomial_print(__isl_keep isl_qpolynomial
*qp
, FILE *out
,
1715 unsigned output_format
)
1722 isl_assert(qp
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
1723 p
= isl_printer_to_file(qp
->dim
->ctx
, out
);
1724 p
= isl_printer_print_qpolynomial(p
, qp
);
1725 isl_printer_free(p
);
1728 static __isl_give isl_printer
*qpolynomial_fold_print(
1729 __isl_keep isl_qpolynomial_fold
*fold
, __isl_take isl_printer
*p
)
1733 if (fold
->type
== isl_fold_min
)
1734 p
= isl_printer_print_str(p
, "min");
1735 else if (fold
->type
== isl_fold_max
)
1736 p
= isl_printer_print_str(p
, "max");
1737 p
= isl_printer_print_str(p
, "(");
1738 for (i
= 0; i
< fold
->n
; ++i
) {
1740 p
= isl_printer_print_str(p
, ", ");
1741 p
= print_qpolynomial(p
, fold
->qp
[i
]);
1743 p
= isl_printer_print_str(p
, ")");
1747 void isl_qpolynomial_fold_print(__isl_keep isl_qpolynomial_fold
*fold
,
1748 FILE *out
, unsigned output_format
)
1755 isl_assert(fold
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
1757 p
= isl_printer_to_file(fold
->dim
->ctx
, out
);
1758 p
= isl_printer_print_qpolynomial_fold(p
, fold
);
1760 isl_printer_free(p
);
1763 static __isl_give isl_printer
*isl_pwqp_print_isl_body(
1764 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
1766 struct isl_print_space_data data
= { 0 };
1769 for (i
= 0; i
< pwqp
->n
; ++i
) {
1773 p
= isl_printer_print_str(p
, "; ");
1774 space
= isl_qpolynomial_get_domain_space(pwqp
->p
[i
].qp
);
1775 if (!isl_space_is_params(space
)) {
1776 p
= isl_print_space(space
, p
, 0, &data
);
1777 p
= isl_printer_print_str(p
, " -> ");
1779 p
= print_qpolynomial(p
, pwqp
->p
[i
].qp
);
1780 p
= print_disjuncts(set_to_map(pwqp
->p
[i
].set
), space
, p
, 0);
1781 isl_space_free(space
);
1787 static __isl_give isl_printer
*print_pw_qpolynomial_isl(
1788 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
1790 struct isl_print_space_data data
= { 0 };
1795 p
= print_param_tuple(p
, pwqp
->dim
, &data
);
1796 p
= isl_printer_print_str(p
, "{ ");
1798 if (!isl_space_is_set(pwqp
->dim
)) {
1799 p
= print_tuple(pwqp
->dim
, p
, isl_dim_in
, &data
);
1800 p
= isl_printer_print_str(p
, " -> ");
1802 p
= isl_printer_print_str(p
, "0");
1804 p
= isl_pwqp_print_isl_body(p
, pwqp
);
1805 p
= isl_printer_print_str(p
, " }");
1808 isl_printer_free(p
);
1812 void isl_pw_qpolynomial_print(__isl_keep isl_pw_qpolynomial
*pwqp
, FILE *out
,
1813 unsigned output_format
)
1820 p
= isl_printer_to_file(pwqp
->dim
->ctx
, out
);
1821 p
= isl_printer_set_output_format(p
, output_format
);
1822 p
= isl_printer_print_pw_qpolynomial(p
, pwqp
);
1824 isl_printer_free(p
);
1827 static __isl_give isl_printer
*isl_pwf_print_isl_body(
1828 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
1830 struct isl_print_space_data data
= { 0 };
1833 for (i
= 0; i
< pwf
->n
; ++i
) {
1837 p
= isl_printer_print_str(p
, "; ");
1838 space
= isl_qpolynomial_fold_get_domain_space(pwf
->p
[i
].fold
);
1839 if (!isl_space_is_params(space
)) {
1840 p
= isl_print_space(space
, p
, 0, &data
);
1841 p
= isl_printer_print_str(p
, " -> ");
1843 p
= qpolynomial_fold_print(pwf
->p
[i
].fold
, p
);
1844 p
= print_disjuncts(set_to_map(pwf
->p
[i
].set
), space
, p
, 0);
1845 isl_space_free(space
);
1851 static __isl_give isl_printer
*print_pw_qpolynomial_fold_isl(
1852 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
1854 struct isl_print_space_data data
= { 0 };
1856 p
= print_param_tuple(p
, pwf
->dim
, &data
);
1857 p
= isl_printer_print_str(p
, "{ ");
1859 if (!isl_space_is_set(pwf
->dim
)) {
1860 p
= print_tuple(pwf
->dim
, p
, isl_dim_in
, &data
);
1861 p
= isl_printer_print_str(p
, " -> ");
1863 p
= isl_printer_print_str(p
, "0");
1865 p
= isl_pwf_print_isl_body(p
, pwf
);
1866 p
= isl_printer_print_str(p
, " }");
1870 static __isl_give isl_printer
*print_affine_c(__isl_take isl_printer
*p
,
1871 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
, isl_int
*c
);
1873 static __isl_give isl_printer
*print_name_c(__isl_take isl_printer
*p
,
1874 __isl_keep isl_space
*dim
,
1875 __isl_keep isl_basic_set
*bset
, enum isl_dim_type type
, unsigned pos
)
1877 if (type
== isl_dim_div
) {
1878 p
= isl_printer_print_str(p
, "floord(");
1879 p
= print_affine_c(p
, dim
, bset
, bset
->div
[pos
] + 1);
1880 p
= isl_printer_print_str(p
, ", ");
1881 p
= isl_printer_print_isl_int(p
, bset
->div
[pos
][0]);
1882 p
= isl_printer_print_str(p
, ")");
1886 name
= isl_space_get_dim_name(dim
, type
, pos
);
1889 p
= isl_printer_print_str(p
, name
);
1894 static __isl_give isl_printer
*print_term_c(__isl_take isl_printer
*p
,
1895 __isl_keep isl_space
*dim
,
1896 __isl_keep isl_basic_set
*bset
, isl_int c
, unsigned pos
)
1898 enum isl_dim_type type
;
1901 return isl_printer_print_isl_int(p
, c
);
1903 if (isl_int_is_one(c
))
1905 else if (isl_int_is_negone(c
))
1906 p
= isl_printer_print_str(p
, "-");
1908 p
= isl_printer_print_isl_int(p
, c
);
1909 p
= isl_printer_print_str(p
, "*");
1911 type
= pos2type(dim
, &pos
);
1912 p
= print_name_c(p
, dim
, bset
, type
, pos
);
1916 static __isl_give isl_printer
*print_partial_affine_c(__isl_take isl_printer
*p
,
1917 __isl_keep isl_space
*dim
,
1918 __isl_keep isl_basic_set
*bset
, isl_int
*c
, unsigned len
)
1923 for (i
= 0, first
= 1; i
< len
; ++i
) {
1925 if (isl_int_is_zero(c
[i
]))
1928 if (isl_int_is_neg(c
[i
])) {
1930 isl_int_neg(c
[i
], c
[i
]);
1931 p
= isl_printer_print_str(p
, " - ");
1933 p
= isl_printer_print_str(p
, " + ");
1936 p
= print_term_c(p
, dim
, bset
, c
[i
], i
);
1938 isl_int_neg(c
[i
], c
[i
]);
1941 p
= isl_printer_print_str(p
, "0");
1945 static __isl_give isl_printer
*print_affine_c(__isl_take isl_printer
*p
,
1946 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
, isl_int
*c
)
1948 unsigned len
= 1 + isl_basic_set_total_dim(bset
);
1949 return print_partial_affine_c(p
, dim
, bset
, c
, len
);
1952 /* We skip the constraint if it is implied by the div expression.
1954 * *first indicates whether this is the first constraint in the conjunction and
1955 * is updated if the constraint is actually printed.
1957 static __isl_give isl_printer
*print_constraint_c(__isl_take isl_printer
*p
,
1958 __isl_keep isl_space
*dim
,
1959 __isl_keep isl_basic_set
*bset
, isl_int
*c
, const char *op
, int *first
)
1965 o_div
= isl_basic_set_offset(bset
, isl_dim_div
);
1966 n_div
= isl_basic_set_dim(bset
, isl_dim_div
);
1967 div
= isl_seq_last_non_zero(c
+ o_div
, n_div
);
1969 isl_bool is_div
= isl_basic_set_is_div_constraint(bset
, c
, div
);
1971 return isl_printer_free(p
);
1977 p
= isl_printer_print_str(p
, " && ");
1979 p
= print_affine_c(p
, dim
, bset
, c
);
1980 p
= isl_printer_print_str(p
, " ");
1981 p
= isl_printer_print_str(p
, op
);
1982 p
= isl_printer_print_str(p
, " 0");
1989 static __isl_give isl_printer
*print_basic_set_c(__isl_take isl_printer
*p
,
1990 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
)
1994 unsigned n_div
= isl_basic_set_dim(bset
, isl_dim_div
);
1995 unsigned total
= isl_basic_set_total_dim(bset
) - n_div
;
1997 for (i
= 0; i
< bset
->n_eq
; ++i
) {
1998 j
= isl_seq_last_non_zero(bset
->eq
[i
] + 1 + total
, n_div
);
2000 p
= print_constraint_c(p
, dim
, bset
,
2001 bset
->eq
[i
], "==", &first
);
2004 p
= isl_printer_print_str(p
, " && ");
2005 p
= isl_printer_print_str(p
, "(");
2006 p
= print_partial_affine_c(p
, dim
, bset
, bset
->eq
[i
],
2008 p
= isl_printer_print_str(p
, ") % ");
2009 p
= isl_printer_print_isl_int(p
,
2010 bset
->eq
[i
][1 + total
+ j
]);
2011 p
= isl_printer_print_str(p
, " == 0");
2015 for (i
= 0; i
< bset
->n_ineq
; ++i
)
2016 p
= print_constraint_c(p
, dim
, bset
, bset
->ineq
[i
], ">=",
2021 static __isl_give isl_printer
*print_set_c(__isl_take isl_printer
*p
,
2022 __isl_keep isl_space
*dim
, __isl_keep isl_set
*set
)
2027 return isl_printer_free(p
);
2030 p
= isl_printer_print_str(p
, "0");
2032 for (i
= 0; i
< set
->n
; ++i
) {
2034 p
= isl_printer_print_str(p
, " || ");
2036 p
= isl_printer_print_str(p
, "(");
2037 p
= print_basic_set_c(p
, dim
, set
->p
[i
]);
2039 p
= isl_printer_print_str(p
, ")");
2044 static __isl_give isl_printer
*print_pw_qpolynomial_c(
2045 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2049 if (pwqp
->n
== 1 && isl_set_plain_is_universe(pwqp
->p
[0].set
))
2050 return print_qpolynomial_c(p
, pwqp
->dim
, pwqp
->p
[0].qp
);
2052 for (i
= 0; i
< pwqp
->n
; ++i
) {
2053 p
= isl_printer_print_str(p
, "(");
2054 p
= print_set_c(p
, pwqp
->dim
, pwqp
->p
[i
].set
);
2055 p
= isl_printer_print_str(p
, ") ? (");
2056 p
= print_qpolynomial_c(p
, pwqp
->dim
, pwqp
->p
[i
].qp
);
2057 p
= isl_printer_print_str(p
, ") : ");
2060 p
= isl_printer_print_str(p
, "0");
2064 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial(
2065 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2070 if (p
->output_format
== ISL_FORMAT_ISL
)
2071 return print_pw_qpolynomial_isl(p
, pwqp
);
2072 else if (p
->output_format
== ISL_FORMAT_C
)
2073 return print_pw_qpolynomial_c(p
, pwqp
);
2074 isl_assert(p
->ctx
, 0, goto error
);
2076 isl_printer_free(p
);
2080 static isl_stat
print_pwqp_body(__isl_take isl_pw_qpolynomial
*pwqp
, void *user
)
2082 struct isl_union_print_data
*data
;
2083 data
= (struct isl_union_print_data
*)user
;
2086 data
->p
= isl_printer_print_str(data
->p
, "; ");
2089 data
->p
= isl_pwqp_print_isl_body(data
->p
, pwqp
);
2090 isl_pw_qpolynomial_free(pwqp
);
2095 static __isl_give isl_printer
*print_union_pw_qpolynomial_isl(
2096 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2098 struct isl_union_print_data data
;
2099 struct isl_print_space_data space_data
= { 0 };
2102 space
= isl_union_pw_qpolynomial_get_space(upwqp
);
2103 p
= print_param_tuple(p
, space
, &space_data
);
2104 isl_space_free(space
);
2105 p
= isl_printer_print_str(p
, "{ ");
2108 isl_union_pw_qpolynomial_foreach_pw_qpolynomial(upwqp
, &print_pwqp_body
,
2111 p
= isl_printer_print_str(p
, " }");
2115 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial(
2116 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2121 if (p
->output_format
== ISL_FORMAT_ISL
)
2122 return print_union_pw_qpolynomial_isl(p
, upwqp
);
2123 isl_die(p
->ctx
, isl_error_invalid
,
2124 "invalid output format for isl_union_pw_qpolynomial",
2127 isl_printer_free(p
);
2131 static __isl_give isl_printer
*print_qpolynomial_fold_c(
2132 __isl_take isl_printer
*p
, __isl_keep isl_space
*dim
,
2133 __isl_keep isl_qpolynomial_fold
*fold
)
2137 for (i
= 0; i
< fold
->n
- 1; ++i
)
2138 if (fold
->type
== isl_fold_min
)
2139 p
= isl_printer_print_str(p
, "min(");
2140 else if (fold
->type
== isl_fold_max
)
2141 p
= isl_printer_print_str(p
, "max(");
2143 for (i
= 0; i
< fold
->n
; ++i
) {
2145 p
= isl_printer_print_str(p
, ", ");
2146 p
= print_qpolynomial_c(p
, dim
, fold
->qp
[i
]);
2148 p
= isl_printer_print_str(p
, ")");
2153 __isl_give isl_printer
*isl_printer_print_qpolynomial_fold(
2154 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial_fold
*fold
)
2158 if (p
->output_format
== ISL_FORMAT_ISL
)
2159 return qpolynomial_fold_print(fold
, p
);
2160 else if (p
->output_format
== ISL_FORMAT_C
)
2161 return print_qpolynomial_fold_c(p
, fold
->dim
, fold
);
2162 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2165 isl_printer_free(p
);
2169 static __isl_give isl_printer
*print_pw_qpolynomial_fold_c(
2170 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2174 if (pwf
->n
== 1 && isl_set_plain_is_universe(pwf
->p
[0].set
))
2175 return print_qpolynomial_fold_c(p
, pwf
->dim
, pwf
->p
[0].fold
);
2177 for (i
= 0; i
< pwf
->n
; ++i
) {
2178 p
= isl_printer_print_str(p
, "(");
2179 p
= print_set_c(p
, pwf
->dim
, pwf
->p
[i
].set
);
2180 p
= isl_printer_print_str(p
, ") ? (");
2181 p
= print_qpolynomial_fold_c(p
, pwf
->dim
, pwf
->p
[i
].fold
);
2182 p
= isl_printer_print_str(p
, ") : ");
2185 p
= isl_printer_print_str(p
, "0");
2189 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial_fold(
2190 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2195 if (p
->output_format
== ISL_FORMAT_ISL
)
2196 return print_pw_qpolynomial_fold_isl(p
, pwf
);
2197 else if (p
->output_format
== ISL_FORMAT_C
)
2198 return print_pw_qpolynomial_fold_c(p
, pwf
);
2199 isl_assert(p
->ctx
, 0, goto error
);
2201 isl_printer_free(p
);
2205 void isl_pw_qpolynomial_fold_print(__isl_keep isl_pw_qpolynomial_fold
*pwf
,
2206 FILE *out
, unsigned output_format
)
2213 p
= isl_printer_to_file(pwf
->dim
->ctx
, out
);
2214 p
= isl_printer_set_output_format(p
, output_format
);
2215 p
= isl_printer_print_pw_qpolynomial_fold(p
, pwf
);
2217 isl_printer_free(p
);
2220 static isl_stat
print_pwf_body(__isl_take isl_pw_qpolynomial_fold
*pwf
,
2223 struct isl_union_print_data
*data
;
2224 data
= (struct isl_union_print_data
*)user
;
2227 data
->p
= isl_printer_print_str(data
->p
, "; ");
2230 data
->p
= isl_pwf_print_isl_body(data
->p
, pwf
);
2231 isl_pw_qpolynomial_fold_free(pwf
);
2236 static __isl_give isl_printer
*print_union_pw_qpolynomial_fold_isl(
2237 __isl_take isl_printer
*p
,
2238 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2240 struct isl_union_print_data data
;
2241 struct isl_print_space_data space_data
= { 0 };
2244 space
= isl_union_pw_qpolynomial_fold_get_space(upwf
);
2245 p
= print_param_tuple(p
, space
, &space_data
);
2246 isl_space_free(space
);
2247 p
= isl_printer_print_str(p
, "{ ");
2250 isl_union_pw_qpolynomial_fold_foreach_pw_qpolynomial_fold(upwf
,
2251 &print_pwf_body
, &data
);
2253 p
= isl_printer_print_str(p
, " }");
2257 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial_fold(
2258 __isl_take isl_printer
*p
,
2259 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2264 if (p
->output_format
== ISL_FORMAT_ISL
)
2265 return print_union_pw_qpolynomial_fold_isl(p
, upwf
);
2266 isl_die(p
->ctx
, isl_error_invalid
,
2267 "invalid output format for isl_union_pw_qpolynomial_fold",
2270 isl_printer_free(p
);
2274 /* Print the isl_constraint "c" to "p".
2276 __isl_give isl_printer
*isl_printer_print_constraint(__isl_take isl_printer
*p
,
2277 __isl_keep isl_constraint
*c
)
2279 struct isl_print_space_data data
= { 0 };
2280 isl_local_space
*ls
;
2287 ls
= isl_constraint_get_local_space(c
);
2289 return isl_printer_free(p
);
2290 space
= isl_local_space_get_space(ls
);
2291 p
= print_param_tuple(p
, space
, &data
);
2292 p
= isl_printer_print_str(p
, "{ ");
2293 p
= isl_print_space(space
, p
, 0, &data
);
2294 p
= isl_printer_print_str(p
, " : ");
2295 exists
= need_exists(p
, ls
->div
);
2297 p
= isl_printer_free(p
);
2298 if (exists
>= 0 && exists
)
2299 p
= open_exists(p
, space
, ls
->div
, 0);
2300 p
= print_affine_of_len(space
, ls
->div
, p
, c
->v
->el
, c
->v
->size
);
2301 if (isl_constraint_is_equality(c
))
2302 p
= isl_printer_print_str(p
, " = 0");
2304 p
= isl_printer_print_str(p
, " >= 0");
2305 if (exists
>= 0 && exists
)
2306 p
= isl_printer_print_str(p
, s_close_exists
[0]);
2307 p
= isl_printer_print_str(p
, " }");
2308 isl_space_free(space
);
2309 isl_local_space_free(ls
);
2313 isl_printer_free(p
);
2317 static __isl_give isl_printer
*isl_printer_print_space_isl(
2318 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
)
2320 struct isl_print_space_data data
= { 0 };
2325 p
= print_param_tuple(p
, space
, &data
);
2327 p
= isl_printer_print_str(p
, "{ ");
2328 if (isl_space_is_params(space
))
2329 p
= isl_printer_print_str(p
, s_such_that
[0]);
2331 p
= isl_print_space(space
, p
, 0, &data
);
2332 p
= isl_printer_print_str(p
, " }");
2336 isl_printer_free(p
);
2340 __isl_give isl_printer
*isl_printer_print_space(__isl_take isl_printer
*p
,
2341 __isl_keep isl_space
*space
)
2344 return isl_printer_free(p
);
2345 if (p
->output_format
== ISL_FORMAT_ISL
)
2346 return isl_printer_print_space_isl(p
, space
);
2347 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
2348 return print_omega_parameters(space
, p
);
2350 isl_die(isl_space_get_ctx(space
), isl_error_unsupported
,
2351 "output format not supported for space",
2352 return isl_printer_free(p
));
2355 __isl_give isl_printer
*isl_printer_print_local_space(__isl_take isl_printer
*p
,
2356 __isl_keep isl_local_space
*ls
)
2358 struct isl_print_space_data data
= { 0 };
2364 p
= print_param_tuple(p
, ls
->dim
, &data
);
2365 p
= isl_printer_print_str(p
, "{ ");
2366 p
= isl_print_space(ls
->dim
, p
, 0, &data
);
2367 n_div
= isl_local_space_dim(ls
, isl_dim_div
);
2369 p
= isl_printer_print_str(p
, " : ");
2370 p
= isl_printer_print_str(p
, s_open_exists
[0]);
2371 p
= print_div_list(p
, ls
->dim
, ls
->div
, 0, 1);
2372 p
= isl_printer_print_str(p
, s_close_exists
[0]);
2373 } else if (isl_space_is_params(ls
->dim
))
2374 p
= isl_printer_print_str(p
, s_such_that
[0]);
2375 p
= isl_printer_print_str(p
, " }");
2378 isl_printer_free(p
);
2382 static __isl_give isl_printer
*print_aff_body(__isl_take isl_printer
*p
,
2383 __isl_keep isl_aff
*aff
)
2387 if (isl_aff_is_nan(aff
))
2388 return isl_printer_print_str(p
, "NaN");
2390 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2391 p
= isl_printer_print_str(p
, "(");
2392 p
= print_affine_of_len(aff
->ls
->dim
, aff
->ls
->div
, p
,
2393 aff
->v
->el
+ 1, 1 + total
);
2394 if (isl_int_is_one(aff
->v
->el
[0]))
2395 p
= isl_printer_print_str(p
, ")");
2397 p
= isl_printer_print_str(p
, ")/");
2398 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2404 static __isl_give isl_printer
*print_aff(__isl_take isl_printer
*p
,
2405 __isl_keep isl_aff
*aff
)
2407 struct isl_print_space_data data
= { 0 };
2409 if (isl_space_is_params(aff
->ls
->dim
))
2412 p
= print_tuple(aff
->ls
->dim
, p
, isl_dim_set
, &data
);
2413 p
= isl_printer_print_str(p
, " -> ");
2415 p
= isl_printer_print_str(p
, "[");
2416 p
= print_aff_body(p
, aff
);
2417 p
= isl_printer_print_str(p
, "]");
2422 static __isl_give isl_printer
*print_aff_isl(__isl_take isl_printer
*p
,
2423 __isl_keep isl_aff
*aff
)
2425 struct isl_print_space_data data
= { 0 };
2430 p
= print_param_tuple(p
, aff
->ls
->dim
, &data
);
2431 p
= isl_printer_print_str(p
, "{ ");
2432 p
= print_aff(p
, aff
);
2433 p
= isl_printer_print_str(p
, " }");
2436 isl_printer_free(p
);
2440 /* Print the body of an isl_pw_aff, i.e., a semicolon delimited
2441 * sequence of affine expressions, each followed by constraints.
2443 static __isl_give isl_printer
*print_pw_aff_body(
2444 __isl_take isl_printer
*p
, __isl_keep isl_pw_aff
*pa
)
2449 return isl_printer_free(p
);
2451 for (i
= 0; i
< pa
->n
; ++i
) {
2455 p
= isl_printer_print_str(p
, "; ");
2456 p
= print_aff(p
, pa
->p
[i
].aff
);
2457 space
= isl_aff_get_domain_space(pa
->p
[i
].aff
);
2458 p
= print_disjuncts(set_to_map(pa
->p
[i
].set
), space
, p
, 0);
2459 isl_space_free(space
);
2465 static __isl_give isl_printer
*print_pw_aff_isl(__isl_take isl_printer
*p
,
2466 __isl_keep isl_pw_aff
*pwaff
)
2468 struct isl_print_space_data data
= { 0 };
2473 p
= print_param_tuple(p
, pwaff
->dim
, &data
);
2474 p
= isl_printer_print_str(p
, "{ ");
2475 p
= print_pw_aff_body(p
, pwaff
);
2476 p
= isl_printer_print_str(p
, " }");
2479 isl_printer_free(p
);
2483 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2484 __isl_keep isl_local_space
*ls
, isl_int
*c
);
2486 static __isl_give isl_printer
*print_ls_name_c(__isl_take isl_printer
*p
,
2487 __isl_keep isl_local_space
*ls
, enum isl_dim_type type
, unsigned pos
)
2489 if (type
== isl_dim_div
) {
2490 p
= isl_printer_print_str(p
, "floord(");
2491 p
= print_ls_affine_c(p
, ls
, ls
->div
->row
[pos
] + 1);
2492 p
= isl_printer_print_str(p
, ", ");
2493 p
= isl_printer_print_isl_int(p
, ls
->div
->row
[pos
][0]);
2494 p
= isl_printer_print_str(p
, ")");
2498 name
= isl_space_get_dim_name(ls
->dim
, type
, pos
);
2501 p
= isl_printer_print_str(p
, name
);
2506 static __isl_give isl_printer
*print_ls_term_c(__isl_take isl_printer
*p
,
2507 __isl_keep isl_local_space
*ls
, isl_int c
, unsigned pos
)
2509 enum isl_dim_type type
;
2512 return isl_printer_print_isl_int(p
, c
);
2514 if (isl_int_is_one(c
))
2516 else if (isl_int_is_negone(c
))
2517 p
= isl_printer_print_str(p
, "-");
2519 p
= isl_printer_print_isl_int(p
, c
);
2520 p
= isl_printer_print_str(p
, "*");
2522 type
= pos2type(ls
->dim
, &pos
);
2523 p
= print_ls_name_c(p
, ls
, type
, pos
);
2527 static __isl_give isl_printer
*print_ls_partial_affine_c(
2528 __isl_take isl_printer
*p
, __isl_keep isl_local_space
*ls
,
2529 isl_int
*c
, unsigned len
)
2534 for (i
= 0, first
= 1; i
< len
; ++i
) {
2536 if (isl_int_is_zero(c
[i
]))
2539 if (isl_int_is_neg(c
[i
])) {
2541 isl_int_neg(c
[i
], c
[i
]);
2542 p
= isl_printer_print_str(p
, " - ");
2544 p
= isl_printer_print_str(p
, " + ");
2547 p
= print_ls_term_c(p
, ls
, c
[i
], i
);
2549 isl_int_neg(c
[i
], c
[i
]);
2552 p
= isl_printer_print_str(p
, "0");
2556 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2557 __isl_keep isl_local_space
*ls
, isl_int
*c
)
2559 unsigned len
= 1 + isl_local_space_dim(ls
, isl_dim_all
);
2560 return print_ls_partial_affine_c(p
, ls
, c
, len
);
2563 static __isl_give isl_printer
*print_aff_c(__isl_take isl_printer
*p
,
2564 __isl_keep isl_aff
*aff
)
2568 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2569 if (!isl_int_is_one(aff
->v
->el
[0]))
2570 p
= isl_printer_print_str(p
, "(");
2571 p
= print_ls_partial_affine_c(p
, aff
->ls
, aff
->v
->el
+ 1, 1 + total
);
2572 if (!isl_int_is_one(aff
->v
->el
[0])) {
2573 p
= isl_printer_print_str(p
, ")/");
2574 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2579 /* In the C format, we cannot express that "pwaff" may be undefined
2580 * on parts of the domain space. We therefore assume that the expression
2581 * will only be evaluated on its definition domain and compute the gist
2582 * of each cell with respect to this domain.
2584 static __isl_give isl_printer
*print_pw_aff_c(__isl_take isl_printer
*p
,
2585 __isl_keep isl_pw_aff
*pwaff
)
2588 isl_ast_build
*build
;
2592 isl_die(p
->ctx
, isl_error_unsupported
,
2593 "cannot print empty isl_pw_aff in C format",
2594 return isl_printer_free(p
));
2596 domain
= isl_pw_aff_domain(isl_pw_aff_copy(pwaff
));
2597 build
= isl_ast_build_from_context(domain
);
2598 expr
= isl_ast_build_expr_from_pw_aff(build
, isl_pw_aff_copy(pwaff
));
2599 p
= isl_printer_print_ast_expr(p
, expr
);
2600 isl_ast_expr_free(expr
);
2601 isl_ast_build_free(build
);
2606 __isl_give isl_printer
*isl_printer_print_aff(__isl_take isl_printer
*p
,
2607 __isl_keep isl_aff
*aff
)
2612 if (p
->output_format
== ISL_FORMAT_ISL
)
2613 return print_aff_isl(p
, aff
);
2614 else if (p
->output_format
== ISL_FORMAT_C
)
2615 return print_aff_c(p
, aff
);
2616 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2619 isl_printer_free(p
);
2623 __isl_give isl_printer
*isl_printer_print_pw_aff(__isl_take isl_printer
*p
,
2624 __isl_keep isl_pw_aff
*pwaff
)
2629 if (p
->output_format
== ISL_FORMAT_ISL
)
2630 return print_pw_aff_isl(p
, pwaff
);
2631 else if (p
->output_format
== ISL_FORMAT_C
)
2632 return print_pw_aff_c(p
, pwaff
);
2633 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2636 isl_printer_free(p
);
2640 /* Print "pa" in a sequence of isl_pw_affs delimited by semicolons.
2641 * Each isl_pw_aff itself is also printed as semicolon delimited
2642 * sequence of pieces.
2643 * If data->first = 1, then this is the first in the sequence.
2644 * Update data->first to tell the next element that it is not the first.
2646 static isl_stat
print_pw_aff_body_wrap(__isl_take isl_pw_aff
*pa
,
2649 struct isl_union_print_data
*data
;
2650 data
= (struct isl_union_print_data
*) user
;
2653 data
->p
= isl_printer_print_str(data
->p
, "; ");
2656 data
->p
= print_pw_aff_body(data
->p
, pa
);
2657 isl_pw_aff_free(pa
);
2659 return data
->p
? isl_stat_ok
: isl_stat_error
;
2662 /* Print the body of an isl_union_pw_aff, i.e., a semicolon delimited
2663 * sequence of affine expressions, each followed by constraints,
2664 * with the sequence enclosed in braces.
2666 static __isl_give isl_printer
*print_union_pw_aff_body(
2667 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2669 struct isl_union_print_data data
= { p
, 1 };
2671 p
= isl_printer_print_str(p
, s_open_set
[0]);
2673 if (isl_union_pw_aff_foreach_pw_aff(upa
,
2674 &print_pw_aff_body_wrap
, &data
) < 0)
2675 data
.p
= isl_printer_free(p
);
2677 p
= isl_printer_print_str(p
, s_close_set
[0]);
2682 /* Print the isl_union_pw_aff "upa" to "p" in isl format.
2684 * The individual isl_pw_affs are delimited by a semicolon.
2686 static __isl_give isl_printer
*print_union_pw_aff_isl(
2687 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2689 struct isl_print_space_data data
= { 0 };
2692 space
= isl_union_pw_aff_get_space(upa
);
2693 p
= print_param_tuple(p
, space
, &data
);
2694 isl_space_free(space
);
2695 p
= print_union_pw_aff_body(p
, upa
);
2699 /* Print the isl_union_pw_aff "upa" to "p".
2701 * We currently only support an isl format.
2703 __isl_give isl_printer
*isl_printer_print_union_pw_aff(
2704 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2707 return isl_printer_free(p
);
2709 if (p
->output_format
== ISL_FORMAT_ISL
)
2710 return print_union_pw_aff_isl(p
, upa
);
2711 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
2712 "unsupported output format", return isl_printer_free(p
));
2715 /* Print dimension "pos" of data->space to "p".
2717 * data->user is assumed to be an isl_multi_aff.
2719 * If the current dimension is an output dimension, then print
2720 * the corresponding expression. Otherwise, print the name of the dimension.
2722 static __isl_give isl_printer
*print_dim_ma(__isl_take isl_printer
*p
,
2723 struct isl_print_space_data
*data
, unsigned pos
)
2725 isl_multi_aff
*ma
= data
->user
;
2727 if (data
->type
== isl_dim_out
)
2728 p
= print_aff_body(p
, ma
->p
[pos
]);
2730 p
= print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
2735 static __isl_give isl_printer
*print_multi_aff(__isl_take isl_printer
*p
,
2736 __isl_keep isl_multi_aff
*maff
)
2738 struct isl_print_space_data data
= { 0 };
2740 data
.print_dim
= &print_dim_ma
;
2742 return isl_print_space(maff
->space
, p
, 0, &data
);
2745 static __isl_give isl_printer
*print_multi_aff_isl(__isl_take isl_printer
*p
,
2746 __isl_keep isl_multi_aff
*maff
)
2748 struct isl_print_space_data data
= { 0 };
2753 p
= print_param_tuple(p
, maff
->space
, &data
);
2754 p
= isl_printer_print_str(p
, "{ ");
2755 p
= print_multi_aff(p
, maff
);
2756 p
= isl_printer_print_str(p
, " }");
2759 isl_printer_free(p
);
2763 __isl_give isl_printer
*isl_printer_print_multi_aff(__isl_take isl_printer
*p
,
2764 __isl_keep isl_multi_aff
*maff
)
2769 if (p
->output_format
== ISL_FORMAT_ISL
)
2770 return print_multi_aff_isl(p
, maff
);
2771 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2774 isl_printer_free(p
);
2778 static __isl_give isl_printer
*print_pw_multi_aff_body(
2779 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2786 for (i
= 0; i
< pma
->n
; ++i
) {
2790 p
= isl_printer_print_str(p
, "; ");
2791 p
= print_multi_aff(p
, pma
->p
[i
].maff
);
2792 space
= isl_multi_aff_get_domain_space(pma
->p
[i
].maff
);
2793 p
= print_disjuncts(set_to_map(pma
->p
[i
].set
), space
, p
, 0);
2794 isl_space_free(space
);
2798 isl_printer_free(p
);
2802 static __isl_give isl_printer
*print_pw_multi_aff_isl(__isl_take isl_printer
*p
,
2803 __isl_keep isl_pw_multi_aff
*pma
)
2805 struct isl_print_space_data data
= { 0 };
2810 p
= print_param_tuple(p
, pma
->dim
, &data
);
2811 p
= isl_printer_print_str(p
, "{ ");
2812 p
= print_pw_multi_aff_body(p
, pma
);
2813 p
= isl_printer_print_str(p
, " }");
2816 isl_printer_free(p
);
2820 static __isl_give isl_printer
*print_unnamed_pw_multi_aff_c(
2821 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2825 for (i
= 0; i
< pma
->n
- 1; ++i
) {
2826 p
= isl_printer_print_str(p
, "(");
2827 p
= print_set_c(p
, pma
->dim
, pma
->p
[i
].set
);
2828 p
= isl_printer_print_str(p
, ") ? (");
2829 p
= print_aff_c(p
, pma
->p
[i
].maff
->p
[0]);
2830 p
= isl_printer_print_str(p
, ") : ");
2833 return print_aff_c(p
, pma
->p
[pma
->n
- 1].maff
->p
[0]);
2836 static __isl_give isl_printer
*print_pw_multi_aff_c(__isl_take isl_printer
*p
,
2837 __isl_keep isl_pw_multi_aff
*pma
)
2845 isl_die(p
->ctx
, isl_error_unsupported
,
2846 "cannot print empty isl_pw_multi_aff in C format",
2848 name
= isl_pw_multi_aff_get_tuple_name(pma
, isl_dim_out
);
2849 if (!name
&& isl_pw_multi_aff_dim(pma
, isl_dim_out
) == 1)
2850 return print_unnamed_pw_multi_aff_c(p
, pma
);
2852 isl_die(p
->ctx
, isl_error_unsupported
,
2853 "cannot print unnamed isl_pw_multi_aff in C format",
2856 p
= isl_printer_print_str(p
, name
);
2857 n
= isl_pw_multi_aff_dim(pma
, isl_dim_out
);
2859 isl_die(p
->ctx
, isl_error_unsupported
,
2860 "not supported yet", goto error
);
2864 isl_printer_free(p
);
2868 __isl_give isl_printer
*isl_printer_print_pw_multi_aff(
2869 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2874 if (p
->output_format
== ISL_FORMAT_ISL
)
2875 return print_pw_multi_aff_isl(p
, pma
);
2876 if (p
->output_format
== ISL_FORMAT_C
)
2877 return print_pw_multi_aff_c(p
, pma
);
2878 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2881 isl_printer_free(p
);
2885 static isl_stat
print_pw_multi_aff_body_wrap(__isl_take isl_pw_multi_aff
*pma
,
2888 struct isl_union_print_data
*data
;
2889 data
= (struct isl_union_print_data
*) user
;
2892 data
->p
= isl_printer_print_str(data
->p
, "; ");
2895 data
->p
= print_pw_multi_aff_body(data
->p
, pma
);
2896 isl_pw_multi_aff_free(pma
);
2901 static __isl_give isl_printer
*print_union_pw_multi_aff_isl(
2902 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
2904 struct isl_union_print_data data
;
2905 struct isl_print_space_data space_data
= { 0 };
2908 space
= isl_union_pw_multi_aff_get_space(upma
);
2909 p
= print_param_tuple(p
, space
, &space_data
);
2910 isl_space_free(space
);
2911 p
= isl_printer_print_str(p
, s_open_set
[0]);
2914 isl_union_pw_multi_aff_foreach_pw_multi_aff(upma
,
2915 &print_pw_multi_aff_body_wrap
, &data
);
2917 p
= isl_printer_print_str(p
, s_close_set
[0]);
2921 __isl_give isl_printer
*isl_printer_print_union_pw_multi_aff(
2922 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
2927 if (p
->output_format
== ISL_FORMAT_ISL
)
2928 return print_union_pw_multi_aff_isl(p
, upma
);
2929 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2932 isl_printer_free(p
);
2936 /* Print dimension "pos" of data->space to "p".
2938 * data->user is assumed to be an isl_multi_pw_aff.
2940 * If the current dimension is an output dimension, then print
2941 * the corresponding piecewise affine expression.
2942 * Otherwise, print the name of the dimension.
2944 static __isl_give isl_printer
*print_dim_mpa(__isl_take isl_printer
*p
,
2945 struct isl_print_space_data
*data
, unsigned pos
)
2949 isl_multi_pw_aff
*mpa
= data
->user
;
2952 if (data
->type
!= isl_dim_out
)
2953 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
2957 return isl_printer_print_str(p
, "(0 : 1 = 0)");
2959 need_parens
= pa
->n
!= 1 || !isl_set_plain_is_universe(pa
->p
[0].set
);
2961 p
= isl_printer_print_str(p
, "(");
2962 for (i
= 0; i
< pa
->n
; ++i
) {
2966 p
= isl_printer_print_str(p
, "; ");
2967 p
= print_aff_body(p
, pa
->p
[i
].aff
);
2968 space
= isl_aff_get_domain_space(pa
->p
[i
].aff
);
2969 p
= print_disjuncts(pa
->p
[i
].set
, space
, p
, 0);
2970 isl_space_free(space
);
2973 p
= isl_printer_print_str(p
, ")");
2978 /* Print "mpa" to "p" in isl format.
2980 static __isl_give isl_printer
*print_multi_pw_aff_isl(__isl_take isl_printer
*p
,
2981 __isl_keep isl_multi_pw_aff
*mpa
)
2983 struct isl_print_space_data data
= { 0 };
2986 return isl_printer_free(p
);
2988 p
= print_param_tuple(p
, mpa
->space
, &data
);
2989 p
= isl_printer_print_str(p
, "{ ");
2990 data
.print_dim
= &print_dim_mpa
;
2992 p
= isl_print_space(mpa
->space
, p
, 0, &data
);
2993 p
= isl_printer_print_str(p
, " }");
2997 __isl_give isl_printer
*isl_printer_print_multi_pw_aff(
2998 __isl_take isl_printer
*p
, __isl_keep isl_multi_pw_aff
*mpa
)
3001 return isl_printer_free(p
);
3003 if (p
->output_format
== ISL_FORMAT_ISL
)
3004 return print_multi_pw_aff_isl(p
, mpa
);
3005 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3006 return isl_printer_free(p
));
3009 /* Print dimension "pos" of data->space to "p".
3011 * data->user is assumed to be an isl_multi_val.
3013 * If the current dimension is an output dimension, then print
3014 * the corresponding value. Otherwise, print the name of the dimension.
3016 static __isl_give isl_printer
*print_dim_mv(__isl_take isl_printer
*p
,
3017 struct isl_print_space_data
*data
, unsigned pos
)
3019 isl_multi_val
*mv
= data
->user
;
3021 if (data
->type
== isl_dim_out
)
3022 return isl_printer_print_val(p
, mv
->p
[pos
]);
3024 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
3027 /* Print the isl_multi_val "mv" to "p" in isl format.
3029 static __isl_give isl_printer
*print_multi_val_isl(__isl_take isl_printer
*p
,
3030 __isl_keep isl_multi_val
*mv
)
3032 struct isl_print_space_data data
= { 0 };
3035 return isl_printer_free(p
);
3037 p
= print_param_tuple(p
, mv
->space
, &data
);
3038 p
= isl_printer_print_str(p
, "{ ");
3039 data
.print_dim
= &print_dim_mv
;
3041 p
= isl_print_space(mv
->space
, p
, 0, &data
);
3042 p
= isl_printer_print_str(p
, " }");
3046 /* Print the isl_multi_val "mv" to "p".
3048 * Currently only supported in isl format.
3050 __isl_give isl_printer
*isl_printer_print_multi_val(
3051 __isl_take isl_printer
*p
, __isl_keep isl_multi_val
*mv
)
3054 return isl_printer_free(p
);
3056 if (p
->output_format
== ISL_FORMAT_ISL
)
3057 return print_multi_val_isl(p
, mv
);
3058 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3059 return isl_printer_free(p
));
3062 /* Print dimension "pos" of data->space to "p".
3064 * data->user is assumed to be an isl_multi_union_pw_aff.
3066 * The current dimension is necessarily a set dimension, so
3067 * we print the corresponding isl_union_pw_aff, including
3070 static __isl_give isl_printer
*print_union_pw_aff_dim(__isl_take isl_printer
*p
,
3071 struct isl_print_space_data
*data
, unsigned pos
)
3073 isl_multi_union_pw_aff
*mupa
= data
->user
;
3074 isl_union_pw_aff
*upa
;
3076 upa
= isl_multi_union_pw_aff_get_union_pw_aff(mupa
, pos
);
3077 p
= print_union_pw_aff_body(p
, upa
);
3078 isl_union_pw_aff_free(upa
);
3083 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3085 static __isl_give isl_printer
*print_multi_union_pw_aff_isl(
3086 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3088 struct isl_print_space_data data
= { 0 };
3091 space
= isl_multi_union_pw_aff_get_space(mupa
);
3092 p
= print_param_tuple(p
, space
, &data
);
3094 data
.print_dim
= &print_union_pw_aff_dim
;
3097 p
= isl_print_space(space
, p
, 0, &data
);
3098 isl_space_free(space
);
3103 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3105 * We currently only support an isl format.
3107 __isl_give isl_printer
*isl_printer_print_multi_union_pw_aff(
3108 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3111 return isl_printer_free(p
);
3113 if (p
->output_format
== ISL_FORMAT_ISL
)
3114 return print_multi_union_pw_aff_isl(p
, mupa
);
3115 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
3116 "unsupported output format", return isl_printer_free(p
));