omputation to determine set of aliased parameter indices was very conservative,
[IRC.git] / Robust / src / IR / Flat / FlatCall.java
1 package IR.Flat;
2 import IR.MethodDescriptor;
3
4 public class FlatCall extends FlatNode {
5   TempDescriptor args[];
6   TempDescriptor this_temp;
7   TempDescriptor dst;
8   MethodDescriptor method;
9
10   public FlatCall(MethodDescriptor md, TempDescriptor dst, TempDescriptor this_temp, TempDescriptor[] args) {
11     this.method=md;
12     this.dst=dst;
13     this.this_temp=this_temp;
14     this.args=args;
15   }
16   public void rewriteUse(TempMap t) {
17     for(int i=0;i<args.length;i++)
18       args[i]=t.tempMap(args[i]);
19     this_temp=t.tempMap(this_temp);
20   }
21   public void rewriteDef(TempMap t) {
22     dst=t.tempMap(dst);
23   }
24   public FlatNode clone(TempMap t) {
25     TempDescriptor ndst=t.tempMap(dst);
26     TempDescriptor nthis=t.tempMap(this_temp);
27     TempDescriptor[] nargs=new TempDescriptor[args.length];
28     for(int i=0;i<nargs.length;i++)
29       nargs[i]=t.tempMap(args[i]);
30     return new FlatCall(method, ndst, nthis, nargs);
31   }
32
33   public MethodDescriptor getMethod() {
34     return method;
35   }
36
37   public TempDescriptor getThis() {
38     return this_temp;
39   }
40
41   public TempDescriptor getReturnTemp() {
42     return dst;
43   }
44
45   public int numArgs() {
46     return args.length;
47   }
48
49   public TempDescriptor getArg(int i) {
50     return args[i];
51   }
52
53   public TempDescriptor getArgMatchingParamIndex(FlatMethod fm, int i) {
54     // in non-static methods the "this" pointer
55     // affects the matching index
56     if( method.isStatic() ) {
57       assert numArgs()   == fm.numParameters();
58     } else {
59       assert numArgs()+1 == fm.numParameters();
60     }
61
62     if( method.isStatic() ) {
63       return args[i];
64     }
65
66     if( i == 0 ) {
67       return this_temp;
68     }
69     
70     return args[i-1];
71   }
72
73   public String toString() {
74     String st="FlatCall_";
75     if (dst==null) {
76       if (method==null)
77         st+="null(";
78       else
79         st+=method.getSymbol()+"(";
80     } else
81       st+=dst+"="+method.getSymbol()+"(";
82     if (this_temp!=null) {
83       st+=this_temp;
84       if (args.length!=0)
85         st+=", ";
86     }
87
88     for(int i=0; i<args.length; i++) {
89       st+=args[i].toString();
90       if ((i+1)<args.length)
91         st+=", ";
92     }
93     return st+")";
94   }
95
96   public int kind() {
97     return FKind.FlatCall;
98   }
99
100   public TempDescriptor [] readsTemps() {
101     int size=args.length;
102     if (this_temp!=null)
103       size++;
104     TempDescriptor [] t=new TempDescriptor[size];
105     int offset=0;
106     if (this_temp!=null)
107       t[offset++]=this_temp;
108     for(int i=0; i<args.length; i++)
109       t[offset++]=args[i];
110     return t;
111   }
112
113   public TempDescriptor [] writesTemps() {
114     if (dst!=null)
115       return new TempDescriptor[] {dst};
116     else
117       return new TempDescriptor[0];
118   }
119 }