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_Lookupswitch extends Instruction { 64 public Instruction_Lookupswitch() { super((byte)ByteCode.LOOKUPSWITCH); name = "lookupswitch"; branches = true; } 65 public byte pad; public int default_offset; 67 public int npairs; 68 public int match_offsets[]; 69 public Instruction default_inst; 70 public Instruction match_insts[]; 71 public String toString(cp_info constant_pool[]) { 72 String args; 74 int i; 75 args = super.toString(constant_pool) + argsep + "(" + 76 Integer.toString(pad) + ")"; 77 args = args + argsep + Integer.toString(default_inst.label); 78 args = args + argsep + Integer.toString(npairs) + ": "; 79 for (i=0;i<npairs;i++) 80 args = args + "case " + Integer.toString(match_offsets[i*2]) + 81 ": label_" + Integer.toString(match_insts[i].label); 82 return args; 83 } 84 public int parse(byte bc[],int index) { 85 int i,j,baseindex; 87 baseindex = index; 88 i = index % 4; 89 if (i != 0) 90 pad = (byte)(4 - i); 91 else 92 pad = (byte)0; 93 index += pad; 94 default_offset = getInt(bc,index); 95 index += 4; 96 npairs = getInt(bc,index); 97 index += 4; 98 if (npairs>0) { 99 match_offsets = new int[npairs*2]; 100 j = 0; 101 do { 102 match_offsets[j] = getInt(bc,index); 103 j++; 104 index += 4; 105 match_offsets[j] = getInt(bc,index); 106 index += 4; 107 j++; 108 } while(j<npairs*2); 109 } 110 return index; 111 } 112 public int nextOffset(int curr) { 113 int i,j,baseindex,siz=0; 114 baseindex = curr; 115 i = (curr+1) % 4; 116 if (i != 0) 117 siz = (4 - i); 118 return (curr + siz + 9 + npairs*8); 119 } 120 public int compile(byte bc[],int index) { 121 int i; 122 bc[index++] = code; 123 for (i=0;i<pad;i++) 125 bc[index++] = 0; 126 if (default_inst!=null) 127 index = intToBytes(default_inst.label-label,bc,index); 128 else 129 index = intToBytes(default_offset,bc,index); 130 index = intToBytes(npairs,bc,index); 131 for (i=0;i<npairs;i++) { 132 index = intToBytes(match_offsets[i*2],bc,index); 133 if (match_insts[i]!=null) 134 index = intToBytes((match_insts[i]).label-label,bc,index); 135 else 136 index = intToBytes(match_offsets[i*2+1],bc,index); 137 } 138 return index; 139 } 140 public void offsetToPointer(ByteCode bc) { 141 int i; 142 default_inst = bc.locateInst(default_offset+label); 143 if (default_inst==null) { 144 G.v().out.println("Warning: can't locate target of instruction"); 145 G.v().out.println(" which should be at byte address " + (label+default_offset)); 146 } else 147 default_inst.labelled = true; 148 if (npairs>0) { 149 match_insts = new Instruction[npairs]; 150 for (i=0;i<npairs;i++) { 151 match_insts[i] = bc.locateInst(match_offsets[i*2+1]+label); 152 if (match_insts[i]==null) { 153 G.v().out.println("Warning: can't locate target of instruction"); 154 G.v().out.println(" which should be at byte address " + 155 (label+match_offsets[i*2+1])); 156 } else 157 match_insts[i].labelled = true; 158 } 159 } 160 } 161 public Instruction[] branchpoints(Instruction next) { 162 Instruction i[] = new Instruction[npairs+1]; 163 int j; 164 i[0] = default_inst; 165 for (j=1;j<npairs+1;j++) 166 i[j] = match_insts[j-1]; 167 return i; 168 } 169 } 170 | Popular Tags |