1 /*
   2  * Copyright (c) 2012, 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.PrimitiveConstant;
  36 import jdk.vm.ci.meta.ResolvedJavaType;
  37 
  38 /**
  39  * This stamp represents the type of the {@link JavaKind#Illegal} value in the second slot of
  40  * {@link JavaKind#Long} and {@link JavaKind#Double} values. It can only appear in framestates or
  41  * virtual objects.
  42  */
  43 public final class IllegalStamp extends Stamp {
  44 
  45     private IllegalStamp() {
  46     }
  47 
  48     @Override
  49     public void accept(Visitor v) {
  50     }
  51 
  52     @Override
  53     public JavaKind getStackKind() {
  54         return JavaKind.Illegal;
  55     }
  56 
  57     @Override
  58     public LIRKind getLIRKind(LIRKindTool tool) {
  59         return LIRKind.Illegal;
  60     }
  61 
  62     @Override
  63     public Stamp unrestricted() {
  64         return this;
  65     }
  66 
  67     @Override
  68     public boolean isUnrestricted() {
  69         return true;
  70     }
  71 
  72     @Override
  73     public Stamp empty() {
  74         return this;
  75     }
  76 
  77     @Override
  78     public Stamp constant(Constant c, MetaAccessProvider meta) {
  79         assert ((PrimitiveConstant) c).getJavaKind() == JavaKind.Illegal;
  80         return this;
  81     }
  82 
  83     @Override
  84     public ResolvedJavaType javaType(MetaAccessProvider metaAccess) {
  85         throw GraalError.shouldNotReachHere("illegal stamp has no Java type");
  86     }
  87 
  88     @Override
  89     public Stamp meet(Stamp other) {
  90         assert other instanceof IllegalStamp;
  91         return this;
  92     }
  93 
  94     @Override
  95     public Stamp join(Stamp other) {
  96         assert other instanceof IllegalStamp;
  97         return this;
  98     }
  99 
 100     @Override
 101     public boolean isCompatible(Stamp stamp) {
 102         return stamp instanceof IllegalStamp;
 103     }
 104 
 105     @Override
 106     public boolean isCompatible(Constant constant) {
 107         if (constant instanceof PrimitiveConstant) {
 108             PrimitiveConstant prim = (PrimitiveConstant) constant;
 109             return prim.getJavaKind() == JavaKind.Illegal;
 110         }
 111         return false;
 112     }
 113 
 114     @Override
 115     public String toString() {
 116         return "ILLEGAL";
 117     }
 118 
 119     @Override
 120     public boolean hasValues() {
 121         return true;
 122     }
 123 
 124     @Override
 125     public Stamp improveWith(Stamp other) {
 126         assert other instanceof IllegalStamp;
 127         return this;
 128     }
 129 
 130     @Override
 131     public Constant readConstant(MemoryAccessProvider provider, Constant base, long displacement) {
 132         throw GraalError.shouldNotReachHere("can't read values of illegal stamp");
 133     }
 134 
 135     private static final IllegalStamp instance = new IllegalStamp();
 136 
 137     static IllegalStamp getInstance() {
 138         return instance;
 139     }
 140 }