#include <stdlib.h>
#include <string.h>
-#include <isl_set.h>
-#include <isl_seq.h>
+#include <isl_ctx_private.h>
+#include <isl_map_private.h>
+#include <isl/set.h>
+#include <isl/seq.h>
#include <isl_polynomial_private.h>
#include <isl_printer_private.h>
#include <isl_dim_private.h>
-#include <isl_map_private.h>
-#include <isl_union_map.h>
+#include <isl_mat_private.h>
+#include <isl/union_map.h>
+#include <isl/constraint.h>
+#include <isl_local_space_private.h>
+#include <isl_aff_private.h>
static const char *s_to[2] = { " -> ", " \\to " };
static const char *s_and[2] = { " and ", " \\wedge " };
}
static __isl_give isl_printer *isl_basic_map_print_polylib(
- __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p)
+ __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p, int ext)
{
unsigned total = isl_basic_map_total_dim(bmap);
p = isl_printer_start_line(p);
p = isl_printer_print_int(p, bmap->n_eq + bmap->n_ineq);
p = isl_printer_print_str(p, " ");
p = isl_printer_print_int(p, 1 + total + 1);
+ if (ext) {
+ p = isl_printer_print_str(p, " ");
+ p = isl_printer_print_int(p,
+ isl_basic_map_dim(bmap, isl_dim_out));
+ p = isl_printer_print_str(p, " ");
+ p = isl_printer_print_int(p,
+ isl_basic_map_dim(bmap, isl_dim_in));
+ p = isl_printer_print_str(p, " ");
+ p = isl_printer_print_int(p,
+ isl_basic_map_dim(bmap, isl_dim_div));
+ p = isl_printer_print_str(p, " ");
+ p = isl_printer_print_int(p,
+ isl_basic_map_dim(bmap, isl_dim_param));
+ }
p = isl_printer_end_line(p);
return print_constraints_polylib(bmap, p);
}
static __isl_give isl_printer *isl_basic_set_print_polylib(
- __isl_keep isl_basic_set *bset, __isl_take isl_printer *p)
+ __isl_keep isl_basic_set *bset, __isl_take isl_printer *p, int ext)
{
- return isl_basic_map_print_polylib((struct isl_basic_map *)bset, p);
+ return isl_basic_map_print_polylib((struct isl_basic_map *)bset, p, ext);
}
static __isl_give isl_printer *isl_map_print_polylib(__isl_keep isl_map *map,
- __isl_take isl_printer *p)
+ __isl_take isl_printer *p, int ext)
{
int i;
for (i = 0; i < map->n; ++i) {
p = isl_printer_start_line(p);
p = isl_printer_end_line(p);
- p = isl_basic_map_print_polylib(map->p[i], p);
+ p = isl_basic_map_print_polylib(map->p[i], p, ext);
}
return p;
}
static __isl_give isl_printer *isl_set_print_polylib(__isl_keep isl_set *set,
- __isl_take isl_printer *p)
+ __isl_take isl_printer *p, int ext)
{
- return isl_map_print_polylib((struct isl_map *)set, p);
+ return isl_map_print_polylib((struct isl_map *)set, p, ext);
}
static int count_same_name(__isl_keep isl_dim *dim,
return type;
}
+static __isl_give isl_printer *print_div(__isl_keep isl_dim *dim,
+ __isl_keep isl_mat *div, int pos, __isl_take isl_printer *p);
+
static __isl_give isl_printer *print_term(__isl_keep isl_dim *dim,
+ __isl_keep isl_mat *div,
isl_int c, unsigned pos, __isl_take isl_printer *p, int set, int latex)
{
enum isl_dim_type type;
+ int print_div_def;
if (pos == 0)
return isl_printer_print_isl_int(p, c);
+ type = pos2type(dim, &pos);
+ print_div_def = type == isl_dim_div && div &&
+ !isl_int_is_zero(div->row[pos][0]);
+
if (isl_int_is_one(c))
;
else if (isl_int_is_negone(c))
p = isl_printer_print_str(p, "-");
- else
+ else {
p = isl_printer_print_isl_int(p, c);
- type = pos2type(dim, &pos);
- p = print_name(dim, p, type, pos, set, latex);
+ if (p->output_format == ISL_FORMAT_C || print_div_def)
+ p = isl_printer_print_str(p, "*");
+ }
+ if (print_div_def)
+ p = print_div(dim, div, pos, p);
+ else
+ p = print_name(dim, p, type, pos, set, latex);
return p;
}
static __isl_give isl_printer *print_affine_of_len(__isl_keep isl_dim *dim,
+ __isl_keep isl_mat *div,
__isl_take isl_printer *p, isl_int *c, int len, int set)
{
int i;
p = isl_printer_print_str(p, " + ");
}
first = 0;
- p = print_term(dim, c[i], i, p, set, 0);
+ p = print_term(dim, div, c[i], i, p, set, 0);
if (flip)
isl_int_neg(c[i], c[i]);
}
__isl_keep isl_dim *dim, __isl_take isl_printer *p, isl_int *c, int set)
{
unsigned len = 1 + isl_basic_map_total_dim(bmap);
- return print_affine_of_len(dim, p, c, len, set);
+ return print_affine_of_len(dim, NULL, p, c, len, set);
}
static int defining_equality(__isl_keep isl_basic_map *eq,
- enum isl_dim_type type, int pos)
+ __isl_keep isl_dim *dim, enum isl_dim_type type, int pos)
{
int i;
unsigned total;
if (!eq)
return -1;
- pos += isl_dim_offset(eq->dim, type);
+ pos += isl_dim_offset(dim, type);
total = isl_basic_map_total_dim(eq);
for (i = 0; i < eq->n_eq; ++i) {
return -1;
}
-static __isl_give isl_printer *print_var_list(__isl_keep isl_dim *dim,
- __isl_take isl_printer *p, enum isl_dim_type type, int set, int latex,
- __isl_keep isl_basic_map *eq)
+/* offset is the offset of local_dim inside global_type of global_dim.
+ */
+static __isl_give isl_printer *print_nested_var_list(__isl_take isl_printer *p,
+ __isl_keep isl_dim *global_dim, enum isl_dim_type global_type,
+ __isl_keep isl_dim *local_dim, enum isl_dim_type local_type,
+ int set, int latex, __isl_keep isl_basic_map *eq, int offset)
{
int i, j;
- for (i = 0; i < isl_dim_size(dim, type); ++i) {
+ if (global_dim != local_dim && local_type == isl_dim_out)
+ offset += local_dim->n_in;
+
+ for (i = 0; i < isl_dim_size(local_dim, local_type); ++i) {
if (i)
p = isl_printer_print_str(p, ", ");
- j = defining_equality(eq, type, i);
+ j = defining_equality(eq, global_dim, global_type, offset + i);
if (j >= 0) {
- int pos = 1 + isl_dim_offset(dim, type) + i;
- p = print_affine_of_len(dim, p, eq->eq[j], pos, set);
- } else
- p = print_name(dim, p, type, i, set, latex);
+ int pos = 1 + isl_dim_offset(global_dim, global_type)
+ + offset + i;
+ p = print_affine_of_len(eq->dim, NULL,
+ p, eq->eq[j], pos, set);
+ } else {
+ p = print_name(global_dim, p, global_type, offset + i,
+ set, latex);
+ }
}
return p;
}
-static __isl_give isl_printer *print_tuple(__isl_keep isl_dim *dim,
- __isl_take isl_printer *p, enum isl_dim_type type, int set, int latex,
- __isl_keep isl_basic_map *eq)
+static __isl_give isl_printer *print_var_list(__isl_keep isl_dim *dim,
+ __isl_take isl_printer *p, enum isl_dim_type type,
+ int set, int latex, __isl_keep isl_basic_map *eq)
+{
+ return print_nested_var_list(p, dim, type, dim, type, set, latex, eq, 0);
+}
+
+static __isl_give isl_printer *print_nested_map_dim(__isl_take isl_printer *p,
+ __isl_keep isl_dim *global_dim, enum isl_dim_type global_type,
+ __isl_keep isl_dim *local_dim,
+ int set, int latex, __isl_keep isl_basic_map *eq, int offset);
+
+static __isl_give isl_printer *print_nested_tuple(__isl_take isl_printer *p,
+ __isl_keep isl_dim *global_dim, enum isl_dim_type global_type,
+ __isl_keep isl_dim *local_dim, enum isl_dim_type local_type,
+ int set, int latex, __isl_keep isl_basic_map *eq, int offset)
{
const char *name = NULL;
- unsigned n = isl_dim_size(dim, type);
- if ((type == isl_dim_in || type == isl_dim_out)) {
- name = isl_dim_get_tuple_name(dim, type);
+ unsigned n = isl_dim_size(local_dim, local_type);
+ if ((local_type == isl_dim_in || local_type == isl_dim_out)) {
+ name = isl_dim_get_tuple_name(local_dim, local_type);
if (name) {
if (latex)
p = isl_printer_print_str(p, "\\mathrm{");
}
if (!latex || n != 1 || name)
p = isl_printer_print_str(p, s_open_list[latex]);
- p = print_var_list(dim, p, type, set, latex, eq);
+ if ((local_type == isl_dim_in || local_type == isl_dim_out) &&
+ local_dim->nested[local_type - isl_dim_in]) {
+ if (global_dim != local_dim && local_type == isl_dim_out)
+ offset += local_dim->n_in;
+ p = print_nested_map_dim(p, global_dim, global_type,
+ local_dim->nested[local_type - isl_dim_in],
+ set, latex, eq, offset);
+ } else
+ p = print_nested_var_list(p, global_dim, global_type,
+ local_dim, local_type, set, latex, eq, offset);
if (!latex || n != 1 || name)
p = isl_printer_print_str(p, s_close_list[latex]);
return p;
}
+static __isl_give isl_printer *print_tuple(__isl_keep isl_dim *dim,
+ __isl_take isl_printer *p, enum isl_dim_type type,
+ int set, int latex, __isl_keep isl_basic_map *eq)
+{
+ return print_nested_tuple(p, dim, type, dim, type, set, latex, eq, 0);
+}
+
+static __isl_give isl_printer *print_nested_map_dim(__isl_take isl_printer *p,
+ __isl_keep isl_dim *global_dim, enum isl_dim_type global_type,
+ __isl_keep isl_dim *local_dim,
+ int set, int latex, __isl_keep isl_basic_map *eq, int offset)
+{
+ p = print_nested_tuple(p, global_dim, global_type,
+ local_dim, isl_dim_in, set, latex, eq, offset);
+ p = isl_printer_print_str(p, s_to[latex]);
+ p = print_nested_tuple(p, global_dim, global_type,
+ local_dim, isl_dim_out, set, latex, eq, offset);
+
+ return p;
+}
+
+static __isl_give isl_printer *print_dim(__isl_keep isl_dim *dim,
+ __isl_take isl_printer *p, int set, int latex, int rational,
+ __isl_keep isl_basic_map *eq)
+{
+ if (rational && !latex)
+ p = isl_printer_print_str(p, "rat: ");
+ if (set)
+ p = print_tuple(dim, p, isl_dim_set, 1, latex, eq);
+ else {
+ p = print_tuple(dim, p, isl_dim_in, 0, latex, eq);
+ p = isl_printer_print_str(p, s_to[latex]);
+ p = print_tuple(dim, p, isl_dim_out, 0, latex, eq);
+ }
+
+ return p;
+}
+
static __isl_give isl_printer *print_omega_parameters(__isl_keep isl_dim *dim,
__isl_take isl_printer *p)
{
isl_int_abs(c[last], c[last]);
- p = print_term(dim, c[last], last, p, set, latex);
+ p = print_term(dim, NULL, c[last], last, p, set, latex);
p = isl_printer_print_str(p, " ");
p = isl_printer_print_str(p, op);
for (i = bmap->n_eq - 1; i >= 0; --i) {
int l = isl_seq_last_non_zero(bmap->eq[i], 1 + total);
- isl_assert(bmap->ctx, l >= 0, goto error);
+ if (l < 0) {
+ if (i != bmap->n_eq - 1)
+ p = isl_printer_print_str(p, s_and[latex]);
+ p = isl_printer_print_str(p, "0 = 0");
+ continue;
+ }
if (isl_int_is_neg(bmap->eq[i][l]))
isl_seq_cpy(c->el, bmap->eq[i], 1 + total);
else
return p;
error:
+ isl_vec_free(c);
isl_printer_free(p);
return NULL;
}
}
static __isl_give isl_printer *isl_basic_map_print_isl(
- __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p, int latex)
+ __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p,
+ int set, int latex)
{
- int i;
-
- p = isl_printer_start_line(p);
+ int rational = ISL_F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL);
if (isl_basic_map_dim(bmap, isl_dim_param) > 0) {
p = print_tuple(bmap->dim, p, isl_dim_param, 0, latex, NULL);
p = isl_printer_print_str(p, " -> ");
}
p = isl_printer_print_str(p, "{ ");
- p = print_tuple(bmap->dim, p, isl_dim_in, 0, latex, NULL);
- p = isl_printer_print_str(p, " -> ");
- p = print_tuple(bmap->dim, p, isl_dim_out, 0, latex, NULL);
- p = isl_printer_print_str(p, " : ");
- p = print_disjunct(bmap, bmap->dim, p, 0, latex);
- p = isl_printer_print_str(p, " }");
- p = isl_printer_end_line(p);
- return p;
-}
-
-static __isl_give isl_printer *isl_basic_set_print_isl(
- __isl_keep isl_basic_set *bset, __isl_take isl_printer *p, int latex)
-{
- int i;
-
- p = isl_printer_start_line(p);
- if (isl_basic_set_dim(bset, isl_dim_param) > 0) {
- p = print_tuple(bset->dim, p, isl_dim_param, 0, latex, NULL);
- p = isl_printer_print_str(p, " -> ");
- }
- p = isl_printer_print_str(p, "{ ");
- p = print_tuple(bset->dim, p, isl_dim_set, 1, latex, NULL);
+ p = print_dim(bmap->dim, p, set, latex, rational, NULL);
p = isl_printer_print_str(p, " : ");
- p = print_disjunct((isl_basic_map *)bset, bset->dim, p, 1, latex);
+ p = print_disjunct(bmap, bmap->dim, p, set, latex);
p = isl_printer_print_str(p, " }");
- p = isl_printer_end_line(p);
return p;
}
{
int i;
- if (isl_map_fast_is_universe(map))
+ if (isl_map_plain_is_universe(map))
return p;
p = isl_printer_print_str(p, s_such_that[latex]);
s1 = (const struct isl_aff_split *) p1;
s2 = (const struct isl_aff_split *) p2;
- return isl_basic_map_fast_cmp(s1->aff, s2->aff);
+ return isl_basic_map_plain_cmp(s1->aff, s2->aff);
}
static __isl_give isl_basic_map *drop_aff(__isl_take isl_basic_map *bmap,
{
int i, n;
struct isl_aff_split *split;
+ isl_ctx *ctx;
- split = isl_calloc_array(map->isl, struct isl_aff_split, map->n);
+ ctx = isl_map_get_ctx(map);
+ split = isl_calloc_array(ctx, struct isl_aff_split, map->n);
if (!split)
return NULL;
-
+
for (i = 0; i < map->n; ++i) {
isl_basic_map *bmap;
split[i].aff = get_aff(isl_basic_map_copy(map->p[i]));
n = map->n;
for (i = n - 1; i >= 1; --i) {
- if (!isl_basic_map_fast_is_equal(split[i - 1].aff,
+ if (!isl_basic_map_plain_is_equal(split[i - 1].aff,
split[i].aff))
continue;
isl_basic_map_free(split[i].aff);
struct isl_aff_split *split, int n, int set)
{
int i;
+ int rational;
for (i = 0; i < n; ++i) {
isl_dim *dim;
if (!split[i].map)
break;
dim = split[i].map->dim;
+ rational = split[i].map->n > 0 &&
+ ISL_F_ISSET(split[i].map->p[0], ISL_BASIC_MAP_RATIONAL);
if (i)
p = isl_printer_print_str(p, "; ");
- if (set)
- p = print_tuple(dim, p, isl_dim_set, 1, 0, split[i].aff);
- else {
- p = print_tuple(dim, p, isl_dim_in, 0, 0, split[i].aff);
- p = isl_printer_print_str(p, s_to[0]);
- p = print_tuple(dim, p, isl_dim_out, 0, 0, split[i].aff);
- }
+ p = print_dim(dim, p, set, 0, rational, split[i].aff);
p = print_disjuncts(split[i].map, p, set, 0);
}
__isl_take isl_printer *p, int set)
{
struct isl_aff_split *split = NULL;
+ int rational;
if (map->n > 0)
split = split_aff(map);
if (split) {
p = print_split_map(p, split, map->n, set);
} else {
- if (set)
- p = print_tuple(map->dim, p, isl_dim_set, 1, 0, NULL);
- else {
- p = print_tuple(map->dim, p, isl_dim_in, 0, 0, NULL);
- p = isl_printer_print_str(p, s_to[0]);
- p = print_tuple(map->dim, p, isl_dim_out, 0, 0, NULL);
- }
+ rational = map->n > 0 &&
+ ISL_F_ISSET(map->p[0], ISL_BASIC_MAP_RATIONAL);
+ p = print_dim(map->dim, p, set, 0, rational, NULL);
p = print_disjuncts(map, p, set, 0);
}
free_split(split, map->n);
p = isl_printer_print_str(p, s_to[1]);
}
p = isl_printer_print_str(p, s_open_set[1]);
- if (set)
- p = print_tuple(map->dim, p, isl_dim_set, 1, 1, aff);
- else {
- p = print_tuple(map->dim, p, isl_dim_in, 0, 1, aff);
- p = isl_printer_print_str(p, s_to[1]);
- p = print_tuple(map->dim, p, isl_dim_out, 0, 1, aff);
- }
+ p = print_dim(map->dim, p, set, 1, 0, aff);
p = print_disjuncts(map, p, set, 1);
p = isl_printer_print_str(p, s_close_set[1]);
if (!p || !bmap)
goto error;
if (p->output_format == ISL_FORMAT_ISL)
- return isl_basic_map_print_isl(bmap, p, 0);
+ return isl_basic_map_print_isl(bmap, p, 0, 0);
else if (p->output_format == ISL_FORMAT_OMEGA)
return isl_basic_map_print_omega(bmap, p);
isl_assert(bmap->ctx, 0, goto error);
goto error;
if (p->output_format == ISL_FORMAT_ISL)
- return isl_basic_set_print_isl(bset, p, 0);
+ return isl_basic_map_print_isl(bset, p, 1, 0);
else if (p->output_format == ISL_FORMAT_POLYLIB)
- return isl_basic_set_print_polylib(bset, p);
+ return isl_basic_set_print_polylib(bset, p, 0);
+ else if (p->output_format == ISL_FORMAT_EXT_POLYLIB)
+ return isl_basic_set_print_polylib(bset, p, 1);
else if (p->output_format == ISL_FORMAT_POLYLIB_CONSTRAINTS)
return bset_print_constraints_polylib(bset, p);
else if (p->output_format == ISL_FORMAT_OMEGA)
if (p->output_format == ISL_FORMAT_ISL)
return isl_map_print_isl((isl_map *)set, p, 1);
else if (p->output_format == ISL_FORMAT_POLYLIB)
- return isl_set_print_polylib(set, p);
+ return isl_set_print_polylib(set, p, 0);
+ else if (p->output_format == ISL_FORMAT_EXT_POLYLIB)
+ return isl_set_print_polylib(set, p, 1);
else if (p->output_format == ISL_FORMAT_OMEGA)
return isl_set_print_omega(set, p);
else if (p->output_format == ISL_FORMAT_LATEX)
if (p->output_format == ISL_FORMAT_ISL)
return isl_map_print_isl(map, p, 0);
else if (p->output_format == ISL_FORMAT_POLYLIB)
- return isl_map_print_polylib(map, p);
+ return isl_map_print_polylib(map, p, 0);
+ else if (p->output_format == ISL_FORMAT_EXT_POLYLIB)
+ return isl_map_print_polylib(map, p, 1);
else if (p->output_format == ISL_FORMAT_OMEGA)
return isl_map_print_omega(map, p);
else if (p->output_format == ISL_FORMAT_LATEX)
isl_printer_free(printer);
}
+void isl_basic_map_dump(__isl_keep isl_basic_map *bmap)
+{
+ isl_printer *printer;
+
+ if (!bmap)
+ return;
+
+ printer = isl_printer_to_file(isl_basic_map_get_ctx(bmap), stderr);
+ printer = isl_printer_print_basic_map(printer, bmap);
+ printer = isl_printer_end_line(printer);
+
+ isl_printer_free(printer);
+}
+
+void isl_basic_set_dump(__isl_keep isl_basic_set *bset)
+{
+ isl_printer *printer;
+
+ if (!bset)
+ return;
+
+ printer = isl_printer_to_file(isl_basic_set_get_ctx(bset), stderr);
+ printer = isl_printer_print_basic_set(printer, bset);
+ printer = isl_printer_end_line(printer);
+
+ isl_printer_free(printer);
+}
+
+void isl_map_dump(__isl_keep isl_map *map)
+{
+ isl_printer *printer;
+
+ if (!map)
+ return;
+
+ printer = isl_printer_to_file(isl_map_get_ctx(map), stderr);
+ printer = isl_printer_print_map(printer, map);
+ printer = isl_printer_end_line(printer);
+
+ isl_printer_free(printer);
+}
+
+void isl_set_dump(__isl_keep isl_set *set)
+{
+ isl_printer *printer;
+
+ if (!set)
+ return;
+
+ printer = isl_printer_to_file(isl_set_get_ctx(set), stderr);
+ printer = isl_printer_print_set(printer, set);
+ printer = isl_printer_end_line(printer);
+
+ isl_printer_free(printer);
+}
+
+void isl_union_map_dump(__isl_keep isl_union_map *umap)
+{
+ isl_printer *printer;
+
+ if (!umap)
+ return;
+
+ printer = isl_printer_to_file(isl_union_map_get_ctx(umap), stderr);
+ printer = isl_printer_print_union_map(printer, umap);
+ printer = isl_printer_end_line(printer);
+
+ isl_printer_free(printer);
+}
+
+void isl_union_set_dump(__isl_keep isl_union_set *uset)
+{
+ isl_printer *printer;
+
+ if (!uset)
+ return;
+
+ printer = isl_printer_to_file(isl_union_set_get_ctx(uset), stderr);
+ printer = isl_printer_print_union_set(printer, uset);
+ printer = isl_printer_end_line(printer);
+
+ isl_printer_free(printer);
+}
+
+void isl_union_pw_qpolynomial_dump(__isl_keep isl_union_pw_qpolynomial *upwqp)
+{
+ isl_printer *printer;
+
+ if (!upwqp)
+ return;
+
+ printer = isl_printer_to_file(isl_union_pw_qpolynomial_get_ctx(upwqp),
+ stderr);
+ printer = isl_printer_print_union_pw_qpolynomial(printer, upwqp);
+ printer = isl_printer_end_line(printer);
+
+ isl_printer_free(printer);
+}
+
+void isl_qpolynomial_dump(__isl_keep isl_qpolynomial *qp)
+{
+ isl_printer *printer;
+
+ if (!qp)
+ return;
+
+ printer = isl_printer_to_file(isl_qpolynomial_get_ctx(qp), stderr);
+ printer = isl_printer_print_qpolynomial(printer, qp);
+ printer = isl_printer_end_line(printer);
+
+ isl_printer_free(printer);
+}
+
+void isl_qpolynomial_fold_dump(__isl_keep isl_qpolynomial_fold *fold)
+{
+ isl_printer *printer;
+
+ if (!fold)
+ return;
+
+ printer = isl_printer_to_file(isl_qpolynomial_fold_get_ctx(fold),
+ stderr);
+ printer = isl_printer_print_qpolynomial_fold(printer, fold);
+ printer = isl_printer_end_line(printer);
+
+ isl_printer_free(printer);
+}
+
+void isl_pw_qpolynomial_dump(__isl_keep isl_pw_qpolynomial *pwqp)
+{
+ isl_printer *printer;
+
+ if (!pwqp)
+ return;
+
+ printer = isl_printer_to_file(isl_pw_qpolynomial_get_ctx(pwqp), stderr);
+ printer = isl_printer_print_pw_qpolynomial(printer, pwqp);
+ printer = isl_printer_end_line(printer);
+
+ isl_printer_free(printer);
+}
+
+void isl_pw_qpolynomial_fold_dump(__isl_keep isl_pw_qpolynomial_fold *pwf)
+{
+ isl_printer *printer;
+
+ if (!pwf)
+ return;
+
+ printer = isl_printer_to_file(
+ isl_pw_qpolynomial_fold_get_ctx(pwf), stderr);
+ printer = isl_printer_print_pw_qpolynomial_fold(printer, pwf);
+ printer = isl_printer_end_line(printer);
+
+ isl_printer_free(printer);
+}
+
+void isl_union_pw_qpolynomial_fold_dump(
+ __isl_keep isl_union_pw_qpolynomial_fold *upwf)
+{
+ isl_printer *printer;
+
+ if (!upwf)
+ return;
+
+ printer = isl_printer_to_file(
+ isl_union_pw_qpolynomial_fold_get_ctx(upwf), stderr);
+ printer = isl_printer_print_union_pw_qpolynomial_fold(printer, upwf);
+ printer = isl_printer_end_line(printer);
+
+ isl_printer_free(printer);
+}
+
static int upoly_rec_n_non_zero(__isl_keep struct isl_upoly_rec *rec)
{
int i;
{
int c = p->output_format == ISL_FORMAT_C;
p = isl_printer_print_str(p, c ? "floord(" : "[(");
- p = print_affine_of_len(dim, p, div->row[pos] + 1, div->n_col - 1, 1);
+ p = print_affine_of_len(dim, div, p,
+ div->row[pos] + 1, div->n_col - 1, 1);
p = isl_printer_print_str(p, c ? ", " : ")/");
p = isl_printer_print_isl_int(p, div->row[pos][0]);
p = isl_printer_print_str(p, c ? ")" : "]");
total = isl_dim_total(dim);
if (var < total)
- p = print_term(dim, dim->ctx->one, 1 + var, p, 1, 0);
+ p = print_term(dim, NULL, dim->ctx->one, 1 + var, p, 1, 0);
else
p = print_div(dim, div, var - total, p);
return p;
static __isl_give isl_printer *upoly_print(__isl_keep struct isl_upoly *up,
__isl_keep isl_dim *dim, __isl_keep isl_mat *div,
- __isl_take isl_printer *p)
+ __isl_take isl_printer *p, int outer)
{
- int i, n, first;
+ int i, n, first, print_parens;
struct isl_upoly_rec *rec;
if (!p || !up || !dim || !div)
if (!rec)
goto error;
n = upoly_rec_n_non_zero(rec);
- if (n > 1)
+ print_parens = n > 1 || (outer && rec->up.var >= isl_dim_total(dim));
+ if (print_parens)
p = isl_printer_print_str(p, "(");
for (i = 0, first = 1; i < rec->n; ++i) {
if (isl_upoly_is_zero(rec->p[i]))
if (!first)
p = isl_printer_print_str(p, " + ");
if (i == 0 || !isl_upoly_is_one(rec->p[i]))
- p = upoly_print(rec->p[i], dim, div, p);
+ p = upoly_print(rec->p[i], dim, div, p, 0);
}
first = 0;
if (i == 0)
p = isl_printer_print_str(p, " * ");
p = print_pow(p, dim, div, rec->up.var, i);
}
- if (n > 1)
+ if (print_parens)
p = isl_printer_print_str(p, ")");
return p;
error:
return NULL;
}
-__isl_give isl_printer *isl_printer_print_qpolynomial(__isl_take isl_printer *p,
+static __isl_give isl_printer *print_qpolynomial(__isl_take isl_printer *p,
+ __isl_keep isl_qpolynomial *qp)
+{
+ if (!p || !qp)
+ goto error;
+ p = upoly_print(qp->upoly, qp->dim, qp->div, p, 1);
+ return p;
+error:
+ isl_printer_free(p);
+ return NULL;
+}
+
+static __isl_give isl_printer *print_qpolynomial_isl(__isl_take isl_printer *p,
__isl_keep isl_qpolynomial *qp)
{
if (!p || !qp)
goto error;
- p = upoly_print(qp->upoly, qp->dim, qp->div, p);
+
+ if (isl_dim_size(qp->dim, isl_dim_param) > 0) {
+ p = print_tuple(qp->dim, p, isl_dim_param, 0, 0, NULL);
+ p = isl_printer_print_str(p, " -> ");
+ }
+ p = isl_printer_print_str(p, "{ ");
+ if (isl_dim_size(qp->dim, isl_dim_set) > 0 ||
+ isl_dim_is_named_or_nested(qp->dim, isl_dim_set)) {
+ p = print_dim(qp->dim, p, 1, 0, 0, NULL);
+ p = isl_printer_print_str(p, " -> ");
+ }
+ p = print_qpolynomial(p, qp);
+ p = isl_printer_print_str(p, " }");
+ return p;
+error:
+ isl_printer_free(p);
+ return NULL;
+}
+
+static __isl_give isl_printer *print_qpolynomial_c(__isl_take isl_printer *p,
+ __isl_keep isl_dim *dim, __isl_keep isl_qpolynomial *qp)
+{
+ isl_int den;
+
+ isl_int_init(den);
+ isl_qpolynomial_get_den(qp, &den);
+ if (!isl_int_is_one(den)) {
+ isl_qpolynomial *f;
+ p = isl_printer_print_str(p, "(");
+ qp = isl_qpolynomial_copy(qp);
+ f = isl_qpolynomial_rat_cst(isl_dim_copy(qp->dim),
+ den, qp->dim->ctx->one);
+ qp = isl_qpolynomial_mul(qp, f);
+ }
+ if (qp)
+ p = upoly_print(qp->upoly, dim, qp->div, p, 0);
+ if (!isl_int_is_one(den)) {
+ p = isl_printer_print_str(p, ")/");
+ p = isl_printer_print_isl_int(p, den);
+ isl_qpolynomial_free(qp);
+ }
+ isl_int_clear(den);
return p;
+}
+
+__isl_give isl_printer *isl_printer_print_qpolynomial(
+ __isl_take isl_printer *p, __isl_keep isl_qpolynomial *qp)
+{
+ if (!p || !qp)
+ goto error;
+
+ if (p->output_format == ISL_FORMAT_ISL)
+ return print_qpolynomial_isl(p, qp);
+ else if (p->output_format == ISL_FORMAT_C)
+ return print_qpolynomial_c(p, qp->dim, qp);
+ else
+ isl_die(qp->dim->ctx, isl_error_unsupported,
+ "output format not supported for isl_qpolynomials",
+ goto error);
error:
isl_printer_free(p);
return NULL;
for (i = 0; i < fold->n; ++i) {
if (i)
p = isl_printer_print_str(p, ", ");
- p = isl_printer_print_qpolynomial(p, fold->qp[i]);
+ p = print_qpolynomial(p, fold->qp[i]);
}
p = isl_printer_print_str(p, ")");
return p;
}
-__isl_give isl_printer *isl_printer_print_qpolynomial_fold(
- __isl_take isl_printer *p, __isl_keep isl_qpolynomial_fold *fold)
-{
- if (!p || !fold)
- goto error;
- p = qpolynomial_fold_print(fold, p);
- return p;
-error:
- isl_printer_free(p);
- return NULL;
-}
-
void isl_qpolynomial_fold_print(__isl_keep isl_qpolynomial_fold *fold,
FILE *out, unsigned output_format)
{
for (i = 0; i < pwqp->n; ++i) {
if (i)
p = isl_printer_print_str(p, "; ");
- if (isl_dim_size(pwqp->p[i].set->dim, isl_dim_set) > 0 ||
- isl_dim_get_tuple_name(pwqp->p[i].set->dim, isl_dim_set)) {
- p = print_tuple(pwqp->p[i].set->dim, p, isl_dim_set, 1, 0, NULL);
+ if (isl_dim_size(pwqp->dim, isl_dim_set) > 0 ||
+ isl_dim_is_named_or_nested(pwqp->dim, isl_dim_set)) {
+ p = print_dim(pwqp->p[i].set->dim, p, 1, 0, 0, NULL);
p = isl_printer_print_str(p, " -> ");
}
- p = isl_printer_print_qpolynomial(p, pwqp->p[i].qp);
+ p = print_qpolynomial(p, pwqp->p[i].qp);
p = print_disjuncts((isl_map *)pwqp->p[i].set, p, 1, 0);
}
}
p = isl_printer_print_str(p, "{ ");
if (pwqp->n == 0) {
- if (isl_dim_size(pwqp->dim, isl_dim_set) > 0) {
- p = print_tuple(pwqp->dim, p, isl_dim_set, 1, 0, NULL);
+ if (isl_dim_size(pwqp->dim, isl_dim_set) > 0 ||
+ isl_dim_is_named_or_nested(pwqp->dim, isl_dim_set)) {
+ p = print_dim(pwqp->dim, p, 1, 0, 0, NULL);
p = isl_printer_print_str(p, " -> ");
}
p = isl_printer_print_str(p, "0");
for (i = 0; i < pwf->n; ++i) {
if (i)
p = isl_printer_print_str(p, "; ");
- if (isl_dim_size(pwf->p[i].set->dim, isl_dim_set) > 0) {
- p = print_tuple(pwf->p[i].set->dim, p, isl_dim_set, 0, 0, NULL);
+ if (isl_dim_size(pwf->dim, isl_dim_set) > 0 ||
+ isl_dim_is_named_or_nested(pwf->dim, isl_dim_set)) {
+ p = print_dim(pwf->p[i].set->dim, p, 1, 0, 0, NULL);
p = isl_printer_print_str(p, " -> ");
}
p = qpolynomial_fold_print(pwf->p[i].fold, p);
}
p = isl_printer_print_str(p, "{ ");
if (pwf->n == 0) {
- if (isl_dim_size(pwf->dim, isl_dim_set) > 0) {
- p = print_tuple(pwf->dim, p, isl_dim_set, 0, 0, NULL);
+ if (isl_dim_size(pwf->dim, isl_dim_set) > 0 ||
+ isl_dim_is_named_or_nested(pwf->dim, isl_dim_set)) {
+ p = print_dim(pwf->dim, p, 1, 0, 0, NULL);
p = isl_printer_print_str(p, " -> ");
}
p = isl_printer_print_str(p, "0");
}
static __isl_give isl_printer *print_affine_c(__isl_take isl_printer *p,
- __isl_keep isl_basic_set *bset, isl_int *c);
+ __isl_keep isl_dim *dim, __isl_keep isl_basic_set *bset, isl_int *c);
static __isl_give isl_printer *print_name_c(__isl_take isl_printer *p,
+ __isl_keep isl_dim *dim,
__isl_keep isl_basic_set *bset, enum isl_dim_type type, unsigned pos)
{
if (type == isl_dim_div) {
p = isl_printer_print_str(p, "floord(");
- p = print_affine_c(p, bset, bset->div[pos] + 1);
+ p = print_affine_c(p, dim, bset, bset->div[pos] + 1);
p = isl_printer_print_str(p, ", ");
p = isl_printer_print_isl_int(p, bset->div[pos][0]);
p = isl_printer_print_str(p, ")");
} else {
const char *name;
- name = isl_dim_get_name(bset->dim, type, pos);
+ name = isl_dim_get_name(dim, type, pos);
if (!name)
name = "UNNAMED";
p = isl_printer_print_str(p, name);
}
static __isl_give isl_printer *print_term_c(__isl_take isl_printer *p,
+ __isl_keep isl_dim *dim,
__isl_keep isl_basic_set *bset, isl_int c, unsigned pos)
{
enum isl_dim_type type;
- unsigned nparam = isl_basic_set_dim(bset, isl_dim_param);
if (pos == 0)
return isl_printer_print_isl_int(p, c);
p = isl_printer_print_isl_int(p, c);
p = isl_printer_print_str(p, "*");
}
- type = pos2type(bset->dim, &pos);
- p = print_name_c(p, bset, type, pos);
+ type = pos2type(dim, &pos);
+ p = print_name_c(p, dim, bset, type, pos);
return p;
}
-static __isl_give isl_printer *print_affine_c(__isl_take isl_printer *p,
- __isl_keep isl_basic_set *bset, isl_int *c)
+static __isl_give isl_printer *print_partial_affine_c(__isl_take isl_printer *p,
+ __isl_keep isl_dim *dim,
+ __isl_keep isl_basic_set *bset, isl_int *c, unsigned len)
{
int i;
int first;
- unsigned len = 1 + isl_basic_set_total_dim(bset);
for (i = 0, first = 1; i < len; ++i) {
int flip = 0;
p = isl_printer_print_str(p, " + ");
}
first = 0;
- p = print_term_c(p, bset, c[i], i);
+ p = print_term_c(p, dim, bset, c[i], i);
if (flip)
isl_int_neg(c[i], c[i]);
}
return p;
}
+static __isl_give isl_printer *print_affine_c(__isl_take isl_printer *p,
+ __isl_keep isl_dim *dim, __isl_keep isl_basic_set *bset, isl_int *c)
+{
+ unsigned len = 1 + isl_basic_set_total_dim(bset);
+ return print_partial_affine_c(p, dim, bset, c, len);
+}
+
static __isl_give isl_printer *print_constraint_c(__isl_take isl_printer *p,
+ __isl_keep isl_dim *dim,
__isl_keep isl_basic_set *bset, isl_int *c, const char *op, int first)
{
if (!first)
p = isl_printer_print_str(p, " && ");
- p = print_affine_c(p, bset, c);
+ p = print_affine_c(p, dim, bset, c);
p = isl_printer_print_str(p, " ");
p = isl_printer_print_str(p, op);
p = isl_printer_print_str(p, " 0");
}
static __isl_give isl_printer *print_basic_set_c(__isl_take isl_printer *p,
- __isl_keep isl_basic_set *bset)
+ __isl_keep isl_dim *dim, __isl_keep isl_basic_set *bset)
{
- int i;
-
- for (i = 0; i < bset->n_eq; ++i)
- p = print_constraint_c(p, bset, bset->eq[i], "==", !i);
+ int i, j;
+ unsigned n_div = isl_basic_set_dim(bset, isl_dim_div);
+ unsigned total = isl_basic_set_total_dim(bset) - n_div;
+
+ for (i = 0; i < bset->n_eq; ++i) {
+ j = isl_seq_last_non_zero(bset->eq[i] + 1 + total, n_div);
+ if (j < 0)
+ p = print_constraint_c(p, dim, bset,
+ bset->eq[i], "==", !i);
+ else {
+ if (i)
+ p = isl_printer_print_str(p, " && ");
+ p = isl_printer_print_str(p, "(");
+ p = print_partial_affine_c(p, dim, bset, bset->eq[i],
+ 1 + total + j);
+ p = isl_printer_print_str(p, ") % ");
+ p = isl_printer_print_isl_int(p,
+ bset->eq[i][1 + total + j]);
+ p = isl_printer_print_str(p, " == 0");
+ }
+ }
for (i = 0; i < bset->n_ineq; ++i)
- p = print_constraint_c(p, bset, bset->ineq[i], ">=",
+ p = print_constraint_c(p, dim, bset, bset->ineq[i], ">=",
!bset->n_eq && !i);
return p;
}
static __isl_give isl_printer *print_set_c(__isl_take isl_printer *p,
- __isl_keep isl_set *set)
+ __isl_keep isl_dim *dim, __isl_keep isl_set *set)
{
int i;
p = isl_printer_print_str(p, " || ");
if (set->n > 1)
p = isl_printer_print_str(p, "(");
- p = print_basic_set_c(p, set->p[i]);
+ p = print_basic_set_c(p, dim, set->p[i]);
if (set->n > 1)
p = isl_printer_print_str(p, ")");
}
return p;
}
-static __isl_give isl_printer *print_qpolynomial_c(__isl_take isl_printer *p,
- __isl_keep isl_qpolynomial *qp)
-{
- isl_int den;
-
- isl_int_init(den);
- isl_qpolynomial_get_den(qp, &den);
- if (!isl_int_is_one(den)) {
- isl_qpolynomial *f;
- p = isl_printer_print_str(p, "(");
- qp = isl_qpolynomial_copy(qp);
- f = isl_qpolynomial_rat_cst(isl_dim_copy(qp->dim),
- den, qp->dim->ctx->one);
- qp = isl_qpolynomial_mul(qp, f);
- }
- if (qp)
- p = upoly_print(qp->upoly, qp->dim, qp->div, p);
- if (!isl_int_is_one(den)) {
- p = isl_printer_print_str(p, ")/");
- p = isl_printer_print_isl_int(p, den);
- isl_qpolynomial_free(qp);
- }
- isl_int_clear(den);
- return p;
-}
-
static __isl_give isl_printer *print_pw_qpolynomial_c(
- __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial *pwpq)
+ __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial *pwqp)
{
int i;
- if (pwpq->n == 1 && isl_set_fast_is_universe(pwpq->p[0].set))
- return print_qpolynomial_c(p, pwpq->p[0].qp);
+ if (pwqp->n == 1 && isl_set_plain_is_universe(pwqp->p[0].set))
+ return print_qpolynomial_c(p, pwqp->dim, pwqp->p[0].qp);
- for (i = 0; i < pwpq->n; ++i) {
+ for (i = 0; i < pwqp->n; ++i) {
p = isl_printer_print_str(p, "(");
- p = print_set_c(p, pwpq->p[i].set);
+ p = print_set_c(p, pwqp->dim, pwqp->p[i].set);
p = isl_printer_print_str(p, ") ? (");
- p = print_qpolynomial_c(p, pwpq->p[i].qp);
+ p = print_qpolynomial_c(p, pwqp->dim, pwqp->p[i].qp);
p = isl_printer_print_str(p, ") : ");
}
}
static __isl_give isl_printer *print_qpolynomial_fold_c(
- __isl_take isl_printer *p, __isl_keep isl_qpolynomial_fold *fold)
+ __isl_take isl_printer *p, __isl_keep isl_dim *dim,
+ __isl_keep isl_qpolynomial_fold *fold)
{
int i;
for (i = 0; i < fold->n; ++i) {
if (i)
p = isl_printer_print_str(p, ", ");
- p = print_qpolynomial_c(p, fold->qp[i]);
+ p = print_qpolynomial_c(p, dim, fold->qp[i]);
if (i)
p = isl_printer_print_str(p, ")");
}
return p;
}
+__isl_give isl_printer *isl_printer_print_qpolynomial_fold(
+ __isl_take isl_printer *p, __isl_keep isl_qpolynomial_fold *fold)
+{
+ if (!p || !fold)
+ goto error;
+ if (p->output_format == ISL_FORMAT_ISL)
+ return qpolynomial_fold_print(fold, p);
+ else if (p->output_format == ISL_FORMAT_C)
+ return print_qpolynomial_fold_c(p, fold->dim, fold);
+ isl_die(p->ctx, isl_error_unsupported, "unsupported output format",
+ goto error);
+error:
+ isl_printer_free(p);
+ return NULL;
+}
+
static __isl_give isl_printer *print_pw_qpolynomial_fold_c(
__isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial_fold *pwf)
{
int i;
- if (pwf->n == 1 && isl_set_fast_is_universe(pwf->p[0].set))
- return print_qpolynomial_fold_c(p, pwf->p[0].fold);
+ if (pwf->n == 1 && isl_set_plain_is_universe(pwf->p[0].set))
+ return print_qpolynomial_fold_c(p, pwf->dim, pwf->p[0].fold);
for (i = 0; i < pwf->n; ++i) {
p = isl_printer_print_str(p, "(");
- p = print_set_c(p, pwf->p[i].set);
+ p = print_set_c(p, pwf->dim, pwf->p[i].set);
p = isl_printer_print_str(p, ") ? (");
- p = print_qpolynomial_fold_c(p, pwf->p[i].fold);
+ p = print_qpolynomial_fold_c(p, pwf->dim, pwf->p[i].fold);
p = isl_printer_print_str(p, ") : ");
}
isl_printer_free(p);
return NULL;
}
+
+__isl_give isl_printer *isl_printer_print_constraint(__isl_take isl_printer *p,
+ __isl_keep isl_constraint *c)
+{
+ isl_basic_map *bmap;
+
+ if (!p || !c)
+ goto error;
+
+ bmap = isl_basic_map_from_constraint(isl_constraint_copy(c));
+ p = isl_printer_print_basic_map(p, bmap);
+ isl_basic_map_free(bmap);
+ return p;
+error:
+ isl_printer_free(p);
+ return NULL;
+}
+
+void isl_constraint_dump(__isl_keep isl_constraint *c)
+{
+ isl_printer *printer;
+
+ if (!c)
+ return;
+
+ printer = isl_printer_to_file(isl_constraint_get_ctx(c), stderr);
+ printer = isl_printer_print_constraint(printer, c);
+ printer = isl_printer_end_line(printer);
+
+ isl_printer_free(printer);
+}
+
+__isl_give isl_printer *isl_printer_print_dim(__isl_take isl_printer *p,
+ __isl_keep isl_dim *dim)
+{
+ if (!dim)
+ goto error;
+
+ if (isl_dim_size(dim, isl_dim_param) > 0) {
+ p = print_tuple(dim, p, isl_dim_param, 0, 0, NULL);
+ p = isl_printer_print_str(p, " -> ");
+ }
+
+ p = isl_printer_print_str(p, "{ ");
+ p = print_tuple(dim, p, isl_dim_in, 0, 0, NULL);
+ p = isl_printer_print_str(p, " -> ");
+ p = print_tuple(dim, p, isl_dim_out, 0, 0, NULL);
+ p = isl_printer_print_str(p, " }");
+
+ return p;
+error:
+ isl_printer_free(p);
+ return NULL;
+}
+
+void isl_dim_dump(__isl_keep isl_dim *dim)
+{
+ isl_printer *printer;
+
+ if (!dim)
+ return;
+
+ printer = isl_printer_to_file(isl_dim_get_ctx(dim), stderr);
+ printer = isl_printer_print_dim(printer, dim);
+ printer = isl_printer_end_line(printer);
+
+ isl_printer_free(printer);
+}
+
+__isl_give isl_printer *isl_printer_print_local_space(__isl_take isl_printer *p,
+ __isl_keep isl_local_space *ls)
+{
+ unsigned total;
+ unsigned n_div;
+
+ if (!ls)
+ goto error;
+
+ total = isl_local_space_dim(ls, isl_dim_all);
+ if (isl_local_space_dim(ls, isl_dim_param) > 0) {
+ p = print_tuple(ls->dim, p, isl_dim_param, 0, 0, NULL);
+ p = isl_printer_print_str(p, " -> ");
+ }
+ p = isl_printer_print_str(p, "{ ");
+ p = print_tuple(ls->dim, p, isl_dim_in, 0, 0, NULL);
+ p = isl_printer_print_str(p, " -> ");
+ p = print_tuple(ls->dim, p, isl_dim_out, 0, 0, NULL);
+ n_div = isl_local_space_dim(ls, isl_dim_div);
+ if (n_div > 0) {
+ int i;
+ p = isl_printer_print_str(p, " : ");
+ p = isl_printer_print_str(p, s_open_exists[0]);
+ for (i = 0; i < n_div; ++i) {
+ if (i)
+ p = isl_printer_print_str(p, ", ");
+ p = print_name(ls->dim, p, isl_dim_div, i, 0, 0);
+ if (isl_int_is_zero(ls->div->row[i][0]))
+ continue;
+ p = isl_printer_print_str(p, " = [(");
+ p = print_affine_of_len(ls->dim, ls->div, p,
+ ls->div->row[i] + 1, 1 + total, 0);
+ p = isl_printer_print_str(p, ")/");
+ p = isl_printer_print_isl_int(p, ls->div->row[i][0]);
+ p = isl_printer_print_str(p, "]");
+ }
+ }
+ p = isl_printer_print_str(p, " }");
+ return p;
+error:
+ isl_printer_free(p);
+ return NULL;
+}
+
+void isl_local_space_dump(__isl_keep isl_local_space *ls)
+{
+ isl_printer *printer;
+
+ if (!ls)
+ return;
+
+ printer = isl_printer_to_file(isl_local_space_get_ctx(ls), stderr);
+ printer = isl_printer_print_local_space(printer, ls);
+ printer = isl_printer_end_line(printer);
+
+ isl_printer_free(printer);
+}
+
+static __isl_give isl_printer *print_aff(__isl_take isl_printer *p,
+ __isl_keep isl_aff *aff)
+{
+ unsigned total;
+
+ total = isl_local_space_dim(aff->ls, isl_dim_all);
+ p = print_tuple(aff->ls->dim, p, isl_dim_set, 1, 0, NULL);
+ p = isl_printer_print_str(p, " -> [");
+ p = isl_printer_print_str(p, "(");
+ p = print_affine_of_len(aff->ls->dim, aff->ls->div, p,
+ aff->v->el + 1, 1 + total, 1);
+ if (isl_int_is_one(aff->v->el[0]))
+ p = isl_printer_print_str(p, ")");
+ else {
+ p = isl_printer_print_str(p, ")/");
+ p = isl_printer_print_isl_int(p, aff->v->el[0]);
+ }
+ p = isl_printer_print_str(p, "]");
+
+ return p;
+}
+
+static __isl_give isl_printer *print_aff_isl(__isl_take isl_printer *p,
+ __isl_keep isl_aff *aff)
+{
+ if (!aff)
+ goto error;
+
+ if (isl_local_space_dim(aff->ls, isl_dim_param) > 0) {
+ p = print_tuple(aff->ls->dim, p, isl_dim_param, 0, 0, NULL);
+ p = isl_printer_print_str(p, " -> ");
+ }
+ p = isl_printer_print_str(p, "{ ");
+ p = print_aff(p, aff);
+ p = isl_printer_print_str(p, " }");
+ return p;
+error:
+ isl_printer_free(p);
+ return NULL;
+}
+
+void isl_aff_dump(__isl_keep isl_aff *aff)
+{
+ isl_printer *printer;
+
+ if (!aff)
+ return;
+
+ printer = isl_printer_to_file(isl_aff_get_ctx(aff), stderr);
+ printer = isl_printer_print_aff(printer, aff);
+ printer = isl_printer_end_line(printer);
+
+ isl_printer_free(printer);
+}
+
+static __isl_give isl_printer *print_pw_aff_isl(__isl_take isl_printer *p,
+ __isl_keep isl_pw_aff *pwaff)
+{
+ int i;
+
+ if (!pwaff)
+ goto error;
+
+ if (isl_dim_size(pwaff->dim, isl_dim_param) > 0) {
+ p = print_tuple(pwaff->dim, p, isl_dim_param, 0, 0, NULL);
+ p = isl_printer_print_str(p, " -> ");
+ }
+ p = isl_printer_print_str(p, "{ ");
+ for (i = 0; i < pwaff->n; ++i) {
+ if (i)
+ p = isl_printer_print_str(p, "; ");
+ p = print_aff(p, pwaff->p[i].aff);
+ p = print_disjuncts((isl_map *)pwaff->p[i].set, p, 1, 0);
+ }
+ p = isl_printer_print_str(p, " }");
+ return p;
+error:
+ isl_printer_free(p);
+ return NULL;
+}
+
+static __isl_give isl_printer *print_ls_affine_c(__isl_take isl_printer *p,
+ __isl_keep isl_local_space *ls, isl_int *c);
+
+static __isl_give isl_printer *print_ls_name_c(__isl_take isl_printer *p,
+ __isl_keep isl_local_space *ls, enum isl_dim_type type, unsigned pos)
+{
+ if (type == isl_dim_div) {
+ p = isl_printer_print_str(p, "floord(");
+ p = print_ls_affine_c(p, ls, ls->div->row[pos] + 1);
+ p = isl_printer_print_str(p, ", ");
+ p = isl_printer_print_isl_int(p, ls->div->row[pos][0]);
+ p = isl_printer_print_str(p, ")");
+ } else {
+ const char *name;
+
+ name = isl_dim_get_name(ls->dim, type, pos);
+ if (!name)
+ name = "UNNAMED";
+ p = isl_printer_print_str(p, name);
+ }
+ return p;
+}
+
+static __isl_give isl_printer *print_ls_term_c(__isl_take isl_printer *p,
+ __isl_keep isl_local_space *ls, isl_int c, unsigned pos)
+{
+ enum isl_dim_type type;
+
+ if (pos == 0)
+ return isl_printer_print_isl_int(p, c);
+
+ if (isl_int_is_one(c))
+ ;
+ else if (isl_int_is_negone(c))
+ p = isl_printer_print_str(p, "-");
+ else {
+ p = isl_printer_print_isl_int(p, c);
+ p = isl_printer_print_str(p, "*");
+ }
+ type = pos2type(ls->dim, &pos);
+ p = print_ls_name_c(p, ls, type, pos);
+ return p;
+}
+
+static __isl_give isl_printer *print_ls_partial_affine_c(
+ __isl_take isl_printer *p, __isl_keep isl_local_space *ls,
+ isl_int *c, unsigned len)
+{
+ int i;
+ int first;
+
+ for (i = 0, first = 1; i < len; ++i) {
+ int flip = 0;
+ if (isl_int_is_zero(c[i]))
+ continue;
+ if (!first) {
+ if (isl_int_is_neg(c[i])) {
+ flip = 1;
+ isl_int_neg(c[i], c[i]);
+ p = isl_printer_print_str(p, " - ");
+ } else
+ p = isl_printer_print_str(p, " + ");
+ }
+ first = 0;
+ p = print_ls_term_c(p, ls, c[i], i);
+ if (flip)
+ isl_int_neg(c[i], c[i]);
+ }
+ if (first)
+ p = isl_printer_print_str(p, "0");
+ return p;
+}
+
+static __isl_give isl_printer *print_ls_affine_c(__isl_take isl_printer *p,
+ __isl_keep isl_local_space *ls, isl_int *c)
+{
+ unsigned len = 1 + isl_local_space_dim(ls, isl_dim_all);
+ return print_ls_partial_affine_c(p, ls, c, len);
+}
+
+static __isl_give isl_printer *print_aff_c(__isl_take isl_printer *p,
+ __isl_keep isl_aff *aff)
+{
+ unsigned total;
+
+ total = isl_local_space_dim(aff->ls, isl_dim_all);
+ p = isl_printer_print_str(p, "(");
+ p = print_ls_partial_affine_c(p, aff->ls, aff->v->el + 1, 1 + total);
+ if (isl_int_is_one(aff->v->el[0]))
+ p = isl_printer_print_str(p, ")");
+ else {
+ p = isl_printer_print_str(p, ")/");
+ p = isl_printer_print_isl_int(p, aff->v->el[0]);
+ }
+ return p;
+}
+
+static __isl_give isl_printer *print_pw_aff_c(__isl_take isl_printer *p,
+ __isl_keep isl_pw_aff *pwaff)
+{
+ int i;
+
+ if (pwaff->n < 1)
+ isl_die(p->ctx, isl_error_unsupported,
+ "cannot print empty isl_pw_aff in C format", goto error);
+
+ for (i = 0; i < pwaff->n - 1; ++i) {
+ p = isl_printer_print_str(p, "(");
+ p = print_set_c(p, pwaff->dim, pwaff->p[i].set);
+ p = isl_printer_print_str(p, ") ? (");
+ p = print_aff_c(p, pwaff->p[i].aff);
+ p = isl_printer_print_str(p, ") : ");
+ }
+
+ return print_aff_c(p, pwaff->p[pwaff->n - 1].aff);
+error:
+ isl_printer_free(p);
+ return NULL;
+}
+
+__isl_give isl_printer *isl_printer_print_aff(__isl_take isl_printer *p,
+ __isl_keep isl_aff *aff)
+{
+ if (!p || !aff)
+ goto error;
+
+ if (p->output_format == ISL_FORMAT_ISL)
+ return print_aff_isl(p, aff);
+ else if (p->output_format == ISL_FORMAT_C)
+ return print_aff_c(p, aff);
+ isl_die(p->ctx, isl_error_unsupported, "unsupported output format",
+ goto error);
+error:
+ isl_printer_free(p);
+ return NULL;
+}
+
+__isl_give isl_printer *isl_printer_print_pw_aff(__isl_take isl_printer *p,
+ __isl_keep isl_pw_aff *pwaff)
+{
+ if (!p || !pwaff)
+ goto error;
+
+ if (p->output_format == ISL_FORMAT_ISL)
+ return print_pw_aff_isl(p, pwaff);
+ else if (p->output_format == ISL_FORMAT_C)
+ return print_pw_aff_c(p, pwaff);
+ isl_die(p->ctx, isl_error_unsupported, "unsupported output format",
+ goto error);
+error:
+ isl_printer_free(p);
+ return NULL;
+}
+
+void isl_pw_aff_dump(__isl_keep isl_pw_aff *pwaff)
+{
+ isl_printer *printer;
+
+ if (!pwaff)
+ return;
+
+ printer = isl_printer_to_file(isl_pw_aff_get_ctx(pwaff), stderr);
+ printer = isl_printer_print_pw_aff(printer, pwaff);
+ printer = isl_printer_end_line(printer);
+
+ isl_printer_free(printer);
+}