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