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 JavaKind getStackKind() {
50        return JavaKind.Void;
51    }
52
53    @Override
54    public Stamp improveWith(Stamp other) {
55        assert other instanceof VoidStamp;
56        return this;
57    }
58
59    @Override
60    public LIRKind getLIRKind(LIRKindTool tool) {
61        throw GraalError.shouldNotReachHere("void stamp has no value");
62    }
63
64    @Override
65    public ResolvedJavaType javaType(MetaAccessProvider metaAccess) {
66        return metaAccess.lookupJavaType(Void.TYPE);
67    }
68
69    @Override
70    public String toString() {
71        return "void";
72    }
73
74    @Override
75    public boolean alwaysDistinct(Stamp other) {
76        return this != other;
77    }
78
79    @Override
80    public Stamp meet(Stamp other) {
81        assert other instanceof VoidStamp;
82        return this;
83    }
84
85    @Override
86    public Stamp join(Stamp other) {
87        assert other instanceof VoidStamp;
88        return this;
89    }
90
91    @Override
92    public boolean isCompatible(Stamp stamp) {
93        return stamp instanceof VoidStamp;
94    }
95
96    @Override
97    public boolean isCompatible(Constant constant) {
98        return false;
99    }
100
101    @Override
102    public Stamp empty() {
103        // the void stamp is always empty
104        return this;
105    }
106
107    @Override
108    public boolean hasValues() {
109        return false;
110    }
111
112    @Override
113    public Constant readConstant(MemoryAccessProvider provider, Constant base, long displacement) {
114        throw GraalError.shouldNotReachHere("can't read values of void stamp");
115    }
116
117    @Override
118    public Stamp constant(Constant c, MetaAccessProvider meta) {
119        throw GraalError.shouldNotReachHere("void stamp has no value");
120    }
121
122    private static final VoidStamp instance = new VoidStamp();
123
124    static VoidStamp getInstance() {
125        return instance;
126    }
127}
128