From dc65c28891adea2b3be878a07736a84a20441d4e Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Fri, 11 Feb 2011 17:02:23 +0100 Subject: [PATCH] isl_stream_read_map: accept disjunctions within a conjunct Signed-off-by: Sven Verdoolaege --- isl_input.c | 68 +++++++++++++++++++++++++++++++++++++++++-------------------- isl_test.c | 2 ++ 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/isl_input.c b/isl_input.c index 247c00a3..512fd15f 100644 --- a/isl_input.c +++ b/isl_input.c @@ -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) diff --git a/isl_test.c b/isl_test.c index 0050848e..2f197996 100644 --- a/isl_test.c +++ b/isl_test.c @@ -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); -- 2.11.4.GIT