From 7ab71c47743c98feeb4c89fb9d785a7ba6d0180c Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sun, 28 Aug 2011 18:15:39 +0200 Subject: [PATCH] add isl_multi_aff_read_from_str Signed-off-by: Sven Verdoolaege --- doc/user.pod | 2 ++ include/isl/aff.h | 2 ++ isl_input.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/doc/user.pod b/doc/user.pod index 5b800fd2..a41d1d9c 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -3064,6 +3064,8 @@ Operations include An expression can be read from input using #include + __isl_give isl_multi_aff *isl_multi_aff_read_from_str( + isl_ctx *ctx, const char *str); __isl_give isl_pw_multi_aff *isl_pw_multi_aff_read_from_str( isl_ctx *ctx, const char *str); diff --git a/include/isl/aff.h b/include/isl/aff.h index a4edf1cb..2ada9f8d 100644 --- a/include/isl/aff.h +++ b/include/isl/aff.h @@ -251,6 +251,8 @@ __isl_give isl_multi_aff *isl_multi_aff_gist(__isl_take isl_multi_aff *maff, __isl_give isl_printer *isl_printer_print_multi_aff(__isl_take isl_printer *p, __isl_keep isl_multi_aff *maff); +__isl_give isl_multi_aff *isl_multi_aff_read_from_str(isl_ctx *ctx, + const char *str); void isl_multi_aff_dump(__isl_keep isl_multi_aff *maff); __isl_give isl_pw_multi_aff *isl_pw_multi_aff_alloc(__isl_take isl_set *set, diff --git a/isl_input.c b/isl_input.c index f8df8350..2133ba9e 100644 --- a/isl_input.c +++ b/isl_input.c @@ -2609,3 +2609,40 @@ __isl_give isl_pw_multi_aff *isl_pw_multi_aff_read_from_str(isl_ctx *ctx, isl_stream_free(s); return pma; } + +/* Read a multi-affine expression from "s". + * We call isl_stream_read_pw_multi_aff to parse a possibly piecewise + * multi-affine expression and then check that the result is + * a single multi-affine expression on a universe domain. + */ +__isl_give isl_multi_aff *isl_stream_read_multi_aff(struct isl_stream *s) +{ + isl_pw_multi_aff *pma; + isl_multi_aff *maff; + + pma = isl_stream_read_pw_multi_aff(s); + if (!pma) + return NULL; + if (pma->n != 1) + isl_die(s->ctx, isl_error_invalid, + "expecting single list of affine expressions", + return isl_pw_multi_aff_free(pma)); + if (!isl_set_plain_is_universe(pma->p[0].set)) + isl_die(s->ctx, isl_error_invalid, "expecting universe domain", + return isl_pw_multi_aff_free(pma)); + maff = isl_multi_aff_copy(pma->p[0].maff); + isl_pw_multi_aff_free(pma); + return maff; +} + +__isl_give isl_multi_aff *isl_multi_aff_read_from_str(isl_ctx *ctx, + const char *str) +{ + isl_multi_aff *maff; + struct isl_stream *s = isl_stream_new_str(ctx, str); + if (!s) + return NULL; + maff = isl_stream_read_multi_aff(s); + isl_stream_free(s); + return maff; +} -- 2.11.4.GIT