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 #include <bset_to_bmap.c>
36 #include <set_to_map.c>
38 static const char *s_to
[2] = { " -> ", " \\to " };
39 static const char *s_and
[2] = { " and ", " \\wedge " };
40 static const char *s_or
[2] = { " or ", " \\vee " };
41 static const char *s_le
[2] = { "<=", "\\le" };
42 static const char *s_ge
[2] = { ">=", "\\ge" };
43 static const char *s_open_set
[2] = { "{ ", "\\{\\, " };
44 static const char *s_close_set
[2] = { " }", " \\,\\}" };
45 static const char *s_open_list
[2] = { "[", "(" };
46 static const char *s_close_list
[2] = { "]", ")" };
47 static const char *s_such_that
[2] = { " : ", " \\mid " };
48 static const char *s_open_exists
[2] = { "exists (", "\\exists \\, " };
49 static const char *s_close_exists
[2] = { ")", "" };
50 static const char *s_div_prefix
[2] = { "e", "\\alpha_" };
51 static const char *s_param_prefix
[2] = { "p", "p_" };
52 static const char *s_input_prefix
[2] = { "i", "i_" };
53 static const char *s_output_prefix
[2] = { "o", "o_" };
55 static __isl_give isl_printer
*print_constraint_polylib(
56 struct isl_basic_map
*bmap
, int ineq
, int n
, __isl_take isl_printer
*p
)
59 unsigned n_in
= isl_basic_map_dim(bmap
, isl_dim_in
);
60 unsigned n_out
= isl_basic_map_dim(bmap
, isl_dim_out
);
61 unsigned nparam
= isl_basic_map_dim(bmap
, isl_dim_param
);
62 isl_int
*c
= ineq
? bmap
->ineq
[n
] : bmap
->eq
[n
];
64 p
= isl_printer_start_line(p
);
65 p
= isl_printer_print_int(p
, ineq
);
66 for (i
= 0; i
< n_out
; ++i
) {
67 p
= isl_printer_print_str(p
, " ");
68 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+n_in
+i
]);
70 for (i
= 0; i
< n_in
; ++i
) {
71 p
= isl_printer_print_str(p
, " ");
72 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+i
]);
74 for (i
= 0; i
< bmap
->n_div
; ++i
) {
75 p
= isl_printer_print_str(p
, " ");
76 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+n_in
+n_out
+i
]);
78 for (i
= 0; i
< nparam
; ++i
) {
79 p
= isl_printer_print_str(p
, " ");
80 p
= isl_printer_print_isl_int(p
, c
[1+i
]);
82 p
= isl_printer_print_str(p
, " ");
83 p
= isl_printer_print_isl_int(p
, c
[0]);
84 p
= isl_printer_end_line(p
);
88 static __isl_give isl_printer
*print_constraints_polylib(
89 struct isl_basic_map
*bmap
, __isl_take isl_printer
*p
)
93 p
= isl_printer_set_isl_int_width(p
, 5);
95 for (i
= 0; i
< bmap
->n_eq
; ++i
)
96 p
= print_constraint_polylib(bmap
, 0, i
, p
);
97 for (i
= 0; i
< bmap
->n_ineq
; ++i
)
98 p
= print_constraint_polylib(bmap
, 1, i
, p
);
103 static __isl_give isl_printer
*bset_print_constraints_polylib(
104 struct isl_basic_set
*bset
, __isl_take isl_printer
*p
)
106 return print_constraints_polylib(bset_to_bmap(bset
), p
);
109 static __isl_give isl_printer
*isl_basic_map_print_polylib(
110 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
, int ext
)
112 unsigned total
= isl_basic_map_total_dim(bmap
);
113 p
= isl_printer_start_line(p
);
114 p
= isl_printer_print_int(p
, bmap
->n_eq
+ bmap
->n_ineq
);
115 p
= isl_printer_print_str(p
, " ");
116 p
= isl_printer_print_int(p
, 1 + total
+ 1);
118 p
= isl_printer_print_str(p
, " ");
119 p
= isl_printer_print_int(p
,
120 isl_basic_map_dim(bmap
, isl_dim_out
));
121 p
= isl_printer_print_str(p
, " ");
122 p
= isl_printer_print_int(p
,
123 isl_basic_map_dim(bmap
, isl_dim_in
));
124 p
= isl_printer_print_str(p
, " ");
125 p
= isl_printer_print_int(p
,
126 isl_basic_map_dim(bmap
, isl_dim_div
));
127 p
= isl_printer_print_str(p
, " ");
128 p
= isl_printer_print_int(p
,
129 isl_basic_map_dim(bmap
, isl_dim_param
));
131 p
= isl_printer_end_line(p
);
132 return print_constraints_polylib(bmap
, p
);
135 static __isl_give isl_printer
*isl_basic_set_print_polylib(
136 __isl_keep isl_basic_set
*bset
, __isl_take isl_printer
*p
, int ext
)
138 return isl_basic_map_print_polylib(bset_to_bmap(bset
), p
, ext
);
141 static __isl_give isl_printer
*isl_map_print_polylib(__isl_keep isl_map
*map
,
142 __isl_take isl_printer
*p
, int ext
)
146 p
= isl_printer_start_line(p
);
147 p
= isl_printer_print_int(p
, map
->n
);
148 p
= isl_printer_end_line(p
);
149 for (i
= 0; i
< map
->n
; ++i
) {
150 p
= isl_printer_start_line(p
);
151 p
= isl_printer_end_line(p
);
152 p
= isl_basic_map_print_polylib(map
->p
[i
], p
, ext
);
157 static __isl_give isl_printer
*isl_set_print_polylib(__isl_keep isl_set
*set
,
158 __isl_take isl_printer
*p
, int ext
)
160 return isl_map_print_polylib(set_to_map(set
), p
, ext
);
163 static int count_same_name(__isl_keep isl_space
*dim
,
164 enum isl_dim_type type
, unsigned pos
, const char *name
)
170 for (t
= isl_dim_param
; t
<= type
&& t
<= isl_dim_out
; ++t
) {
171 s
= t
== type
? pos
: isl_space_dim(dim
, t
);
172 for (p
= 0; p
< s
; ++p
) {
173 const char *n
= isl_space_get_dim_name(dim
, t
, p
);
174 if (n
&& !strcmp(n
, name
))
181 /* Print the name of the variable of type "type" and position "pos"
184 static __isl_give isl_printer
*print_name(__isl_keep isl_space
*space
,
185 __isl_take isl_printer
*p
, enum isl_dim_type type
, unsigned pos
,
192 name
= type
== isl_dim_div
? NULL
193 : isl_space_get_dim_name(space
, type
, pos
);
197 if (type
== isl_dim_param
)
198 prefix
= s_param_prefix
[latex
];
199 else if (type
== isl_dim_div
)
200 prefix
= s_div_prefix
[latex
];
201 else if (isl_space_is_set(space
) || type
== isl_dim_in
)
202 prefix
= s_input_prefix
[latex
];
204 prefix
= s_output_prefix
[latex
];
205 snprintf(buffer
, sizeof(buffer
), "%s%d", prefix
, pos
);
208 primes
= count_same_name(space
, name
== buffer
? isl_dim_div
: type
,
210 p
= isl_printer_print_str(p
, name
);
212 p
= isl_printer_print_str(p
, "'");
216 static enum isl_dim_type
pos2type(__isl_keep isl_space
*dim
, unsigned *pos
)
218 enum isl_dim_type type
;
219 unsigned n_in
= isl_space_dim(dim
, isl_dim_in
);
220 unsigned n_out
= isl_space_dim(dim
, isl_dim_out
);
221 unsigned nparam
= isl_space_dim(dim
, isl_dim_param
);
223 if (*pos
< 1 + nparam
) {
224 type
= isl_dim_param
;
226 } else if (*pos
< 1 + nparam
+ n_in
) {
229 } else if (*pos
< 1 + nparam
+ n_in
+ n_out
) {
231 *pos
-= 1 + nparam
+ n_in
;
234 *pos
-= 1 + nparam
+ n_in
+ n_out
;
240 /* Can the div expression of the integer division at position "row" of "div"
242 * In particular, are the div expressions available and does the selected
243 * variable have a known explicit representation?
244 * Furthermore, the Omega format does not allow any div expressions
247 static isl_bool
can_print_div_expr(__isl_keep isl_printer
*p
,
248 __isl_keep isl_mat
*div
, int pos
)
250 if (p
->output_format
== ISL_FORMAT_OMEGA
)
251 return isl_bool_false
;
253 return isl_bool_false
;
254 return !isl_int_is_zero(div
->row
[pos
][0]);
257 static __isl_give isl_printer
*print_div(__isl_keep isl_space
*dim
,
258 __isl_keep isl_mat
*div
, int pos
, __isl_take isl_printer
*p
);
260 static __isl_give isl_printer
*print_term(__isl_keep isl_space
*space
,
261 __isl_keep isl_mat
*div
,
262 isl_int c
, unsigned pos
, __isl_take isl_printer
*p
, int latex
)
264 enum isl_dim_type type
;
268 return isl_printer_print_isl_int(p
, c
);
270 type
= pos2type(space
, &pos
);
271 print_div_def
= type
== isl_dim_div
&& can_print_div_expr(p
, div
, pos
);
273 if (isl_int_is_one(c
))
275 else if (isl_int_is_negone(c
))
276 p
= isl_printer_print_str(p
, "-");
278 p
= isl_printer_print_isl_int(p
, c
);
279 if (p
->output_format
== ISL_FORMAT_C
|| print_div_def
)
280 p
= isl_printer_print_str(p
, "*");
283 p
= print_div(space
, div
, pos
, p
);
285 p
= print_name(space
, p
, type
, pos
, latex
);
289 static __isl_give isl_printer
*print_affine_of_len(__isl_keep isl_space
*dim
,
290 __isl_keep isl_mat
*div
,
291 __isl_take isl_printer
*p
, isl_int
*c
, int len
)
296 for (i
= 0, first
= 1; i
< len
; ++i
) {
298 if (isl_int_is_zero(c
[i
]))
301 if (isl_int_is_neg(c
[i
])) {
303 isl_int_neg(c
[i
], c
[i
]);
304 p
= isl_printer_print_str(p
, " - ");
306 p
= isl_printer_print_str(p
, " + ");
309 p
= print_term(dim
, div
, c
[i
], i
, p
, 0);
311 isl_int_neg(c
[i
], c
[i
]);
314 p
= isl_printer_print_str(p
, "0");
318 /* Print an affine expression "c" corresponding to a constraint in "bmap"
319 * to "p", with the variable names taken from "space" and
320 * the integer division definitions taken from "div".
322 static __isl_give isl_printer
*print_affine(__isl_keep isl_basic_map
*bmap
,
323 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
324 __isl_take isl_printer
*p
, isl_int
*c
)
326 unsigned len
= 1 + isl_basic_map_total_dim(bmap
);
327 return print_affine_of_len(space
, div
, p
, c
, len
);
330 /* offset is the offset of local_dim inside data->type of data->space.
332 static __isl_give isl_printer
*print_nested_var_list(__isl_take isl_printer
*p
,
333 __isl_keep isl_space
*local_dim
, enum isl_dim_type local_type
,
334 struct isl_print_space_data
*data
, int offset
)
338 if (data
->space
!= local_dim
&& local_type
== isl_dim_out
)
339 offset
+= local_dim
->n_in
;
341 for (i
= 0; i
< isl_space_dim(local_dim
, local_type
); ++i
) {
343 p
= isl_printer_print_str(p
, ", ");
345 p
= data
->print_dim(p
, data
, offset
+ i
);
347 p
= print_name(data
->space
, p
, data
->type
, offset
+ i
,
353 static __isl_give isl_printer
*print_var_list(__isl_take isl_printer
*p
,
354 __isl_keep isl_space
*space
, enum isl_dim_type type
)
356 struct isl_print_space_data data
= { .space
= space
, .type
= type
};
358 return print_nested_var_list(p
, space
, type
, &data
, 0);
361 static __isl_give isl_printer
*print_nested_map_dim(__isl_take isl_printer
*p
,
362 __isl_keep isl_space
*local_dim
,
363 struct isl_print_space_data
*data
, int offset
);
365 static __isl_give isl_printer
*print_nested_tuple(__isl_take isl_printer
*p
,
366 __isl_keep isl_space
*local_dim
, enum isl_dim_type local_type
,
367 struct isl_print_space_data
*data
, int offset
)
369 const char *name
= NULL
;
370 unsigned n
= isl_space_dim(local_dim
, local_type
);
371 if ((local_type
== isl_dim_in
|| local_type
== isl_dim_out
)) {
372 name
= isl_space_get_tuple_name(local_dim
, local_type
);
375 p
= isl_printer_print_str(p
, "\\mathrm{");
376 p
= isl_printer_print_str(p
, name
);
378 p
= isl_printer_print_str(p
, "}");
381 if (!data
->latex
|| n
!= 1 || name
)
382 p
= isl_printer_print_str(p
, s_open_list
[data
->latex
]);
383 if ((local_type
== isl_dim_in
|| local_type
== isl_dim_out
) &&
384 local_dim
->nested
[local_type
- isl_dim_in
]) {
385 if (data
->space
!= local_dim
&& local_type
== isl_dim_out
)
386 offset
+= local_dim
->n_in
;
387 p
= print_nested_map_dim(p
,
388 local_dim
->nested
[local_type
- isl_dim_in
],
391 p
= print_nested_var_list(p
, local_dim
, local_type
, data
,
393 if (!data
->latex
|| n
!= 1 || name
)
394 p
= isl_printer_print_str(p
, s_close_list
[data
->latex
]);
398 static __isl_give isl_printer
*print_tuple(__isl_keep isl_space
*dim
,
399 __isl_take isl_printer
*p
, enum isl_dim_type type
,
400 struct isl_print_space_data
*data
)
404 return print_nested_tuple(p
, dim
, type
, data
, 0);
407 static __isl_give isl_printer
*print_nested_map_dim(__isl_take isl_printer
*p
,
408 __isl_keep isl_space
*local_dim
,
409 struct isl_print_space_data
*data
, int offset
)
411 p
= print_nested_tuple(p
, local_dim
, isl_dim_in
, data
, offset
);
412 p
= isl_printer_print_str(p
, s_to
[data
->latex
]);
413 p
= print_nested_tuple(p
, local_dim
, isl_dim_out
, data
, offset
);
418 __isl_give isl_printer
*isl_print_space(__isl_keep isl_space
*space
,
419 __isl_take isl_printer
*p
, int rational
,
420 struct isl_print_space_data
*data
)
422 if (rational
&& !data
->latex
)
423 p
= isl_printer_print_str(p
, "rat: ");
424 if (isl_space_is_params(space
))
426 else if (isl_space_is_set(space
))
427 p
= print_tuple(space
, p
, isl_dim_set
, data
);
429 p
= print_tuple(space
, p
, isl_dim_in
, data
);
430 p
= isl_printer_print_str(p
, s_to
[data
->latex
]);
431 p
= print_tuple(space
, p
, isl_dim_out
, data
);
437 static __isl_give isl_printer
*print_omega_parameters(__isl_keep isl_space
*dim
,
438 __isl_take isl_printer
*p
)
440 if (isl_space_dim(dim
, isl_dim_param
) == 0)
443 p
= isl_printer_start_line(p
);
444 p
= isl_printer_print_str(p
, "symbolic ");
445 p
= print_var_list(p
, dim
, isl_dim_param
);
446 p
= isl_printer_print_str(p
, ";");
447 p
= isl_printer_end_line(p
);
451 /* Does the inequality constraint following "i" in "bmap"
452 * have an opposite value for the same last coefficient?
453 * "last" is the position of the last coefficient of inequality "i".
454 * If the next constraint is a div constraint, then it is ignored
455 * since div constraints are not printed.
457 static int next_is_opposite(__isl_keep isl_basic_map
*bmap
, int i
, int last
)
459 unsigned total
= isl_basic_map_total_dim(bmap
);
460 unsigned o_div
= isl_basic_map_offset(bmap
, isl_dim_div
);
462 if (i
+ 1 >= bmap
->n_ineq
)
464 if (isl_seq_last_non_zero(bmap
->ineq
[i
+ 1], 1 + total
) != last
)
467 isl_basic_map_is_div_constraint(bmap
, bmap
->ineq
[i
+ 1],
470 return isl_int_abs_eq(bmap
->ineq
[i
][last
], bmap
->ineq
[i
+ 1][last
]) &&
471 !isl_int_eq(bmap
->ineq
[i
][last
], bmap
->ineq
[i
+ 1][last
]);
474 /* Return a string representation of the operator used when
475 * printing a constraint where the LHS is greater than or equal to the LHS
476 * (sign > 0) or smaller than or equal to the LHS (sign < 0).
477 * If "strict" is set, then return the strict version of the comparison
480 static const char *constraint_op(int sign
, int strict
, int latex
)
483 return sign
< 0 ? "<" : ">";
490 /* Print one side of a constraint "c" from "bmap" to "p", with
491 * the variable names taken from "space" and the integer division definitions
493 * "last" is the position of the last non-zero coefficient.
494 * Let c' be the result of zeroing out this coefficient, then
495 * the partial constraint
500 * "first_constraint" is set if this is the first constraint
501 * in the conjunction.
503 static __isl_give isl_printer
*print_half_constraint(struct isl_basic_map
*bmap
,
504 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
505 __isl_take isl_printer
*p
, isl_int
*c
, int last
, const char *op
,
506 int first_constraint
, int latex
)
508 if (!first_constraint
)
509 p
= isl_printer_print_str(p
, s_and
[latex
]);
511 isl_int_set_si(c
[last
], 0);
512 p
= print_affine(bmap
, space
, div
, p
, c
);
514 p
= isl_printer_print_str(p
, " ");
515 p
= isl_printer_print_str(p
, op
);
516 p
= isl_printer_print_str(p
, " ");
521 /* Print a constraint "c" from "bmap" to "p", with the variable names
522 * taken from "space" and the integer division definitions taken from "div".
523 * "last" is the position of the last non-zero coefficient, which is
524 * moreover assumed to be negative.
525 * Let c' be the result of zeroing out this coefficient, then
526 * the constraint is printed in the form
530 * "first_constraint" is set if this is the first constraint
531 * in the conjunction.
533 static __isl_give isl_printer
*print_constraint(struct isl_basic_map
*bmap
,
534 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
535 __isl_take isl_printer
*p
,
536 isl_int
*c
, int last
, const char *op
, int first_constraint
, int latex
)
538 if (!first_constraint
)
539 p
= isl_printer_print_str(p
, s_and
[latex
]);
541 isl_int_abs(c
[last
], c
[last
]);
543 p
= print_term(space
, div
, c
[last
], last
, p
, latex
);
545 p
= isl_printer_print_str(p
, " ");
546 p
= isl_printer_print_str(p
, op
);
547 p
= isl_printer_print_str(p
, " ");
549 isl_int_set_si(c
[last
], 0);
550 p
= print_affine(bmap
, space
, div
, p
, c
);
555 /* Print the constraints of "bmap" to "p".
556 * The names of the variables are taken from "space" and
557 * the integer division definitions are taken from "div".
558 * Div constraints are only printed in "dump" mode.
559 * The constraints are sorted prior to printing (except in "dump" mode).
561 * If x is the last variable with a non-zero coefficient,
570 * while an upper bound
578 * If the next constraint has an opposite sign for the same last coefficient,
579 * then it is printed as
587 * instead. In fact, the "a x" part is not printed explicitly, but
588 * reused from the next constraint, which is therefore treated as
589 * a first constraint in the conjunction.
591 * If the constant term of "f" is -1, then "f" is replaced by "f + 1" and
592 * the comparison operator is replaced by the strict variant.
593 * Essentially, ">= 1" is replaced by "> 0".
595 static __isl_give isl_printer
*print_constraints(__isl_keep isl_basic_map
*bmap
,
596 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
597 __isl_take isl_printer
*p
, int latex
)
601 int rational
= ISL_F_ISSET(bmap
, ISL_BASIC_MAP_RATIONAL
);
602 unsigned total
= isl_basic_map_total_dim(bmap
);
603 unsigned o_div
= isl_basic_map_offset(bmap
, isl_dim_div
);
609 bmap
= isl_basic_map_copy(bmap
);
612 bmap
= isl_basic_map_sort_constraints(bmap
);
616 c
= isl_vec_alloc(bmap
->ctx
, 1 + total
);
620 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
621 int l
= isl_seq_last_non_zero(bmap
->eq
[i
], 1 + total
);
623 if (i
!= bmap
->n_eq
- 1)
624 p
= isl_printer_print_str(p
, s_and
[latex
]);
625 p
= isl_printer_print_str(p
, "0 = 0");
628 if (isl_int_is_neg(bmap
->eq
[i
][l
]))
629 isl_seq_cpy(c
->el
, bmap
->eq
[i
], 1 + total
);
631 isl_seq_neg(c
->el
, bmap
->eq
[i
], 1 + total
);
632 p
= print_constraint(bmap
, space
, div
, p
, c
->el
, l
,
636 for (i
= 0; i
< bmap
->n_ineq
; ++i
) {
637 int l
= isl_seq_last_non_zero(bmap
->ineq
[i
], 1 + total
);
643 if (!dump
&& l
>= o_div
&&
644 can_print_div_expr(p
, div
, l
- o_div
) &&
645 isl_basic_map_is_div_constraint(bmap
, bmap
->ineq
[i
],
648 s
= isl_int_sgn(bmap
->ineq
[i
][l
]);
649 strict
= !rational
&& isl_int_is_negone(bmap
->ineq
[i
][0]);
651 isl_seq_cpy(c
->el
, bmap
->ineq
[i
], 1 + total
);
653 isl_seq_neg(c
->el
, bmap
->ineq
[i
], 1 + total
);
655 isl_int_set_si(c
->el
[0], 0);
656 if (!dump
&& next_is_opposite(bmap
, i
, l
)) {
657 op
= constraint_op(-s
, strict
, latex
);
658 p
= print_half_constraint(bmap
, space
, div
, p
, c
->el
, l
,
662 op
= constraint_op(s
, strict
, latex
);
663 p
= print_constraint(bmap
, space
, div
, p
, c
->el
, l
,
669 isl_basic_map_free(bmap
);
674 isl_basic_map_free(bmap
);
680 static __isl_give isl_printer
*print_div(__isl_keep isl_space
*dim
,
681 __isl_keep isl_mat
*div
, int pos
, __isl_take isl_printer
*p
)
686 return isl_printer_free(p
);
688 c
= p
->output_format
== ISL_FORMAT_C
;
689 p
= isl_printer_print_str(p
, c
? "floord(" : "floor((");
690 p
= print_affine_of_len(dim
, div
, p
,
691 div
->row
[pos
] + 1, div
->n_col
- 1);
692 p
= isl_printer_print_str(p
, c
? ", " : ")/");
693 p
= isl_printer_print_isl_int(p
, div
->row
[pos
][0]);
694 p
= isl_printer_print_str(p
, ")");
698 /* Print a comma separated list of div names, except those that have
699 * a definition that can be printed.
700 * If "print_defined_divs" is set, then those div names are printed
701 * as well, along with their definitions.
703 static __isl_give isl_printer
*print_div_list(__isl_take isl_printer
*p
,
704 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, int latex
,
705 int print_defined_divs
)
711 if (!p
|| !space
|| !div
)
712 return isl_printer_free(p
);
714 n_div
= isl_mat_rows(div
);
716 for (i
= 0; i
< n_div
; ++i
) {
717 if (!print_defined_divs
&& can_print_div_expr(p
, div
, i
))
720 p
= isl_printer_print_str(p
, ", ");
721 p
= print_name(space
, p
, isl_dim_div
, i
, latex
);
723 if (!can_print_div_expr(p
, div
, i
))
725 p
= isl_printer_print_str(p
, " = ");
726 p
= print_div(space
, div
, i
, p
);
732 /* Does printing "bmap" require an "exists" clause?
733 * That is, are there any local variables without an explicit representation?
735 static isl_bool
need_exists(__isl_keep isl_printer
*p
,
736 __isl_keep isl_basic_map
*bmap
, __isl_keep isl_mat
*div
)
741 return isl_bool_error
;
742 if (bmap
->n_div
== 0)
743 return isl_bool_false
;
744 for (i
= 0; i
< bmap
->n_div
; ++i
)
745 if (!can_print_div_expr(p
, div
, i
))
746 return isl_bool_true
;
747 return isl_bool_false
;
750 /* Print the constraints of "bmap" to "p".
751 * The names of the variables are taken from "space".
752 * "latex" is set if the constraints should be printed in LaTeX format.
753 * Do not print inline explicit div representations in "dump" mode.
755 static __isl_give isl_printer
*print_disjunct(__isl_keep isl_basic_map
*bmap
,
756 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
765 div
= isl_basic_map_get_divs(bmap
);
767 exists
= bmap
->n_div
> 0;
769 exists
= need_exists(p
, bmap
, div
);
770 if (exists
>= 0 && exists
) {
771 p
= isl_printer_print_str(p
, s_open_exists
[latex
]);
772 p
= print_div_list(p
, space
, div
, latex
, dump
);
773 p
= isl_printer_print_str(p
, ": ");
777 div
= isl_mat_free(div
);
778 p
= print_constraints(bmap
, space
, div
, p
, latex
);
781 if (exists
>= 0 && exists
)
782 p
= isl_printer_print_str(p
, s_close_exists
[latex
]);
786 /* Print a colon followed by the constraints of "bmap"
787 * to "p", provided there are any constraints.
788 * The names of the variables are taken from "space".
789 * "latex" is set if the constraints should be printed in LaTeX format.
791 static __isl_give isl_printer
*print_optional_disjunct(
792 __isl_keep isl_basic_map
*bmap
, __isl_keep isl_space
*space
,
793 __isl_take isl_printer
*p
, int latex
)
795 if (isl_basic_map_plain_is_universe(bmap
))
798 p
= isl_printer_print_str(p
, ": ");
799 p
= print_disjunct(bmap
, space
, p
, latex
);
804 static __isl_give isl_printer
*basic_map_print_omega(
805 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
)
807 p
= isl_printer_print_str(p
, "{ [");
808 p
= print_var_list(p
, bmap
->dim
, isl_dim_in
);
809 p
= isl_printer_print_str(p
, "] -> [");
810 p
= print_var_list(p
, bmap
->dim
, isl_dim_out
);
811 p
= isl_printer_print_str(p
, "] ");
812 p
= print_optional_disjunct(bmap
, bmap
->dim
, p
, 0);
813 p
= isl_printer_print_str(p
, " }");
817 static __isl_give isl_printer
*basic_set_print_omega(
818 __isl_keep isl_basic_set
*bset
, __isl_take isl_printer
*p
)
820 p
= isl_printer_print_str(p
, "{ [");
821 p
= print_var_list(p
, bset
->dim
, isl_dim_set
);
822 p
= isl_printer_print_str(p
, "] ");
823 p
= print_optional_disjunct(bset
, bset
->dim
, p
, 0);
824 p
= isl_printer_print_str(p
, " }");
828 static __isl_give isl_printer
*isl_map_print_omega(__isl_keep isl_map
*map
,
829 __isl_take isl_printer
*p
)
833 for (i
= 0; i
< map
->n
; ++i
) {
835 p
= isl_printer_print_str(p
, " union ");
836 p
= basic_map_print_omega(map
->p
[i
], p
);
841 static __isl_give isl_printer
*isl_set_print_omega(__isl_keep isl_set
*set
,
842 __isl_take isl_printer
*p
)
846 for (i
= 0; i
< set
->n
; ++i
) {
848 p
= isl_printer_print_str(p
, " union ");
849 p
= basic_set_print_omega(set
->p
[i
], p
);
854 static __isl_give isl_printer
*isl_basic_map_print_isl(
855 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
,
858 struct isl_print_space_data data
= { .latex
= latex
};
859 int rational
= ISL_F_ISSET(bmap
, ISL_BASIC_MAP_RATIONAL
);
861 if (isl_basic_map_dim(bmap
, isl_dim_param
) > 0) {
862 p
= print_tuple(bmap
->dim
, p
, isl_dim_param
, &data
);
863 p
= isl_printer_print_str(p
, " -> ");
865 p
= isl_printer_print_str(p
, "{ ");
866 p
= isl_print_space(bmap
->dim
, p
, rational
, &data
);
867 p
= isl_printer_print_str(p
, " : ");
868 p
= print_disjunct(bmap
, bmap
->dim
, p
, latex
);
869 p
= isl_printer_print_str(p
, " }");
873 /* Print the disjuncts of a map (or set) "map" to "p".
874 * The names of the variables are taken from "space".
875 * "latex" is set if the constraints should be printed in LaTeX format.
877 static __isl_give isl_printer
*print_disjuncts_core(__isl_keep isl_map
*map
,
878 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
883 p
= isl_printer_print_str(p
, "1 = 0");
884 for (i
= 0; i
< map
->n
; ++i
) {
886 p
= isl_printer_print_str(p
, s_or
[latex
]);
887 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
888 p
= isl_printer_print_str(p
, "(");
889 p
= print_disjunct(map
->p
[i
], space
, p
, latex
);
890 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
891 p
= isl_printer_print_str(p
, ")");
896 /* Print the disjuncts of a map (or set) "map" to "p".
897 * The names of the variables are taken from "space".
898 * "hull" describes constraints shared by all disjuncts of "map".
899 * "latex" is set if the constraints should be printed in LaTeX format.
901 * Print the disjuncts as a conjunction of "hull" and
902 * the result of removing the constraints of "hull" from "map".
903 * If this result turns out to be the universe, then simply print "hull".
905 static __isl_give isl_printer
*print_disjuncts_in_hull(__isl_keep isl_map
*map
,
906 __isl_keep isl_space
*space
, __isl_take isl_basic_map
*hull
,
907 __isl_take isl_printer
*p
, int latex
)
909 isl_bool is_universe
;
911 p
= print_disjunct(hull
, space
, p
, latex
);
912 map
= isl_map_plain_gist_basic_map(isl_map_copy(map
), hull
);
913 is_universe
= isl_map_plain_is_universe(map
);
917 p
= isl_printer_print_str(p
, s_and
[latex
]);
918 p
= isl_printer_print_str(p
, "(");
919 p
= print_disjuncts_core(map
, space
, p
, latex
);
920 p
= isl_printer_print_str(p
, ")");
931 /* Print the disjuncts of a map (or set) "map" to "p".
932 * The names of the variables are taken from "space".
933 * "latex" is set if the constraints should be printed in LaTeX format.
935 * If there are at least two disjuncts and "dump" mode is not turned out,
936 * check for any shared constraints among all disjuncts.
937 * If there are any, then print them separately in print_disjuncts_in_hull.
939 static __isl_give isl_printer
*print_disjuncts(__isl_keep isl_map
*map
,
940 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
942 if (isl_map_plain_is_universe(map
))
945 p
= isl_printer_print_str(p
, s_such_that
[latex
]);
949 if (!p
->dump
&& map
->n
>= 2) {
951 isl_bool is_universe
;
953 hull
= isl_map_plain_unshifted_simple_hull(isl_map_copy(map
));
954 is_universe
= isl_basic_map_plain_is_universe(hull
);
956 p
= isl_printer_free(p
);
957 else if (!is_universe
)
958 return print_disjuncts_in_hull(map
, space
, hull
,
960 isl_basic_map_free(hull
);
963 return print_disjuncts_core(map
, space
, p
, latex
);
966 /* Print the disjuncts of a map (or set).
967 * The names of the variables are taken from "space".
968 * "latex" is set if the constraints should be printed in LaTeX format.
970 * If the map turns out to be a universal parameter domain, then
971 * we need to print the colon. Otherwise, the output looks identical
974 static __isl_give isl_printer
*print_disjuncts_map(__isl_keep isl_map
*map
,
975 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
977 if (isl_map_plain_is_universe(map
) && isl_space_is_params(map
->dim
))
978 return isl_printer_print_str(p
, s_such_that
[latex
]);
980 return print_disjuncts(map
, space
, p
, latex
);
983 struct isl_aff_split
{
988 static void free_split(__isl_take
struct isl_aff_split
*split
, int n
)
995 for (i
= 0; i
< n
; ++i
) {
996 isl_basic_map_free(split
[i
].aff
);
997 isl_map_free(split
[i
].map
);
1003 static __isl_give isl_basic_map
*get_aff(__isl_take isl_basic_map
*bmap
)
1006 unsigned nparam
, n_in
, n_out
, total
;
1008 bmap
= isl_basic_map_cow(bmap
);
1011 if (isl_basic_map_free_inequality(bmap
, bmap
->n_ineq
) < 0)
1014 nparam
= isl_basic_map_dim(bmap
, isl_dim_param
);
1015 n_in
= isl_basic_map_dim(bmap
, isl_dim_in
);
1016 n_out
= isl_basic_map_dim(bmap
, isl_dim_out
);
1017 total
= isl_basic_map_dim(bmap
, isl_dim_all
);
1018 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
1019 j
= isl_seq_last_non_zero(bmap
->eq
[i
] + 1, total
);
1020 if (j
>= nparam
&& j
< nparam
+ n_in
+ n_out
&&
1021 (isl_int_is_one(bmap
->eq
[i
][1 + j
]) ||
1022 isl_int_is_negone(bmap
->eq
[i
][1 + j
])))
1024 if (isl_basic_map_drop_equality(bmap
, i
) < 0)
1028 bmap
= isl_basic_map_finalize(bmap
);
1032 isl_basic_map_free(bmap
);
1036 static int aff_split_cmp(const void *p1
, const void *p2
, void *user
)
1038 const struct isl_aff_split
*s1
, *s2
;
1039 s1
= (const struct isl_aff_split
*) p1
;
1040 s2
= (const struct isl_aff_split
*) p2
;
1042 return isl_basic_map_plain_cmp(s1
->aff
, s2
->aff
);
1045 static __isl_give isl_basic_map
*drop_aff(__isl_take isl_basic_map
*bmap
,
1046 __isl_keep isl_basic_map
*aff
)
1054 total
= isl_space_dim(bmap
->dim
, isl_dim_all
);
1056 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
1057 if (isl_seq_first_non_zero(bmap
->eq
[i
] + 1 + total
,
1060 for (j
= 0; j
< aff
->n_eq
; ++j
) {
1061 if (!isl_seq_eq(bmap
->eq
[i
], aff
->eq
[j
], 1 + total
) &&
1062 !isl_seq_is_neg(bmap
->eq
[i
], aff
->eq
[j
], 1 + total
))
1064 if (isl_basic_map_drop_equality(bmap
, i
) < 0)
1072 isl_basic_map_free(bmap
);
1076 static __isl_give
struct isl_aff_split
*split_aff(__isl_keep isl_map
*map
)
1079 struct isl_aff_split
*split
;
1082 ctx
= isl_map_get_ctx(map
);
1083 split
= isl_calloc_array(ctx
, struct isl_aff_split
, map
->n
);
1087 for (i
= 0; i
< map
->n
; ++i
) {
1088 isl_basic_map
*bmap
;
1089 split
[i
].aff
= get_aff(isl_basic_map_copy(map
->p
[i
]));
1090 bmap
= isl_basic_map_copy(map
->p
[i
]);
1091 bmap
= isl_basic_map_cow(bmap
);
1092 bmap
= drop_aff(bmap
, split
[i
].aff
);
1093 split
[i
].map
= isl_map_from_basic_map(bmap
);
1094 if (!split
[i
].aff
|| !split
[i
].map
)
1098 if (isl_sort(split
, map
->n
, sizeof(struct isl_aff_split
),
1099 &aff_split_cmp
, NULL
) < 0)
1103 for (i
= n
- 1; i
>= 1; --i
) {
1104 if (!isl_basic_map_plain_is_equal(split
[i
- 1].aff
,
1107 isl_basic_map_free(split
[i
].aff
);
1108 split
[i
- 1].map
= isl_map_union(split
[i
- 1].map
,
1111 split
[i
] = split
[n
- 1];
1112 split
[n
- 1].aff
= NULL
;
1113 split
[n
- 1].map
= NULL
;
1119 free_split(split
, map
->n
);
1123 static int defining_equality(__isl_keep isl_basic_map
*eq
,
1124 __isl_keep isl_space
*dim
, enum isl_dim_type type
, int pos
)
1132 pos
+= isl_space_offset(dim
, type
);
1133 total
= isl_basic_map_total_dim(eq
);
1135 for (i
= 0; i
< eq
->n_eq
; ++i
) {
1136 if (isl_seq_last_non_zero(eq
->eq
[i
] + 1, total
) != pos
)
1138 if (isl_int_is_one(eq
->eq
[i
][1 + pos
]))
1139 isl_seq_neg(eq
->eq
[i
], eq
->eq
[i
], 1 + total
);
1146 /* Print dimension "pos" of data->space to "p".
1148 * data->user is assumed to be an isl_basic_map keeping track of equalities.
1150 * If the current dimension is defined by these equalities, then print
1151 * the corresponding expression, assigned to the name of the dimension
1152 * if there is any. Otherwise, print the name of the dimension.
1154 static __isl_give isl_printer
*print_dim_eq(__isl_take isl_printer
*p
,
1155 struct isl_print_space_data
*data
, unsigned pos
)
1157 isl_basic_map
*eq
= data
->user
;
1160 j
= defining_equality(eq
, data
->space
, data
->type
, pos
);
1162 if (isl_space_has_dim_name(data
->space
, data
->type
, pos
)) {
1163 p
= print_name(data
->space
, p
, data
->type
, pos
,
1165 p
= isl_printer_print_str(p
, " = ");
1167 pos
+= 1 + isl_space_offset(data
->space
, data
->type
);
1168 p
= print_affine_of_len(data
->space
, NULL
, p
, eq
->eq
[j
], pos
);
1170 p
= print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
1176 static __isl_give isl_printer
*print_split_map(__isl_take isl_printer
*p
,
1177 struct isl_aff_split
*split
, int n
, __isl_keep isl_space
*space
)
1179 struct isl_print_space_data data
= { 0 };
1183 data
.print_dim
= &print_dim_eq
;
1184 for (i
= 0; i
< n
; ++i
) {
1187 rational
= split
[i
].map
->n
> 0 &&
1188 ISL_F_ISSET(split
[i
].map
->p
[0], ISL_BASIC_MAP_RATIONAL
);
1190 p
= isl_printer_print_str(p
, "; ");
1191 data
.user
= split
[i
].aff
;
1192 p
= isl_print_space(space
, p
, rational
, &data
);
1193 p
= print_disjuncts_map(split
[i
].map
, space
, p
, 0);
1199 static __isl_give isl_printer
*isl_map_print_isl_body(__isl_keep isl_map
*map
,
1200 __isl_take isl_printer
*p
)
1202 struct isl_print_space_data data
= { 0 };
1203 struct isl_aff_split
*split
= NULL
;
1207 return isl_printer_free(p
);
1208 if (!p
->dump
&& map
->n
> 0)
1209 split
= split_aff(map
);
1211 p
= print_split_map(p
, split
, map
->n
, map
->dim
);
1213 rational
= map
->n
> 0 &&
1214 ISL_F_ISSET(map
->p
[0], ISL_BASIC_MAP_RATIONAL
);
1215 p
= isl_print_space(map
->dim
, p
, rational
, &data
);
1216 p
= print_disjuncts_map(map
, map
->dim
, p
, 0);
1218 free_split(split
, map
->n
);
1222 static __isl_give isl_printer
*isl_map_print_isl(__isl_keep isl_map
*map
,
1223 __isl_take isl_printer
*p
)
1225 struct isl_print_space_data data
= { 0 };
1227 if (isl_map_dim(map
, isl_dim_param
) > 0) {
1228 p
= print_tuple(map
->dim
, p
, isl_dim_param
, &data
);
1229 p
= isl_printer_print_str(p
, s_to
[0]);
1231 p
= isl_printer_print_str(p
, s_open_set
[0]);
1232 p
= isl_map_print_isl_body(map
, p
);
1233 p
= isl_printer_print_str(p
, s_close_set
[0]);
1237 static __isl_give isl_printer
*print_latex_map(__isl_keep isl_map
*map
,
1238 __isl_take isl_printer
*p
, __isl_keep isl_basic_map
*aff
)
1240 struct isl_print_space_data data
= { 0 };
1243 if (isl_map_dim(map
, isl_dim_param
) > 0) {
1244 p
= print_tuple(map
->dim
, p
, isl_dim_param
, &data
);
1245 p
= isl_printer_print_str(p
, s_to
[1]);
1247 p
= isl_printer_print_str(p
, s_open_set
[1]);
1248 data
.print_dim
= &print_dim_eq
;
1250 p
= isl_print_space(map
->dim
, p
, 0, &data
);
1251 p
= print_disjuncts_map(map
, map
->dim
, p
, 1);
1252 p
= isl_printer_print_str(p
, s_close_set
[1]);
1257 static __isl_give isl_printer
*isl_map_print_latex(__isl_keep isl_map
*map
,
1258 __isl_take isl_printer
*p
)
1261 struct isl_aff_split
*split
= NULL
;
1264 split
= split_aff(map
);
1267 return print_latex_map(map
, p
, NULL
);
1269 for (i
= 0; i
< map
->n
; ++i
) {
1273 p
= isl_printer_print_str(p
, " \\cup ");
1274 p
= print_latex_map(split
[i
].map
, p
, split
[i
].aff
);
1277 free_split(split
, map
->n
);
1281 __isl_give isl_printer
*isl_printer_print_basic_map(__isl_take isl_printer
*p
,
1282 __isl_keep isl_basic_map
*bmap
)
1286 if (p
->output_format
== ISL_FORMAT_ISL
)
1287 return isl_basic_map_print_isl(bmap
, p
, 0);
1288 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1289 return basic_map_print_omega(bmap
, p
);
1290 isl_assert(bmap
->ctx
, 0, goto error
);
1292 isl_printer_free(p
);
1296 __isl_give isl_printer
*isl_printer_print_basic_set(__isl_take isl_printer
*p
,
1297 __isl_keep isl_basic_set
*bset
)
1302 if (p
->output_format
== ISL_FORMAT_ISL
)
1303 return isl_basic_map_print_isl(bset
, p
, 0);
1304 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1305 return isl_basic_set_print_polylib(bset
, p
, 0);
1306 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1307 return isl_basic_set_print_polylib(bset
, p
, 1);
1308 else if (p
->output_format
== ISL_FORMAT_POLYLIB_CONSTRAINTS
)
1309 return bset_print_constraints_polylib(bset
, p
);
1310 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1311 return basic_set_print_omega(bset
, p
);
1312 isl_assert(p
->ctx
, 0, goto error
);
1314 isl_printer_free(p
);
1318 __isl_give isl_printer
*isl_printer_print_set(__isl_take isl_printer
*p
,
1319 __isl_keep isl_set
*set
)
1323 if (p
->output_format
== ISL_FORMAT_ISL
)
1324 return isl_map_print_isl(set_to_map(set
), p
);
1325 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1326 return isl_set_print_polylib(set
, p
, 0);
1327 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1328 return isl_set_print_polylib(set
, p
, 1);
1329 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1330 return isl_set_print_omega(set
, p
);
1331 else if (p
->output_format
== ISL_FORMAT_LATEX
)
1332 return isl_map_print_latex(set_to_map(set
), p
);
1333 isl_assert(set
->ctx
, 0, goto error
);
1335 isl_printer_free(p
);
1339 __isl_give isl_printer
*isl_printer_print_map(__isl_take isl_printer
*p
,
1340 __isl_keep isl_map
*map
)
1345 if (p
->output_format
== ISL_FORMAT_ISL
)
1346 return isl_map_print_isl(map
, p
);
1347 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1348 return isl_map_print_polylib(map
, p
, 0);
1349 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1350 return isl_map_print_polylib(map
, p
, 1);
1351 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1352 return isl_map_print_omega(map
, p
);
1353 else if (p
->output_format
== ISL_FORMAT_LATEX
)
1354 return isl_map_print_latex(map
, p
);
1355 isl_assert(map
->ctx
, 0, goto error
);
1357 isl_printer_free(p
);
1361 struct isl_union_print_data
{
1366 static isl_stat
print_map_body(__isl_take isl_map
*map
, void *user
)
1368 struct isl_union_print_data
*data
;
1369 data
= (struct isl_union_print_data
*)user
;
1372 data
->p
= isl_printer_print_str(data
->p
, "; ");
1375 data
->p
= isl_map_print_isl_body(map
, data
->p
);
1381 static __isl_give isl_printer
*isl_union_map_print_isl(
1382 __isl_keep isl_union_map
*umap
, __isl_take isl_printer
*p
)
1384 struct isl_union_print_data data
;
1385 struct isl_print_space_data space_data
= { 0 };
1388 dim
= isl_union_map_get_space(umap
);
1389 if (isl_space_dim(dim
, isl_dim_param
) > 0) {
1390 p
= print_tuple(dim
, p
, isl_dim_param
, &space_data
);
1391 p
= isl_printer_print_str(p
, s_to
[0]);
1393 isl_space_free(dim
);
1394 p
= isl_printer_print_str(p
, s_open_set
[0]);
1397 isl_union_map_foreach_map(umap
, &print_map_body
, &data
);
1399 p
= isl_printer_print_str(p
, s_close_set
[0]);
1403 static isl_stat
print_latex_map_body(__isl_take isl_map
*map
, void *user
)
1405 struct isl_union_print_data
*data
;
1406 data
= (struct isl_union_print_data
*)user
;
1409 data
->p
= isl_printer_print_str(data
->p
, " \\cup ");
1412 data
->p
= isl_map_print_latex(map
, data
->p
);
1418 static __isl_give isl_printer
*isl_union_map_print_latex(
1419 __isl_keep isl_union_map
*umap
, __isl_take isl_printer
*p
)
1421 struct isl_union_print_data data
= { p
, 1 };
1422 isl_union_map_foreach_map(umap
, &print_latex_map_body
, &data
);
1427 __isl_give isl_printer
*isl_printer_print_union_map(__isl_take isl_printer
*p
,
1428 __isl_keep isl_union_map
*umap
)
1433 if (p
->output_format
== ISL_FORMAT_ISL
)
1434 return isl_union_map_print_isl(umap
, p
);
1435 if (p
->output_format
== ISL_FORMAT_LATEX
)
1436 return isl_union_map_print_latex(umap
, p
);
1438 isl_die(p
->ctx
, isl_error_invalid
,
1439 "invalid output format for isl_union_map", goto error
);
1441 isl_printer_free(p
);
1445 __isl_give isl_printer
*isl_printer_print_union_set(__isl_take isl_printer
*p
,
1446 __isl_keep isl_union_set
*uset
)
1451 if (p
->output_format
== ISL_FORMAT_ISL
)
1452 return isl_union_map_print_isl((isl_union_map
*)uset
, p
);
1453 if (p
->output_format
== ISL_FORMAT_LATEX
)
1454 return isl_union_map_print_latex((isl_union_map
*)uset
, p
);
1456 isl_die(p
->ctx
, isl_error_invalid
,
1457 "invalid output format for isl_union_set", goto error
);
1459 isl_printer_free(p
);
1463 static int upoly_rec_n_non_zero(__isl_keep
struct isl_upoly_rec
*rec
)
1468 for (i
= 0, n
= 0; i
< rec
->n
; ++i
)
1469 if (!isl_upoly_is_zero(rec
->p
[i
]))
1475 static __isl_give isl_printer
*upoly_print_cst(__isl_keep
struct isl_upoly
*up
,
1476 __isl_take isl_printer
*p
, int first
)
1478 struct isl_upoly_cst
*cst
;
1481 cst
= isl_upoly_as_cst(up
);
1484 neg
= !first
&& isl_int_is_neg(cst
->n
);
1486 p
= isl_printer_print_str(p
, neg
? " - " : " + ");
1488 isl_int_neg(cst
->n
, cst
->n
);
1489 if (isl_int_is_zero(cst
->d
)) {
1490 int sgn
= isl_int_sgn(cst
->n
);
1491 p
= isl_printer_print_str(p
, sgn
< 0 ? "-infty" :
1492 sgn
== 0 ? "NaN" : "infty");
1494 p
= isl_printer_print_isl_int(p
, cst
->n
);
1496 isl_int_neg(cst
->n
, cst
->n
);
1497 if (!isl_int_is_zero(cst
->d
) && !isl_int_is_one(cst
->d
)) {
1498 p
= isl_printer_print_str(p
, "/");
1499 p
= isl_printer_print_isl_int(p
, cst
->d
);
1503 isl_printer_free(p
);
1507 static __isl_give isl_printer
*print_base(__isl_take isl_printer
*p
,
1508 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
, int var
)
1512 total
= isl_space_dim(dim
, isl_dim_all
);
1514 p
= print_term(dim
, NULL
, dim
->ctx
->one
, 1 + var
, p
, 0);
1516 p
= print_div(dim
, div
, var
- total
, p
);
1520 static __isl_give isl_printer
*print_pow(__isl_take isl_printer
*p
,
1521 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
, int var
, int exp
)
1523 p
= print_base(p
, dim
, div
, var
);
1526 if (p
->output_format
== ISL_FORMAT_C
) {
1528 for (i
= 1; i
< exp
; ++i
) {
1529 p
= isl_printer_print_str(p
, "*");
1530 p
= print_base(p
, dim
, div
, var
);
1533 p
= isl_printer_print_str(p
, "^");
1534 p
= isl_printer_print_int(p
, exp
);
1539 static __isl_give isl_printer
*upoly_print(__isl_keep
struct isl_upoly
*up
,
1540 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
,
1541 __isl_take isl_printer
*p
, int outer
)
1543 int i
, n
, first
, print_parens
;
1544 struct isl_upoly_rec
*rec
;
1546 if (!p
|| !up
|| !dim
|| !div
)
1549 if (isl_upoly_is_cst(up
))
1550 return upoly_print_cst(up
, p
, 1);
1552 rec
= isl_upoly_as_rec(up
);
1555 n
= upoly_rec_n_non_zero(rec
);
1556 print_parens
= n
> 1 ||
1557 (outer
&& rec
->up
.var
>= isl_space_dim(dim
, isl_dim_all
));
1559 p
= isl_printer_print_str(p
, "(");
1560 for (i
= 0, first
= 1; i
< rec
->n
; ++i
) {
1561 if (isl_upoly_is_zero(rec
->p
[i
]))
1563 if (isl_upoly_is_negone(rec
->p
[i
])) {
1565 p
= isl_printer_print_str(p
, "-1");
1567 p
= isl_printer_print_str(p
, "-");
1569 p
= isl_printer_print_str(p
, " - ");
1570 } else if (isl_upoly_is_cst(rec
->p
[i
]) &&
1571 !isl_upoly_is_one(rec
->p
[i
]))
1572 p
= upoly_print_cst(rec
->p
[i
], p
, first
);
1575 p
= isl_printer_print_str(p
, " + ");
1576 if (i
== 0 || !isl_upoly_is_one(rec
->p
[i
]))
1577 p
= upoly_print(rec
->p
[i
], dim
, div
, p
, 0);
1582 if (!isl_upoly_is_one(rec
->p
[i
]) &&
1583 !isl_upoly_is_negone(rec
->p
[i
]))
1584 p
= isl_printer_print_str(p
, " * ");
1585 p
= print_pow(p
, dim
, div
, rec
->up
.var
, i
);
1588 p
= isl_printer_print_str(p
, ")");
1591 isl_printer_free(p
);
1595 static __isl_give isl_printer
*print_qpolynomial(__isl_take isl_printer
*p
,
1596 __isl_keep isl_qpolynomial
*qp
)
1600 p
= upoly_print(qp
->upoly
, qp
->dim
, qp
->div
, p
, 1);
1603 isl_printer_free(p
);
1607 static __isl_give isl_printer
*print_qpolynomial_isl(__isl_take isl_printer
*p
,
1608 __isl_keep isl_qpolynomial
*qp
)
1610 struct isl_print_space_data data
= { 0 };
1615 if (isl_space_dim(qp
->dim
, isl_dim_param
) > 0) {
1616 p
= print_tuple(qp
->dim
, p
, isl_dim_param
, &data
);
1617 p
= isl_printer_print_str(p
, " -> ");
1619 p
= isl_printer_print_str(p
, "{ ");
1620 if (!isl_space_is_params(qp
->dim
)) {
1621 p
= isl_print_space(qp
->dim
, p
, 0, &data
);
1622 p
= isl_printer_print_str(p
, " -> ");
1624 p
= print_qpolynomial(p
, qp
);
1625 p
= isl_printer_print_str(p
, " }");
1628 isl_printer_free(p
);
1632 static __isl_give isl_printer
*print_qpolynomial_c(__isl_take isl_printer
*p
,
1633 __isl_keep isl_space
*dim
, __isl_keep isl_qpolynomial
*qp
)
1638 isl_qpolynomial_get_den(qp
, &den
);
1639 if (!isl_int_is_one(den
)) {
1641 p
= isl_printer_print_str(p
, "(");
1642 qp
= isl_qpolynomial_copy(qp
);
1643 f
= isl_qpolynomial_rat_cst_on_domain(isl_space_copy(qp
->dim
),
1644 den
, qp
->dim
->ctx
->one
);
1645 qp
= isl_qpolynomial_mul(qp
, f
);
1648 p
= upoly_print(qp
->upoly
, dim
, qp
->div
, p
, 0);
1650 p
= isl_printer_free(p
);
1651 if (!isl_int_is_one(den
)) {
1652 p
= isl_printer_print_str(p
, ")/");
1653 p
= isl_printer_print_isl_int(p
, den
);
1654 isl_qpolynomial_free(qp
);
1660 __isl_give isl_printer
*isl_printer_print_qpolynomial(
1661 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial
*qp
)
1666 if (p
->output_format
== ISL_FORMAT_ISL
)
1667 return print_qpolynomial_isl(p
, qp
);
1668 else if (p
->output_format
== ISL_FORMAT_C
)
1669 return print_qpolynomial_c(p
, qp
->dim
, qp
);
1671 isl_die(qp
->dim
->ctx
, isl_error_unsupported
,
1672 "output format not supported for isl_qpolynomials",
1675 isl_printer_free(p
);
1679 void isl_qpolynomial_print(__isl_keep isl_qpolynomial
*qp
, FILE *out
,
1680 unsigned output_format
)
1687 isl_assert(qp
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
1688 p
= isl_printer_to_file(qp
->dim
->ctx
, out
);
1689 p
= isl_printer_print_qpolynomial(p
, qp
);
1690 isl_printer_free(p
);
1693 static __isl_give isl_printer
*qpolynomial_fold_print(
1694 __isl_keep isl_qpolynomial_fold
*fold
, __isl_take isl_printer
*p
)
1698 if (fold
->type
== isl_fold_min
)
1699 p
= isl_printer_print_str(p
, "min");
1700 else if (fold
->type
== isl_fold_max
)
1701 p
= isl_printer_print_str(p
, "max");
1702 p
= isl_printer_print_str(p
, "(");
1703 for (i
= 0; i
< fold
->n
; ++i
) {
1705 p
= isl_printer_print_str(p
, ", ");
1706 p
= print_qpolynomial(p
, fold
->qp
[i
]);
1708 p
= isl_printer_print_str(p
, ")");
1712 void isl_qpolynomial_fold_print(__isl_keep isl_qpolynomial_fold
*fold
,
1713 FILE *out
, unsigned output_format
)
1720 isl_assert(fold
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
1722 p
= isl_printer_to_file(fold
->dim
->ctx
, out
);
1723 p
= isl_printer_print_qpolynomial_fold(p
, fold
);
1725 isl_printer_free(p
);
1728 static __isl_give isl_printer
*isl_pwqp_print_isl_body(
1729 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
1731 struct isl_print_space_data data
= { 0 };
1734 for (i
= 0; i
< pwqp
->n
; ++i
) {
1738 p
= isl_printer_print_str(p
, "; ");
1739 space
= isl_qpolynomial_get_domain_space(pwqp
->p
[i
].qp
);
1740 if (!isl_space_is_params(space
)) {
1741 p
= isl_print_space(space
, p
, 0, &data
);
1742 p
= isl_printer_print_str(p
, " -> ");
1744 p
= print_qpolynomial(p
, pwqp
->p
[i
].qp
);
1745 p
= print_disjuncts(set_to_map(pwqp
->p
[i
].set
), space
, p
, 0);
1746 isl_space_free(space
);
1752 static __isl_give isl_printer
*print_pw_qpolynomial_isl(
1753 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
1755 struct isl_print_space_data data
= { 0 };
1760 if (isl_space_dim(pwqp
->dim
, isl_dim_param
) > 0) {
1761 p
= print_tuple(pwqp
->dim
, p
, isl_dim_param
, &data
);
1762 p
= isl_printer_print_str(p
, " -> ");
1764 p
= isl_printer_print_str(p
, "{ ");
1766 if (!isl_space_is_set(pwqp
->dim
)) {
1767 p
= print_tuple(pwqp
->dim
, p
, isl_dim_in
, &data
);
1768 p
= isl_printer_print_str(p
, " -> ");
1770 p
= isl_printer_print_str(p
, "0");
1772 p
= isl_pwqp_print_isl_body(p
, pwqp
);
1773 p
= isl_printer_print_str(p
, " }");
1776 isl_printer_free(p
);
1780 void isl_pw_qpolynomial_print(__isl_keep isl_pw_qpolynomial
*pwqp
, FILE *out
,
1781 unsigned output_format
)
1788 p
= isl_printer_to_file(pwqp
->dim
->ctx
, out
);
1789 p
= isl_printer_set_output_format(p
, output_format
);
1790 p
= isl_printer_print_pw_qpolynomial(p
, pwqp
);
1792 isl_printer_free(p
);
1795 static __isl_give isl_printer
*isl_pwf_print_isl_body(
1796 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
1798 struct isl_print_space_data data
= { 0 };
1801 for (i
= 0; i
< pwf
->n
; ++i
) {
1805 p
= isl_printer_print_str(p
, "; ");
1806 space
= isl_qpolynomial_fold_get_domain_space(pwf
->p
[i
].fold
);
1807 if (!isl_space_is_params(space
)) {
1808 p
= isl_print_space(space
, p
, 0, &data
);
1809 p
= isl_printer_print_str(p
, " -> ");
1811 p
= qpolynomial_fold_print(pwf
->p
[i
].fold
, p
);
1812 p
= print_disjuncts(set_to_map(pwf
->p
[i
].set
), space
, p
, 0);
1813 isl_space_free(space
);
1819 static __isl_give isl_printer
*print_pw_qpolynomial_fold_isl(
1820 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
1822 struct isl_print_space_data data
= { 0 };
1824 if (isl_space_dim(pwf
->dim
, isl_dim_param
) > 0) {
1825 p
= print_tuple(pwf
->dim
, p
, isl_dim_param
, &data
);
1826 p
= isl_printer_print_str(p
, " -> ");
1828 p
= isl_printer_print_str(p
, "{ ");
1830 if (!isl_space_is_set(pwf
->dim
)) {
1831 p
= print_tuple(pwf
->dim
, p
, isl_dim_in
, &data
);
1832 p
= isl_printer_print_str(p
, " -> ");
1834 p
= isl_printer_print_str(p
, "0");
1836 p
= isl_pwf_print_isl_body(p
, pwf
);
1837 p
= isl_printer_print_str(p
, " }");
1841 static __isl_give isl_printer
*print_affine_c(__isl_take isl_printer
*p
,
1842 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
, isl_int
*c
);
1844 static __isl_give isl_printer
*print_name_c(__isl_take isl_printer
*p
,
1845 __isl_keep isl_space
*dim
,
1846 __isl_keep isl_basic_set
*bset
, enum isl_dim_type type
, unsigned pos
)
1848 if (type
== isl_dim_div
) {
1849 p
= isl_printer_print_str(p
, "floord(");
1850 p
= print_affine_c(p
, dim
, bset
, bset
->div
[pos
] + 1);
1851 p
= isl_printer_print_str(p
, ", ");
1852 p
= isl_printer_print_isl_int(p
, bset
->div
[pos
][0]);
1853 p
= isl_printer_print_str(p
, ")");
1857 name
= isl_space_get_dim_name(dim
, type
, pos
);
1860 p
= isl_printer_print_str(p
, name
);
1865 static __isl_give isl_printer
*print_term_c(__isl_take isl_printer
*p
,
1866 __isl_keep isl_space
*dim
,
1867 __isl_keep isl_basic_set
*bset
, isl_int c
, unsigned pos
)
1869 enum isl_dim_type type
;
1872 return isl_printer_print_isl_int(p
, c
);
1874 if (isl_int_is_one(c
))
1876 else if (isl_int_is_negone(c
))
1877 p
= isl_printer_print_str(p
, "-");
1879 p
= isl_printer_print_isl_int(p
, c
);
1880 p
= isl_printer_print_str(p
, "*");
1882 type
= pos2type(dim
, &pos
);
1883 p
= print_name_c(p
, dim
, bset
, type
, pos
);
1887 static __isl_give isl_printer
*print_partial_affine_c(__isl_take isl_printer
*p
,
1888 __isl_keep isl_space
*dim
,
1889 __isl_keep isl_basic_set
*bset
, isl_int
*c
, unsigned len
)
1894 for (i
= 0, first
= 1; i
< len
; ++i
) {
1896 if (isl_int_is_zero(c
[i
]))
1899 if (isl_int_is_neg(c
[i
])) {
1901 isl_int_neg(c
[i
], c
[i
]);
1902 p
= isl_printer_print_str(p
, " - ");
1904 p
= isl_printer_print_str(p
, " + ");
1907 p
= print_term_c(p
, dim
, bset
, c
[i
], i
);
1909 isl_int_neg(c
[i
], c
[i
]);
1912 p
= isl_printer_print_str(p
, "0");
1916 static __isl_give isl_printer
*print_affine_c(__isl_take isl_printer
*p
,
1917 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
, isl_int
*c
)
1919 unsigned len
= 1 + isl_basic_set_total_dim(bset
);
1920 return print_partial_affine_c(p
, dim
, bset
, c
, len
);
1923 /* We skip the constraint if it is implied by the div expression.
1925 * *first indicates whether this is the first constraint in the conjunction and
1926 * is updated if the constraint is actually printed.
1928 static __isl_give isl_printer
*print_constraint_c(__isl_take isl_printer
*p
,
1929 __isl_keep isl_space
*dim
,
1930 __isl_keep isl_basic_set
*bset
, isl_int
*c
, const char *op
, int *first
)
1936 o_div
= isl_basic_set_offset(bset
, isl_dim_div
);
1937 n_div
= isl_basic_set_dim(bset
, isl_dim_div
);
1938 div
= isl_seq_last_non_zero(c
+ o_div
, n_div
);
1939 if (div
>= 0 && isl_basic_set_is_div_constraint(bset
, c
, div
))
1943 p
= isl_printer_print_str(p
, " && ");
1945 p
= print_affine_c(p
, dim
, bset
, c
);
1946 p
= isl_printer_print_str(p
, " ");
1947 p
= isl_printer_print_str(p
, op
);
1948 p
= isl_printer_print_str(p
, " 0");
1955 static __isl_give isl_printer
*print_basic_set_c(__isl_take isl_printer
*p
,
1956 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
)
1960 unsigned n_div
= isl_basic_set_dim(bset
, isl_dim_div
);
1961 unsigned total
= isl_basic_set_total_dim(bset
) - n_div
;
1963 for (i
= 0; i
< bset
->n_eq
; ++i
) {
1964 j
= isl_seq_last_non_zero(bset
->eq
[i
] + 1 + total
, n_div
);
1966 p
= print_constraint_c(p
, dim
, bset
,
1967 bset
->eq
[i
], "==", &first
);
1970 p
= isl_printer_print_str(p
, " && ");
1971 p
= isl_printer_print_str(p
, "(");
1972 p
= print_partial_affine_c(p
, dim
, bset
, bset
->eq
[i
],
1974 p
= isl_printer_print_str(p
, ") % ");
1975 p
= isl_printer_print_isl_int(p
,
1976 bset
->eq
[i
][1 + total
+ j
]);
1977 p
= isl_printer_print_str(p
, " == 0");
1981 for (i
= 0; i
< bset
->n_ineq
; ++i
)
1982 p
= print_constraint_c(p
, dim
, bset
, bset
->ineq
[i
], ">=",
1987 static __isl_give isl_printer
*print_set_c(__isl_take isl_printer
*p
,
1988 __isl_keep isl_space
*dim
, __isl_keep isl_set
*set
)
1993 return isl_printer_free(p
);
1996 p
= isl_printer_print_str(p
, "0");
1998 for (i
= 0; i
< set
->n
; ++i
) {
2000 p
= isl_printer_print_str(p
, " || ");
2002 p
= isl_printer_print_str(p
, "(");
2003 p
= print_basic_set_c(p
, dim
, set
->p
[i
]);
2005 p
= isl_printer_print_str(p
, ")");
2010 static __isl_give isl_printer
*print_pw_qpolynomial_c(
2011 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2015 if (pwqp
->n
== 1 && isl_set_plain_is_universe(pwqp
->p
[0].set
))
2016 return print_qpolynomial_c(p
, pwqp
->dim
, pwqp
->p
[0].qp
);
2018 for (i
= 0; i
< pwqp
->n
; ++i
) {
2019 p
= isl_printer_print_str(p
, "(");
2020 p
= print_set_c(p
, pwqp
->dim
, pwqp
->p
[i
].set
);
2021 p
= isl_printer_print_str(p
, ") ? (");
2022 p
= print_qpolynomial_c(p
, pwqp
->dim
, pwqp
->p
[i
].qp
);
2023 p
= isl_printer_print_str(p
, ") : ");
2026 p
= isl_printer_print_str(p
, "0");
2030 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial(
2031 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2036 if (p
->output_format
== ISL_FORMAT_ISL
)
2037 return print_pw_qpolynomial_isl(p
, pwqp
);
2038 else if (p
->output_format
== ISL_FORMAT_C
)
2039 return print_pw_qpolynomial_c(p
, pwqp
);
2040 isl_assert(p
->ctx
, 0, goto error
);
2042 isl_printer_free(p
);
2046 static isl_stat
print_pwqp_body(__isl_take isl_pw_qpolynomial
*pwqp
, void *user
)
2048 struct isl_union_print_data
*data
;
2049 data
= (struct isl_union_print_data
*)user
;
2052 data
->p
= isl_printer_print_str(data
->p
, "; ");
2055 data
->p
= isl_pwqp_print_isl_body(data
->p
, pwqp
);
2056 isl_pw_qpolynomial_free(pwqp
);
2061 static __isl_give isl_printer
*print_union_pw_qpolynomial_isl(
2062 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2064 struct isl_union_print_data data
;
2065 struct isl_print_space_data space_data
= { 0 };
2068 dim
= isl_union_pw_qpolynomial_get_space(upwqp
);
2069 if (isl_space_dim(dim
, isl_dim_param
) > 0) {
2070 p
= print_tuple(dim
, p
, isl_dim_param
, &space_data
);
2071 p
= isl_printer_print_str(p
, " -> ");
2073 isl_space_free(dim
);
2074 p
= isl_printer_print_str(p
, "{ ");
2077 isl_union_pw_qpolynomial_foreach_pw_qpolynomial(upwqp
, &print_pwqp_body
,
2080 p
= isl_printer_print_str(p
, " }");
2084 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial(
2085 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2090 if (p
->output_format
== ISL_FORMAT_ISL
)
2091 return print_union_pw_qpolynomial_isl(p
, upwqp
);
2092 isl_die(p
->ctx
, isl_error_invalid
,
2093 "invalid output format for isl_union_pw_qpolynomial",
2096 isl_printer_free(p
);
2100 static __isl_give isl_printer
*print_qpolynomial_fold_c(
2101 __isl_take isl_printer
*p
, __isl_keep isl_space
*dim
,
2102 __isl_keep isl_qpolynomial_fold
*fold
)
2106 for (i
= 0; i
< fold
->n
- 1; ++i
)
2107 if (fold
->type
== isl_fold_min
)
2108 p
= isl_printer_print_str(p
, "min(");
2109 else if (fold
->type
== isl_fold_max
)
2110 p
= isl_printer_print_str(p
, "max(");
2112 for (i
= 0; i
< fold
->n
; ++i
) {
2114 p
= isl_printer_print_str(p
, ", ");
2115 p
= print_qpolynomial_c(p
, dim
, fold
->qp
[i
]);
2117 p
= isl_printer_print_str(p
, ")");
2122 __isl_give isl_printer
*isl_printer_print_qpolynomial_fold(
2123 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial_fold
*fold
)
2127 if (p
->output_format
== ISL_FORMAT_ISL
)
2128 return qpolynomial_fold_print(fold
, p
);
2129 else if (p
->output_format
== ISL_FORMAT_C
)
2130 return print_qpolynomial_fold_c(p
, fold
->dim
, fold
);
2131 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2134 isl_printer_free(p
);
2138 static __isl_give isl_printer
*print_pw_qpolynomial_fold_c(
2139 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2143 if (pwf
->n
== 1 && isl_set_plain_is_universe(pwf
->p
[0].set
))
2144 return print_qpolynomial_fold_c(p
, pwf
->dim
, pwf
->p
[0].fold
);
2146 for (i
= 0; i
< pwf
->n
; ++i
) {
2147 p
= isl_printer_print_str(p
, "(");
2148 p
= print_set_c(p
, pwf
->dim
, pwf
->p
[i
].set
);
2149 p
= isl_printer_print_str(p
, ") ? (");
2150 p
= print_qpolynomial_fold_c(p
, pwf
->dim
, pwf
->p
[i
].fold
);
2151 p
= isl_printer_print_str(p
, ") : ");
2154 p
= isl_printer_print_str(p
, "0");
2158 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial_fold(
2159 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2164 if (p
->output_format
== ISL_FORMAT_ISL
)
2165 return print_pw_qpolynomial_fold_isl(p
, pwf
);
2166 else if (p
->output_format
== ISL_FORMAT_C
)
2167 return print_pw_qpolynomial_fold_c(p
, pwf
);
2168 isl_assert(p
->ctx
, 0, goto error
);
2170 isl_printer_free(p
);
2174 void isl_pw_qpolynomial_fold_print(__isl_keep isl_pw_qpolynomial_fold
*pwf
,
2175 FILE *out
, unsigned output_format
)
2182 p
= isl_printer_to_file(pwf
->dim
->ctx
, out
);
2183 p
= isl_printer_set_output_format(p
, output_format
);
2184 p
= isl_printer_print_pw_qpolynomial_fold(p
, pwf
);
2186 isl_printer_free(p
);
2189 static isl_stat
print_pwf_body(__isl_take isl_pw_qpolynomial_fold
*pwf
,
2192 struct isl_union_print_data
*data
;
2193 data
= (struct isl_union_print_data
*)user
;
2196 data
->p
= isl_printer_print_str(data
->p
, "; ");
2199 data
->p
= isl_pwf_print_isl_body(data
->p
, pwf
);
2200 isl_pw_qpolynomial_fold_free(pwf
);
2205 static __isl_give isl_printer
*print_union_pw_qpolynomial_fold_isl(
2206 __isl_take isl_printer
*p
,
2207 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2209 struct isl_union_print_data data
;
2210 struct isl_print_space_data space_data
= { 0 };
2213 dim
= isl_union_pw_qpolynomial_fold_get_space(upwf
);
2214 if (isl_space_dim(dim
, isl_dim_param
) > 0) {
2215 p
= print_tuple(dim
, p
, isl_dim_param
, &space_data
);
2216 p
= isl_printer_print_str(p
, " -> ");
2218 isl_space_free(dim
);
2219 p
= isl_printer_print_str(p
, "{ ");
2222 isl_union_pw_qpolynomial_fold_foreach_pw_qpolynomial_fold(upwf
,
2223 &print_pwf_body
, &data
);
2225 p
= isl_printer_print_str(p
, " }");
2229 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial_fold(
2230 __isl_take isl_printer
*p
,
2231 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2236 if (p
->output_format
== ISL_FORMAT_ISL
)
2237 return print_union_pw_qpolynomial_fold_isl(p
, upwf
);
2238 isl_die(p
->ctx
, isl_error_invalid
,
2239 "invalid output format for isl_union_pw_qpolynomial_fold",
2242 isl_printer_free(p
);
2246 __isl_give isl_printer
*isl_printer_print_constraint(__isl_take isl_printer
*p
,
2247 __isl_keep isl_constraint
*c
)
2249 isl_basic_map
*bmap
;
2254 bmap
= isl_basic_map_from_constraint(isl_constraint_copy(c
));
2255 p
= isl_printer_print_basic_map(p
, bmap
);
2256 isl_basic_map_free(bmap
);
2259 isl_printer_free(p
);
2263 static __isl_give isl_printer
*isl_printer_print_space_isl(
2264 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
)
2266 struct isl_print_space_data data
= { 0 };
2271 if (isl_space_dim(space
, isl_dim_param
) > 0) {
2272 p
= print_tuple(space
, p
, isl_dim_param
, &data
);
2273 p
= isl_printer_print_str(p
, " -> ");
2276 p
= isl_printer_print_str(p
, "{ ");
2277 if (isl_space_is_params(space
))
2278 p
= isl_printer_print_str(p
, s_such_that
[0]);
2280 p
= isl_print_space(space
, p
, 0, &data
);
2281 p
= isl_printer_print_str(p
, " }");
2285 isl_printer_free(p
);
2289 __isl_give isl_printer
*isl_printer_print_space(__isl_take isl_printer
*p
,
2290 __isl_keep isl_space
*space
)
2293 return isl_printer_free(p
);
2294 if (p
->output_format
== ISL_FORMAT_ISL
)
2295 return isl_printer_print_space_isl(p
, space
);
2296 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
2297 return print_omega_parameters(space
, p
);
2299 isl_die(isl_space_get_ctx(space
), isl_error_unsupported
,
2300 "output format not supported for space",
2301 return isl_printer_free(p
));
2304 __isl_give isl_printer
*isl_printer_print_local_space(__isl_take isl_printer
*p
,
2305 __isl_keep isl_local_space
*ls
)
2307 struct isl_print_space_data data
= { 0 };
2313 if (isl_local_space_dim(ls
, isl_dim_param
) > 0) {
2314 p
= print_tuple(ls
->dim
, p
, isl_dim_param
, &data
);
2315 p
= isl_printer_print_str(p
, " -> ");
2317 p
= isl_printer_print_str(p
, "{ ");
2318 p
= isl_print_space(ls
->dim
, p
, 0, &data
);
2319 n_div
= isl_local_space_dim(ls
, isl_dim_div
);
2321 p
= isl_printer_print_str(p
, " : ");
2322 p
= isl_printer_print_str(p
, s_open_exists
[0]);
2323 p
= print_div_list(p
, ls
->dim
, ls
->div
, 0, 1);
2324 p
= isl_printer_print_str(p
, s_close_exists
[0]);
2325 } else if (isl_space_is_params(ls
->dim
))
2326 p
= isl_printer_print_str(p
, s_such_that
[0]);
2327 p
= isl_printer_print_str(p
, " }");
2330 isl_printer_free(p
);
2334 static __isl_give isl_printer
*print_aff_body(__isl_take isl_printer
*p
,
2335 __isl_keep isl_aff
*aff
)
2339 if (isl_aff_is_nan(aff
))
2340 return isl_printer_print_str(p
, "NaN");
2342 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2343 p
= isl_printer_print_str(p
, "(");
2344 p
= print_affine_of_len(aff
->ls
->dim
, aff
->ls
->div
, p
,
2345 aff
->v
->el
+ 1, 1 + total
);
2346 if (isl_int_is_one(aff
->v
->el
[0]))
2347 p
= isl_printer_print_str(p
, ")");
2349 p
= isl_printer_print_str(p
, ")/");
2350 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2356 static __isl_give isl_printer
*print_aff(__isl_take isl_printer
*p
,
2357 __isl_keep isl_aff
*aff
)
2359 struct isl_print_space_data data
= { 0 };
2361 if (isl_space_is_params(aff
->ls
->dim
))
2364 p
= print_tuple(aff
->ls
->dim
, p
, isl_dim_set
, &data
);
2365 p
= isl_printer_print_str(p
, " -> ");
2367 p
= isl_printer_print_str(p
, "[");
2368 p
= print_aff_body(p
, aff
);
2369 p
= isl_printer_print_str(p
, "]");
2374 static __isl_give isl_printer
*print_aff_isl(__isl_take isl_printer
*p
,
2375 __isl_keep isl_aff
*aff
)
2377 struct isl_print_space_data data
= { 0 };
2382 if (isl_local_space_dim(aff
->ls
, isl_dim_param
) > 0) {
2383 p
= print_tuple(aff
->ls
->dim
, p
, isl_dim_param
, &data
);
2384 p
= isl_printer_print_str(p
, " -> ");
2386 p
= isl_printer_print_str(p
, "{ ");
2387 p
= print_aff(p
, aff
);
2388 p
= isl_printer_print_str(p
, " }");
2391 isl_printer_free(p
);
2395 /* Print the body of an isl_pw_aff, i.e., a semicolon delimited
2396 * sequence of affine expressions, each followed by constraints.
2398 static __isl_give isl_printer
*print_pw_aff_body(
2399 __isl_take isl_printer
*p
, __isl_keep isl_pw_aff
*pa
)
2404 return isl_printer_free(p
);
2406 for (i
= 0; i
< pa
->n
; ++i
) {
2410 p
= isl_printer_print_str(p
, "; ");
2411 p
= print_aff(p
, pa
->p
[i
].aff
);
2412 space
= isl_aff_get_domain_space(pa
->p
[i
].aff
);
2413 p
= print_disjuncts(set_to_map(pa
->p
[i
].set
), space
, p
, 0);
2414 isl_space_free(space
);
2420 static __isl_give isl_printer
*print_pw_aff_isl(__isl_take isl_printer
*p
,
2421 __isl_keep isl_pw_aff
*pwaff
)
2423 struct isl_print_space_data data
= { 0 };
2428 if (isl_space_dim(pwaff
->dim
, isl_dim_param
) > 0) {
2429 p
= print_tuple(pwaff
->dim
, p
, isl_dim_param
, &data
);
2430 p
= isl_printer_print_str(p
, " -> ");
2432 p
= isl_printer_print_str(p
, "{ ");
2433 p
= print_pw_aff_body(p
, pwaff
);
2434 p
= isl_printer_print_str(p
, " }");
2437 isl_printer_free(p
);
2441 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2442 __isl_keep isl_local_space
*ls
, isl_int
*c
);
2444 static __isl_give isl_printer
*print_ls_name_c(__isl_take isl_printer
*p
,
2445 __isl_keep isl_local_space
*ls
, enum isl_dim_type type
, unsigned pos
)
2447 if (type
== isl_dim_div
) {
2448 p
= isl_printer_print_str(p
, "floord(");
2449 p
= print_ls_affine_c(p
, ls
, ls
->div
->row
[pos
] + 1);
2450 p
= isl_printer_print_str(p
, ", ");
2451 p
= isl_printer_print_isl_int(p
, ls
->div
->row
[pos
][0]);
2452 p
= isl_printer_print_str(p
, ")");
2456 name
= isl_space_get_dim_name(ls
->dim
, type
, pos
);
2459 p
= isl_printer_print_str(p
, name
);
2464 static __isl_give isl_printer
*print_ls_term_c(__isl_take isl_printer
*p
,
2465 __isl_keep isl_local_space
*ls
, isl_int c
, unsigned pos
)
2467 enum isl_dim_type type
;
2470 return isl_printer_print_isl_int(p
, c
);
2472 if (isl_int_is_one(c
))
2474 else if (isl_int_is_negone(c
))
2475 p
= isl_printer_print_str(p
, "-");
2477 p
= isl_printer_print_isl_int(p
, c
);
2478 p
= isl_printer_print_str(p
, "*");
2480 type
= pos2type(ls
->dim
, &pos
);
2481 p
= print_ls_name_c(p
, ls
, type
, pos
);
2485 static __isl_give isl_printer
*print_ls_partial_affine_c(
2486 __isl_take isl_printer
*p
, __isl_keep isl_local_space
*ls
,
2487 isl_int
*c
, unsigned len
)
2492 for (i
= 0, first
= 1; i
< len
; ++i
) {
2494 if (isl_int_is_zero(c
[i
]))
2497 if (isl_int_is_neg(c
[i
])) {
2499 isl_int_neg(c
[i
], c
[i
]);
2500 p
= isl_printer_print_str(p
, " - ");
2502 p
= isl_printer_print_str(p
, " + ");
2505 p
= print_ls_term_c(p
, ls
, c
[i
], i
);
2507 isl_int_neg(c
[i
], c
[i
]);
2510 p
= isl_printer_print_str(p
, "0");
2514 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2515 __isl_keep isl_local_space
*ls
, isl_int
*c
)
2517 unsigned len
= 1 + isl_local_space_dim(ls
, isl_dim_all
);
2518 return print_ls_partial_affine_c(p
, ls
, c
, len
);
2521 static __isl_give isl_printer
*print_aff_c(__isl_take isl_printer
*p
,
2522 __isl_keep isl_aff
*aff
)
2526 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2527 if (!isl_int_is_one(aff
->v
->el
[0]))
2528 p
= isl_printer_print_str(p
, "(");
2529 p
= print_ls_partial_affine_c(p
, aff
->ls
, aff
->v
->el
+ 1, 1 + total
);
2530 if (!isl_int_is_one(aff
->v
->el
[0])) {
2531 p
= isl_printer_print_str(p
, ")/");
2532 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2537 /* In the C format, we cannot express that "pwaff" may be undefined
2538 * on parts of the domain space. We therefore assume that the expression
2539 * will only be evaluated on its definition domain and compute the gist
2540 * of each cell with respect to this domain.
2542 static __isl_give isl_printer
*print_pw_aff_c(__isl_take isl_printer
*p
,
2543 __isl_keep isl_pw_aff
*pwaff
)
2546 isl_ast_build
*build
;
2550 isl_die(p
->ctx
, isl_error_unsupported
,
2551 "cannot print empty isl_pw_aff in C format",
2552 return isl_printer_free(p
));
2554 domain
= isl_pw_aff_domain(isl_pw_aff_copy(pwaff
));
2555 build
= isl_ast_build_from_context(domain
);
2556 expr
= isl_ast_build_expr_from_pw_aff(build
, isl_pw_aff_copy(pwaff
));
2557 p
= isl_printer_print_ast_expr(p
, expr
);
2558 isl_ast_expr_free(expr
);
2559 isl_ast_build_free(build
);
2564 __isl_give isl_printer
*isl_printer_print_aff(__isl_take isl_printer
*p
,
2565 __isl_keep isl_aff
*aff
)
2570 if (p
->output_format
== ISL_FORMAT_ISL
)
2571 return print_aff_isl(p
, aff
);
2572 else if (p
->output_format
== ISL_FORMAT_C
)
2573 return print_aff_c(p
, aff
);
2574 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2577 isl_printer_free(p
);
2581 __isl_give isl_printer
*isl_printer_print_pw_aff(__isl_take isl_printer
*p
,
2582 __isl_keep isl_pw_aff
*pwaff
)
2587 if (p
->output_format
== ISL_FORMAT_ISL
)
2588 return print_pw_aff_isl(p
, pwaff
);
2589 else if (p
->output_format
== ISL_FORMAT_C
)
2590 return print_pw_aff_c(p
, pwaff
);
2591 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2594 isl_printer_free(p
);
2598 /* Print "pa" in a sequence of isl_pw_affs delimited by semicolons.
2599 * Each isl_pw_aff itself is also printed as semicolon delimited
2600 * sequence of pieces.
2601 * If data->first = 1, then this is the first in the sequence.
2602 * Update data->first to tell the next element that it is not the first.
2604 static isl_stat
print_pw_aff_body_wrap(__isl_take isl_pw_aff
*pa
,
2607 struct isl_union_print_data
*data
;
2608 data
= (struct isl_union_print_data
*) user
;
2611 data
->p
= isl_printer_print_str(data
->p
, "; ");
2614 data
->p
= print_pw_aff_body(data
->p
, pa
);
2615 isl_pw_aff_free(pa
);
2617 return data
->p
? isl_stat_ok
: isl_stat_error
;
2620 /* Print the body of an isl_union_pw_aff, i.e., a semicolon delimited
2621 * sequence of affine expressions, each followed by constraints,
2622 * with the sequence enclosed in braces.
2624 static __isl_give isl_printer
*print_union_pw_aff_body(
2625 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2627 struct isl_union_print_data data
= { p
, 1 };
2629 p
= isl_printer_print_str(p
, s_open_set
[0]);
2631 if (isl_union_pw_aff_foreach_pw_aff(upa
,
2632 &print_pw_aff_body_wrap
, &data
) < 0)
2633 data
.p
= isl_printer_free(p
);
2635 p
= isl_printer_print_str(p
, s_close_set
[0]);
2640 /* Print the isl_union_pw_aff "upa" to "p" in isl format.
2642 * The individual isl_pw_affs are delimited by a semicolon.
2644 static __isl_give isl_printer
*print_union_pw_aff_isl(
2645 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2647 struct isl_print_space_data data
= { 0 };
2650 space
= isl_union_pw_aff_get_space(upa
);
2651 if (isl_space_dim(space
, isl_dim_param
) > 0) {
2652 p
= print_tuple(space
, p
, isl_dim_param
, &data
);
2653 p
= isl_printer_print_str(p
, s_to
[0]);
2655 isl_space_free(space
);
2656 p
= print_union_pw_aff_body(p
, upa
);
2660 /* Print the isl_union_pw_aff "upa" to "p".
2662 * We currently only support an isl format.
2664 __isl_give isl_printer
*isl_printer_print_union_pw_aff(
2665 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2668 return isl_printer_free(p
);
2670 if (p
->output_format
== ISL_FORMAT_ISL
)
2671 return print_union_pw_aff_isl(p
, upa
);
2672 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
2673 "unsupported output format", return isl_printer_free(p
));
2676 /* Print dimension "pos" of data->space to "p".
2678 * data->user is assumed to be an isl_multi_aff.
2680 * If the current dimension is an output dimension, then print
2681 * the corresponding expression. Otherwise, print the name of the dimension.
2683 static __isl_give isl_printer
*print_dim_ma(__isl_take isl_printer
*p
,
2684 struct isl_print_space_data
*data
, unsigned pos
)
2686 isl_multi_aff
*ma
= data
->user
;
2688 if (data
->type
== isl_dim_out
)
2689 p
= print_aff_body(p
, ma
->p
[pos
]);
2691 p
= print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
2696 static __isl_give isl_printer
*print_multi_aff(__isl_take isl_printer
*p
,
2697 __isl_keep isl_multi_aff
*maff
)
2699 struct isl_print_space_data data
= { 0 };
2701 data
.print_dim
= &print_dim_ma
;
2703 return isl_print_space(maff
->space
, p
, 0, &data
);
2706 static __isl_give isl_printer
*print_multi_aff_isl(__isl_take isl_printer
*p
,
2707 __isl_keep isl_multi_aff
*maff
)
2709 struct isl_print_space_data data
= { 0 };
2714 if (isl_space_dim(maff
->space
, isl_dim_param
) > 0) {
2715 p
= print_tuple(maff
->space
, p
, isl_dim_param
, &data
);
2716 p
= isl_printer_print_str(p
, " -> ");
2718 p
= isl_printer_print_str(p
, "{ ");
2719 p
= print_multi_aff(p
, maff
);
2720 p
= isl_printer_print_str(p
, " }");
2723 isl_printer_free(p
);
2727 __isl_give isl_printer
*isl_printer_print_multi_aff(__isl_take isl_printer
*p
,
2728 __isl_keep isl_multi_aff
*maff
)
2733 if (p
->output_format
== ISL_FORMAT_ISL
)
2734 return print_multi_aff_isl(p
, maff
);
2735 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2738 isl_printer_free(p
);
2742 static __isl_give isl_printer
*print_pw_multi_aff_body(
2743 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2750 for (i
= 0; i
< pma
->n
; ++i
) {
2754 p
= isl_printer_print_str(p
, "; ");
2755 p
= print_multi_aff(p
, pma
->p
[i
].maff
);
2756 space
= isl_multi_aff_get_domain_space(pma
->p
[i
].maff
);
2757 p
= print_disjuncts(set_to_map(pma
->p
[i
].set
), space
, p
, 0);
2758 isl_space_free(space
);
2762 isl_printer_free(p
);
2766 static __isl_give isl_printer
*print_pw_multi_aff_isl(__isl_take isl_printer
*p
,
2767 __isl_keep isl_pw_multi_aff
*pma
)
2769 struct isl_print_space_data data
= { 0 };
2774 if (isl_space_dim(pma
->dim
, isl_dim_param
) > 0) {
2775 p
= print_tuple(pma
->dim
, p
, isl_dim_param
, &data
);
2776 p
= isl_printer_print_str(p
, " -> ");
2778 p
= isl_printer_print_str(p
, "{ ");
2779 p
= print_pw_multi_aff_body(p
, pma
);
2780 p
= isl_printer_print_str(p
, " }");
2783 isl_printer_free(p
);
2787 static __isl_give isl_printer
*print_unnamed_pw_multi_aff_c(
2788 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2792 for (i
= 0; i
< pma
->n
- 1; ++i
) {
2793 p
= isl_printer_print_str(p
, "(");
2794 p
= print_set_c(p
, pma
->dim
, pma
->p
[i
].set
);
2795 p
= isl_printer_print_str(p
, ") ? (");
2796 p
= print_aff_c(p
, pma
->p
[i
].maff
->p
[0]);
2797 p
= isl_printer_print_str(p
, ") : ");
2800 return print_aff_c(p
, pma
->p
[pma
->n
- 1].maff
->p
[0]);
2803 static __isl_give isl_printer
*print_pw_multi_aff_c(__isl_take isl_printer
*p
,
2804 __isl_keep isl_pw_multi_aff
*pma
)
2812 isl_die(p
->ctx
, isl_error_unsupported
,
2813 "cannot print empty isl_pw_multi_aff in C format",
2815 name
= isl_pw_multi_aff_get_tuple_name(pma
, isl_dim_out
);
2816 if (!name
&& isl_pw_multi_aff_dim(pma
, isl_dim_out
) == 1)
2817 return print_unnamed_pw_multi_aff_c(p
, pma
);
2819 isl_die(p
->ctx
, isl_error_unsupported
,
2820 "cannot print unnamed isl_pw_multi_aff in C format",
2823 p
= isl_printer_print_str(p
, name
);
2824 n
= isl_pw_multi_aff_dim(pma
, isl_dim_out
);
2826 isl_die(p
->ctx
, isl_error_unsupported
,
2827 "not supported yet", goto error
);
2831 isl_printer_free(p
);
2835 __isl_give isl_printer
*isl_printer_print_pw_multi_aff(
2836 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2841 if (p
->output_format
== ISL_FORMAT_ISL
)
2842 return print_pw_multi_aff_isl(p
, pma
);
2843 if (p
->output_format
== ISL_FORMAT_C
)
2844 return print_pw_multi_aff_c(p
, pma
);
2845 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2848 isl_printer_free(p
);
2852 static isl_stat
print_pw_multi_aff_body_wrap(__isl_take isl_pw_multi_aff
*pma
,
2855 struct isl_union_print_data
*data
;
2856 data
= (struct isl_union_print_data
*) user
;
2859 data
->p
= isl_printer_print_str(data
->p
, "; ");
2862 data
->p
= print_pw_multi_aff_body(data
->p
, pma
);
2863 isl_pw_multi_aff_free(pma
);
2868 static __isl_give isl_printer
*print_union_pw_multi_aff_isl(
2869 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
2871 struct isl_union_print_data data
;
2872 struct isl_print_space_data space_data
= { 0 };
2875 space
= isl_union_pw_multi_aff_get_space(upma
);
2876 if (isl_space_dim(space
, isl_dim_param
) > 0) {
2877 p
= print_tuple(space
, p
, isl_dim_param
, &space_data
);
2878 p
= isl_printer_print_str(p
, s_to
[0]);
2880 isl_space_free(space
);
2881 p
= isl_printer_print_str(p
, s_open_set
[0]);
2884 isl_union_pw_multi_aff_foreach_pw_multi_aff(upma
,
2885 &print_pw_multi_aff_body_wrap
, &data
);
2887 p
= isl_printer_print_str(p
, s_close_set
[0]);
2891 __isl_give isl_printer
*isl_printer_print_union_pw_multi_aff(
2892 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
2897 if (p
->output_format
== ISL_FORMAT_ISL
)
2898 return print_union_pw_multi_aff_isl(p
, upma
);
2899 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2902 isl_printer_free(p
);
2906 /* Print dimension "pos" of data->space to "p".
2908 * data->user is assumed to be an isl_multi_pw_aff.
2910 * If the current dimension is an output dimension, then print
2911 * the corresponding piecewise affine expression.
2912 * Otherwise, print the name of the dimension.
2914 static __isl_give isl_printer
*print_dim_mpa(__isl_take isl_printer
*p
,
2915 struct isl_print_space_data
*data
, unsigned pos
)
2919 isl_multi_pw_aff
*mpa
= data
->user
;
2922 if (data
->type
!= isl_dim_out
)
2923 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
2927 return isl_printer_print_str(p
, "(0 : 1 = 0)");
2929 need_parens
= pa
->n
!= 1 || !isl_set_plain_is_universe(pa
->p
[0].set
);
2931 p
= isl_printer_print_str(p
, "(");
2932 for (i
= 0; i
< pa
->n
; ++i
) {
2936 p
= isl_printer_print_str(p
, "; ");
2937 p
= print_aff_body(p
, pa
->p
[i
].aff
);
2938 space
= isl_aff_get_domain_space(pa
->p
[i
].aff
);
2939 p
= print_disjuncts(pa
->p
[i
].set
, space
, p
, 0);
2940 isl_space_free(space
);
2943 p
= isl_printer_print_str(p
, ")");
2948 /* Print "mpa" to "p" in isl format.
2950 static __isl_give isl_printer
*print_multi_pw_aff_isl(__isl_take isl_printer
*p
,
2951 __isl_keep isl_multi_pw_aff
*mpa
)
2953 struct isl_print_space_data data
= { 0 };
2956 return isl_printer_free(p
);
2958 if (isl_space_dim(mpa
->space
, isl_dim_param
) > 0) {
2959 p
= print_tuple(mpa
->space
, p
, isl_dim_param
, &data
);
2960 p
= isl_printer_print_str(p
, " -> ");
2962 p
= isl_printer_print_str(p
, "{ ");
2963 data
.print_dim
= &print_dim_mpa
;
2965 p
= isl_print_space(mpa
->space
, p
, 0, &data
);
2966 p
= isl_printer_print_str(p
, " }");
2970 __isl_give isl_printer
*isl_printer_print_multi_pw_aff(
2971 __isl_take isl_printer
*p
, __isl_keep isl_multi_pw_aff
*mpa
)
2974 return isl_printer_free(p
);
2976 if (p
->output_format
== ISL_FORMAT_ISL
)
2977 return print_multi_pw_aff_isl(p
, mpa
);
2978 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2979 return isl_printer_free(p
));
2982 /* Print dimension "pos" of data->space to "p".
2984 * data->user is assumed to be an isl_multi_val.
2986 * If the current dimension is an output dimension, then print
2987 * the corresponding value. Otherwise, print the name of the dimension.
2989 static __isl_give isl_printer
*print_dim_mv(__isl_take isl_printer
*p
,
2990 struct isl_print_space_data
*data
, unsigned pos
)
2992 isl_multi_val
*mv
= data
->user
;
2994 if (data
->type
== isl_dim_out
)
2995 return isl_printer_print_val(p
, mv
->p
[pos
]);
2997 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
3000 /* Print the isl_multi_val "mv" to "p" in isl format.
3002 static __isl_give isl_printer
*print_multi_val_isl(__isl_take isl_printer
*p
,
3003 __isl_keep isl_multi_val
*mv
)
3005 struct isl_print_space_data data
= { 0 };
3008 return isl_printer_free(p
);
3010 if (isl_space_dim(mv
->space
, isl_dim_param
) > 0) {
3011 p
= print_tuple(mv
->space
, p
, isl_dim_param
, &data
);
3012 p
= isl_printer_print_str(p
, " -> ");
3014 p
= isl_printer_print_str(p
, "{ ");
3015 data
.print_dim
= &print_dim_mv
;
3017 p
= isl_print_space(mv
->space
, p
, 0, &data
);
3018 p
= isl_printer_print_str(p
, " }");
3022 /* Print the isl_multi_val "mv" to "p".
3024 * Currently only supported in isl format.
3026 __isl_give isl_printer
*isl_printer_print_multi_val(
3027 __isl_take isl_printer
*p
, __isl_keep isl_multi_val
*mv
)
3030 return isl_printer_free(p
);
3032 if (p
->output_format
== ISL_FORMAT_ISL
)
3033 return print_multi_val_isl(p
, mv
);
3034 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3035 return isl_printer_free(p
));
3038 /* Print dimension "pos" of data->space to "p".
3040 * data->user is assumed to be an isl_multi_union_pw_aff.
3042 * The current dimension is necessarily a set dimension, so
3043 * we print the corresponding isl_union_pw_aff, including
3046 static __isl_give isl_printer
*print_union_pw_aff_dim(__isl_take isl_printer
*p
,
3047 struct isl_print_space_data
*data
, unsigned pos
)
3049 isl_multi_union_pw_aff
*mupa
= data
->user
;
3050 isl_union_pw_aff
*upa
;
3052 upa
= isl_multi_union_pw_aff_get_union_pw_aff(mupa
, pos
);
3053 p
= print_union_pw_aff_body(p
, upa
);
3054 isl_union_pw_aff_free(upa
);
3059 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3061 static __isl_give isl_printer
*print_multi_union_pw_aff_isl(
3062 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3064 struct isl_print_space_data data
= { 0 };
3067 space
= isl_multi_union_pw_aff_get_space(mupa
);
3068 if (isl_space_dim(space
, isl_dim_param
) > 0) {
3069 struct isl_print_space_data space_data
= { 0 };
3070 p
= print_tuple(space
, p
, isl_dim_param
, &space_data
);
3071 p
= isl_printer_print_str(p
, s_to
[0]);
3074 data
.print_dim
= &print_union_pw_aff_dim
;
3077 p
= isl_print_space(space
, p
, 0, &data
);
3078 isl_space_free(space
);
3083 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3085 * We currently only support an isl format.
3087 __isl_give isl_printer
*isl_printer_print_multi_union_pw_aff(
3088 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3091 return isl_printer_free(p
);
3093 if (p
->output_format
== ISL_FORMAT_ISL
)
3094 return print_multi_union_pw_aff_isl(p
, mupa
);
3095 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
3096 "unsupported output format", return isl_printer_free(p
));