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