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