From 554e4d0ca049892d9c799adedcbd3b27017bd496 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Mon, 14 May 2012 17:30:25 +0200 Subject: [PATCH] isl_printer_print_pw_aff: use isl_ast_expr when printing in C format isl_ast_expr_from_aff tries a bit harder to print a nice result, so we might as well reuse that functionality. Signed-off-by: Sven Verdoolaege --- isl_output.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/isl_output.c b/isl_output.c index 35c7cd36..452a30d3 100644 --- a/isl_output.c +++ b/isl_output.c @@ -24,6 +24,7 @@ #include #include #include +#include static const char *s_to[2] = { " -> ", " \\to " }; static const char *s_and[2] = { " and ", " \\wedge " }; @@ -2211,6 +2212,29 @@ static __isl_give isl_printer *print_aff_c(__isl_take isl_printer *p, return p; } +/* Print the affine expression "aff" in C format to "p". + * The dimension names are taken from "space" + * "set" represents the domain of the affine expression. + */ +static __isl_give isl_printer *print_aff_on_domain_c(__isl_take isl_printer *p, + __isl_keep isl_space *space, __isl_keep isl_aff *aff, + __isl_keep isl_set *set) +{ + isl_set *u; + isl_ast_build *build; + isl_ast_expr *expr; + + u = isl_set_universe(isl_space_copy(space)); + build = isl_ast_build_from_context(u); + build = isl_ast_build_restrict(build, isl_set_copy(set)); + expr = isl_ast_expr_from_aff(isl_aff_copy(aff), build); + p = isl_printer_print_ast_expr(p, expr); + isl_ast_expr_free(expr); + isl_ast_build_free(build); + + return p; +} + /* In the C format, we cannot express that "pwaff" may be undefined * on parts of the domain space. We therefore assume that the expression * will only be evaluated on its definition domain and compute the gist @@ -2243,14 +2267,17 @@ static __isl_give isl_printer *print_pw_aff_c(__isl_take isl_printer *p, isl_set_free(set_i); p = isl_printer_print_str(p, ") ? ("); - p = print_aff_c(p, pwaff->p[i].aff); + p = print_aff_on_domain_c(p, space, + pwaff->p[i].aff, pwaff->p[i].set); p = isl_printer_print_str(p, ") : "); } isl_set_free(domain); - isl_space_free(space); - return print_aff_c(p, pwaff->p[pwaff->n - 1].aff); + p = print_aff_on_domain_c(p, space, pwaff->p[pwaff->n - 1].aff, + pwaff->p[pwaff->n - 1].set); + isl_space_free(space); + return p; error: isl_printer_free(p); return NULL; -- 2.11.4.GIT