* the source that corresponds to a relative address in the byte code. This
* is used for debugging purposes.
*
- * @version $Id: LineNumber.java,v 1.3 2004/11/19 16:45:18 aclement Exp $
+ * @version $Id: LineNumber.java,v 1.4 2007/02/28 13:10:32 aclement Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see LineNumberTable
*/
* @return String representation
*/
public final String toString() {
- return "LineNumber(" + start_pc + ", " + line_number + ")";
+ return "LineNumber(pc=" + start_pc + ", line=" + line_number + ")";
}
/**
* A list is finally dumped to a byte code array with <a
* href="#getByteCode()">getByteCode</a>.
*
- * @version $Id: InstructionList.java,v 1.4 2006/05/12 08:17:43 aclement Exp $
+ * @version $Id: InstructionList.java,v 1.5 2007/02/28 13:10:32 aclement Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Instruction
* @see InstructionHandle
*/
public boolean isEmpty() { return start == null; } // && end == null
+ public static InstructionHandle findHandle(InstructionHandle[] ihs,int[] pos,int count,int target) {
+ return findHandle(ihs,pos,count,target,false);
+ }
/**
* Find the target instruction (handle) that corresponds to the given target
* position (byte code offset).
* @return target position's instruction handle if available
*/
public static InstructionHandle findHandle(InstructionHandle[] ihs,
- int[] pos, int count,int target) {
+ int[] pos, int count,int target,boolean returnClosestIfNoExactMatch) {
int l=0, r = count - 1;
// Do a binary search since the pos array is ordered
else l=i+1; // target > j
} while(l <= r);
+ if (returnClosestIfNoExactMatch) {
+ i = (l+r)/2; if (i<0) i=0;
+ return ihs[i];
+ }
return null;
}
public InstructionHandle[] getInstructionsAsArray() {
return getInstructionHandles();
}
-
+
public InstructionHandle findHandle(int pos,InstructionHandle[] instructionArray) {
return findHandle(instructionArray,byte_positions,length,pos);
}
+
+ public InstructionHandle findHandle(int pos,InstructionHandle[] instructionArray,boolean useClosestApproximationIfNoExactFound) {
+ return findHandle(instructionArray,byte_positions,length,pos,useClosestApproximationIfNoExactFound);
+ }
/**
* Initialize instruction list from byte array.
* use the `removeNOPs' method to get rid off them.
* The resulting method object can be obtained via the `getMethod()' method.
*
- * @version $Id: MethodGen.java,v 1.7 2006/02/21 10:49:15 aclement Exp $
+ * @version $Id: MethodGen.java,v 1.8 2007/02/28 13:10:32 aclement Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @author <A HREF="http://www.vmeng.com/beard">Patrick C. Beard</A> [setMaxStack()]
* @see InstructionList
int lnum = l.getLineNumber();
if (lnum>highestLineNumber) highestLineNumber=lnum;
LineNumberTag lt = new LineNumberTag(lnum);
- il.findHandle(l.getStartPC(),arrayOfInstructions).addTargeter(lt);
+ il.findHandle(l.getStartPC(),arrayOfInstructions,true).addTargeter(lt);
}
} else {
for (int k = 0; k < ln.length; k++) {
LineNumber l = ln[k];
- addLineNumber(il.findHandle(l.getStartPC(),arrayOfInstructions),
+ addLineNumber(il.findHandle(l.getStartPC(),arrayOfInstructions,true),
l.getLineNumber());
}
}
} else if (a instanceof LocalVariableTable) {
-
// Lets have a go at creating Tags directly
if (useTags) {
LocalVariable[] lv = ((LocalVariableTable) a).getLocalVariableTable();
LocalVariable l = lv[k];
Type t = Type.getType(l.getSignature());
LocalVariableTag lvt = new LocalVariableTag(t,l.getSignature(),l.getName(),l.getIndex(),l.getStartPC());
- InstructionHandle start = il.findHandle(l.getStartPC(), arrayOfInstructions);
+ InstructionHandle start = il.findHandle(l.getStartPC(), arrayOfInstructions,true);
byte b = t.getType();
if (b!= Constants.T_ADDRESS) {
int increment = t.getSize();