From: Sven Verdoolaege Date: Fri, 22 Jan 2010 12:54:47 +0000 (+0100) Subject: isl_map_read_from_file: allow unions in isl format input X-Git-Tag: isl-0.02~149 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3454019bf1ebe3c143436ed0b400c79ff3f6d84f;p=platform%2Fupstream%2Fisl.git isl_map_read_from_file: allow unions in isl format input --- diff --git a/isl_input.c b/isl_input.c index 3aaad8c..db3d619 100644 --- a/isl_input.c +++ b/isl_input.c @@ -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; diff --git a/isl_stream.c b/isl_stream.c index 2cc4854..276759e 100644 --- a/isl_stream.c +++ b/isl_stream.c @@ -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) diff --git a/isl_stream.h b/isl_stream.h index 18b559f..2d0119b 100644 --- a/isl_stream.h +++ b/isl_stream.h @@ -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;