KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > baf > Baf


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 1999 Patrick Lam, Patrick Pominville and Raja Vallee-Rai
3  * Copyright (C) 2004 Ondrej Lhotak
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */

20
21 /*
22  * Modified by the Sable Research Group and others 1997-1999.
23  * See the 'credits' file distributed with Soot for the complete list of
24  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
25  */

26
27
28
29
30
31 package soot.baf;
32
33 import soot.*;
34 import soot.jimple.*;
35 import soot.jimple.internal.*;
36 import soot.baf.internal.*;
37 import soot.util.*;
38 import java.util.*;
39
40 public class Baf
41 {
42     public Baf( Singletons.Global g ) {}
43     public static Baf v() { return G.v().soot_baf_Baf(); }
44
45     public static Type getDescriptorTypeOf(Type opType)
46     {
47         if(opType instanceof NullType || opType instanceof ArrayType || opType instanceof RefType)
48             opType = RefType.v();
49         
50         return opType;
51     }
52
53     /**
54         Constructs a Local with the given name and type.
55     */

56
57     public Local newLocal(String JavaDoc name, Type t)
58     {
59         return new BafLocal(name, t);
60     }
61
62     /**
63         Constructs a new BTrap for the given exception on the given Unit range with the given Unit handler.
64     */

65
66     public Trap newTrap(SootClass exception, Unit beginUnit, Unit endUnit, Unit handlerUnit)
67     {
68         return new BTrap(exception, beginUnit, endUnit, handlerUnit);
69     }
70
71     /**
72         Constructs a ExitMonitorInst() grammar chunk
73      */

74
75     public ExitMonitorInst newExitMonitorInst()
76     {
77         return new BExitMonitorInst();
78     }
79
80
81     /**
82         Constructs a EnterMonitorInst() grammar chunk.
83      */

84
85     public EnterMonitorInst newEnterMonitorInst()
86     {
87         return new BEnterMonitorInst();
88     }
89
90     public ReturnVoidInst newReturnVoidInst()
91     {
92         return new BReturnVoidInst();
93     }
94     
95     public NopInst newNopInst()
96     {
97         return new BNopInst();
98     }
99
100     public GotoInst newGotoInst(Unit unit)
101     {
102         return new BGotoInst(unit);
103     }
104
105     public PlaceholderInst newPlaceholderInst(Unit source)
106     {
107         return new PlaceholderInst(source);
108     }
109         
110     public UnitBox newInstBox(Unit unit)
111     {
112         return new InstBox((Inst) unit);
113     }
114     
115     public PushInst newPushInst(Constant c)
116     {
117         return new BPushInst(c);
118     }
119     
120     public IdentityInst newIdentityInst(Value local, Value identityRef)
121     {
122         return new BIdentityInst(local, identityRef);
123     }
124
125     public ValueBox newLocalBox(Value value)
126     {
127         return new BafLocalBox(value);
128     }
129     
130     public ValueBox newIdentityRefBox(Value value)
131     {
132         return new IdentityRefBox(value);
133     }
134
135     
136     /**
137         Constructs a ThisRef(RefType) grammar chunk.
138      */

139
140     public ThisRef newThisRef(RefType t)
141     {
142         return new ThisRef(t);
143     }
144     
145     /**
146         Constructs a ParameterRef(SootMethod, int) grammar chunk.
147      */

148
149     public ParameterRef newParameterRef(Type paramType, int number)
150     {
151         return new ParameterRef(paramType, number);
152     }
153     
154     public StoreInst newStoreInst(Type opType, Local l)
155     {
156         return new BStoreInst(opType, l);
157     }
158     
159     public LoadInst newLoadInst(Type opType, Local l)
160     {
161         return new BLoadInst(opType, l);
162     }
163
164     public ArrayWriteInst newArrayWriteInst(Type opType)
165     {
166         return new BArrayWriteInst(opType);
167     }
168     
169     public ArrayReadInst newArrayReadInst(Type opType)
170     {
171         return new BArrayReadInst(opType);
172     }
173
174     public StaticGetInst newStaticGetInst(SootFieldRef fieldRef)
175     {
176         return new BStaticGetInst(fieldRef);
177     }
178     
179     public StaticPutInst newStaticPutInst(SootFieldRef fieldRef)
180     {
181         return new BStaticPutInst(fieldRef);
182     }
183
184     public FieldGetInst newFieldGetInst(SootFieldRef fieldRef)
185     {
186         return new BFieldGetInst(fieldRef);
187     }
188     
189     public FieldPutInst newFieldPutInst(SootFieldRef fieldRef)
190     {
191         return new BFieldPutInst(fieldRef);
192     }
193     
194     public AddInst newAddInst(Type opType)
195     {
196         return new BAddInst(opType);
197     }
198
199     public PopInst newPopInst(Type aType)
200     {
201         return new BPopInst(aType);
202     }
203
204     public SubInst newSubInst(Type opType)
205     {
206         return new BSubInst(opType);
207     }
208
209     public MulInst newMulInst(Type opType)
210     {
211         return new BMulInst(opType);
212     }
213
214     public DivInst newDivInst(Type opType)
215     {
216         return new BDivInst(opType);
217     }
218
219     public AndInst newAndInst(Type opType)
220     {
221         return new BAndInst(opType);
222     }
223
224     public ArrayLengthInst newArrayLengthInst()
225     {
226         return new BArrayLengthInst();
227     }
228
229     public NegInst newNegInst(Type opType)
230     {
231         return new BNegInst(opType);
232     }
233
234     public OrInst newOrInst(Type opType)
235     {
236         return new BOrInst(opType);
237     }
238
239     public RemInst newRemInst(Type opType)
240     {
241         return new BRemInst(opType);
242     }
243
244     public ShlInst newShlInst(Type opType)
245     {
246         return new BShlInst(opType);
247     }
248
249
250
251
252
253     public ShrInst newShrInst(Type opType)
254     {
255         return new BShrInst(opType);
256     }
257
258     public UshrInst newUshrInst(Type opType)
259     {
260         return new BUshrInst(opType);
261     }
262
263     public XorInst newXorInst(Type opType)
264     {
265         return new BXorInst(opType);
266     }
267
268     public InstanceCastInst newInstanceCastInst(Type opType)
269     {
270         return new BInstanceCastInst(opType);
271     }
272
273     public InstanceOfInst newInstanceOfInst(Type opType)
274     {
275         return new BInstanceOfInst(opType);
276     }
277
278     public PrimitiveCastInst newPrimitiveCastInst(Type fromType, Type toType)
279     {
280         return new BPrimitiveCastInst(fromType, toType);
281     }
282
283     public NewInst newNewInst(RefType opType)
284     {
285         return new BNewInst(opType);
286     }
287
288     public NewArrayInst newNewArrayInst(Type opType)
289     {
290         return new BNewArrayInst(opType);
291     }
292
293     public NewMultiArrayInst newNewMultiArrayInst(ArrayType opType, int dimensions)
294     {
295         return new BNewMultiArrayInst(opType, dimensions);
296     }
297
298     public StaticInvokeInst newStaticInvokeInst(SootMethodRef methodRef)
299     {
300         return new BStaticInvokeInst(methodRef);
301     }
302
303     public SpecialInvokeInst newSpecialInvokeInst(SootMethodRef methodRef)
304     {
305         return new BSpecialInvokeInst(methodRef);
306     }
307
308     public VirtualInvokeInst newVirtualInvokeInst(SootMethodRef methodRef)
309     {
310         return new BVirtualInvokeInst(methodRef);
311     }
312
313     public InterfaceInvokeInst newInterfaceInvokeInst(SootMethodRef methodRef, int argCount)
314     {
315         return new BInterfaceInvokeInst(methodRef, argCount);
316     }
317
318     public ReturnInst newReturnInst(Type opType)
319     {
320         return new BReturnInst(opType);
321     }
322
323     public IfCmpEqInst newIfCmpEqInst(Type opType, Unit unit)
324     {
325         return new BIfCmpEqInst(opType, unit);
326     }
327
328     public IfCmpGeInst newIfCmpGeInst(Type opType, Unit unit)
329     {
330         return new BIfCmpGeInst(opType, unit);
331     }
332
333     public IfCmpGtInst newIfCmpGtInst(Type opType, Unit unit)
334     {
335         return new BIfCmpGtInst(opType, unit);
336     }
337
338     public IfCmpLeInst newIfCmpLeInst(Type opType, Unit unit)
339     {
340         return new BIfCmpLeInst(opType, unit);
341     }
342
343     public IfCmpLtInst newIfCmpLtInst(Type opType, Unit unit)
344     {
345         return new BIfCmpLtInst(opType, unit);
346     }
347
348     public IfCmpNeInst newIfCmpNeInst(Type opType, Unit unit)
349     {
350         return new BIfCmpNeInst(opType, unit);
351     }
352
353     public CmpInst newCmpInst(Type opType)
354     {
355         return new BCmpInst(opType);
356     }
357
358     public CmpgInst newCmpgInst(Type opType)
359     {
360         return new BCmpgInst(opType);
361     }
362
363     public CmplInst newCmplInst(Type opType)
364     {
365         return new BCmplInst(opType);
366     }
367
368     public IfEqInst newIfEqInst(Unit unit)
369     {
370         return new BIfEqInst(unit);
371     }
372
373     public IfGeInst newIfGeInst(Unit unit)
374     {
375         return new BIfGeInst(unit);
376     }
377
378     public IfGtInst newIfGtInst(Unit unit)
379     {
380         return new BIfGtInst(unit);
381     }
382
383     public IfLeInst newIfLeInst(Unit unit)
384     {
385         return new BIfLeInst(unit);
386     }
387
388     public IfLtInst newIfLtInst(Unit unit)
389     {
390         return new BIfLtInst(unit);
391     }
392
393     public IfNeInst newIfNeInst(Unit unit)
394     {
395         return new BIfNeInst(unit);
396     }
397
398     public IfNullInst newIfNullInst(Unit unit)
399     {
400         return new BIfNullInst(unit);
401     }
402
403     public IfNonNullInst newIfNonNullInst(Unit unit)
404     {
405         return new BIfNonNullInst(unit);
406     }
407
408     public ThrowInst newThrowInst()
409     {
410         return new BThrowInst();
411     }
412
413     public SwapInst newSwapInst(Type fromType, Type toType)
414     {
415         return new BSwapInst(fromType, toType);
416     }
417   
418     /*
419     public DupInst newDupInst(Type type)
420     {
421         return new BDupInst(new ArrayList(), Arrays.asList(new Type[] {type}));
422         }*/

423     
424
425     public Dup1Inst newDup1Inst(Type type)
426     {
427         return new BDup1Inst(type);
428     }
429
430     public Dup2Inst newDup2Inst(Type aOp1Type, Type aOp2Type)
431     {
432         return new BDup2Inst(aOp1Type,aOp2Type);
433     }
434
435     public Dup1_x1Inst newDup1_x1Inst(Type aOpType, Type aUnderType)
436     {
437         return new BDup1_x1Inst(aOpType, aUnderType);
438     }
439     
440     public Dup1_x2Inst newDup1_x2Inst(Type aOpType,
441                                       Type aUnder1Type, Type aUnder2Type)
442     {
443         return new BDup1_x2Inst(aOpType, aUnder1Type, aUnder2Type);
444     }
445
446     public Dup2_x1Inst newDup2_x1Inst(Type aOp1Type, Type aOp2Type,
447                                       Type aUnderType)
448     {
449         return new BDup2_x1Inst(aOp1Type, aOp2Type, aUnderType);
450     }
451
452     public Dup2_x2Inst newDup2_x2Inst(Type aOp1Type, Type aOp2Type,
453                                       Type aUnder1Type, Type aUnder2Type)
454     {
455         return new BDup2_x2Inst(aOp1Type, aOp2Type, aUnder1Type, aUnder2Type);
456     }
457
458   public IncInst newIncInst(Local aLocal, Constant aConstant)
459   {
460        return new BIncInst(aLocal, aConstant);
461   }
462   
463     public LookupSwitchInst newLookupSwitchInst(Unit defaultTarget,
464                              List lookupValues, List targets)
465     {
466         return new BLookupSwitchInst(defaultTarget, lookupValues, targets);
467     }
468
469     public TableSwitchInst newTableSwitchInst(Unit defaultTarget,
470                              int lowIndex, int highIndex, List targets)
471     {
472         return new BTableSwitchInst(defaultTarget, lowIndex,
473                                      highIndex, targets);
474     }
475
476
477
478     public static String JavaDoc bafDescriptorOf(Type type)
479     {
480         TypeSwitch sw;
481
482         type.apply(sw = new TypeSwitch()
483         {
484             public void caseBooleanType(BooleanType t)
485             {
486                 setResult("b");
487             }
488
489             public void caseByteType(ByteType t)
490             {
491                 setResult("b");
492             }
493
494             public void caseCharType(CharType t)
495             {
496                 setResult("c");
497             }
498
499             public void caseDoubleType(DoubleType t)
500             {
501                 setResult("d");
502             }
503
504             public void caseFloatType(FloatType t)
505             {
506                 setResult("f");
507             }
508
509             public void caseIntType(IntType t)
510             {
511                 setResult("i");
512             }
513
514             public void caseLongType(LongType t)
515             {
516                 setResult("l");
517             }
518
519             public void caseShortType(ShortType t)
520             {
521                 setResult("s");
522             }
523
524             
525             public void defaultCase(Type t)
526             {
527                 throw new RuntimeException JavaDoc("Invalid type: " + t);
528             }
529
530             public void caseRefType(RefType t)
531             {
532                 setResult("r");
533             }
534
535
536         });
537
538         return (String JavaDoc) sw.getResult();
539     }
540
541
542     /** Returns an empty BafBody associated with method m. */
543     public BafBody newBody(SootMethod m)
544     {
545         return new BafBody(m);
546     }
547
548     /** Returns a BafBody constructed from b. */
549     public BafBody newBody(Body b)
550     {
551         return new BafBody(b, new HashMap());
552     }
553
554     /** Returns a BafBody constructed from b. */
555     public BafBody newBody(Body b, String JavaDoc phase)
556     {
557         Map options = PhaseOptions.v().getPhaseOptions(phase);
558         return new BafBody(b, options);
559     }
560 }
561
Popular Tags