Ejemplo n.º 1
0
expression_ptr cpp_from_isl::process_expr(isl_ast_expr * ast_expr)
{
    expression_ptr expr;

    auto type = isl_ast_expr_get_type(ast_expr);

    switch(type)
    {
    case isl_ast_expr_op:
    {
        expr = process_op(ast_expr);
        break;
    }
    case isl_ast_expr_id:
    {
        auto id = isl_ast_expr_get_id(ast_expr);
        string name(isl_id_get_name(id));
        isl_id_free(id);

        if (m_id_func)
            expr = m_id_func(name);
        if (!expr)
            expr = make_shared<id_expression>(name);
        break;
    }
    case isl_ast_expr_int:
    {
        auto val = isl_ast_expr_get_val(ast_expr);
        if (isl_val_is_int(val) != isl_bool_true)
            throw error("Value is not an integer.");
        int ival = isl_val_get_num_si(val);
        isl_val_free(val);
        expr = literal(ival);
        break;
    }
    default:
        throw error("Unexpected AST expression type.");
    }

    return expr;
}
Ejemplo n.º 2
0
expression * isl_expr_to_noclock_expr (isl_ast_expr * expr)
{
    expression * e = NULL;

    enum isl_ast_expr_type expr_t = isl_ast_expr_get_type (expr);

    if (expr_t == isl_ast_expr_id)
    {
        e = expression_from_identifier (isl_id_get_name (
                    isl_ast_expr_get_id (expr)));

        return e;
    }
    else if (expr_t == isl_ast_expr_int)
    {
        e = expression_from_number (
                isl_val_get_num_si (isl_ast_expr_get_val (expr)));

        return e;
    }

    bool binary = false;
    enum isl_ast_op_type t = isl_ast_expr_get_op_type (expr);

    switch (t)
    {
        case isl_ast_op_max:
            e = expression_alloc ();
            expression_set_type (e, EXPR_MAX);
            binary = true;
            break;
        case isl_ast_op_min:
            e = expression_alloc ();
            expression_set_type (e, EXPR_MIN);
            binary = true;
            break;
        case isl_ast_op_minus:
            e = expression_alloc ();
            expression_set_type (e, EXPR_NEG);
            break;
        case isl_ast_op_add:
            e = expression_alloc ();
            expression_set_type (e, EXPR_ADD);
            binary = true;
            break;
        case isl_ast_op_sub:
            e = expression_alloc ();
            expression_set_type (e, EXPR_SUB);
            binary = true;
            break;
        case isl_ast_op_mul:
            e = expression_alloc ();
            expression_set_type (e, EXPR_MULT);
            binary = true;
            break;
        case isl_ast_op_div:
        case isl_ast_op_fdiv_q:
        case isl_ast_op_pdiv_q:
        case isl_ast_op_pdiv_r:
            e = expression_alloc ();
            expression_set_type (e, EXPR_DIV);
            binary = true;
            break;
        case isl_ast_op_member:
        case isl_ast_op_cond:
        case isl_ast_op_select:
            return e;
            break;
        case isl_ast_op_eq:
            e = expression_alloc ();
            expression_set_type (e, EXPR_EQ);
            binary = true;
            break;
        case isl_ast_op_le:
            e = expression_alloc ();
            expression_set_type (e, EXPR_LE);
            binary = true;
            break;
        case isl_ast_op_lt:
            e = expression_alloc ();
            expression_set_type (e, EXPR_LT);
            binary = true;
            break;
        case isl_ast_op_ge:
            e = expression_alloc ();
            expression_set_type (e, EXPR_GE);
            binary = true;
            break;
        case isl_ast_op_gt:
            e = expression_alloc ();
            expression_set_type (e, EXPR_GT);
            binary = true;
            break;
        case isl_ast_op_and:
        case isl_ast_op_and_then:
            e = expression_alloc ();
            expression_set_type (e, EXPR_AND);
            binary = true;
            break;
        case isl_ast_op_or:
        case isl_ast_op_or_else:
            e = expression_alloc ();
            expression_set_type (e, EXPR_OR);
            binary = true;
            break;
        case isl_ast_op_call:
        case isl_ast_op_access:
        case isl_ast_op_address_of:
        default:
            return e;
            break;
    }

    if (binary)
    {
        expression_set_left_operand (e,
                isl_expr_to_noclock_expr (isl_ast_expr_get_op_arg (expr, 0)));
        expression_set_right_operand (e,
                isl_expr_to_noclock_expr (isl_ast_expr_get_op_arg (expr, 1)));
    }
    else
    {
        expression_set_left_operand (e,
                isl_expr_to_noclock_expr (isl_ast_expr_get_op_arg (expr, 0)));
    }

    return e;
}