01: /* Soot - a J*va Optimization Framework
02: * Copyright (C) 1997-1999 Raja Vallee-Rai
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.jbco.bafTransformations;
21:
22: import java.util.HashMap;
23: import java.util.Iterator;
24: import java.util.Map;
25:
26: import soot.Body;
27: import soot.BodyTransformer;
28: import soot.Local;
29: import soot.jbco.IJbcoTransform;
30: import soot.util.Chain;
31:
32: /**
33: * @author Michael Batchelder
34: *
35: * Created on 16-Jun-2006
36: */
37: public class Jimple2BafLocalBuilder extends BodyTransformer implements
38: IJbcoTransform {
39:
40: public static String dependancies[] = new String[] { "jtp.jbco_jl",
41: "bb.jbco_j2bl", "bb.lp" };
42:
43: public String[] getDependancies() {
44: return dependancies;
45: }
46:
47: public static String name = "bb.jbco_j2bl";
48:
49: public String getName() {
50: return name;
51: }
52:
53: public void outputSummary() {
54: }
55:
56: private static boolean runOnce = false;
57:
58: protected void internalTransform(Body b, String phaseName,
59: Map options) {
60: if (soot.jbco.Main.methods2JLocals.size() == 0) {
61: if (!runOnce) {
62: runOnce = true;
63: out
64: .println("[Jimple2BafLocalBuilder]:: Jimple Local Lists have not been built");
65: out
66: .println(" Skipping Jimple To Baf Builder\n");
67: }
68: return;
69: }
70:
71: Chain bLocals = b.getLocals();
72: HashMap<Local, Local> bafToJLocals = new HashMap<Local, Local>();
73: Iterator jlocIt = soot.jbco.Main.methods2JLocals.get(
74: b.getMethod()).iterator();
75: while (jlocIt.hasNext()) {
76: Local jl = (Local) jlocIt.next();
77: Iterator blocIt = bLocals.iterator();
78: while (blocIt.hasNext()) {
79: Local bl = (Local) blocIt.next();
80: if (bl.getName().equals(jl.getName())) {
81: bafToJLocals.put(bl, jl);
82: break;
83: }
84: }
85: }
86: soot.jbco.Main.methods2Baf2JLocals.put(b.getMethod(),
87: bafToJLocals);
88: }
89: }
|