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]);
30 return new FlatCall(method, ndst, nthis, nargs);
33 public MethodDescriptor getMethod() {
37 public TempDescriptor getThis() {
41 public TempDescriptor getReturnTemp() {
45 public int numArgs() {
49 public TempDescriptor getArg(int i) {
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();
59 assert numArgs()+1 == fm.numParameters();
62 if( method.isStatic() ) {
73 // return the temp for the argument in caller that
74 // becomes the given parameter
75 public TempDescriptor getArgMatchingParam(FlatMethod fm,
76 TempDescriptor tdParam) {
77 // in non-static methods the "this" pointer
78 // affects the matching index
79 if( method.isStatic() ) {
80 assert numArgs() == fm.numParameters();
82 assert numArgs()+1 == fm.numParameters();
85 for( int i = 0; i < fm.numParameters(); ++i ) {
86 TempDescriptor tdParamI = fm.getParameter( i );
88 if( tdParamI.equals( tdParam ) ) {
90 if( method.isStatic() ) {
105 public String toString() {
106 String st="FlatCall_";
111 st+=method.getSymbol()+"(";
113 st+=dst+"="+method.getSymbol()+"(";
114 if (this_temp!=null) {
120 for(int i=0; i<args.length; i++) {
121 st+=args[i].toString();
122 if ((i+1)<args.length)
129 return FKind.FlatCall;
132 public TempDescriptor [] readsTemps() {
133 int size=args.length;
136 TempDescriptor [] t=new TempDescriptor[size];
139 t[offset++]=this_temp;
140 for(int i=0; i<args.length; i++)
145 public TempDescriptor [] writesTemps() {
147 return new TempDescriptor[] {dst};
149 return new TempDescriptor[0];