isl_stream_read_map: accept disjunctions within a conjunct
authorSven Verdoolaege <skimo@kotnet.org>
Fri, 11 Feb 2011 16:02:23 +0000 (17:02 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Fri, 11 Feb 2011 16:02:58 +0000 (17:02 +0100)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_input.c
isl_test.c

index 247c00a..512fd15 100644 (file)
@@ -1004,40 +1004,67 @@ error:
        return NULL;
 }
 
-static struct isl_basic_map *read_disjunct(struct isl_stream *s,
+static isl_map *read_constraint(struct isl_stream *s,
        struct vars *v, __isl_take isl_dim *dim)
 {
-       int seen_paren = 0;
-       struct isl_token *tok;
        struct isl_basic_map *bmap;
+       int n = v->n;
 
        bmap = isl_basic_map_alloc_dim(dim, 0, 0, 0);
        if (!bmap)
                return NULL;
 
-       tok = isl_stream_next_token(s);
-       if (!tok)
-               goto error;
-       if (tok->type == '(') {
-               seen_paren = 1;
-               isl_token_free(tok);
-       } else
-               isl_stream_push_token(s, tok);
-
-       bmap = add_constraints(s, v, bmap);
+       bmap = add_constraint(s, v, bmap);
        bmap = isl_basic_map_simplify(bmap);
        bmap = isl_basic_map_finalize(bmap);
 
-       if (seen_paren && isl_stream_eat(s, ')'))
-               goto error;
+       vars_drop(v, v->n - n);
 
-       return bmap;
+       return isl_map_from_basic_map(bmap);
 error:
        isl_basic_map_free(bmap);
        return NULL;
 }
 
 static struct isl_map *read_disjuncts(struct isl_stream *s,
+       struct vars *v, __isl_take isl_dim *dim);
+
+static __isl_give isl_map *read_conjunct(struct isl_stream *s,
+       struct vars *v, __isl_take isl_dim *dim)
+{
+       isl_map *map;
+
+       if (isl_stream_eat_if_available(s, '(')) {
+               map = read_disjuncts(s, v, dim);
+               if (isl_stream_eat(s, ')'))
+                       goto error;
+               return map;
+       }
+               
+       return read_constraint(s, v, dim);
+error:
+       isl_map_free(map);
+       return NULL;
+}
+
+static __isl_give isl_map *read_conjuncts(struct isl_stream *s,
+       struct vars *v, __isl_take isl_dim *dim)
+{
+       isl_map *map;
+
+       map = read_conjunct(s, v, isl_dim_copy(dim));
+       while (isl_stream_eat_if_available(s, ISL_TOKEN_AND)) {
+               isl_map *map_i;
+
+               map_i = read_conjunct(s, v, isl_dim_copy(dim));
+               map = isl_map_intersect(map, map_i);
+       }
+
+       isl_dim_free(dim);
+       return map;
+}
+
+static struct isl_map *read_disjuncts(struct isl_stream *s,
        struct vars *v, __isl_take isl_dim *dim)
 {
        struct isl_token *tok;
@@ -1056,13 +1083,10 @@ static struct isl_map *read_disjuncts(struct isl_stream *s,
 
        map = isl_map_empty(isl_dim_copy(dim));
        for (;;) {
-               struct isl_basic_map *bmap;
-               int n = v->n;
-
-               bmap = read_disjunct(s, v, isl_dim_copy(dim));
-               map = isl_map_union(map, isl_map_from_basic_map(bmap));
+               isl_map *map_i;
 
-               vars_drop(v, v->n - n);
+               map_i = read_conjuncts(s, v, isl_dim_copy(dim));
+               map = isl_map_union(map, map_i);
 
                tok = isl_stream_next_token(s);
                if (!tok || tok->type != ISL_TOKEN_OR)
index 0050848..2f19799 100644 (file)
@@ -55,6 +55,8 @@ void test_parse(struct isl_ctx *ctx)
        isl_map_free(map);
 
        test_parse_map(ctx, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
+       test_parse_map(ctx, "{ [p1, y1, y2] -> [2, y1, y2] : "
+                               "p1 = 1 && (y1 <= y2 || y2 = 0) }");
 
        str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
        map = isl_map_read_from_str(ctx, str, -1);