functions.c
// Using the state of already allocated registers & stack entries in fpa, determine the location for a type and set it in fpl.
Using the state of already allocated registers & stack entries in fpa, determine the location for a type and set it in fpl.
Using the state of already allocated registers & stack entries in fpa determine the location for a type and set it in fpl .
static void add_type_to_allocation(FunctionParamAllocation *fpa, FunctionParamLocation *fpl, Type *type, int force_stack) {
    fpl->int_register = -1;
    fpl->sse_register = -1;
    fpl->stack_offset = -1;
    fpl->stack_padding = -1;
    if (type->type == TYPE_ARRAY) type = decay_array_to_pointer(type);
    if (type->type == TYPE_ENUM) type = new_type(TYPE_INT);
    int is_single_int_register = type_fits_in_single_int_register(type);
    int is_single_sse_register = is_sse_floating_point_type(type);
    int is_long_double = type->type == TYPE_LONG_DOUBLE;
    int in_stack =
        is_long_double ||
        force_stack ||
        (is_single_int_register && fpa->single_int_register_arg_count >= 6) || (is_single_sse_register && fpa->single_sse_register_arg_count >= 8);
    int alignment = get_type_alignment(type);
    if (alignment < 8) alignment = 8;
    if (!in_stack && is_single_int_register)
        fpl->int_register = fpa->single_int_register_arg_count < 6 ? fpa->single_int_register_arg_count : -1;
    else if (!in_stack && is_single_sse_register)
        fpl->sse_register = fpa->single_sse_register_arg_count < 8 ? fpa->single_sse_register_arg_count : -1;
    else {
        if (alignment > fpa->biggest_alignment) fpa->biggest_alignment = alignment;
        int padding = ((fpa->offset + alignment  - 1) & (~(alignment - 1))) - fpa->offset;
        fpa->offset += padding;
        fpl->stack_offset = fpa->offset;
        fpl->stack_padding = padding;
        int type_size = get_type_size(type);
        if (type_size < 8) type_size = 8;
        fpa->offset += type_size;
        if (debug_function_param_allocation)
            printf("  arg %2d with alignment %2d     offset 0x%04x with padding 0x%04x\n", fpa->arg_count, alignment, fpl->stack_offset, fpl->stack_padding);
    }
    if (debug_function_param_allocation && !in_stack && (is_single_int_register || is_single_sse_register)) {
        if (fpl->int_register != -1)
            printf("  arg %2d with alignment %2d     int reg %5d\n", fpa->arg_count, alignment, fpl->int_register);
        else
            printf("  arg %2d with alignment %2d     sse reg %5d\n", fpa->arg_count, alignment, fpl->sse_register);
    }
    fpa->single_int_register_arg_count += is_single_int_register;
    if (!in_stack && is_single_sse_register) fpa->single_sse_register_arg_count++;
}
static void add_type_to_allocation ( FunctionParamAllocation * fpa , FunctionParamLocation * fpl , Type * type , int force_stack ) { fpl -> int_register = -1 ; fpl -> sse_register = -1 ; fpl -> stack_offset = -1 ; fpl -> stack_padding = -1 ; if ( type -> type == TYPE_ARRAY ) type = decay_array_to_pointer ( type ) ; if ( type -> type == TYPE_ENUM ) type = new_type ( TYPE_INT ) ; int is_single_int_register = type_fits_in_single_int_register ( type ) ; int is_single_sse_register = is_sse_floating_point_type ( type ) ; int is_long_double = type -> type == TYPE_LONG_DOUBLE ; int in_stack = is_long_double || force_stack || ( is_single_int_register && fpa -> single_int_register_arg_count >= 6 ) || ( is_single_sse_register && fpa -> single_sse_register_arg_count >= 8 ) ; int alignment = get_type_alignment ( type ) ; if ( alignment < 8 ) alignment = 8 ; if ( ! in_stack && is_single_int_register ) fpl -> int_register = fpa -> single_int_register_arg_count < 6 ? fpa -> single_int_register_arg_count : -1 ; else if ( ! in_stack && is_single_sse_register ) fpl -> sse_register = fpa -> single_sse_register_arg_count < 8 ? fpa -> single_sse_register_arg_count : -1 ; else { if ( alignment > fpa -> biggest_alignment ) fpa -> biggest_alignment = alignment ; int padding = ( ( fpa -> offset + alignment - 1 ) & ( ~ ( alignment - 1 ) ) ) - fpa -> offset ; fpa -> offset += padding ; fpl -> stack_offset = fpa -> offset ; fpl -> stack_padding = padding ; int type_size = get_type_size ( type ) ; if ( type_size < 8 ) type_size = 8 ; fpa -> offset += type_size ; if ( debug_function_param_allocation ) printf ( " \n " , fpa -> arg_count , alignment , fpl -> stack_offset , fpl -> stack_padding ) ; } if ( debug_function_param_allocation && ! in_stack && ( is_single_int_register || is_single_sse_register ) ) { if ( fpl -> int_register != -1 ) printf ( " \n " , fpa -> arg_count , alignment , fpl -> int_register ) ; else printf ( " \n " , fpa -> arg_count , alignment , fpl -> sse_register ) ; } fpa -> single_int_register_arg_count += is_single_int_register ; if ( ! in_stack && is_single_sse_register ) fpa -> single_sse_register_arg_count ++ ; }
Using the state of already allocated registers & stack entries in fpa, determine the location for a type and set it in fpl.
Using the state of already allocated registers & stack entries in fpa determine the location for a type and set it in fpl .
// It's on the stack