functions.c
// Add instructions to copy a struct to the stack
Add instructions to copy a struct to the stack
Add instructions to copy a struct to the stack
static void add_function_call_arg_move_for_struct_or_union_on_stack(Function *function, Tac *ir) {
    int size = get_type_size(ir->src2->type);
    int rounded_up_size = (size + 7) & ~7;
    insert_instruction_from_operation(ir, IR_ALLOCATE_STACK, 0, new_integral_constant(TYPE_LONG, rounded_up_size), 0, 1);
    Value *stack_pointer_temp = make_long_temp(function);
    insert_instruction_from_operation(ir, IR_MOVE_STACK_PTR, stack_pointer_temp, 0, 0, 1);
    Value *dst = dup_value(stack_pointer_temp);
    dst->type = make_pointer_to_void();
    dst->is_lvalue = 1;
    Value *src = dup_value(ir->src2);
    src->type = make_pointer_to_void();
    if (debug_function_arg_mapping)
        printf("Adding memory copy for struct/union SI=%d rounded-up-size=%d\n", src->stack_index, rounded_up_size);
    add_memory_copy(function, ir, dst, src, size);
}
static void add_function_call_arg_move_for_struct_or_union_on_stack ( Function * function , Tac * ir ) { int size = get_type_size ( ir -> src2 -> type ) ; int rounded_up_size = ( size + 7 ) & ~ 7 ; insert_instruction_from_operation ( ir , IR_ALLOCATE_STACK , 0 , new_integral_constant ( TYPE_LONG , rounded_up_size ) , 0 , 1 ) ; Value * stack_pointer_temp = make_long_temp ( function ) ; insert_instruction_from_operation ( ir , IR_MOVE_STACK_PTR , stack_pointer_temp , 0 , 0 , 1 ) ; Value * dst = dup_value ( stack_pointer_temp ) ; dst -> type = make_pointer_to_void ( ) ; dst -> is_lvalue = 1 ; Value * src = dup_value ( ir -> src2 ) ; src -> type = make_pointer_to_void ( ) ; if ( debug_function_arg_mapping ) printf ( " \n " , src -> stack_index , rounded_up_size ) ; add_memory_copy ( function , ir , dst , src , size ) ; }
Add instructions to copy a struct to the stack
Add instructions to copy a struct to the stack
// Allocate stack space with a sub $n, %rsp instruction // Add an instruction to move the stack pointer %rsp to a temporary register // Prepare destination, which must be a * void // Convert src to be a pointer to void