Mercurial > hg > truffle
comparison graal/Compiler/src/com/sun/c1x/ir/TypeCheck.java @ 2507:9ec15d6914ca
Pull over of compiler from maxine repository.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 27 Apr 2011 11:43:22 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2506:4a3bf8a5bf41 | 2507:9ec15d6914ca |
---|---|
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.sun.c1x.value.*; | |
26 import com.sun.cri.ci.*; | |
27 import com.sun.cri.ri.*; | |
28 | |
29 /** | |
30 * The {@code TypeCheck} instruction is the base class of casts and instanceof tests. | |
31 * | |
32 * @author Ben L. Titzer | |
33 */ | |
34 public abstract class TypeCheck extends StateSplit { | |
35 | |
36 final RiType targetClass; | |
37 public Value targetClassInstruction; | |
38 Value object; | |
39 | |
40 /** | |
41 * Creates a new TypeCheck instruction. | |
42 * @param targetClass the class which is being casted to or checked against | |
43 * @param object the instruction which produces the object | |
44 * @param kind the result type of this instruction | |
45 * @param stateBefore the state before this instruction is executed | |
46 */ | |
47 public TypeCheck(RiType targetClass, Value targetClassInstruction, Value object, CiKind kind, FrameState stateBefore) { | |
48 super(kind, stateBefore); | |
49 this.targetClass = targetClass; | |
50 this.targetClassInstruction = targetClassInstruction; | |
51 this.object = object; | |
52 } | |
53 | |
54 /** | |
55 * Gets the instruction that loads the target class object that is used by this checkcast. | |
56 * @return the target class instruction | |
57 */ | |
58 public Value targetClassInstruction() { | |
59 return targetClassInstruction; | |
60 } | |
61 | |
62 /** | |
63 * Gets the target class, i.e. the class being cast to, or the class being tested against. | |
64 * @return the target class | |
65 */ | |
66 public RiType targetClass() { | |
67 return targetClass; | |
68 } | |
69 | |
70 /** | |
71 * Gets the instruction which produces the object input. | |
72 * @return the instruction producing the object | |
73 */ | |
74 public Value object() { | |
75 return object; | |
76 } | |
77 | |
78 /** | |
79 * Checks whether the target class of this instruction is loaded. | |
80 * @return {@code true} if the target class is loaded | |
81 */ | |
82 public boolean isLoaded() { | |
83 return targetClass != null; | |
84 } | |
85 | |
86 /** | |
87 * Checks whether this instruction can trap. | |
88 * @return {@code true}, conservatively assuming the cast may fail | |
89 */ | |
90 @Override | |
91 public boolean canTrap() { | |
92 return true; | |
93 } | |
94 | |
95 /** | |
96 * Iterates over the input values to this instruction. | |
97 * @param closure the closure to apply | |
98 */ | |
99 @Override | |
100 public void inputValuesDo(ValueClosure closure) { | |
101 object = closure.apply(object); | |
102 targetClassInstruction = closure.apply(targetClassInstruction); | |
103 } | |
104 | |
105 /** | |
106 * Sets this type check operation to be a direct compare. | |
107 */ | |
108 public void setDirectCompare() { | |
109 setFlag(Flag.DirectCompare); | |
110 } | |
111 | |
112 /** | |
113 * Checks where this comparison is a direct compare, because the class compared to is a leaf class. | |
114 * @return {@code true} if this typecheck is a direct compare | |
115 */ | |
116 public boolean isDirectCompare() { | |
117 return checkFlag(Flag.DirectCompare); | |
118 } | |
119 } |