01: /* Soot - a J*va Optimization Framework
02: * Copyright (C) 2003 Ondrej Lhotak
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the
16: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17: * Boston, MA 02111-1307, USA.
18: */
19:
20: package soot.jimple.toolkits.pointer;
21:
22: import soot.*;
23: import soot.tagkit.*;
24: import soot.jimple.*;
25:
26: import java.util.*;
27:
28: /** Adds colour tags to indicate potential aliasing between method parameters. */
29: public class ParameterAliasTagger extends BodyTransformer {
30: public ParameterAliasTagger(Singletons.Global g) {
31: }
32:
33: public static ParameterAliasTagger v() {
34: return G.v()
35: .soot_jimple_toolkits_pointer_ParameterAliasTagger();
36: }
37:
38: protected void internalTransform(Body b, String phaseName,
39: Map options) {
40: PointsToAnalysis pa = Scene.v().getPointsToAnalysis();
41: Set<IdentityStmt> parms = new HashSet<IdentityStmt>();
42:
43: for (Iterator sIt = b.getUnits().iterator(); sIt.hasNext();) {
44:
45: final Stmt s = (Stmt) sIt.next();
46: if (!(s instanceof IdentityStmt))
47: continue;
48: IdentityStmt is = (IdentityStmt) s;
49: ValueBox vb = is.getRightOpBox();
50: if (!(vb.getValue() instanceof ParameterRef))
51: continue;
52: ParameterRef pr = (ParameterRef) vb.getValue();
53: if (!(pr.getType() instanceof RefLikeType))
54: continue;
55: parms.add(is);
56: }
57:
58: int colour = 0;
59: while (!parms.isEmpty()) {
60: fill(parms, parms.iterator().next(), colour++, pa);
61: }
62: }
63:
64: private void fill(Set<IdentityStmt> parms, IdentityStmt parm,
65: int colour, PointsToAnalysis pa) {
66: if (!parms.contains(parm))
67: return;
68: parm.getRightOpBox().addTag(
69: new ColorTag(colour, "Parameter Alias"));
70: parms.remove(parm);
71: PointsToSet ps = pa.reachingObjects((Local) parm.getLeftOp());
72: for (Iterator<IdentityStmt> parm2It = (new LinkedList<IdentityStmt>(
73: parms)).iterator(); parm2It.hasNext();) {
74: final IdentityStmt parm2 = parm2It.next();
75: if (ps.hasNonEmptyIntersection(pa
76: .reachingObjects((Local) parm2.getLeftOp()))) {
77: fill(parms, parm2, colour, pa);
78: }
79: }
80: }
81: }
|