ir.c
// The parser allocates a local_index for temporaries and local variables. Allocate
// vregs for them unless any of them is used with an & operator, or are long doubles, in
// which case, they must be on the stack.
// Function parameters aren't touched in this function
The parser allocates a local_index for temporaries and local variables. Allocate
vregs for them unless any of them is used with an & operator, or are long doubles, in
which case, they must be on the stack.
Function parameters aren't touched in this function
The parser allocates a local_index for temporaries and local variables . Allocate vregs for them unless any of them is used with an & operator or are long doubles in which case they must be on the stack . Function parameters aren ' t touched in this function
void allocate_value_vregs(Function *function) {
    char *on_stack = malloc(sizeof(char) * (function->local_symbol_count + 1));
    memset(on_stack, 0, sizeof(char) * (function->local_symbol_count + 1));
    for (Tac *tac = function->ir; tac; tac = tac->next) {
        if (tac->operation == IR_ADDRESS_OF && tac->src1->local_index < 0) on_stack[-tac->src1->local_index] = 1;
        if (tac->dst  && tac->dst ->type && tac->dst ->local_index < 0) set_on_stack(tac->dst,  on_stack);
        if (tac->src1 && tac->src1->type && tac->src1->local_index < 0) set_on_stack(tac->src1, on_stack);
        if (tac->src2 && tac->src2->type && tac->src2->local_index < 0) set_on_stack(tac->src2, on_stack);
    }
    for (int i = 1; i <= function->local_symbol_count; i++) {
        if (on_stack[i]) continue;
        int vreg = ++function->vreg_count;
        for (Tac *tac = function->ir; tac; tac = tac->next) {
            if (tac->dst  && tac->dst ->local_index == -i) assign_local_to_register(tac->dst , vreg);
            if (tac->src1 && tac->src1->local_index == -i) assign_local_to_register(tac->src1, vreg);
            if (tac->src2 && tac->src2->local_index == -i) assign_local_to_register(tac->src2, vreg);
        }
    }
    free(on_stack);
}
void allocate_value_vregs ( Function * function ) { char * on_stack = malloc ( sizeof ( char ) * ( function -> local_symbol_count + 1 ) ) ; memset ( on_stack , 0 , sizeof ( char ) * ( function -> local_symbol_count + 1 ) ) ; for ( Tac * tac = function -> ir ; tac ; tac = tac -> next ) { if ( tac -> operation == IR_ADDRESS_OF && tac -> src1 -> local_index < 0 ) on_stack [ - tac -> src1 -> local_index ] = 1 ; if ( tac -> dst && tac -> dst -> type && tac -> dst -> local_index < 0 ) set_on_stack ( tac -> dst , on_stack ) ; if ( tac -> src1 && tac -> src1 -> type && tac -> src1 -> local_index < 0 ) set_on_stack ( tac -> src1 , on_stack ) ; if ( tac -> src2 && tac -> src2 -> type && tac -> src2 -> local_index < 0 ) set_on_stack ( tac -> src2 , on_stack ) ; } for ( int i = 1 ; i <= function -> local_symbol_count ; i ++ ) { if ( on_stack [ i ] ) continue ; int vreg = ++ function -> vreg_count ; for ( Tac * tac = function -> ir ; tac ; tac = tac -> next ) { if ( tac -> dst && tac -> dst -> local_index == - i ) assign_local_to_register ( tac -> dst , vreg ) ; if ( tac -> src1 && tac -> src1 -> local_index == - i ) assign_local_to_register ( tac -> src1 , vreg ) ; if ( tac -> src2 && tac -> src2 -> local_index == - i ) assign_local_to_register ( tac -> src2 , vreg ) ; } } free ( on_stack ) ; }
The parser allocates a local_index for temporaries and local variables.
The parser allocates a local_index for temporaries and local variables .
// Keep variables that are used with the & operator on the stack // Keep long doubles, struct/unions and arrays on the stack