Пример #1
0
instruction_list * isl_user_to_noclock (isl_ast_node * user_node)
{
    isl_ast_expr * expr = isl_ast_node_user_get_expr (user_node);

    instruction * user = instruction_alloc ();
    user->type = INSTR_CALL;
    user->content.call.identifier = strdup (isl_id_get_name (
                isl_ast_expr_get_id (isl_ast_expr_get_op_arg (expr, 0))));

    for (int i = 1; i < isl_ast_expr_get_op_n_arg (expr); ++i)
    {
        expression_list * e = expression_list_alloc ();
        e->element = isl_expr_to_noclock_expr (isl_ast_expr_get_op_arg (expr, i));
        e->next = NULL;
        user->content.call.arguments = expression_list_cat (
                user->content.call.arguments, e);
    }

    instruction_list * list = instruction_list_alloc ();
    list->element = user;
    list->next = NULL;

    return list;
}
Пример #2
0
expression_ptr cpp_from_isl::process_op(isl_ast_expr * ast_op)
{
    int arg_count = isl_ast_expr_get_op_n_arg(ast_op);
    vector<expression_ptr> args;
    args.reserve(arg_count);
    for(int i = 0; i < arg_count; ++i)
    {
        auto ast_arg = isl_ast_expr_get_op_arg(ast_op, i);
        auto arg = process_expr(ast_arg);
        isl_ast_expr_free(ast_arg);
        args.push_back(arg);
    }

    expression_ptr expr;

    auto type = isl_ast_expr_get_op_type(ast_op);

    switch(type)
    {
    case isl_ast_op_and:
        expr = binop(op::logic_and, args[0], args[1]);
        break;
    case isl_ast_op_or:
        expr = binop(op::logic_or, args[0], args[1]);
        break;
    case isl_ast_op_max:
        expr = make_shared<call_expression>("max", args[0], args[1]);
        break;
    case isl_ast_op_min:
        expr = make_shared<call_expression>("min", args[0], args[1]);
        break;
    case isl_ast_op_minus:
        expr = unop(op::u_minus, args[0]);
        break;
    case isl_ast_op_add:
        expr = binop(op::add, args[0], args[1]);
        break;
    case isl_ast_op_sub:
        expr = binop(op::sub, args[0], args[1]);
        break;
    case isl_ast_op_mul:
        expr = binop(op::mult, args[0], args[1]);
        break;
    case isl_ast_op_div:
        expr = binop(op::div, args[0], args[1]);
        break;
    case isl_ast_op_eq:
        expr = binop(op::equal, args[0], args[1]);
        break;
    case isl_ast_op_le:
        expr = binop(op::lesser_or_equal, args[0], args[1]);
        break;
    case isl_ast_op_lt:
        expr = binop(op::lesser, args[0], args[1]);
        break;
    case isl_ast_op_ge:
        expr = binop(op::greater_or_equal, args[0], args[1]);
        break;
    case isl_ast_op_gt:
        expr = binop(op::greater, args[0], args[1]);
        break;
    case isl_ast_op_call:
    {
        auto id = dynamic_pointer_cast<id_expression>(args[0]);
        if (!id)
            throw error("Function identifier expression is not an identifier.");

        vector<expression_ptr> func_args(++args.begin(), args.end());

        if (m_is_user_stmt && m_stmt_func)
            m_stmt_func(id->name, func_args, m_ctx);
        else
            expr = make_shared<call_expression>(id->name, func_args);

        break;
    }
    case isl_ast_op_zdiv_r:
    {
        // "Equal to zero iff the remainder on integer division is zero."
        expr = binop(op::rem, args[0], args[1]);
        break;
    }
    case isl_ast_op_pdiv_r:
    {
        //Remainder of integer division, where dividend is known to be non-negative.
        expr = binop(op::rem, args[0], args[1]);
        break;
    }
    case isl_ast_op_pdiv_q:
    {
        // Result of integer division, where dividend is known to be non-negative.
        expr = binop(op::div, args[0], args[1]);
        break;
    }
    case isl_ast_op_or_else:
        // not implemented
    case isl_ast_op_and_then:
        // not implemented
    case isl_ast_op_fdiv_q:
        // Not implemented
        // Result of integer division, rounded towards negative infinity.
    case isl_ast_op_cond:
        // Not implemented.
    case isl_ast_op_select:
        // Not implemented.
    case isl_ast_op_access:
        // Not implemented
    case isl_ast_op_member:
        // Not implemented
    default:
        throw error("Unsupported AST expression type.");
    }

    return expr;
}