1: 2: // test control flow with IF statements 3: 4: void main ( ) 5: { 6: int a,b,c,x; 7: 8: x = 0; 9: a = 1; 10: b = 2; 11: c = 3; 12: 13: if ( x != 0 ) 14: { 15: a = a + 1; 16: b = 5 - c; 17: } 18: else 19: { 20: a = 6 + b; 21: b = 3 - c; 22: } 23: 24: if ( x < 2 ) 25: { 26: b = 5 + c; 27: } 28: else 29: { 30: a = 6 + b; 31: } 32: 33: x = a+b+c; 34: 35: printStr("Result (should be 19) = "); 36: printInt( x ); 37: printLn(); 38: } ** Global Variables ** printLn, void, function, param = main, void, function, param = printStr, void, function, param = String printInt, void, function, param = int ** Local Variables in main() ** a, int c, int b, int x, int TREE_PROC: main { TREE_INSTR: x = 0 TREE_INSTR: a = 1 TREE_INSTR: b = 2 TREE_INSTR: c = 3 TREE_IF: CONDITION: (x NE_OP 0) { TREE_INSTR: a = (a PLUS 1) TREE_INSTR: b = (5 MINUS c) } ELSE: { TREE_INSTR: a = (6 PLUS b) TREE_INSTR: b = (3 MINUS c) } END_IF TREE_IF: CONDITION: (x LESS 2) { TREE_INSTR: b = (5 PLUS c) } ELSE: { TREE_INSTR: a = (6 PLUS b) } END_IF TREE_INSTR: x = ((a PLUS b) PLUS c) TREE_INSTR: CALL printStr("Result (should be 19) = ") TREE_INSTR: CALL printInt(x) TREE_INSTR: CALL printLn() } END_PROC ** Basic block: 0 ** Length: 1 Successors: 1 Predecessors: GEN {} KILL {} IN {} OUT {} > 0: iconst_0 ** Basic block: 1 ** Length: 1 Successors: 2 Predecessors: 0 GEN {} KILL {4} IN {} OUT {4} > 1: istore 4 ** Basic block: 2 ** Length: 1 Successors: 3 Predecessors: 1 GEN {} KILL {} IN {4} OUT {4} > 3: iconst_1 ** Basic block: 3 ** Length: 1 Successors: 4 Predecessors: 2 GEN {} KILL {1} IN {4} OUT {1, 4} > 4: istore_1 ** Basic block: 4 ** Length: 1 Successors: 5 Predecessors: 3 GEN {} KILL {} IN {1, 4} OUT {1, 4} > 5: iconst_2 ** Basic block: 5 ** Length: 1 Successors: 6 Predecessors: 4 GEN {} KILL {3} IN {1, 4} OUT {1, 3, 4} > 6: istore_3 ** Basic block: 6 ** Length: 1 Successors: 7 Predecessors: 5 GEN {} KILL {} IN {1, 3, 4} OUT {1, 3, 4} > 7: iconst_3 ** Basic block: 7 ** Length: 1 Successors: 8 Predecessors: 6 GEN {} KILL {2} IN {1, 3, 4} OUT {1, 2, 3, 4} > 8: istore_2 ** Basic block: 8 ** Length: 1 Successors: 9 Predecessors: 7 GEN {4} KILL {} IN {1, 2, 3, 4} OUT {1, 2, 3, 4} > 9: iload 4 ** Basic block: 9 ** Length: 1 Successors: 10 Predecessors: 8 GEN {} KILL {} IN {1, 2, 3, 4} OUT {1, 2, 3, 4} > 11: iconst_0 ** Basic block: 10 ** Length: 1 Successors: 11 13 Predecessors: 9 GEN {} KILL {} IN {1, 2, 3, 4} OUT {1, 2, 3, 4} > 12: if_icmpne -> 20 ** Basic block: 11 ** Length: 1 Successors: 12 Predecessors: 10 GEN {} KILL {} IN {1, 2, 3, 4} OUT {1, 2, 3, 4} > 15: iconst_0 ** Basic block: 12 ** Length: 1 Successors: 14 Predecessors: 11 GEN {} KILL {} IN {1, 2, 3, 4} OUT {1, 2, 3, 4} > 16: goto -> 22 ** Basic block: 13 ** Length: 1 Successors: 14 Predecessors: 10 GEN {} KILL {} IN {1, 2, 3, 4} OUT {1, 2, 3, 4} > 20: iconst_1 ** Basic block: 14 ** Length: 1 Successors: 15 24 Predecessors: 12 13 GEN {} KILL {} IN {1, 2, 3, 4} OUT {1, 2, 3, 4} > 22: ifeq -> 37 ** Basic block: 15 ** Length: 1 Successors: 16 Predecessors: 14 GEN {1} KILL {} IN {1, 2, 4} OUT {2, 4} > 25: iload_1 ** Basic block: 16 ** Length: 1 Successors: 17 Predecessors: 15 GEN {} KILL {} IN {2, 4} OUT {2, 4} > 26: iconst_1 ** Basic block: 17 ** Length: 1 Successors: 18 Predecessors: 16 GEN {} KILL {} IN {2, 4} OUT {2, 4} > 27: iadd ** Basic block: 18 ** Length: 1 Successors: 19 Predecessors: 17 GEN {} KILL {1} IN {2, 4} OUT {1, 2, 4} > 28: istore_1 ** Basic block: 19 ** Length: 1 Successors: 20 Predecessors: 18 GEN {} KILL {} IN {1, 2, 4} OUT {1, 2, 4} > 29: iconst_5 ** Basic block: 20 ** Length: 1 Successors: 21 Predecessors: 19 GEN {2} KILL {} IN {1, 2, 4} OUT {1, 2, 4} > 30: iload_2 ** Basic block: 21 ** Length: 1 Successors: 22 Predecessors: 20 GEN {} KILL {} IN {1, 2, 4} OUT {1, 2, 4} > 31: isub ** Basic block: 22 ** Length: 1 Successors: 23 Predecessors: 21 GEN {} KILL {3} IN {1, 2, 4} OUT {1, 2, 3, 4} > 32: istore_3 ** Basic block: 23 ** Length: 1 Successors: 32 Predecessors: 22 GEN {} KILL {} IN {1, 2, 3, 4} OUT {1, 2, 3, 4} > 33: goto -> 47 ** Basic block: 24 ** Length: 1 Successors: 25 Predecessors: 14 GEN {} KILL {} IN {2, 3, 4} OUT {2, 3, 4} > 37: bipush 6 ** Basic block: 25 ** Length: 1 Successors: 26 Predecessors: 24 GEN {3} KILL {} IN {2, 3, 4} OUT {2, 4} > 39: iload_3 ** Basic block: 26 ** Length: 1 Successors: 27 Predecessors: 25 GEN {} KILL {} IN {2, 4} OUT {2, 4} > 40: iadd ** Basic block: 27 ** Length: 1 Successors: 28 Predecessors: 26 GEN {} KILL {1} IN {2, 4} OUT {1, 2, 4} > 41: istore_1 ** Basic block: 28 ** Length: 1 Successors: 29 Predecessors: 27 GEN {} KILL {} IN {1, 2, 4} OUT {1, 2, 4} > 42: iconst_3 ** Basic block: 29 ** Length: 1 Successors: 30 Predecessors: 28 GEN {2} KILL {} IN {1, 2, 4} OUT {1, 2, 4} > 43: iload_2 ** Basic block: 30 ** Length: 1 Successors: 31 Predecessors: 29 GEN {} KILL {} IN {1, 2, 4} OUT {1, 2, 4} > 44: isub ** Basic block: 31 ** Length: 1 Successors: 32 Predecessors: 30 GEN {} KILL {3} IN {1, 2, 4} OUT {1, 2, 3, 4} > 45: istore_3 ** Basic block: 32 ** Length: 1 Successors: 33 Predecessors: 23 31 GEN {4} KILL {} IN {1, 2, 3, 4} OUT {1, 2, 3} > 47: iload 4 ** Basic block: 33 ** Length: 1 Successors: 34 Predecessors: 32 GEN {} KILL {} IN {1, 2, 3} OUT {1, 2, 3} > 49: iconst_2 ** Basic block: 34 ** Length: 1 Successors: 35 37 Predecessors: 33 GEN {} KILL {} IN {1, 2, 3} OUT {1, 2, 3} > 50: if_icmplt -> 58 ** Basic block: 35 ** Length: 1 Successors: 36 Predecessors: 34 GEN {} KILL {} IN {1, 2, 3} OUT {1, 2, 3} > 53: iconst_0 ** Basic block: 36 ** Length: 1 Successors: 38 Predecessors: 35 GEN {} KILL {} IN {1, 2, 3} OUT {1, 2, 3} > 54: goto -> 60 ** Basic block: 37 ** Length: 1 Successors: 38 Predecessors: 34 GEN {} KILL {} IN {1, 2, 3} OUT {1, 2, 3} > 58: iconst_1 ** Basic block: 38 ** Length: 1 Successors: 39 44 Predecessors: 36 37 GEN {} KILL {} IN {1, 2, 3} OUT {1, 2, 3} > 60: ifeq -> 71 ** Basic block: 39 ** Length: 1 Successors: 40 Predecessors: 38 GEN {} KILL {} IN {1, 2} OUT {1, 2} > 63: iconst_5 ** Basic block: 40 ** Length: 1 Successors: 41 Predecessors: 39 GEN {2} KILL {} IN {1, 2} OUT {1, 2} > 64: iload_2 ** Basic block: 41 ** Length: 1 Successors: 42 Predecessors: 40 GEN {} KILL {} IN {1, 2} OUT {1, 2} > 65: iadd ** Basic block: 42 ** Length: 1 Successors: 43 Predecessors: 41 GEN {} KILL {3} IN {1, 2} OUT {1, 2, 3} > 66: istore_3 ** Basic block: 43 ** Length: 1 Successors: 48 Predecessors: 42 GEN {} KILL {} IN {1, 2, 3} OUT {1, 2, 3} > 67: goto -> 77 ** Basic block: 44 ** Length: 1 Successors: 45 Predecessors: 38 GEN {} KILL {} IN {2, 3} OUT {2, 3} > 71: bipush 6 ** Basic block: 45 ** Length: 1 Successors: 46 Predecessors: 44 GEN {3} KILL {} IN {2, 3} OUT {2, 3} > 73: iload_3 ** Basic block: 46 ** Length: 1 Successors: 47 Predecessors: 45 GEN {} KILL {} IN {2, 3} OUT {2, 3} > 74: iadd ** Basic block: 47 ** Length: 1 Successors: 48 Predecessors: 46 GEN {} KILL {1} IN {2, 3} OUT {1, 2, 3} > 75: istore_1 ** Basic block: 48 ** Length: 1 Successors: 49 Predecessors: 43 47 GEN {1} KILL {} IN {1, 2, 3} OUT {2, 3} > 77: iload_1 ** Basic block: 49 ** Length: 1 Successors: 50 Predecessors: 48 GEN {3} KILL {} IN {2, 3} OUT {2} > 78: iload_3 ** Basic block: 50 ** Length: 1 Successors: 51 Predecessors: 49 GEN {} KILL {} IN {2} OUT {2} > 79: iadd ** Basic block: 51 ** Length: 1 Successors: 52 Predecessors: 50 GEN {2} KILL {} IN {2} OUT {} > 80: iload_2 ** Basic block: 52 ** Length: 1 Successors: 53 Predecessors: 51 GEN {} KILL {} IN {} OUT {} > 81: iadd ** Basic block: 53 ** Length: 1 Successors: 54 Predecessors: 52 GEN {} KILL {4} IN {} OUT {4} > 82: istore 4 ** Basic block: 54 ** Length: 1 Successors: 55 Predecessors: 53 GEN {} KILL {} IN {4} OUT {4} > 84: getstatic 12 ** Basic block: 55 ** Length: 1 Successors: 56 Predecessors: 54 GEN {} KILL {} IN {4} OUT {4} > 87: ldc 31 ** Basic block: 56 ** Length: 1 Successors: 57 Predecessors: 55 GEN {} KILL {} IN {4} OUT {4} > 89: invokevirtual 26 ** Basic block: 57 ** Length: 1 Successors: 58 Predecessors: 56 GEN {} KILL {} IN {4} OUT {4} > 92: getstatic 12 ** Basic block: 58 ** Length: 1 Successors: 59 Predecessors: 57 GEN {4} KILL {} IN {4} OUT {} > 95: iload 4 ** Basic block: 59 ** Length: 1 Successors: 60 Predecessors: 58 GEN {} KILL {} IN {} OUT {} > 97: invokevirtual 29 ** Basic block: 60 ** Length: 1 Successors: 61 Predecessors: 59 GEN {} KILL {} IN {} OUT {} > 100: getstatic 12 ** Basic block: 61 ** Length: 1 Successors: 62 Predecessors: 60 GEN {} KILL {} IN {} OUT {} > 103: invokevirtual 18 ** Basic block: 62 ** Length: 1 Successors: 63 Predecessors: 61 GEN {} KILL {} IN {} OUT {} > 106: return ** Basic block: 63 ** Length: 0 Successors: Predecessors: 62 GEN {} KILL {} IN {} OUT {} <<---- Live Ranges ---->> [B 0] [Live ] 0: iconst_0 [B 1] [Live ] 1: istore 4 [B 2] [Live 4 ] 3: iconst_1 [B 3] [Live 4 ] 4: istore_1 [B 4] [Live 1 4 ] 5: iconst_2 [B 5] [Live 1 4 ] 6: istore_3 [B 6] [Live 1 3 4 ] 7: iconst_3 [B 7] [Live 1 3 4 ] 8: istore_2 [B 8] [Live 1 2 3 4 ] 9: iload 4 [B 9] [Live 1 2 3 4 ] 11: iconst_0 [B 10] [Live 1 2 3 4 ] 12: if_icmpne -> 20 [B 11] [Live 1 2 3 4 ] 15: iconst_0 [B 12] [Live 1 2 3 4 ] 16: goto -> 22 [B 13] [Live 1 2 3 4 ] 20: iconst_1 [B 14] [Live 1 2 3 4 ] 22: ifeq -> 37 [B 15] [Live 1 2 4 ] 25: iload_1 [B 16] [Live 2 4 ] 26: iconst_1 [B 17] [Live 2 4 ] 27: iadd [B 18] [Live 2 4 ] 28: istore_1 [B 19] [Live 1 2 4 ] 29: iconst_5 [B 20] [Live 1 2 4 ] 30: iload_2 [B 21] [Live 1 2 4 ] 31: isub [B 22] [Live 1 2 4 ] 32: istore_3 [B 23] [Live 1 2 3 4 ] 33: goto -> 47 [B 24] [Live 2 3 4 ] 37: bipush 6 [B 25] [Live 2 3 4 ] 39: iload_3 [B 26] [Live 2 4 ] 40: iadd [B 27] [Live 2 4 ] 41: istore_1 [B 28] [Live 1 2 4 ] 42: iconst_3 [B 29] [Live 1 2 4 ] 43: iload_2 [B 30] [Live 1 2 4 ] 44: isub [B 31] [Live 1 2 4 ] 45: istore_3 [B 32] [Live 1 2 3 4 ] 47: iload 4 [B 33] [Live 1 2 3 ] 49: iconst_2 [B 34] [Live 1 2 3 ] 50: if_icmplt -> 58 [B 35] [Live 1 2 3 ] 53: iconst_0 [B 36] [Live 1 2 3 ] 54: goto -> 60 [B 37] [Live 1 2 3 ] 58: iconst_1 [B 38] [Live 1 2 3 ] 60: ifeq -> 71 [B 39] [Live 1 2 ] 63: iconst_5 [B 40] [Live 1 2 ] 64: iload_2 [B 41] [Live 1 2 ] 65: iadd [B 42] [Live 1 2 ] 66: istore_3 [B 43] [Live 1 2 3 ] 67: goto -> 77 [B 44] [Live 2 3 ] 71: bipush 6 [B 45] [Live 2 3 ] 73: iload_3 [B 46] [Live 2 3 ] 74: iadd [B 47] [Live 2 3 ] 75: istore_1 [B 48] [Live 1 2 3 ] 77: iload_1 [B 49] [Live 2 3 ] 78: iload_3 [B 50] [Live 2 ] 79: iadd [B 51] [Live 2 ] 80: iload_2 [B 52] [Live ] 81: iadd [B 53] [Live ] 82: istore 4 [B 54] [Live 4 ] 84: getstatic 12 [B 55] [Live 4 ] 87: ldc 31 [B 56] [Live 4 ] 89: invokevirtual 26 [B 57] [Live 4 ] 92: getstatic 12 [B 58] [Live 4 ] 95: iload 4 [B 59] [Live ] 97: invokevirtual 29 [B 60] [Live ] 100: getstatic 12 [B 61] [Live ] 103: invokevirtual 18 [B 62] [Live ] 106: return <<---- Local Variables in main() ---->> LocalVariable(start_pc = 0, length = 98, index = 0:String[] argv) LocalVariable(start_pc = 0, length = 98, index = 1:int a) LocalVariable(start_pc = 0, length = 98, index = 2:int c) LocalVariable(start_pc = 0, length = 98, index = 3:int b) LocalVariable(start_pc = 0, length = 98, index = 4:int x) <<---- Global Variables ---->> Compiled from "" public class test2 extends java.lang.Object{ public static void main(java.lang.String[]); Code: 0: iconst_0 1: istore 4 3: iconst_1 4: istore_1 5: iconst_2 6: istore_3 7: iconst_3 8: istore_2 9: iload 4 11: iconst_0 12: if_icmpne 19 15: iconst_0 16: goto 20 19: iconst_1 20: ifeq 34 23: iload_1 24: iconst_1 25: iadd 26: istore_1 27: iconst_5 28: iload_2 29: isub 30: istore_3 31: goto 43 34: bipush 6 36: iload_3 37: iadd 38: istore_1 39: iconst_3 40: iload_2 41: isub 42: istore_3 43: iload 4 45: iconst_2 46: if_icmplt 53 49: iconst_0 50: goto 54 53: iconst_1 54: ifeq 64 57: iconst_5 58: iload_2 59: iadd 60: istore_3 61: goto 69 64: bipush 6 66: iload_3 67: iadd 68: istore_1 69: iload_1 70: iload_3 71: iadd 72: iload_2 73: iadd 74: istore 4 76: getstatic #12; //Field java/lang/System.out:Ljava/io/PrintStream; 79: ldc #31; //String Result (should be 19) = 81: invokevirtual #26; //Method java/io/PrintStream.print:(Ljava/lang/String;)V 84: getstatic #12; //Field java/lang/System.out:Ljava/io/PrintStream; 87: iload 4 89: invokevirtual #29; //Method java/io/PrintStream.print:(I)V 92: getstatic #12; //Field java/lang/System.out:Ljava/io/PrintStream; 95: invokevirtual #18; //Method java/io/PrintStream.println:()V 98: return public test2(); Code: 0: aload_0 1: invokespecial #43; //Method java/lang/Object."":()V 4: return }