1 19 20 25 26 27 28 29 30 31 32 package soot.coffi; 33 import soot.*; 34 import java.io.*; 35 63 class Instruction_Tableswitch extends Instruction { 64 public Instruction_Tableswitch() { 65 super((byte)ByteCode.TABLESWITCH); 66 name = "tableswitch"; 67 branches = true; 68 } 69 public byte pad; public int default_offset; 71 public int low; 72 public int high; 73 public int jump_offsets[]; 74 public Instruction default_inst; 75 public Instruction jump_insts[]; 76 public String toString(cp_info constant_pool[]) { 77 String args; 78 int i; 79 args = super.toString(constant_pool) + argsep + "(" + 80 Integer.toString(pad) + ")"; 81 args = args + argsep + "label_" + Integer.toString(default_inst.label); 82 args = args + argsep + Integer.toString(low); 83 args = args + argsep + Integer.toString(high) + ": "; 84 for (i=0;i<high-low+1;i++) { 85 args = args + argsep + "label_" + Integer.toString(jump_insts[i].label); 86 } 87 return args; 88 } 89 public int parse(byte bc[],int index) { 90 int i,j,baseindex; 92 baseindex = index; 93 i = index % 4; 94 if (i != 0) 95 pad = (byte)(4 - i); 96 else 97 pad = (byte)0; 98 index += pad; 99 default_offset = getInt(bc,index); 100 index += 4; 101 low = getInt(bc,index); 102 index += 4; 103 high = getInt(bc,index); 104 index += 4; 105 i = high-low+1; 106 if (i>0) { 107 jump_offsets = new int[i]; 108 j = 0; 109 do { 110 jump_offsets[j] = getInt(bc,index); 111 index += 4; 112 j++; 113 } while(j<i); 114 } 115 return index; 116 } 117 public int nextOffset(int curr) { 118 int i,j,baseindex,siz=0; 119 baseindex = curr; 120 i = (curr+1) % 4; 121 if (i != 0) 122 siz = (4 - i); 123 return (curr + siz + 13 + (high-low+1)*4); 124 } 125 public int compile(byte bc[],int index) { 126 int i; 127 bc[index++] = code; 128 for (i=0;i<pad;i++) 130 bc[index++] = 0; 131 if (default_inst!=null) 132 index = intToBytes(default_inst.label-label,bc,index); 133 else 134 index = intToBytes(default_offset,bc,index); 135 index = intToBytes(low,bc,index); 136 index = intToBytes(high,bc,index); 137 for (i=0;i<=high-low;i++) { 138 if (jump_insts[i]!=null) 139 index = intToBytes((jump_insts[i]).label-label,bc,index); 140 else 141 index = intToBytes(jump_offsets[i],bc,index); 142 } 143 return index; 144 } 145 public void offsetToPointer(ByteCode bc) { 146 int i; 147 default_inst = bc.locateInst(default_offset+label); 148 if (default_inst==null) { 149 G.v().out.println("Warning: can't locate target of instruction"); 150 G.v().out.println(" which should be at byte address " + (label+default_offset)); 151 } else 152 default_inst.labelled = true; 153 if (high-low+1>0) { 154 jump_insts = new Instruction[high-low+1]; 155 for (i=0;i<high-low+1;i++) { 156 jump_insts[i] = bc.locateInst(jump_offsets[i]+label); 157 if (jump_insts[i]==null) { 158 G.v().out.println("Warning: can't locate target of instruction"); 159 G.v().out.println(" which should be at byte address " + 160 (label+jump_offsets[i])); 161 } else 162 jump_insts[i].labelled = true; 163 } 164 } 165 } 166 public Instruction[] branchpoints(Instruction next) { 167 Instruction i[] = new Instruction[high-low+2]; 168 int j; 169 i[0] = default_inst; 170 for (j=1;j<high-low+2;j++) 171 i[j] = jump_insts[j-1]; 172 return i; 173 } 174 } 175 | Popular Tags |