#include <stdlib.h>
#include <string.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_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 *print_dim(__isl_keep isl_dim *dim,
- __isl_take isl_printer *p, int set, int latex,
+ __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 {
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
}
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_dim(bmap->dim, p, 0, latex, NULL);
- p = isl_printer_print_str(p, " : ");
- p = print_disjunct(bmap, bmap->dim, p, 0, latex);
- p = isl_printer_print_str(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_dim(bset->dim, p, 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, " }");
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, "; ");
- p = print_dim(dim, p, set, 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 {
- p = print_dim(map->dim, p, set, 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]);
- p = print_dim(map->dim, p, set, 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, 0);
else if (p->output_format == ISL_FORMAT_EXT_POLYLIB)
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;
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)
{
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)
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;
+
+ 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;
+}
+
void isl_qpolynomial_print(__isl_keep isl_qpolynomial *qp, FILE *out,
unsigned output_format)
{
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;
p = isl_printer_print_str(p, "; ");
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, NULL);
+ 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);
}
if (pwqp->n == 0) {
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, NULL);
+ p = print_dim(pwqp->dim, p, 1, 0, 0, NULL);
p = isl_printer_print_str(p, " -> ");
}
p = isl_printer_print_str(p, "0");
p = isl_printer_print_str(p, "; ");
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, NULL);
+ 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);
if (pwf->n == 0) {
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, NULL);
+ p = print_dim(pwf->dim, p, 1, 0, 0, NULL);
p = isl_printer_print_str(p, " -> ");
}
p = isl_printer_print_str(p, "0");
__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);
return p;
}
-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;
-}
-
static __isl_give isl_printer *print_pw_qpolynomial_c(
__isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial *pwqp)
{
int i;
- if (pwqp->n == 1 && isl_set_fast_is_universe(pwqp->p[0].set))
+ 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 < pwqp->n; ++i) {
{
int i;
- if (pwf->n == 1 && isl_set_fast_is_universe(pwf->p[0].set))
+ 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) {
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);
+}