1 kkz      1.1 // ResilientNoSSA.java, created Fri Jan 24 15:18:27 2003 by kkz
 2 kkz      1.1 // Copyright (C) 2000 Karen Zee <kkz@tmi.lcs.mit.edu>
 3 kkz      1.1 // Licensed under the terms of the GNU GPL; see COPYING for details.
 4 kkz      1.1 package harpoon.IR.Quads;
 5 kkz      1.1 
 6 kkz      1.3 import harpoon.Analysis.ClassHierarchy;
 7 kkz      1.1 import harpoon.ClassFile.HCode;
 8 kkz      1.1 import harpoon.ClassFile.HCodeAndMaps;
 9 kkz      1.1 import harpoon.ClassFile.HCodeFactory;
10 kkz      1.1 import harpoon.ClassFile.HMethod;
11 kkz      1.1 
12 kkz      1.1 /**
13 kkz      1.1  * <code>ResilientNoSSA</code> is a code view with resilient exception
14 kkz      1.1  * handling.  It does not have <code>HANDLER</code> quads, and is not
15 kkz      1.1  * in SSA form.
16 kkz      1.1  * 
17 kkz      1.1  * @author  Karen Zee <kkz@tmi.lcs.mit.edu>
18 kkz      1.3  * @version $Id: ResilientNoSSA.java,v 1.3 2003/03/15 23:24:58 kkz Exp $ */
19 kkz      1.1 public class ResilientNoSSA extends Code {
20 kkz      1.1         /** The name of this code view. */
21 kkz      1.1     public static final String codename = "resilient-no-ssa";
22 kkz      1.1     
23 kkz      1.1     /** Creates a <code>ResilientNoSSA</code> object from a
24 kkz      1.1      *  <code>QuadWithTry</code> object. */
25 kkz      1.3     ResilientNoSSA(Code qwt, ClassHierarchy ch, boolean coalesce) {
26 kkz      1.1         super(qwt.getMethod(), null);
27 kkz      1.1         assert qwt.getName().equals(QuadWithTry.codename) :
28 kkz      1.1             "can't make resilient-no-ssa from "+qwt.getName();
29 kkz      1.3         this.quads = ResilientUnHandler.unhandler(this.qf, qwt, ch, coalesce);
30 kkz      1.1         Peephole.optimize(this.quads);
31 kkz      1.1         Prune.prune(this);
32 kkz      1.1     }
33 kkz      1.1     protected ResilientNoSSA(HMethod parent, Quad quads) {
34 kkz      1.1         super(parent, quads);
35 kkz      1.1     }
36 kkz      1.1     /** Clone this code representation.  The clone has its own copy of
37 kkz      1.1      *  the quad graph. */
38 cananian 1.2     public HCodeAndMaps<Quad> clone(HMethod newMethod) {
39 kkz      1.1         return cloneHelper(new ResilientNoSSA(newMethod, null));
40 kkz      1.1     }
41 kkz      1.1     /**
42 kkz      1.1      * Return the name of this code view.
43 kkz      1.1      * @return the string <code>"quad-no-ssa"</code>.
44 kkz      1.1      */
45 kkz      1.1     public String getName() { return codename; }
46 kkz      1.1 
47 kkz      1.1     /** Return a code factory for <code>ResilientNoSSA</code>, given a
48 kkz      1.1      *  code factory for <code>QuadWithTry</code>.  Given a code
49 kkz      1.1      *  factory for <code>Bytecode</code>, chain through
50 kkz      1.1      *  <code>QuadWithTry.codeFactory()</code>.  */
51 kkz      1.3     public static HCodeFactory codeFactory(final HCodeFactory hcf,
52 kkz      1.3                                            final ClassHierarchy ch) {
53 kkz      1.1         if (hcf.getCodeName().equals(codename)) return hcf;
54 kkz      1.1         if (hcf.getCodeName().equals(QuadWithTry.codename)) {
55 kkz      1.1             return new harpoon.ClassFile.SerializableCodeFactory() {
56 kkz      1.1                 public HCode convert(HMethod m) {
57 kkz      1.1                     HCode c = hcf.convert(m);
58 kkz      1.1                     return (c==null) ? null :
59 kkz      1.3                         new ResilientNoSSA((Code)c, ch,
60 kkz      1.1                                            !Boolean.getBoolean
61 kkz      1.1                                            ("harpoon.quads.nocoalesce"));
62 kkz      1.1                     // set harpoon.quads.nocoalesce to true to disable
63 kkz      1.1                     // coalescing exception handling.  disabling this
64 kkz      1.1                     // will result in shorter branches, on average.
65 kkz      1.1                 }
66 kkz      1.1                 public void clear(HMethod m) { hcf.clear(m); }
67 kkz      1.1                 public String getCodeName() { return codename; }
68 kkz      1.1             };
69 kkz      1.1         }else if (hcf.getCodeName().equals(harpoon.IR.Bytecode.Code.codename)){
70 kkz      1.1             // implicit chaining
71 kkz      1.3             return codeFactory(QuadWithTry.codeFactory(hcf), ch);
72 kkz      1.1         } else throw new Error("don't know how to make " + codename +
73 kkz      1.1                                " from " + hcf.getCodeName());
74 kkz      1.1     }
75 kkz      1.1 }