tests/unit/test-ssa.c
// Make IR for the test example on page 484 of engineering a compiler
Make IR for the test example on page 484 of engineering a compiler
Make IR for the test example on page 484 of engineering a compiler
Function *make_ir2(int init_four_vars) {
    Function *function;
    Tac *tac;
    function = new_function();
    ir_start = 0;
    i(0, IR_NOP,     0,    0,    0   );
    if (init_four_vars) {
        i(0, IR_MOVE, v(2), c(1), 0);
        i(0, IR_MOVE, v(3), c(1), 0);
        i(0, IR_MOVE, v(4), c(1), 0);
        i(0, IR_MOVE, v(5), c(1), 0);
    }
    i(0, IR_MOVE,    v(1), c(1), 0   );
    i(1, IR_MOVE,    v(2), c(1), 0   );
    i(0, IR_MOVE,    v(4), c(1), 0   );
    i(0, IR_ADD,     0,    v(2), v(4)); 
    i(0, IR_JZ,      0,    v(2), l(5));
    i(0, IR_MOVE,    v(3), c(0), 0   );
    i(0, IR_MOVE,    v(4), c(0), 0   );
    i(0, IR_MOVE,    v(5), c(0), 0   );
    i(3, IR_ADD,     v(6), v(2), v(3));
    i(0, IR_ADD,     v(7), v(4), v(5));
    i(0, IR_ADD,     v(1), v(1), c(1));
    i(0, IR_JZ,      0,    v(1), l(1));
    i(0, IR_RETURN,  0,    0,    0   );
    i(5, IR_MOVE,    v(2), c(0), 0   );
    i(0, IR_MOVE,    v(5), c(0), 0   );
    i(0, IR_ADD,     0,    v(2), v(5)); 
    i(0, IR_JZ,      0,    v(2), l(8));
    i(0, IR_MOVE,    v(5), c(0), 0   );
    i(7, IR_MOVE,    v(3), c(0), 0   );
    i(0, IR_JMP,     0,    l(3), 0   );
    i(8, IR_MOVE,    v(4), c(0), 0   );
    i(0, IR_JMP,     0,    l(7), 0   );
    function->ir = ir_start;
    if (debug_ssa) print_ir(function, 0, 0);
    return function;
}
Function * make_ir2 ( int init_four_vars ) { Function * function ; Tac * tac ; function = new_function ( ) ; ir_start = 0 ; i ( 0 , IR_NOP , 0 , 0 , 0 ) ; if ( init_four_vars ) { i ( 0 , IR_MOVE , v ( 2 ) , c ( 1 ) , 0 ) ; i ( 0 , IR_MOVE , v ( 3 ) , c ( 1 ) , 0 ) ; i ( 0 , IR_MOVE , v ( 4 ) , c ( 1 ) , 0 ) ; i ( 0 , IR_MOVE , v ( 5 ) , c ( 1 ) , 0 ) ; } i ( 0 , IR_MOVE , v ( 1 ) , c ( 1 ) , 0 ) ; i ( 1 , IR_MOVE , v ( 2 ) , c ( 1 ) , 0 ) ; i ( 0 , IR_MOVE , v ( 4 ) , c ( 1 ) , 0 ) ; i ( 0 , IR_ADD , 0 , v ( 2 ) , v ( 4 ) ) ; i ( 0 , IR_JZ , 0 , v ( 2 ) , l ( 5 ) ) ; i ( 0 , IR_MOVE , v ( 3 ) , c ( 0 ) , 0 ) ; i ( 0 , IR_MOVE , v ( 4 ) , c ( 0 ) , 0 ) ; i ( 0 , IR_MOVE , v ( 5 ) , c ( 0 ) , 0 ) ; i ( 3 , IR_ADD , v ( 6 ) , v ( 2 ) , v ( 3 ) ) ; i ( 0 , IR_ADD , v ( 7 ) , v ( 4 ) , v ( 5 ) ) ; i ( 0 , IR_ADD , v ( 1 ) , v ( 1 ) , c ( 1 ) ) ; i ( 0 , IR_JZ , 0 , v ( 1 ) , l ( 1 ) ) ; i ( 0 , IR_RETURN , 0 , 0 , 0 ) ; i ( 5 , IR_MOVE , v ( 2 ) , c ( 0 ) , 0 ) ; i ( 0 , IR_MOVE , v ( 5 ) , c ( 0 ) , 0 ) ; i ( 0 , IR_ADD , 0 , v ( 2 ) , v ( 5 ) ) ; i ( 0 , IR_JZ , 0 , v ( 2 ) , l ( 8 ) ) ; i ( 0 , IR_MOVE , v ( 5 ) , c ( 0 ) , 0 ) ; i ( 7 , IR_MOVE , v ( 3 ) , c ( 0 ) , 0 ) ; i ( 0 , IR_JMP , 0 , l ( 3 ) , 0 ) ; i ( 8 , IR_MOVE , v ( 4 ) , c ( 0 ) , 0 ) ; i ( 0 , IR_JMP , 0 , l ( 7 ) , 0 ) ; function -> ir = ir_start ; if ( debug_ssa ) print_ir ( function , 0 , 0 ) ; return function ; }
Make IR for the test example on page 484 of engineering a compiler
Make IR for the test example on page 484 of engineering a compiler
// var/register // i = 1 // a = 2 // b = 3 // c = 4 // d = 5 // y = 6 // z = 7 // Initialize a, b, c, d // Fake conditional on a and c // Fake conditional on a and d