functions.c
// Read a value from va_list. This could be either directly from the stack or from
// an lvalue in a register.
Read a value from va_list. This could be either directly from the stack or from
an lvalue in a register.
Read a value from va_list . This could be either directly from the stack or from an lvalue in a register .
static Tac *read_from_va_list(Function *function, Tac *ir, Value *va_list, Type *src_type, Type *dst_type, int offset, Value **result) {
    *result = new_value();
    (*result)->type = dst_type;
    (*result)->vreg = ++function->vreg_count;
    Value *src1 = dup_value(va_list);
    src1->type = src_type;
    if (src1->vreg) {
        Value *tmp = dup_value(va_list);
        tmp->type = make_pointer(dst_type);
        tmp->vreg = ++function->vreg_count;
        ir = insert_instruction_after_from_operation(ir, IR_MOVE, tmp, va_list, 0);
        src1->type = make_pointer(dst_type);
        src1->offset = offset;
        ir = insert_instruction_after_from_operation(ir, IR_INDIRECT, *result, src1, 0);
    }
    else {
        src1->offset = offset;
        ir = insert_instruction_after_from_operation(ir, IR_MOVE, *result, src1, 0);
    }
    return ir;
}
static Tac * read_from_va_list ( Function * function , Tac * ir , Value * va_list , Type * src_type , Type * dst_type , int offset , Value * * result ) { * result = new_value ( ) ; ( * result ) -> type = dst_type ; ( * result ) -> vreg = ++ function -> vreg_count ; Value * src1 = dup_value ( va_list ) ; src1 -> type = src_type ; if ( src1 -> vreg ) { Value * tmp = dup_value ( va_list ) ; tmp -> type = make_pointer ( dst_type ) ; tmp -> vreg = ++ function -> vreg_count ; ir = insert_instruction_after_from_operation ( ir , IR_MOVE , tmp , va_list , 0 ) ; src1 -> type = make_pointer ( dst_type ) ; src1 -> offset = offset ; ir = insert_instruction_after_from_operation ( ir , IR_INDIRECT , * result , src1 , 0 ) ; } else { src1 -> offset = offset ; ir = insert_instruction_after_from_operation ( ir , IR_MOVE , * result , src1 , 0 ) ; } return ir ; }
Read a value from va_list.
Read a value from va_list .
// va_list is a pointer in a register. Load it, add the offset to it, then // indirect. // Read from the stack