View Javadoc

1   // DirectBindCall.java, created Tue Feb 27  2:59:43 2001 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.Assembler;
5   
6   import java.io.DataOutput;
7   import java.io.IOException;
8   import joeq.Allocator.DefaultCodeAllocator;
9   import joeq.Class.jq_CompiledCode;
10  import joeq.Class.jq_Method;
11  import joeq.Memory.CodeAddress;
12  import jwutil.util.Assert;
13  
14  /***
15   * DirectBindCall
16   *
17   * @author  John Whaley <jwhaley@alum.mit.edu>
18   * @version $Id: DirectBindCall.java 1941 2004-09-30 03:37:06Z joewhaley $
19   */
20  public class DirectBindCall extends Reloc {
21  
22      private CodeAddress source;
23      private jq_Method target;
24  
25      public DirectBindCall(CodeAddress source, jq_Method target) {
26          this.source = source; this.target = target;
27      }
28      
29      public void patch() {
30          patchTo(target.getDefaultCompiledVersion());
31      }
32      
33      public void patchTo(jq_CompiledCode cc) {
34          Assert._assert(cc != null);
35          DefaultCodeAllocator.patchRelativeOffset(source, cc.getEntrypoint());
36      }
37      
38      public CodeAddress getSource() { return source; }
39      public jq_Method getTarget() { return target; }
40  
41      public String toString() {
42          return "from code:"+source.stringRep()+" to method:"+target;
43      }
44  
45      public void dumpCOFF(DataOutput out) throws IOException {
46          out.writeInt(source.to32BitValue());       // r_vaddr
47          out.writeInt(0);                           // r_symndx
48          out.writeChar(Reloc.RELOC_ADDR32);         // r_type
49      }
50      
51  }