add isl_ast_expr_from_val
authorSven Verdoolaege <skimo@kotnet.org>
Tue, 28 May 2013 11:46:57 +0000 (13:46 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Tue, 28 May 2013 18:42:49 +0000 (20:42 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
doc/user.pod
include/isl/ast.h
isl_ast.c

index 3219fd2..9fbff36 100644 (file)
@@ -6044,6 +6044,8 @@ New AST expressions can be created either directly or within
 the context of an C<isl_ast_build>.
 
        #include <isl/ast.h>
+       __isl_give isl_ast_expr *isl_ast_expr_from_val(
+               __isl_take isl_val *v);
        __isl_give isl_ast_expr *isl_ast_expr_from_id(
                __isl_take isl_id *id);
        __isl_give isl_ast_expr *isl_ast_expr_neg(
index 7947acb..615c882 100644 (file)
@@ -67,6 +67,7 @@ ISL_DECLARE_LIST(ast_node)
 int isl_options_set_ast_iterator_type(isl_ctx *ctx, const char *val);
 const char *isl_options_get_ast_iterator_type(isl_ctx *ctx);
 
+__isl_give isl_ast_expr *isl_ast_expr_from_val(__isl_take isl_val *v);
 __isl_give isl_ast_expr *isl_ast_expr_from_id(__isl_take isl_id *id);
 __isl_give isl_ast_expr *isl_ast_expr_neg(__isl_take isl_ast_expr *expr);
 __isl_give isl_ast_expr *isl_ast_expr_add(__isl_take isl_ast_expr *expr1,
index afc4a70..385ea73 100644 (file)
--- a/isl_ast.c
+++ b/isl_ast.c
@@ -419,6 +419,36 @@ __isl_give isl_ast_expr *isl_ast_expr_alloc_int(isl_ctx *ctx, isl_int i)
        return expr;
 }
 
+/* Create a new integer expression representing "v".
+ */
+__isl_give isl_ast_expr *isl_ast_expr_from_val(__isl_take isl_val *v)
+{
+       isl_ctx *ctx;
+       isl_ast_expr *expr;
+
+       if (!v)
+               return NULL;
+       if (!isl_val_is_int(v))
+               isl_die(isl_val_get_ctx(v), isl_error_invalid,
+                       "expecting integer value", return isl_val_free(v));
+
+       ctx = isl_val_get_ctx(v);
+       expr = isl_calloc_type(ctx, isl_ast_expr);
+       if (!expr)
+               return isl_val_free(v);
+
+       expr->ctx = ctx;
+       isl_ctx_ref(ctx);
+       expr->ref = 1;
+       expr->type = isl_ast_expr_int;
+
+       isl_int_init(expr->u.i);
+       isl_int_set(expr->u.i, v->n);
+
+       isl_val_free(v);
+       return expr;
+}
+
 /* Create an expression representing the negation of "arg".
  */
 __isl_give isl_ast_expr *isl_ast_expr_neg(__isl_take isl_ast_expr *arg)