1 /*
2  * Copyright (c) 2014, 2018, 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 
24 
25 package org.graalvm.compiler.core.common.type;
26 
27 import org.graalvm.compiler.core.common.LIRKind;
28 import org.graalvm.compiler.core.common.spi.LIRKindTool;
29 import org.graalvm.compiler.debug.GraalError;
30 
31 import jdk.vm.ci.meta.Constant;
32 import jdk.vm.ci.meta.JavaKind;
33 import jdk.vm.ci.meta.MemoryAccessProvider;
34 import jdk.vm.ci.meta.MetaAccessProvider;
35 import jdk.vm.ci.meta.ResolvedJavaType;
36 
37 /**
38  * Singleton stamp representing the value of type {@code void}.
39  */
40 public final class VoidStamp extends Stamp {
41 
VoidStamp()42     private VoidStamp() {
43     }
44 
45     @Override
unrestricted()46     public Stamp unrestricted() {
47         return this;
48     }
49 
50     @Override
isUnrestricted()51     public boolean isUnrestricted() {
52         return true;
53     }
54 
55     @Override
getStackKind()56     public JavaKind getStackKind() {
57         return JavaKind.Void;
58     }
59 
60     @Override
improveWith(Stamp other)61     public Stamp improveWith(Stamp other) {
62         assert other instanceof VoidStamp;
63         return this;
64     }
65 
66     @Override
getLIRKind(LIRKindTool tool)67     public LIRKind getLIRKind(LIRKindTool tool) {
68         throw GraalError.shouldNotReachHere("void stamp has no value");
69     }
70 
71     @Override
javaType(MetaAccessProvider metaAccess)72     public ResolvedJavaType javaType(MetaAccessProvider metaAccess) {
73         return metaAccess.lookupJavaType(Void.TYPE);
74     }
75 
76     @Override
toString()77     public String toString() {
78         return "void";
79     }
80 
81     @Override
alwaysDistinct(Stamp other)82     public boolean alwaysDistinct(Stamp other) {
83         return this != other;
84     }
85 
86     @Override
meet(Stamp other)87     public Stamp meet(Stamp other) {
88         assert other instanceof VoidStamp;
89         return this;
90     }
91 
92     @Override
join(Stamp other)93     public Stamp join(Stamp other) {
94         assert other instanceof VoidStamp;
95         return this;
96     }
97 
98     @Override
isCompatible(Stamp stamp)99     public boolean isCompatible(Stamp stamp) {
100         return stamp instanceof VoidStamp;
101     }
102 
103     @Override
isCompatible(Constant constant)104     public boolean isCompatible(Constant constant) {
105         return false;
106     }
107 
108     @Override
empty()109     public Stamp empty() {
110         // the void stamp is always empty
111         return this;
112     }
113 
114     @Override
hasValues()115     public boolean hasValues() {
116         return false;
117     }
118 
119     @Override
readConstant(MemoryAccessProvider provider, Constant base, long displacement)120     public Constant readConstant(MemoryAccessProvider provider, Constant base, long displacement) {
121         throw GraalError.shouldNotReachHere("can't read values of void stamp");
122     }
123 
124     @Override
constant(Constant c, MetaAccessProvider meta)125     public Stamp constant(Constant c, MetaAccessProvider meta) {
126         throw GraalError.shouldNotReachHere("void stamp has no value");
127     }
128 
129     private static final VoidStamp instance = new VoidStamp();
130 
getInstance()131     static VoidStamp getInstance() {
132         return instance;
133     }
134 }
135