From 7c3586dd33b6c6f0ec9442928df0b54f7d3d1df6 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 17 Nov 2010 16:24:05 +0100 Subject: [PATCH] add isl_union_map_read_from_str Signed-off-by: Sven Verdoolaege --- doc/user.pod | 8 ++++++ include/isl_stream.h | 1 + include/isl_union_map.h | 2 ++ include/isl_union_set.h | 2 ++ isl_input.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ isl_test.c | 4 +-- 6 files changed, 82 insertions(+), 2 deletions(-) diff --git a/doc/user.pod b/doc/user.pod index 75cb914a..59f4c5e8 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -585,6 +585,14 @@ dimensions is zero. __isl_give isl_map *isl_map_read_from_str(isl_ctx *ctx, const char *str, int nparam); + #include + __isl_give isl_union_set *isl_union_set_read_from_str( + struct isl_ctx *ctx, const char *str); + + #include + __isl_give isl_union_map *isl_union_map_read_from_str( + struct isl_ctx *ctx, const char *str); + The input format is autodetected and may be either the C format or the C format. C specifies how many of the final columns in diff --git a/include/isl_stream.h b/include/isl_stream.h index 75a14564..20f7a2f8 100644 --- a/include/isl_stream.h +++ b/include/isl_stream.h @@ -91,6 +91,7 @@ __isl_give isl_map *isl_stream_read_map(struct isl_stream *s, int nparam); __isl_give isl_set *isl_stream_read_set(struct isl_stream *s, int nparam); __isl_give isl_pw_qpolynomial *isl_stream_read_pw_qpolynomial( struct isl_stream *s); +__isl_give isl_union_map *isl_stream_read_union_map(struct isl_stream *s); #if defined(__cplusplus) } diff --git a/include/isl_union_map.h b/include/isl_union_map.h index 306ac2fe..97d7004b 100644 --- a/include/isl_union_map.h +++ b/include/isl_union_map.h @@ -100,6 +100,8 @@ __isl_give isl_union_map *isl_union_map_lex_gt_union_map( __isl_give isl_union_map *isl_union_map_lex_ge_union_map( __isl_take isl_union_map *umap1, __isl_take isl_union_map *umap2); +__isl_give isl_union_map *isl_union_map_read_from_str(struct isl_ctx *ctx, + const char *str); __isl_give isl_printer *isl_printer_print_union_map(__isl_take isl_printer *p, __isl_keep isl_union_map *umap); diff --git a/include/isl_union_set.h b/include/isl_union_set.h index 010a4a97..a7b7918e 100644 --- a/include/isl_union_set.h +++ b/include/isl_union_set.h @@ -64,6 +64,8 @@ __isl_give isl_union_map *isl_union_set_lex_gt_union_set( __isl_give isl_union_map *isl_union_set_lex_ge_union_set( __isl_take isl_union_set *uset1, __isl_take isl_union_set *uset2); +__isl_give isl_union_set *isl_union_set_read_from_str(struct isl_ctx *ctx, + const char *str); __isl_give isl_printer *isl_printer_print_union_set(__isl_take isl_printer *p, __isl_keep isl_union_set *uset); diff --git a/isl_input.c b/isl_input.c index 84cde79c..9c9c2988 100644 --- a/isl_input.c +++ b/isl_input.c @@ -1819,6 +1819,49 @@ error: return NULL; } +__isl_give isl_union_map *isl_stream_read_union_map(struct isl_stream *s) +{ + struct isl_obj obj; + isl_union_map *umap; + + obj = obj_read(s, -1); + if (obj.type == isl_obj_map) { + obj.type = isl_obj_union_map; + obj.v = isl_union_map_from_map(obj.v); + } + if (obj.type == isl_obj_set) { + obj.type = isl_obj_union_set; + obj.v = isl_union_set_from_set(obj.v); + } + if (obj.v) + isl_assert(s->ctx, obj.type == isl_obj_union_map || + obj.type == isl_obj_union_set, goto error); + + return obj.v; +error: + obj.type->free(obj.v); + return NULL; +} + +__isl_give isl_union_set *isl_stream_read_union_set(struct isl_stream *s) +{ + struct isl_obj obj; + isl_union_set *uset; + + obj = obj_read(s, -1); + if (obj.type == isl_obj_set) { + obj.type = isl_obj_union_set; + obj.v = isl_union_set_from_set(obj.v); + } + if (obj.v) + isl_assert(s->ctx, obj.type == isl_obj_union_set, goto error); + + return obj.v; +error: + obj.type->free(obj.v); + return NULL; +} + static struct isl_basic_map *basic_map_read(struct isl_stream *s, int nparam) { struct isl_obj obj; @@ -1949,6 +1992,30 @@ error: return NULL; } +__isl_give isl_union_map *isl_union_map_read_from_str(struct isl_ctx *ctx, + const char *str) +{ + isl_union_map *umap; + struct isl_stream *s = isl_stream_new_str(ctx, str); + if (!s) + return NULL; + umap = isl_stream_read_union_map(s); + isl_stream_free(s); + return umap; +} + +__isl_give isl_union_set *isl_union_set_read_from_str(struct isl_ctx *ctx, + const char *str) +{ + isl_union_set *uset; + struct isl_stream *s = isl_stream_new_str(ctx, str); + if (!s) + return NULL; + uset = isl_stream_read_union_set(s); + isl_stream_free(s); + return uset; +} + static char *next_line(FILE *input, char *line, unsigned len) { char *p; diff --git a/isl_test.c b/isl_test.c index 1765919d..793248b6 100644 --- a/isl_test.c +++ b/isl_test.c @@ -1504,9 +1504,9 @@ void test_union(isl_ctx *ctx) isl_union_map *umap1, *umap2; str = "{ [i] : 0 <= i <= 1 }"; - uset = isl_union_set_from_set(isl_set_read_from_str(ctx, str, -1)); + uset = isl_union_set_read_from_str(ctx, str); str = "{ [1] -> [0] }"; - umap1 = isl_union_map_from_map(isl_map_read_from_str(ctx, str, -1)); + umap1 = isl_union_map_read_from_str(ctx, str); umap2 = isl_union_set_lex_gt_union_set(isl_union_set_copy(uset), uset); assert(isl_union_map_is_equal(umap1, umap2)); -- 2.11.4.GIT