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