From 05795807194fad22cb7dcc0d0be36577bd31b836 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sat, 1 Jun 2013 20:09:23 +0200 Subject: [PATCH] isl_input.c: accept_div: accept floor/ceil of rational affine expression We may want to print interger divisions as floor(...) instead of [...] in the future, so we might as well start parsing such expressions. Signed-off-by: Sven Verdoolaege --- include/isl/stream.h | 1 + isl_input.c | 23 +++++++++++++++++++++-- isl_stream.c | 4 ++++ isl_test.c | 4 ++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/include/isl/stream.h b/include/isl/stream.h index 7484af1..d3f65e4 100644 --- a/include/isl/stream.h +++ b/include/isl/stream.h @@ -35,6 +35,7 @@ enum isl_token_type { ISL_TOKEN_ERROR = -1, ISL_TOKEN_CEILD, ISL_TOKEN_FLOORD, ISL_TOKEN_MOD, ISL_TOKEN_STRING, ISL_TOKEN_MAP, ISL_TOKEN_AFF, + ISL_TOKEN_CEIL, ISL_TOKEN_FLOOR, ISL_TOKEN_LAST }; struct isl_token { diff --git a/isl_input.c b/isl_input.c index ba10ce8..480d60d 100644 --- a/isl_input.c +++ b/isl_input.c @@ -350,6 +350,10 @@ static int is_start_of_div(struct isl_token *tok) return 0; if (tok->type == '[') return 1; + if (tok->type == ISL_TOKEN_FLOOR) + return 1; + if (tok->type == ISL_TOKEN_CEIL) + return 1; if (tok->type == ISL_TOKEN_FLOORD) return 1; if (tok->type == ISL_TOKEN_CEILD) @@ -357,17 +361,32 @@ static int is_start_of_div(struct isl_token *tok) return 0; } +/* Read an integer division from "s" and return it as an isl_pw_aff. + * + * The integer division can be of the form + * + * [] + * floor() + * ceil() + * floord(,) + * ceild(,) + */ static __isl_give isl_pw_aff *accept_div(struct isl_stream *s, __isl_take isl_space *dim, struct vars *v) { struct isl_token *tok; int f = 0; int c = 0; + int extra = 0; isl_pw_aff *pwaff = NULL; if (isl_stream_eat_if_available(s, ISL_TOKEN_FLOORD)) - f = 1; + extra = f = 1; else if (isl_stream_eat_if_available(s, ISL_TOKEN_CEILD)) + extra = c = 1; + else if (isl_stream_eat_if_available(s, ISL_TOKEN_FLOOR)) + f = 1; + else if (isl_stream_eat_if_available(s, ISL_TOKEN_CEIL)) c = 1; if (f || c) { if (isl_stream_eat(s, '(')) @@ -379,7 +398,7 @@ static __isl_give isl_pw_aff *accept_div(struct isl_stream *s, pwaff = accept_affine(s, isl_space_copy(dim), v); - if (f || c) { + if (extra) { if (isl_stream_eat(s, ',')) goto error; diff --git a/isl_stream.c b/isl_stream.c index c40756d..de69f45 100644 --- a/isl_stream.c +++ b/isl_stream.c @@ -323,6 +323,10 @@ static enum isl_token_type check_keywords(struct isl_stream *s) return ISL_TOKEN_FLOORD; if (!strcasecmp(s->buffer, "mod")) return ISL_TOKEN_MOD; + if (!strcasecmp(s->buffer, "ceil")) + return ISL_TOKEN_CEIL; + if (!strcasecmp(s->buffer, "floor")) + return ISL_TOKEN_FLOOR; if (!s->keywords) return ISL_TOKEN_IDENT; diff --git a/isl_test.c b/isl_test.c index eeb2fc3..5d3e4aa 100644 --- a/isl_test.c +++ b/isl_test.c @@ -209,6 +209,10 @@ int test_parse(struct isl_ctx *ctx) if (test_parse_map_equal(ctx, "{ [*] }", "{ [a] }") < 0) return -1; + if (test_parse_map_equal(ctx, "{ [i] : 2*floor(i/2) = i }", + "{ [i] : exists a : i = 2 a }") < 0) + return -1; + return 0; } -- 2.7.4