From a1329e4f9c4c8ffe00ecaba812301ef7474bd4bc Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 3 Jul 2014 12:23:32 +0200 Subject: [PATCH] isl_stream_read_obj: detect and read schedule objects This allows isl_cat to read schedules. Signed-off-by: Sven Verdoolaege --- isl_input.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/isl_input.c b/isl_input.c index 09dcbb07..b6073dea 100644 --- a/isl_input.c +++ b/isl_input.c @@ -2402,6 +2402,70 @@ error: return obj1; } +/* Are the first two tokens on "s", "domain" (either as a string + * or as an identifier) followed by ":"? + */ +static int next_is_domain_colon(__isl_keep isl_stream *s) +{ + struct isl_token *tok; + char *name; + int res; + + tok = isl_stream_next_token(s); + if (!tok) + return 0; + if (tok->type != ISL_TOKEN_IDENT && tok->type != ISL_TOKEN_STRING) { + isl_stream_push_token(s, tok); + return 0; + } + + name = isl_token_get_str(s->ctx, tok); + res = !strcmp(name, "domain") && isl_stream_next_token_is(s, ':'); + free(name); + + isl_stream_push_token(s, tok); + + return res; +} + +/* Do the first tokens on "s" look like a schedule? + * + * The root of a schedule is always a domain node, so the first thing + * we expect in the stream is a domain key, i.e., "domain" followed + * by ":". If the schedule was printed in YAML flow style, then + * we additionally expect a "{" to open the outer mapping. + */ +static int next_is_schedule(__isl_keep isl_stream *s) +{ + struct isl_token *tok; + int is_schedule; + + tok = isl_stream_next_token(s); + if (!tok) + return 0; + if (tok->type != '{') { + isl_stream_push_token(s, tok); + return next_is_domain_colon(s); + } + + is_schedule = next_is_domain_colon(s); + isl_stream_push_token(s, tok); + + return is_schedule; +} + +/* Read an isl_schedule from "s" and store it in an isl_obj. + */ +static struct isl_obj schedule_read(__isl_keep isl_stream *s) +{ + struct isl_obj obj; + + obj.type = isl_obj_schedule; + obj.v = isl_stream_read_schedule(s); + + return obj; +} + static struct isl_obj obj_read(__isl_keep isl_stream *s) { isl_map *map = NULL; @@ -2409,6 +2473,9 @@ static struct isl_obj obj_read(__isl_keep isl_stream *s) struct vars *v = NULL; struct isl_obj obj = { isl_obj_set, NULL }; + if (next_is_schedule(s)) + return schedule_read(s); + tok = next_token(s); if (!tok) { isl_stream_error(s, NULL, "unexpected EOF"); -- 2.11.4.GIT