1 /* 2 * Copyright (c) 2016, 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 package jdk.vm.ci.meta; 24 25 /** 26 * Represents the type of {@link Value values}. This class can be extended by compilers to track 27 * additional information about values. 28 */ 29 public abstract class ValueKind<K extends ValueKind<K>> { 30 31 private enum IllegalKind implements PlatformKind { 32 ILLEGAL; 33 34 private final EnumKey<IllegalKind> key = new EnumKey<>(this); 35 36 @Override getKey()37 public Key getKey() { 38 return key; 39 } 40 41 @Override getSizeInBytes()42 public int getSizeInBytes() { 43 return 0; 44 } 45 46 @Override getVectorLength()47 public int getVectorLength() { 48 return 0; 49 } 50 51 @Override getTypeChar()52 public char getTypeChar() { 53 return '-'; 54 } 55 } 56 57 private static class IllegalValueKind extends ValueKind<IllegalValueKind> { 58 IllegalValueKind()59 IllegalValueKind() { 60 super(IllegalKind.ILLEGAL); 61 } 62 63 @Override changeType(PlatformKind newPlatformKind)64 public IllegalValueKind changeType(PlatformKind newPlatformKind) { 65 return this; 66 } 67 68 @Override toString()69 public String toString() { 70 return "ILLEGAL"; 71 } 72 } 73 74 /** 75 * The non-type. 76 */ 77 public static final ValueKind<?> Illegal = new IllegalValueKind(); 78 79 private final PlatformKind platformKind; 80 ValueKind(PlatformKind platformKind)81 public ValueKind(PlatformKind platformKind) { 82 this.platformKind = platformKind; 83 } 84 getPlatformKind()85 public final PlatformKind getPlatformKind() { 86 return platformKind; 87 } 88 89 /** 90 * Create a new {@link ValueKind} with a different {@link PlatformKind}. Subclasses must 91 * override this to preserve the additional information added by the compiler. 92 */ changeType(PlatformKind newPlatformKind)93 public abstract K changeType(PlatformKind newPlatformKind); 94 95 /** 96 * Returns a String representation of the kind, which will be included at the end of 97 * {@link Value#toString()} implementation. Defaults to {@link #toString()} but can be 98 * overridden to provide something more specific. 99 */ getKindSuffix()100 public String getKindSuffix() { 101 return toString(); 102 } 103 } 104