001/*
002 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package com.oracle.graal.compiler.common.type;
024
025import jdk.internal.jvmci.common.*;
026import jdk.internal.jvmci.meta.*;
027
028import com.oracle.graal.compiler.common.spi.*;
029
030/**
031 * Singleton stamp representing the value of type {@code void}.
032 */
033public final class VoidStamp extends Stamp {
034
035    private VoidStamp() {
036    }
037
038    @Override
039    public Stamp unrestricted() {
040        return this;
041    }
042
043    @Override
044    public Kind getStackKind() {
045        return Kind.Void;
046    }
047
048    @Override
049    public Stamp improveWith(Stamp other) {
050        assert other instanceof VoidStamp;
051        return this;
052    }
053
054    @Override
055    public LIRKind getLIRKind(LIRKindTool tool) {
056        throw JVMCIError.shouldNotReachHere("void stamp has no value");
057    }
058
059    @Override
060    public ResolvedJavaType javaType(MetaAccessProvider metaAccess) {
061        return metaAccess.lookupJavaType(Void.TYPE);
062    }
063
064    @Override
065    public String toString() {
066        return "void";
067    }
068
069    @Override
070    public boolean alwaysDistinct(Stamp other) {
071        return this != other;
072    }
073
074    @Override
075    public Stamp meet(Stamp other) {
076        assert other instanceof VoidStamp;
077        return this;
078    }
079
080    @Override
081    public Stamp join(Stamp other) {
082        assert other instanceof VoidStamp;
083        return this;
084    }
085
086    @Override
087    public boolean isCompatible(Stamp stamp) {
088        return stamp instanceof VoidStamp;
089    }
090
091    @Override
092    public Stamp empty() {
093        // the void stamp is always empty
094        return this;
095    }
096
097    @Override
098    public boolean hasValues() {
099        return false;
100    }
101
102    @Override
103    public Constant readConstant(MemoryAccessProvider provider, Constant base, long displacement) {
104        throw JVMCIError.shouldNotReachHere("can't read values of void stamp");
105    }
106
107    @Override
108    public Stamp constant(Constant c, MetaAccessProvider meta) {
109        throw JVMCIError.shouldNotReachHere("void stamp has no value");
110    }
111
112    private static final VoidStamp instance = new VoidStamp();
113
114    static VoidStamp getInstance() {
115        return instance;
116    }
117}