#include <isl_ast_private.h>
-#include <isl_list_private.h>
+#include <isl/val_int.h>
#undef BASE
#define BASE ast_expr
ctx = isl_ast_expr_get_ctx(expr);
switch (expr->type) {
case isl_ast_expr_int:
- dup = isl_ast_expr_alloc_int(ctx, expr->u.i);
+ dup = isl_ast_expr_from_val(isl_val_copy(expr->u.v));
break;
case isl_ast_expr_id:
dup = isl_ast_expr_from_id(isl_id_copy(expr->u.id));
switch (expr->type) {
case isl_ast_expr_int:
- isl_int_clear(expr->u.i);
+ isl_val_free(expr->u.v);
break;
case isl_ast_expr_id:
isl_id_free(expr->u.id);
if (expr->type != isl_ast_expr_int)
isl_die(isl_ast_expr_get_ctx(expr), isl_error_invalid,
"expression not an int", return -1);
- isl_int_set(*v, expr->u.i);
- return 0;
+ return isl_val_get_num_isl_int(expr->u.v, v);
+}
+
+/* Return the integer value represented by "expr".
+ */
+__isl_give isl_val *isl_ast_expr_get_val(__isl_keep isl_ast_expr *expr)
+{
+ if (!expr)
+ return NULL;
+ if (expr->type != isl_ast_expr_int)
+ isl_die(isl_ast_expr_get_ctx(expr), isl_error_invalid,
+ "expression not an int", return NULL);
+ return isl_val_copy(expr->u.v);
}
__isl_give isl_id *isl_ast_expr_get_id(__isl_keep isl_ast_expr *expr)
isl_ctx_ref(ctx);
expr->ref = 1;
expr->type = isl_ast_expr_int;
-
- isl_int_init(expr->u.i);
- isl_int_set_si(expr->u.i, i);
+ expr->u.v = isl_val_int_from_si(ctx, i);
+ if (!expr->u.v)
+ return isl_ast_expr_free(expr);
return expr;
}
-/* Create a new integer expression representing "i".
+/* Create a new integer expression representing "v".
*/
-__isl_give isl_ast_expr *isl_ast_expr_alloc_int(isl_ctx *ctx, isl_int i)
+__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 NULL;
+ 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, i);
+ expr->u.v = v;
return expr;
}
p = isl_printer_print_str(p, isl_id_get_name(expr->u.id));
break;
case isl_ast_expr_int:
- p = isl_printer_print_isl_int(p, expr->u.i);
+ p = isl_printer_print_val(p, expr->u.v);
break;
case isl_ast_expr_error:
break;
static __isl_give isl_printer *print_ast_node_c(__isl_take isl_printer *p,
__isl_keep isl_ast_node *node,
- __isl_keep isl_ast_print_options *options, int in_block);
+ __isl_keep isl_ast_print_options *options, int in_block, int in_list);
static __isl_give isl_printer *print_if_c(__isl_take isl_printer *p,
__isl_keep isl_ast_node *node,
__isl_keep isl_ast_print_options *options, int new_line);
p = isl_printer_print_str(p, " {");
p = isl_printer_end_line(p);
p = isl_printer_indent(p, 2);
- p = print_ast_node_c(p, node, options, 1);
+ p = print_ast_node_c(p, node, options, 1, 0);
p = isl_printer_indent(p, -2);
p = isl_printer_start_line(p);
p = isl_printer_print_str(p, "}");
* body
*
* "in_block" is set if we are currently inside a block.
- * We simply pass it along to print_ast_node_c in case of a degenerate
- * for loop.
+ * "in_list" is set if the current node is not alone in the block.
+ * If we are not in a block or if the current not is not alone in the block
+ * then we print a block around a degenerate for loop such that the variable
+ * declaration will not conflict with any potential other declaration
+ * of the same variable.
*/
static __isl_give isl_printer *print_for_c(__isl_take isl_printer *p,
__isl_keep isl_ast_node *node,
- __isl_keep isl_ast_print_options *options, int in_block)
+ __isl_keep isl_ast_print_options *options, int in_block, int in_list)
{
isl_id *id;
const char *name;
id = isl_ast_expr_get_id(node->u.f.iterator);
name = isl_id_get_name(id);
isl_id_free(id);
+ if (!in_block || in_list)
+ p = start_block(p);
p = isl_printer_start_line(p);
p = isl_printer_print_str(p, type);
p = isl_printer_print_str(p, " ");
p = isl_printer_print_ast_expr(p, node->u.f.init);
p = isl_printer_print_str(p, ";");
p = isl_printer_end_line(p);
- p = print_ast_node_c(p, node->u.f.body, options, in_block);
+ p = print_ast_node_c(p, node->u.f.body, options, 1, 0);
+ if (!in_block || in_list)
+ p = end_block(p);
}
return p;
* If so, we do not print a block around the children of a block node.
* We do this to avoid an extra block around the body of a degenerate
* for node.
+ *
+ * "in_list" is set if the current node is not alone in the block.
*/
static __isl_give isl_printer *print_ast_node_c(__isl_take isl_printer *p,
__isl_keep isl_ast_node *node,
- __isl_keep isl_ast_print_options *options, int in_block)
+ __isl_keep isl_ast_print_options *options, int in_block, int in_list)
{
switch (node->type) {
case isl_ast_node_for:
return options->print_for(p,
isl_ast_print_options_copy(options),
node, options->print_for_user);
- p = print_for_c(p, node, options, in_block);
+ p = print_for_c(p, node, options, in_block, in_list);
break;
case isl_ast_node_if:
p = print_if_c(p, node, options, 1);
if (node->type != isl_ast_node_for)
isl_die(isl_ast_node_get_ctx(node), isl_error_invalid,
"not a for node", goto error);
- p = print_for_c(p, node, options, 0);
+ p = print_for_c(p, node, options, 0, 0);
isl_ast_print_options_free(options);
return p;
error:
{
if (!options || !node)
goto error;
- p = print_ast_node_c(p, node, options, 0);
+ p = print_ast_node_c(p, node, options, 0, 0);
isl_ast_print_options_free(options);
return p;
error:
return isl_printer_free(p);
for (i = 0; i < list->n; ++i)
- p = print_ast_node_c(p, list->p[i], options, 1);
+ p = print_ast_node_c(p, list->p[i], options, 1, 1);
return p;
}