add isl_basic_set_print and isl_set_print for printing in PolyLib format
authorSven Verdoolaege <skimo@kotnet.org>
Sat, 27 Sep 2008 16:06:06 +0000 (18:06 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Mon, 13 Oct 2008 22:39:34 +0000 (00:39 +0200)
Makefile.am
include/isl_int.h
include/isl_set.h
isl_map.c
isl_mat.c
isl_output.c [new file with mode: 0644]
isl_vec.c

index e362d4c..ac729ae 100644 (file)
@@ -49,6 +49,7 @@ libisl_la_SOURCES = \
        isl_map_private.h \
        isl_mat.c \
        isl_mat.h \
+       isl_output.c \
        isl_sample.h \
        isl_sample.c \
        isl_seq.c \
index ad04056..48e4bf9 100644 (file)
@@ -41,12 +41,12 @@ typedef mpz_t       isl_int;
 #define isl_int_fdiv_r(r,i,j)  mpz_fdiv_r(r,i,j)
 
 #define isl_int_read(r,s)      mpz_set_str(r,s,10)
-#define isl_int_print(out,i)                                           \
+#define isl_int_print(out,i,width)                                     \
        do {                                                            \
                char *s;                                                \
                void (*gmp_free) (void *, size_t);                      \
                s = mpz_get_str(0, 10, i);                              \
-               fprintf(out, "%s", s);                                  \
+               fprintf(out, "%*s", width, s);                          \
                mp_get_memory_functions(NULL, NULL, &gmp_free);         \
                (*gmp_free)(s, strlen(s)+1);                            \
        } while (0)
index bdec438..fd097cf 100644 (file)
@@ -88,12 +88,18 @@ struct isl_basic_set *isl_basic_set_apply(
                struct isl_basic_map *bmap);
 struct isl_basic_set *isl_basic_set_affine_hull(struct isl_basic_set *bset);
 struct isl_basic_set *isl_basic_set_simplify(struct isl_basic_set *bset);
-#define ISL_FORMAT_POLYLIB     1
-#define ISL_FORMAT_OMEGA       2
+#define ISL_FORMAT_POLYLIB             1
+#define ISL_FORMAT_OMEGA               2
 struct isl_basic_set *isl_basic_set_read_from_file(struct isl_ctx *ctx,
                FILE *input, unsigned nparam, unsigned input_format);
 struct isl_set *isl_set_read_from_file(struct isl_ctx *ctx,
                FILE *input, unsigned nparam, unsigned input_format);
+#define ISL_FORMAT_POLYLIB_CONSTRAINTS 3
+void isl_basic_set_print(struct isl_basic_set *bset, FILE *out, int indent,
+       const char *prefix, const char *suffix, unsigned output_format);
+void isl_set_print(struct isl_set *set, FILE *out, int indent,
+       unsigned output_format);
+
 struct isl_basic_set *isl_basic_set_from_underlying_set(
        struct isl_basic_set *bset, struct isl_basic_set *like);
 struct isl_set *isl_set_from_underlying_set(
index d22872b..9b26875 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -1473,10 +1473,10 @@ static void dump_term(struct isl_basic_map *bmap,
        unsigned in = bmap->n_in;
        unsigned dim = bmap->n_in + bmap->n_out;
        if (!pos)
-               isl_int_print(out, c);
+               isl_int_print(out, c, 0);
        else {
                if (!isl_int_is_one(c))
-                       isl_int_print(out, c);
+                       isl_int_print(out, c, 0);
                if (pos < 1 + bmap->nparam)
                        fprintf(out, "p%d", pos - 1);
                else if (pos < 1 + bmap->nparam + in)
@@ -1570,7 +1570,7 @@ static void dump(struct isl_basic_map *bmap, FILE *out, int indent)
                fprintf(out, "e%d = [(", i);
                dump_affine(bmap, bmap->div[i]+1, out);
                fprintf(out, ")/");
-               isl_int_print(out, bmap->div[i][0]);
+               isl_int_print(out, bmap->div[i][0], 0);
                fprintf(out, "]\n");
        }
 }
index 07c695e..0a26e72 100644 (file)
--- a/isl_mat.c
+++ b/isl_mat.c
@@ -777,7 +777,7 @@ void isl_mat_dump(struct isl_ctx *ctx, struct isl_mat *mat,
                for (j = 0; j < mat->n_col; ++j) {
                        if (j)
                            fprintf(out, ",");
-                       isl_int_print(out, mat->row[i][j]);
+                       isl_int_print(out, mat->row[i][j], 0);
                }
                if (i == mat->n_row-1)
                        fprintf(out, "]]\n");
diff --git a/isl_output.c b/isl_output.c
new file mode 100644 (file)
index 0000000..bffa5ba
--- /dev/null
@@ -0,0 +1,86 @@
+#include <isl_set.h>
+
+static void print_constraint_polylib(struct isl_basic_set *bset,
+       int ineq, int n,
+       FILE *out, int indent, const char *prefix, const char *suffix)
+{
+       int i;
+       isl_int *c = ineq ? bset->ineq[n] : bset->eq[n];
+
+       fprintf(out, "%*s%s", indent, "", prefix ? prefix : "");
+       fprintf(out, "%d", ineq);
+       for (i = 0; i < bset->dim; ++i) {
+               fprintf(out, " ");
+               isl_int_print(out, c[1+bset->nparam+i], 5);
+       }
+       for (i = 0; i < bset->n_div; ++i) {
+               fprintf(out, " ");
+               isl_int_print(out, c[1+bset->nparam+bset->dim+i], 5);
+       }
+       for (i = 0; i < bset->nparam; ++i) {
+               fprintf(out, " ");
+               isl_int_print(out, c[1+i], 5);
+       }
+       fprintf(out, " ");
+       isl_int_print(out, c[0], 5);
+       fprintf(out, "%s\n", suffix ? suffix : "");
+}
+
+static void print_constraints_polylib(struct isl_basic_set *bset,
+       FILE *out, int indent, const char *prefix, const char *suffix)
+{
+       int i;
+
+       for (i = 0; i < bset->n_eq; ++i)
+               print_constraint_polylib(bset, 0, i, out,
+                                       indent, prefix, suffix);
+       for (i = 0; i < bset->n_ineq; ++i)
+               print_constraint_polylib(bset, 1, i, out,
+                                       indent, prefix, suffix);
+}
+
+static void isl_basic_set_print_polylib(struct isl_basic_set *bset, FILE *out,
+       int indent, const char *prefix, const char *suffix)
+{
+       unsigned total = bset->nparam + bset->dim + bset->n_div;
+       fprintf(out, "%*s%s", indent, "", prefix ? prefix : "");
+       fprintf(out, "%d %d", bset->n_eq + bset->n_ineq, 1 + total + 1);
+       fprintf(out, "%s\n", suffix ? suffix : "");
+       print_constraints_polylib(bset, out, indent, prefix, suffix);
+}
+
+static void isl_set_print_polylib(struct isl_set *set, FILE *out, int indent)
+{
+       int i;
+
+       fprintf(out, "%*s", indent, "");
+       fprintf(out, "%d\n", set->n);
+       for (i = 0; i < set->n; ++i) {
+               fprintf(out, "\n");
+               isl_basic_set_print_polylib(set->p[i], out, indent, NULL, NULL);
+       }
+}
+
+void isl_basic_set_print(struct isl_basic_set *bset, FILE *out, int indent,
+       const char *prefix, const char *suffix, unsigned output_format)
+{
+       if (!bset)
+               return;
+       if (output_format == ISL_FORMAT_POLYLIB)
+               isl_basic_set_print_polylib(bset, out, indent, prefix, suffix);
+       else if (output_format == ISL_FORMAT_POLYLIB_CONSTRAINTS)
+               print_constraints_polylib(bset, out, indent, prefix, suffix);
+       else
+               isl_assert(bset->ctx, 0, return);
+}
+
+void isl_set_print(struct isl_set *set, FILE *out, int indent,
+       unsigned output_format)
+{
+       if (!set)
+               return;
+       if (output_format == ISL_FORMAT_POLYLIB)
+               isl_set_print_polylib(set, out, indent);
+       else
+               isl_assert(set->ctx, 0, return);
+}
index c27dcc8..215e239 100644 (file)
--- a/isl_vec.c
+++ b/isl_vec.c
@@ -50,7 +50,7 @@ void isl_vec_dump(struct isl_ctx *ctx, struct isl_vec *vec,
        for (i = 0; i < vec->size; ++i) {
                if (i)
                    fprintf(out, ",");
-               isl_int_print(out, vec->block.data[i]);
+               isl_int_print(out, vec->block.data[i], 0);
        }
        fprintf(out, "]\n");
 }