Esempio n. 1
0
/* Insert an if node around "node" testing the condition encoded
 * in guard "guard".
 *
 * If the user does not want any disjunctions in the if conditions
 * and if "guard" does involve a disjunction, then we make the different
 * disjuncts disjoint and insert an if node corresponding to each disjunct
 * around a copy of "node".  The result is then a block node containing
 * this sequence of guarded copies of "node".
 */
static __isl_give isl_ast_node *ast_node_insert_if(
	__isl_take isl_ast_node *node, __isl_take isl_set *guard,
	__isl_keep isl_ast_build *build)
{
	struct isl_insert_if_data data;
	isl_ctx *ctx;

	ctx = isl_ast_build_get_ctx(build);
	if (isl_options_get_ast_build_allow_or(ctx) ||
	    isl_set_n_basic_set(guard) <= 1) {
		isl_ast_node *if_node;
		isl_ast_expr *expr;

		expr = isl_ast_build_expr_from_set_internal(build, guard);

		if_node = isl_ast_node_alloc_if(expr);
		return isl_ast_node_if_set_then(if_node, node);
	}

	guard = isl_set_make_disjoint(guard);

	data.list = isl_ast_node_list_alloc(ctx, 0);
	data.node = node;
	data.build = build;
	if (isl_set_foreach_basic_set(guard, &insert_if, &data) < 0)
		data.list = isl_ast_node_list_free(data.list);

	isl_set_free(guard);
	isl_ast_node_free(data.node);
	return isl_ast_node_alloc_block(data.list);
}
Esempio n. 2
0
void cpp_from_isl::process_block(isl_ast_node *node)
{
    // The generate AST is weird:
    // Blocks have at most 2 statements.
    // If there are more consecutive statements,
    // all but the last are grouped into a nested block,
    // and so on recursively.

    //auto block = make_shared<block_statement>();

    //m_ctx->push(&block->statements);

    auto list = isl_ast_node_block_get_children(node);
    int n_children = isl_ast_node_list_n_ast_node(list);

    for(int i = 0; i < n_children; ++i)
    {
        auto child = isl_ast_node_list_get_ast_node(list, i);
        process_node(child);
        isl_ast_node_free(child);
    }

    isl_ast_node_list_free(list);

    //m_ctx->pop();

    //m_ctx->add(block);
}