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_ir3(int loop_count) {
    Function *function;
    Tac *tac;
    function = new_function();
    ir_start = 0;
    i(0, IR_NOP,    0,    0,    0   );
    i(0, IR_MOVE,   v(1), c(1), 0   ); 
    i(0, IR_JZ,     0,    v(1), l(1)); 
    i(0, IR_MOVE,   v(2), c(0), 0   ); 
    i(0, IR_ADD,    0,    v(2), v(2)); 
    i(0, IR_MOVE,   v(4), c(0), 0   ); 
    i(0, IR_JMP,    0 ,   l(2), 0   ); 
    i(1, IR_NOP,    0,    0,    0   );
    if (loop_count > 0) i(0, IR_START_LOOP,  0, c(0), c(1));
    if (loop_count > 1) i(0, IR_START_LOOP,  0, c(1), c(2));
    i(0, IR_MOVE,   v(3), c(0), 0   ); 
    if (loop_count > 1) i(0, IR_END_LOOP,  0, c(1), c(2));
    if (loop_count > 0) i(0, IR_END_LOOP,  0, c(0), c(1));
    i(0, IR_MOVE,   v(4), v(3), 0   ); 
    i(2, IR_NOP,    0,    0,    0   );
    i(0, IR_ADD,    0,    v(1), v(1)); 
    i(0, IR_ADD,    0,    v(4), v(4)); 
    function->ir = ir_start;
    return function;
}
Function * make_ir3 ( int loop_count ) { Function * function ; Tac * tac ; function = new_function ( ) ; ir_start = 0 ; i ( 0 , IR_NOP , 0 , 0 , 0 ) ; i ( 0 , IR_MOVE , v ( 1 ) , c ( 1 ) , 0 ) ; i ( 0 , IR_JZ , 0 , v ( 1 ) , l ( 1 ) ) ; i ( 0 , IR_MOVE , v ( 2 ) , c ( 0 ) , 0 ) ; i ( 0 , IR_ADD , 0 , v ( 2 ) , v ( 2 ) ) ; i ( 0 , IR_MOVE , v ( 4 ) , c ( 0 ) , 0 ) ; i ( 0 , IR_JMP , 0 , l ( 2 ) , 0 ) ; i ( 1 , IR_NOP , 0 , 0 , 0 ) ; if ( loop_count > 0 ) i ( 0 , IR_START_LOOP , 0 , c ( 0 ) , c ( 1 ) ) ; if ( loop_count > 1 ) i ( 0 , IR_START_LOOP , 0 , c ( 1 ) , c ( 2 ) ) ; i ( 0 , IR_MOVE , v ( 3 ) , c ( 0 ) , 0 ) ; if ( loop_count > 1 ) i ( 0 , IR_END_LOOP , 0 , c ( 1 ) , c ( 2 ) ) ; if ( loop_count > 0 ) i ( 0 , IR_END_LOOP , 0 , c ( 0 ) , c ( 1 ) ) ; i ( 0 , IR_MOVE , v ( 4 ) , v ( 3 ) , 0 ) ; i ( 2 , IR_NOP , 0 , 0 , 0 ) ; i ( 0 , IR_ADD , 0 , v ( 1 ) , v ( 1 ) ) ; i ( 0 , IR_ADD , 0 , v ( 4 ) , v ( 4 ) ) ; function -> ir = ir_start ; 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
// a = 0 // jz l1 // b   = 0 // ... = b // d   = 0 // jmp l2 // c   = 0 // d   = c // ... = a // ... = d