Mercurial > hg > truffle
comparison graal/com.oracle.max.graal.compiler/src/com/sun/c1x/ir/ExceptionDispatch.java @ 2872:0341b6424579
Project renaming.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 08 Jun 2011 08:42:25 +0200 |
parents | graal/GraalCompiler/src/com/sun/c1x/ir/ExceptionDispatch.java@14708c03abba |
children |
comparison
equal
deleted
inserted
replaced
2871:d704eb526603 | 2872:0341b6424579 |
---|---|
1 /* | |
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.sun.c1x.ir; | |
24 | |
25 import com.oracle.graal.graph.*; | |
26 import com.sun.c1x.debug.*; | |
27 import com.sun.cri.ci.*; | |
28 import com.sun.cri.ri.*; | |
29 | |
30 /** | |
31 * This instruction takes an exception object and has two successors: | |
32 * The catchSuccessor is called whenever the exception matches the given type, otherwise otherSuccessor is called. | |
33 */ | |
34 public final class ExceptionDispatch extends BlockEnd { | |
35 | |
36 private static final int INPUT_COUNT = 1; | |
37 private static final int INPUT_EXCEPTION = 0; | |
38 | |
39 private static final int SUCCESSOR_COUNT = 0; | |
40 | |
41 @Override | |
42 protected int inputCount() { | |
43 return super.inputCount() + INPUT_COUNT; | |
44 } | |
45 | |
46 @Override | |
47 protected int successorCount() { | |
48 return super.successorCount() + SUCCESSOR_COUNT; | |
49 } | |
50 | |
51 /** | |
52 * The instruction producing the exception object. | |
53 */ | |
54 public Value exception() { | |
55 return (Value) inputs().get(super.inputCount() + INPUT_EXCEPTION); | |
56 } | |
57 | |
58 public Value setException(Value n) { | |
59 return (Value) inputs().set(super.inputCount() + INPUT_EXCEPTION, n); | |
60 } | |
61 | |
62 private final RiType catchType; | |
63 | |
64 /** | |
65 * Constructs a new ExceptionDispatch instruction. | |
66 */ | |
67 public ExceptionDispatch(Value exception, Instruction catchSuccessor, Instruction otherSuccessor, RiType catchType, Graph graph) { | |
68 super(CiKind.Int, 2, INPUT_COUNT, SUCCESSOR_COUNT, graph); | |
69 setException(exception); | |
70 setBlockSuccessor(0, otherSuccessor); | |
71 setBlockSuccessor(1, catchSuccessor); | |
72 this.catchType = catchType; | |
73 } | |
74 | |
75 public RiType catchType() { | |
76 return catchType; | |
77 } | |
78 | |
79 /** | |
80 * Gets the block corresponding to the catch block. | |
81 * @return the true successor | |
82 */ | |
83 public Instruction catchSuccessor() { | |
84 return blockSuccessor(1); | |
85 } | |
86 | |
87 /** | |
88 * Gets the block corresponding to the rest of the dispatch chain. | |
89 * @return the false successor | |
90 */ | |
91 public Instruction otherSuccessor() { | |
92 return blockSuccessor(0); | |
93 } | |
94 | |
95 /** | |
96 * Gets the block corresponding to the specified outcome of the branch. | |
97 * @param istrue {@code true} if the true successor is requested, {@code false} otherwise | |
98 * @return the corresponding successor | |
99 */ | |
100 public Instruction successor(boolean istrue) { | |
101 return blockSuccessor(istrue ? 1 : 0); | |
102 } | |
103 | |
104 @Override | |
105 public void accept(ValueVisitor v) { | |
106 v.visitExceptionDispatch(this); | |
107 } | |
108 | |
109 @Override | |
110 public void print(LogStream out) { | |
111 out.print("exception_dispatch "). | |
112 print(exception()). | |
113 print(' '). | |
114 print("instanceof"). | |
115 print(' '). | |
116 print(catchType().name()). | |
117 print(" then "). | |
118 print(blockSuccessors().get(1).toString()). | |
119 print(" else B"). | |
120 print(blockSuccessors().get(0).toString()); | |
121 } | |
122 | |
123 @Override | |
124 public String shortName() { | |
125 return "Dispatch " + catchType().name(); | |
126 } | |
127 | |
128 @Override | |
129 public Node copy(Graph into) { | |
130 ExceptionDispatch x = new ExceptionDispatch(null, null, null, catchType, into); | |
131 return x; | |
132 } | |
133 } |