2 import IR.MethodDescriptor;
4 public class FlatCall extends FlatNode {
6 TempDescriptor this_temp;
8 MethodDescriptor method;
10 public FlatCall(MethodDescriptor md, TempDescriptor dst, TempDescriptor this_temp, TempDescriptor[] args) {
13 this.this_temp=this_temp;
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);
21 public void rewriteDef(TempMap t) {
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]);
31 return new FlatCall(method, ndst, nthis, nargs);
34 public MethodDescriptor getMethod() {
38 public TempDescriptor getThis() {
42 public TempDescriptor getReturnTemp() {
46 public int numArgs() {
50 public TempDescriptor getArg(int i) {
54 public TempDescriptor getArgMatchingParamIndex(FlatMethod fm, int i) {
55 // in non-static methods the "this" pointer
56 // affects the matching index
57 if( method.isStatic() ) {
58 assert numArgs() == fm.numParameters();
60 assert numArgs()+1 == fm.numParameters();
63 if( method.isStatic() ) {
74 // return the temp for the argument in caller that
75 // becomes the given parameter
76 public TempDescriptor getArgMatchingParam(FlatMethod fm,
77 TempDescriptor tdParam) {
78 // in non-static methods the "this" pointer
79 // affects the matching index
80 if( method.isStatic() ) {
81 assert numArgs() == fm.numParameters();
83 assert numArgs()+1 == fm.numParameters();
86 for( int i = 0; i < fm.numParameters(); ++i ) {
87 TempDescriptor tdParamI = fm.getParameter( i );
89 if( tdParamI.equals( tdParam ) ) {
91 if( method.isStatic() ) {
106 public String toString() {
107 String st="FlatCall_";
112 st+=method.getSymbol()+"(";
114 st+=dst+"="+method.getSymbol()+"(";
115 if (this_temp!=null) {
121 for(int i=0; i<args.length; i++) {
122 st+=args[i].toString();
123 if ((i+1)<args.length)
130 return FKind.FlatCall;
133 public TempDescriptor [] readsTemps() {
134 int size=args.length;
137 TempDescriptor [] t=new TempDescriptor[size];
140 t[offset++]=this_temp;
141 for(int i=0; i<args.length; i++)
146 public TempDescriptor [] writesTemps() {
148 return new TempDescriptor[] {dst};
150 return new TempDescriptor[0];