isl_input.c: optionally read parameters from input
authorSven Verdoolaege <skimo@kotnet.org>
Sun, 24 Jan 2010 21:30:12 +0000 (22:30 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Mon, 25 Jan 2010 16:45:12 +0000 (17:45 +0100)
doc/user.pod
include/isl_map.h
include/isl_set.h
isl_input.c

index 625b3c4..67c5091 100644 (file)
@@ -377,25 +377,29 @@ to foreign file formats.
 
        #include <isl_set.h>
        __isl_give isl_basic_set *isl_basic_set_read_from_file(
-               isl_ctx *ctx, FILE *input, unsigned nparam);
+               isl_ctx *ctx, FILE *input, int nparam);
        __isl_give isl_basic_set *isl_basic_set_read_from_str(
-               isl_ctx *ctx, const char *str, unsigned nparam);
+               isl_ctx *ctx, const char *str, int nparam);
        __isl_give isl_set *isl_set_read_from_file(isl_ctx *ctx,
-               FILE *input, unsigned nparam);
+               FILE *input, int nparam);
 
        #include <isl_map.h>
        __isl_give isl_basic_map *isl_basic_map_read_from_file(
-               isl_ctx *ctx, FILE *input, unsigned nparam);
+               isl_ctx *ctx, FILE *input, int nparam);
        __isl_give isl_basic_map *isl_basic_map_read_from_str(
-               isl_ctx *ctx, const char *str, unsigned nparam);
+               isl_ctx *ctx, const char *str, int nparam);
        __isl_give isl_map *isl_map_read_from_file(
-               struct isl_ctx *ctx, FILE *input, unsigned nparam);
+               struct isl_ctx *ctx, FILE *input, int nparam);
 
-The input may be either in C<PolyLib> format or in an
-C<Omega>-like format.
+The input may be either in C<PolyLib> format or in the
+C<isl> format, which is similar to the C<Omega> format.
 C<nparam> specifies how many of the final columns in
-the C<PolyLib> format correspond to parameters.  It should
-be zero when C<Omega>-like input is expected.
+the C<PolyLib> format correspond to parameters.
+If input is given in the C<isl> format, then the number
+of parameters needs to be equal to C<nparam>.
+If C<nparam> is negative, then any number of parameters
+is accepted in the C<isl> format and zero parameters
+are assumed in the C<PolyLib> format.
 
 =head3 Output
 
index 16478bf..3cc0492 100644 (file)
@@ -182,11 +182,11 @@ struct isl_basic_map *isl_basic_map_simplify(struct isl_basic_map *bmap);
 struct isl_basic_map *isl_basic_map_detect_equalities(
                                                struct isl_basic_map *bmap);
 __isl_give isl_basic_map *isl_basic_map_read_from_file(isl_ctx *ctx,
-               FILE *input, unsigned nparam);
+               FILE *input, int nparam);
 __isl_give isl_basic_map *isl_basic_map_read_from_str(isl_ctx *ctx,
-               const char *str, unsigned nparam);
+               const char *str, int nparam);
 __isl_give isl_map *isl_map_read_from_file(struct isl_ctx *ctx,
-               FILE *input, unsigned nparam);
+               FILE *input, int nparam);
 struct isl_basic_map *isl_basic_map_fix_si(struct isl_basic_map *bmap,
                enum isl_dim_type type, unsigned pos, int value);
 
index 99dde24..db2d476 100644 (file)
@@ -128,11 +128,11 @@ __isl_give isl_basic_set *isl_basic_set_detect_equalities(
 struct isl_basic_set *isl_basic_set_product(struct isl_basic_set_list *list);
 
 __isl_give isl_basic_set *isl_basic_set_read_from_file(isl_ctx *ctx,
-               FILE *input, unsigned nparam);
+               FILE *input, int nparam);
 __isl_give isl_basic_set *isl_basic_set_read_from_str(isl_ctx *ctx,
-               const char *str, unsigned nparam);
+               const char *str, int nparam);
 __isl_give isl_set *isl_set_read_from_file(isl_ctx *ctx,
-               FILE *input, unsigned nparam);
+               FILE *input, int nparam);
 #define ISL_FORMAT_POLYLIB             1
 #define ISL_FORMAT_POLYLIB_CONSTRAINTS 2
 void isl_basic_set_print(__isl_keep isl_basic_set *bset, FILE *out, int indent,
index 770f0d4..2e09bc6 100644 (file)
@@ -510,8 +510,36 @@ static struct isl_map *map_read_polylib(struct isl_stream *s, int nparam)
        return map;
 }
 
