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 */ 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 Stamp unrestricted() { 47 return this; 48 } 49 50 @Override 51 public boolean isUnrestricted() { 52 return true; 53 } 54 55 @Override 56 public JavaKind getStackKind() { 57 return JavaKind.Void; 58 } 59 60 @Override 61 public Stamp improveWith(Stamp other) { 62 assert other instanceof VoidStamp; 63 return this; 64 } 65 66 @Override 67 public LIRKind getLIRKind(LIRKindTool tool) { 68 throw GraalError.shouldNotReachHere("void stamp has no value"); 69 } 70 71 @Override 72 public ResolvedJavaType javaType(MetaAccessProvider metaAccess) { 73 return metaAccess.lookupJavaType(Void.TYPE); 74 } 75 76 @Override 77 public String toString() { 78 return "void"; 79 } 80 81 @Override 82 public boolean alwaysDistinct(Stamp other) { 83 return this != other; 84 } 85 86 @Override 87 public Stamp meet(Stamp other) { 88 assert other instanceof VoidStamp; 89 return this; 90 } 91 92 @Override 93 public Stamp join(Stamp other) { 94 assert other instanceof VoidStamp; 95 return this; 96 } 97 98 @Override 99 public boolean isCompatible(Stamp stamp) { 100 return stamp instanceof VoidStamp; 101 } 102 103 @Override 104 public boolean isCompatible(Constant constant) { 105 return false; 106 } 107 108 @Override 109 public Stamp empty() { 110 // the void stamp is always empty 111 return this; 112 } 113 114 @Override 115 public boolean hasValues() { 116 return false; 117 } 118 119 @Override 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 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 131 static VoidStamp getInstance() { 132 return instance; 133 } 134 }