isl_map_read_from_file: allow unions in isl format input
authorSven Verdoolaege <skimo@kotnet.org>
Fri, 22 Jan 2010 12:54:47 +0000 (13:54 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Mon, 25 Jan 2010 16:45:12 +0000 (17:45 +0100)
isl_input.c
isl_stream.c
isl_stream.h

index 3aaad8c..db3d619 100644 (file)
@@ -468,6 +468,60 @@ error:
        return NULL;
 }
 
+static struct isl_basic_map *read_disjunct(struct isl_stream *s,
+       struct vars **v, __isl_take isl_dim *dim)
+{
+       struct isl_basic_map *bmap;
+
+       bmap = isl_basic_map_alloc_dim(dim, 0, 0, 0);
+       if (!bmap)
+               return NULL;
+
+       bmap = add_constraints(s, v, bmap);
+       bmap = isl_basic_map_simplify(bmap);
+       bmap = isl_basic_map_finalize(bmap);
+       return bmap;
+}
+
+static struct isl_map *read_disjuncts(struct isl_stream *s,
+       struct vars **v, __isl_take isl_dim *dim)
+{
+       struct isl_token *tok;
+       struct isl_map *map;
+
+       tok = isl_stream_next_token(s);
+       if (!tok) {
+               isl_stream_error(s, NULL, "unexpected EOF");
+               goto error;
+       }
+       if (tok->type == '}') {
+               isl_stream_push_token(s, tok);
+               return isl_map_universe(dim);
+       }
+       isl_stream_push_token(s, tok);
+
+       map = isl_map_empty(isl_dim_copy(dim));
+       for (;;) {
+               struct isl_basic_map *bmap;
+
+               bmap = read_disjunct(s, v, isl_dim_copy(dim));
+               map = isl_map_union(map, isl_map_from_basic_map(bmap));
+
+               tok = isl_stream_next_token(s);
+               if (!tok || tok->type != ISL_TOKEN_OR)
+                       break;
+               isl_token_free(tok);
+       }
+       if (tok)
+               isl_stream_push_token(s, tok);
+
+       isl_dim_free(dim);
+       return map;
+error:
+       isl_dim_free(dim);
+       return NULL;
+}
+
 static __isl_give isl_basic_map *basic_map_read_polylib_constraint(
        struct isl_stream *s, __isl_take isl_basic_map *bmap)
 {
@@ -663,8 +717,8 @@ static struct isl_dim *dim_from_vars(struct vars *vars,
 
 static struct isl_map *map_read(struct isl_stream *s, int nparam)
 {
-       struct isl_dim *dim;
-       struct isl_basic_map *bmap = NULL;
+       struct isl_dim *dim = NULL;
+       struct isl_map *map = NULL;
        struct isl_token *tok;
        struct vars *v = NULL;
        int n1;
@@ -725,15 +779,17 @@ static struct isl_map *map_read(struct isl_stream *s, int nparam)
                n1 = 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);
-       if (tok && tok->type == ':') {
+       if (!tok) {
+               isl_stream_error(s, NULL, "unexpected EOF");
+               goto error;
+       }
+       if (tok->type == ':') {
                isl_token_free(tok);
-               bmap = add_constraints(s, &v, bmap);
+               map = read_disjuncts(s, &v, isl_dim_copy(dim));
                tok = isl_stream_next_token(s);
-       }
+       } else
+               map = isl_map_universe(isl_dim_copy(dim));
        if (tok && tok->type == '}') {
                isl_token_free(tok);
        } else {
@@ -743,12 +799,12 @@ static struct isl_map *map_read(struct isl_stream *s, int nparam)
                goto error;
        }
        vars_free(v);
+       isl_dim_free(dim);
 
-       bmap = isl_basic_map_simplify(bmap);
-       bmap = isl_basic_map_finalize(bmap);
-       return isl_map_from_basic_map(bmap);
+       return map;
 error:
-       isl_basic_map_free(bmap);
+       isl_dim_free(dim);
+       isl_map_free(map);
        if (v)
                vars_free(v);
        return NULL;
index 2cc4854..276759e 100644 (file)
@@ -240,6 +240,8 @@ struct isl_token *isl_stream_next_token(struct isl_stream *s)
                        tok->type = ISL_TOKEN_EXISTS;
                else if (!strcasecmp(s->buffer, "and"))
                        tok->type = ISL_TOKEN_AND;
+               else if (!strcasecmp(s->buffer, "or"))
+                       tok->type = ISL_TOKEN_OR;
                else {
                        tok->type = ISL_TOKEN_IDENT;
                        tok->u.s = strdup(s->buffer);
@@ -279,6 +281,15 @@ struct isl_token *isl_stream_next_token(struct isl_stream *s)
                        isl_stream_ungetc(s, c);
                return tok;
        }
+       if (c == '|') {
+               tok = isl_token_new(s->ctx, line, col, old_line != line);
+               if (!tok)
+                       return NULL;
+               tok->type = ISL_TOKEN_OR;
+               if ((c = isl_stream_getc(s)) != '|' && c != -1)
+                       isl_stream_ungetc(s, c);
+               return tok;
+       }
 
        tok = isl_token_new(s->ctx, line, col, old_line != line);
        if (!tok)
index 18b559f..2d0119b 100644 (file)
@@ -19,7 +19,7 @@ extern "C" {
 enum isl_token_type { ISL_TOKEN_UNKNOWN = 256, ISL_TOKEN_VALUE,
                        ISL_TOKEN_IDENT, ISL_TOKEN_GE,
                        ISL_TOKEN_LE, ISL_TOKEN_TO, ISL_TOKEN_AND,
-                       ISL_TOKEN_EXISTS };
+                       ISL_TOKEN_OR, ISL_TOKEN_EXISTS };
 
 struct isl_token {
        enum isl_token_type  type;