+static struct isl_dim *set_names(struct isl_dim *dim, struct vars *vars,
+       enum isl_dim_type type, int offset, int n)
+{
+       int i;
+       struct variable *v;
+
+       for (i = 0, v = vars->v; i < offset; ++i, v = v->next)
+               ;
+       for (i = n - 1; i >= 0; --i, v = v->next)
+               dim = isl_dim_set_name(dim, type, i, v->name);
+
+       return dim;
+}
+
+static struct isl_dim *dim_from_vars(struct vars *vars,
+       int nparam, int n_in, int n_out)
+{
+       struct isl_dim *dim;
+
+       dim = isl_dim_alloc(vars->ctx, nparam, n_in, n_out);
+       dim = set_names(dim, vars, isl_dim_param, n_out + n_in, nparam);
+       dim = set_names(dim, vars, isl_dim_in, n_out, n_in);
+       dim = set_names(dim, vars, isl_dim_out, 0, n_out);
+
+       return dim;
+}
+
 static struct isl_map *map_read(struct isl_stream *s, int nparam)
 {
+       struct isl_dim *dim;
        struct isl_basic_map *bmap = NULL;
        struct isl_token *tok;
        struct vars *v = NULL;
@@ -527,33 +555,53 @@ static struct isl_map *map_read(struct isl_stream *s, int nparam)
                isl_stream_push_token(s, tok);
                return map_read_polylib(s, nparam);
        }
-       if (tok->type != '{') {
+       v = vars_new(s->ctx);
+       if (tok->type == '[') {
+               isl_stream_push_token(s, tok);
+               v = read_tuple(s, v);
+               if (!v)
+                       return NULL;
+               if (nparam >= 0)
+                       isl_assert(s->ctx, nparam == v->n, goto error);
+               nparam = v->n;
+               tok = isl_stream_next_token(s);
+               if (!tok || tok->type != ISL_TOKEN_TO) {
+                       isl_stream_error(s, tok, "expecting '->'");
+                       if (tok)
+                               isl_stream_push_token(s, tok);
+                       goto error;
+               }
+               isl_token_free(tok);
+               tok = isl_stream_next_token(s);
+       }
+       if (nparam < 0)
+               nparam = 0;
+       if (!tok || tok->type != '{') {
                isl_stream_error(s, tok, "expecting '{'");
                if (tok)
                        isl_stream_push_token(s, tok);
                goto error;
        }
        isl_token_free(tok);
-       isl_assert(s->ctx, nparam == 0, goto error);
-       v = vars_new(s->ctx);
        v = read_tuple(s, v);
        if (!v)
                return NULL;
-       n1 = v->n;
+       n1 = v->n - nparam;
        tok = isl_stream_next_token(s);
        if (tok && tok->type == ISL_TOKEN_TO) {
                isl_token_free(tok);
                v = read_tuple(s, v);
                if (!v)
                        return NULL;
-               n2 = v->n - n1;
+               n2 = v->n - n1 - nparam;
        } else {
                if (tok)
                        isl_stream_push_token(s, tok);
                n2 = n1;
                n1 = 0;
        }
-       bmap = isl_basic_map_alloc(s->ctx, 0, n1, n2, 0, 0,0);
+       dim = dim_from_vars(v, nparam, n1, n2);
+       bmap = isl_basic_map_alloc_dim(dim, 0, 0, 0);
        if (!bmap)
                goto error;
        tok = isl_stream_next_token(s);
@@ -607,7 +655,7 @@ error:
 }
 
 __isl_give isl_basic_map *isl_basic_map_read_from_file(isl_ctx *ctx,
-               FILE *input, unsigned nparam)
+               FILE *input, int nparam)
 {
        struct isl_basic_map *bmap;
        struct isl_stream *s = isl_stream_new_file(ctx, input);
@@ -619,7 +667,7 @@ __isl_give isl_basic_map *isl_basic_map_read_from_file(isl_ctx *ctx,
 }
 
 __isl_give isl_basic_set *isl_basic_set_read_from_file(isl_ctx *ctx,
-               FILE *input, unsigned nparam)
+               FILE *input, int nparam)
 {
        struct isl_basic_map *bmap;
        bmap = isl_basic_map_read_from_file(ctx, input, nparam);
@@ -633,7 +681,7 @@ error:
 }
 
 struct isl_basic_map *isl_basic_map_read_from_str(struct isl_ctx *ctx,
-               const char *str, unsigned nparam)
+               const char *str, int nparam)
 {
        struct isl_basic_map *bmap;
        struct isl_stream *s = isl_stream_new_str(ctx, str);
@@ -645,7 +693,7 @@ struct isl_basic_map *isl_basic_map_read_from_str(struct isl_ctx *ctx,
 }
 
 struct isl_basic_set *isl_basic_set_read_from_str(struct isl_ctx *ctx,
-               const char *str, unsigned nparam)
+               const char *str, int nparam)
 {
        struct isl_basic_map *bmap;
        bmap = isl_basic_map_read_from_str(ctx, str, nparam);
@@ -659,7 +707,7 @@ error:
 }
 
 __isl_give isl_map *isl_map_read_from_file(struct isl_ctx *ctx,
-               FILE *input, unsigned nparam)
+               FILE *input, int nparam)
 {
        struct isl_map *map;
        struct isl_stream *s = isl_stream_new_file(ctx, input);
@@ -671,7 +719,7 @@ __isl_give isl_map *isl_map_read_from_file(struct isl_ctx *ctx,
 }
 
 __isl_give isl_set *isl_set_read_from_file(struct isl_ctx *ctx,
-               FILE *input, unsigned nparam)
+               FILE *input, int nparam)
 {
        struct isl_map *map;
        map = isl_map_read_from_file(ctx, input, nparam);