1 duncan   1.1.2.1  // CALL.java, created Wed Jan 13 21:14:57 1999 by cananian
 2 cananian 1.1.2.10 // Copyright (C) 1998 Duncan Bryce <duncan@lcs.mit.edu>
 3 cananian 1.1.2.10 // Licensed under the terms of the GNU GPL; see COPYING for details.
 4 duncan   1.1.2.1  package harpoon.IR.Tree;
 5 duncan   1.1.2.1  
 6 duncan   1.1.2.1  import harpoon.ClassFile.HCodeElement;
 7 cananian 1.1.2.23 import harpoon.Temp.TempMap;
 8 duncan   1.1.2.1  import harpoon.Util.Util;
 9 duncan   1.1.2.1  
10 duncan   1.1.2.9  import java.util.HashSet;
11 duncan   1.1.2.9  import java.util.Set;
12 duncan   1.1.2.9  
13 duncan   1.1.2.1  /**
14 duncan   1.1.2.1   * <code>NATIVECALL</code> objects are statements which stand for
15 cananian 1.1.2.7   * function calls using standard C calling convention.  These are
16 cananian 1.1.2.14  * typically used to implement parts of the runtime system
17 cananian 1.1.2.14  * (for example, to invoke the garbage collector) and <i>not</i>
18 cananian 1.1.2.14  * for java native method calls (which must use the standard java
19 cananian 1.1.2.14  * method calling convention).
20 duncan   1.1.2.1   * 
21 duncan   1.1.2.1   * @author  Duncan Bryce <duncan@lcs.mit.edu>, based on
22 duncan   1.1.2.1   *          <i>Modern Compiler Implementation in Java</i> by Andrew Appel.
23 cananian 1.4       * @version $Id: NATIVECALL.java,v 1.4 2002/04/10 03:05:45 cananian Exp $
24 pnkfelix 1.1.2.4   * @see harpoon.IR.Quads.CALL
25 pnkfelix 1.1.2.4   * @see CALL
26 cananian 1.1.2.5   * @see INVOCATION
27 duncan   1.1.2.1   */
28 duncan   1.1.2.2  public class NATIVECALL extends INVOCATION {
29 duncan   1.1.2.1      /** Constructor. */
30 duncan   1.1.2.1      public NATIVECALL(TreeFactory tf, HCodeElement source,
31 cananian 1.1.2.13                       TEMP retval, Exp func, ExpList args) {
32 cananian 1.1.2.22         super(tf, source, retval, func, args, 0);
33 duncan   1.1.2.1      }
34 duncan   1.1.2.1  
35 duncan   1.1.2.1      public boolean isNative() { return true; }
36 duncan   1.1.2.17 
37 duncan   1.1.2.6      public int kind() { return TreeKind.NATIVECALL; }
38 duncan   1.1.2.8  
39 duncan   1.1.2.8      public Stm build(TreeFactory tf, ExpList kids) {
40 cananian 1.1.2.14         for (ExpList e = kids; e!=null; e=e.tail)
41 cananian 1.3.2.1              assert tf == e.head.tf;
42 cananian 1.3.2.1          assert tf==this.tf : "cloning retval not yet implemented";
43 cananian 1.1.2.22         return new NATIVECALL(tf, this, getRetval()/*XXX needs to clone*/,
44 cananian 1.1.2.14                               kids.head,  // func
45 cananian 1.1.2.14                               kids.tail); // args
46 duncan   1.1.2.1      }
47 duncan   1.1.2.1  
48 duncan   1.1.2.1      /** Accept a visitor */
49 cananian 1.1.2.12     public void accept(TreeVisitor v) { v.visit(this); }
50 duncan   1.1.2.1  
51 cananian 1.1.2.23     public Tree rename(TreeFactory tf, TempMap tm, CloneCallback cb) {
52 cananian 1.1.2.23         return cb.callback(this, new NATIVECALL
53 cananian 1.1.2.23                            (tf, this, 
54 cananian 1.1.2.23                             (this.getRetval()==null) ? null :
55 cananian 1.1.2.23                             (TEMP)this.getRetval().rename(tf, tm, cb),
56 cananian 1.1.2.23                             (Exp)this.getFunc().rename(tf, tm, cb),
57 cananian 1.1.2.24                             ExpList.rename(this.getArgs(), tf, tm, cb)),
58 cananian 1.1.2.24                            tm);
59 duncan   1.1.2.17     }
60 duncan   1.1.2.17 
61 andyb    1.1.2.3      public String toString() {
62 andyb    1.1.2.3          StringBuffer s = new StringBuffer();
63 andyb    1.1.2.3  
64 cananian 1.1.2.14         s.append("NATIVECALL(");
65 duncan   1.1.2.17         if (this.getRetval()!=null) 
66 duncan   1.1.2.17             { s.append(" # "+this.getRetval().getID()+","); } 
67 duncan   1.1.2.17         s.append(" #"+this.getFunc().getID()+", {");
68 duncan   1.1.2.17         for (ExpList list = this.getArgs(); list != null; list=list.tail) {
69 andyb    1.1.2.3              s.append(" #" + list.head.getID());
70 duncan   1.1.2.9              if (list.tail != null) s.append(",");
71 andyb    1.1.2.3          }
72 andyb    1.1.2.3          s.append(" })");
73 andyb    1.1.2.3          return new String(s);
74 andyb    1.1.2.3      }
75 cananian 1.2      }