From 8eb72d6a2b1ba6f8789b482a38506e22ff446e88 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Fri, 11 Aug 2017 13:42:59 +0200 Subject: [PATCH] add exported isl_*_list_read_from_str The Python bindings print objects as a call of the constructor with a string argument. However, this constructor is only created when a corresponding isl_*_read_from_str function is available, but this was missing, in particular, for all exported isl_*_list types. Add such a function for the exported lists of types for which a parser is available. In particular, no such function is added for ast_node_list. Signed-off-by: Sven Verdoolaege --- Makefile.am | 1 + doc/user.pod | 33 ++++++++++++++++++++++++++ include/isl/aff.h | 4 ++++ include/isl/id.h | 1 + include/isl/list.h | 8 +++++++ include/isl/union_set.h | 1 + include/isl/val.h | 1 + isl_aff.c | 4 ++++ isl_id.c | 1 + isl_list_read_templ.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ isl_set_list.c | 1 + isl_val.c | 1 + 12 files changed, 119 insertions(+) create mode 100644 isl_list_read_templ.c diff --git a/Makefile.am b/Makefile.am index c9f7507d..d403e26d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -512,6 +512,7 @@ EXTRA_DIST = \ isl_list_macro.h \ isl_list_templ.c \ isl_list_templ.h \ + isl_list_read_templ.c \ isl_map_bound_templ.c \ isl_map_lexopt_templ.c \ isl_maybe_ast_graft_list.h \ diff --git a/doc/user.pod b/doc/user.pod index 9dc6e10a..382d263d 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -9408,6 +9408,39 @@ in isl format. __isl_give char *isl_set_list_to_str( __isl_keep isl_set_list *list); +An C, C, +C, C, C, +C or +C object +can also be read from input using the following functions. + + #include + __isl_give isl_val_list *isl_val_list_read_from_str( + isl_ctx *ctx, const char *str); + + #include + __isl_give isl_id_list *isl_id_list_read_from_str( + isl_ctx *ctx, const char *str); + + #include + __isl_give isl_aff_list * + isl_aff_list_read_from_str(isl_ctx *ctx, + const char *str); + __isl_give isl_pw_aff_list * + isl_pw_aff_list_read_from_str(isl_ctx *ctx, + const char *str); + __isl_give isl_pw_multi_aff_list * + isl_pw_multi_aff_list_read_from_str(isl_ctx *ctx, + const char *str); + __isl_give isl_union_pw_aff_list * + isl_union_pw_aff_list_read_from_str(isl_ctx *ctx, + const char *str); + + #include + __isl_give isl_union_set_list * + isl_union_set_list_read_from_str(isl_ctx *ctx, + const char *str); + =head2 Associative arrays Associative arrays map isl objects of a specific type to isl objects diff --git a/include/isl/aff.h b/include/isl/aff.h index e55479ea..e3921bc5 100644 --- a/include/isl/aff.h +++ b/include/isl/aff.h @@ -1458,9 +1458,13 @@ __isl_give isl_printer *isl_printer_print_multi_union_pw_aff( void isl_multi_union_pw_aff_dump(__isl_keep isl_multi_union_pw_aff *mupa); ISL_DECLARE_EXPORTED_LIST_FN(aff) +ISL_DECLARE_EXPORTED_LIST_FN_READ(aff) ISL_DECLARE_EXPORTED_LIST_FN(pw_aff) +ISL_DECLARE_EXPORTED_LIST_FN_READ(pw_aff) ISL_DECLARE_EXPORTED_LIST_FN(pw_multi_aff) +ISL_DECLARE_EXPORTED_LIST_FN_READ(pw_multi_aff) ISL_DECLARE_EXPORTED_LIST_FN(union_pw_aff) +ISL_DECLARE_EXPORTED_LIST_FN_READ(union_pw_aff) ISL_DECLARE_LIST_FN(union_pw_multi_aff) #if defined(__cplusplus) diff --git a/include/isl/id.h b/include/isl/id.h index 956b962e..3e71cb00 100644 --- a/include/isl/id.h +++ b/include/isl/id.h @@ -13,6 +13,7 @@ extern "C" { #endif ISL_DECLARE_EXPORTED_LIST_FN(id) +ISL_DECLARE_EXPORTED_LIST_FN_READ(id) ISL_DECLARE_MULTI(id) diff --git a/include/isl/list.h b/include/isl/list.h index 99c68069..3d8dabed 100644 --- a/include/isl/list.h +++ b/include/isl/list.h @@ -104,6 +104,14 @@ void isl_##EL##_list_dump(__isl_keep isl_##EL##_list *list); ISL_DECLARE_LIST_FN3(EL,,) #define ISL_DECLARE_EXPORTED_LIST_FN(EL) \ ISL_DECLARE_LIST_FN3(EL,__isl_constructor,__isl_export) +#define ISL_DECLARE_LIST_FN_READ2(EL,CONSTRUCTOR) \ +CONSTRUCTOR \ +__isl_give isl_##EL##_list *isl_##EL##_list_read_from_str( \ + isl_ctx *ctx, const char *str); +#define ISL_DECLARE_LIST_FN_READ(EL) \ + ISL_DECLARE_LIST_FN_READ2(EL,) +#define ISL_DECLARE_EXPORTED_LIST_FN_READ(EL) \ + ISL_DECLARE_LIST_FN_READ2(EL,__isl_constructor) #define ISL_DECLARE_LIST(EL) \ ISL_DECLARE_LIST_TYPE(EL) \ diff --git a/include/isl/union_set.h b/include/isl/union_set.h index 61725db6..35ae11c9 100644 --- a/include/isl/union_set.h +++ b/include/isl/union_set.h @@ -186,6 +186,7 @@ __isl_give isl_printer *isl_printer_print_union_set(__isl_take isl_printer *p, void isl_union_set_dump(__isl_keep isl_union_set *uset); ISL_DECLARE_EXPORTED_LIST_FN(union_set) +ISL_DECLARE_EXPORTED_LIST_FN_READ(union_set) __isl_give isl_union_set *isl_union_set_list_union( __isl_take isl_union_set_list *list); diff --git a/include/isl/val.h b/include/isl/val.h index f09252c4..942207db 100644 --- a/include/isl/val.h +++ b/include/isl/val.h @@ -170,6 +170,7 @@ void isl_multi_val_dump(__isl_keep isl_multi_val *mv); __isl_give char *isl_multi_val_to_str(__isl_keep isl_multi_val *mv); ISL_DECLARE_EXPORTED_LIST_FN(val) +ISL_DECLARE_EXPORTED_LIST_FN_READ(val) #if defined(__cplusplus) } diff --git a/isl_aff.c b/isl_aff.c index 0dc81fcb..40ca78de 100644 --- a/isl_aff.c +++ b/isl_aff.c @@ -38,21 +38,25 @@ #define EL_BASE aff #include +#include #undef EL_BASE #define EL_BASE pw_aff #include +#include #undef EL_BASE #define EL_BASE pw_multi_aff #include +#include #undef EL_BASE #define EL_BASE union_pw_aff #include +#include #undef EL_BASE #define EL_BASE union_pw_multi_aff diff --git a/isl_id.c b/isl_id.c index 982d9ebb..ab0f75b3 100644 --- a/isl_id.c +++ b/isl_id.c @@ -15,6 +15,7 @@ #define EL_BASE id #include +#include /* A special, static isl_id to use as domains (and ranges) * of sets and parameters domains. diff --git a/isl_list_read_templ.c b/isl_list_read_templ.c new file mode 100644 index 00000000..25b3478c --- /dev/null +++ b/isl_list_read_templ.c @@ -0,0 +1,63 @@ +/* + * Copyright 2017 Sven Verdoolaege + * + * Use of this software is governed by the MIT license + * + * Written by Sven Verdoolaege. + */ + +#include + +#include + +/* Read a list of elements of type EL from "s". + * The input format corresponds to the way lists are printed + * by isl_printer_print_list_*. + * In particular, the elements are separated by a comma and + * the entire list is surrounded by parentheses. + */ +static __isl_give LIST(EL) *FN(isl_stream_read,LIST(EL_BASE))(isl_stream *s) +{ + isl_ctx *ctx; + LIST(EL) *list; + + if (!s) + return NULL; + ctx = isl_stream_get_ctx(s); + list = FN(LIST(EL),alloc)(ctx, 0); + if (!list) + return NULL; + if (isl_stream_eat(s, '(') < 0) + return FN(LIST(EL),free)(list); + do { + EL *el; + + el = FN(isl_stream_read,EL_BASE)(s); + list = FN(LIST(EL),add)(list, el); + if (!list) + return NULL; + } while (isl_stream_eat_if_available(s, ',')); + if (isl_stream_eat(s, ')') < 0) + return FN(LIST(EL),free)(list); + return list; +} + +/* Read a list of elements of type EL from the string "str". + * The input format corresponds to the way lists are printed + * by isl_printer_print_list_*. + * In particular, the elements are separated by a comma and + * the entire list is surrounded by parentheses. + */ +__isl_give LIST(EL) *FN(LIST(EL),read_from_str)(isl_ctx *ctx, + const char *str) +{ + LIST(EL) *list; + isl_stream *s; + + s = isl_stream_new_str(ctx, str); + if (!s) + return NULL; + list = FN(isl_stream_read,LIST(EL_BASE))(s); + isl_stream_free(s); + return list; +} diff --git a/isl_set_list.c b/isl_set_list.c index 2a6749aa..e505552e 100644 --- a/isl_set_list.c +++ b/isl_set_list.c @@ -30,3 +30,4 @@ #define EL_BASE union_set #include +#include diff --git a/isl_val.c b/isl_val.c index dc6f7149..3744aa74 100644 --- a/isl_val.c +++ b/isl_val.c @@ -15,6 +15,7 @@ #define EL_BASE val #include +#include /* Allocate an isl_val object with indeterminate value. */ -- 2.11.4.GIT