From a1acee6ec51feff99d4f35f20131321ba4d7e3cc Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Fri, 18 Mar 2011 11:46:59 +0100 Subject: [PATCH] isl_stream_read_map: accept floord and ceild expressions in constraints Signed-off-by: Sven Verdoolaege --- include/isl/stream.h | 1 + isl_input.c | 59 +++++++++++++++++++++++++++++++++++----------------- isl_stream.c | 4 ++++ isl_test.c | 4 ++++ 4 files changed, 49 insertions(+), 19 deletions(-) diff --git a/include/isl/stream.h b/include/isl/stream.h index 6695157..779c6cf 100644 --- a/include/isl/stream.h +++ b/include/isl/stream.h @@ -29,6 +29,7 @@ enum isl_token_type { ISL_TOKEN_ERROR = -1, ISL_TOKEN_DEF, ISL_TOKEN_INFTY, ISL_TOKEN_NAN, ISL_TOKEN_MIN, ISL_TOKEN_MAX, ISL_TOKEN_RAT, ISL_TOKEN_TRUE, ISL_TOKEN_FALSE, + ISL_TOKEN_CEILD, ISL_TOKEN_FLOORD, ISL_TOKEN_STRING, ISL_TOKEN_LAST }; diff --git a/isl_input.c b/isl_input.c index 319937c..d979f1e 100644 --- a/isl_input.c +++ b/isl_input.c @@ -317,18 +317,26 @@ static __isl_give isl_vec *accept_affine_factor(struct isl_stream *s, goto error; if (isl_stream_eat(s, ')')) goto error; - } else if (tok->type == '[') { + } else if (tok->type == '[' || + tok->type == ISL_TOKEN_FLOORD || + tok->type == ISL_TOKEN_CEILD) { + int ceil = tok->type == ISL_TOKEN_CEILD; + struct variable *var; if (vars_add_anon(v) < 0) goto error; + var = v->v; aff = isl_vec_alloc(v->ctx, 1 + v->n); if (!aff) goto error; isl_seq_clr(aff->el, aff->size); - isl_int_set_si(aff->el[1 + v->n - 1], 1); + isl_int_set_si(aff->el[1 + v->n - 1], ceil ? -1 : 1); isl_stream_push_token(s, tok); tok = NULL; if (read_div_definition(s, v) < 0) goto error; + if (ceil) + isl_seq_neg(var->def->el + 1, var->def->el + 1, + var->def->size - 1); aff = isl_vec_zero_extend(aff, 1 + v->n); } else if (tok->type == ISL_TOKEN_MIN || tok->type == ISL_TOKEN_MAX) { if (vars_add_anon(v) < 0) @@ -393,6 +401,8 @@ static struct isl_vec *accept_affine(struct isl_stream *s, struct vars *v) } if (tok->type == '(' || tok->type == '[' || tok->type == ISL_TOKEN_MIN || tok->type == ISL_TOKEN_MAX || + tok->type == ISL_TOKEN_FLOORD || + tok->type == ISL_TOKEN_CEILD || tok->type == ISL_TOKEN_IDENT) { isl_vec *aff2; isl_stream_push_token(s, tok); @@ -657,18 +667,19 @@ static int read_div_definition(struct isl_stream *s, struct vars *v) int seen_paren = 0; struct isl_vec *aff; struct variable *var; + int fc = 0; - if (isl_stream_eat(s, '[')) - return -1; - - tok = isl_stream_next_token(s); - if (!tok) - return -1; - if (tok->type == '(') { - seen_paren = 1; - isl_token_free(tok); - } else - isl_stream_push_token(s, tok); + if (isl_stream_eat_if_available(s, ISL_TOKEN_FLOORD) || + isl_stream_eat_if_available(s, ISL_TOKEN_CEILD)) { + fc = 1; + if (isl_stream_eat(s, '(')) + return -1; + } else { + if (isl_stream_eat(s, '[')) + return -1; + if (isl_stream_eat_if_available(s, '(')) + seen_paren = 1; + } var = v->v; @@ -686,10 +697,15 @@ static int read_div_definition(struct isl_stream *s, struct vars *v) isl_vec_free(aff); - if (seen_paren && isl_stream_eat(s, ')')) - return -1; - if (isl_stream_eat(s, '/')) - return -1; + if (fc) { + if (isl_stream_eat(s, ',')) + return -1; + } else { + if (seen_paren && isl_stream_eat(s, ')')) + return -1; + if (isl_stream_eat(s, '/')) + return -1; + } tok = next_token(s); if (!tok) @@ -702,8 +718,13 @@ static int read_div_definition(struct isl_stream *s, struct vars *v) isl_int_set(var->def->el[0], tok->u.v); isl_token_free(tok); - if (isl_stream_eat(s, ']')) - return -1; + if (fc) { + if (isl_stream_eat(s, ')')) + return -1; + } else { + if (isl_stream_eat(s, ']')) + return -1; + } return 0; } diff --git a/isl_stream.c b/isl_stream.c index 2cb6e0b..c544149 100644 --- a/isl_stream.c +++ b/isl_stream.c @@ -260,6 +260,10 @@ static enum isl_token_type check_keywords(struct isl_stream *s) return ISL_TOKEN_TRUE; if (!strcasecmp(s->buffer, "false")) return ISL_TOKEN_FALSE; + if (!strcasecmp(s->buffer, "ceild")) + return ISL_TOKEN_CEILD; + if (!strcasecmp(s->buffer, "floord")) + return ISL_TOKEN_FLOORD; if (!s->keywords) return ISL_TOKEN_IDENT; diff --git a/isl_test.c b/isl_test.c index 30879d9..1f2c6f1 100644 --- a/isl_test.c +++ b/isl_test.c @@ -97,6 +97,10 @@ void test_parse(struct isl_ctx *ctx) isl_map_free(map); isl_map_free(map2); + str = "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }"; + str2 = "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }"; + test_parse_map_equal(ctx, str, str2); + test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }"); } -- 2.7.4