Mercurial > hg > truffle
diff graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Value.java @ 18186:ef357effbda7
Backout of changeset 9a804ec7f707 (converted Constant and Value to be interfaces).
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Thu, 30 Oct 2014 11:18:48 +0100 |
parents | c88ab4f1f04a |
children | 56cc1a799a60 |
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Value.java Wed Oct 29 15:23:46 2014 +0100 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Value.java Thu Oct 30 11:18:48 2014 +0100 @@ -22,13 +22,17 @@ */ package com.oracle.graal.api.meta; +import java.io.*; + /** * Abstract base class for values manipulated by the compiler. All values have a {@linkplain Kind * kind} and are immutable. */ -public interface Value extends KindProvider { +public abstract class Value implements Serializable, KindProvider { - @SuppressWarnings("serial") AllocatableValue ILLEGAL = new AllocatableValue(LIRKind.Illegal) { + private static final long serialVersionUID = -6909397188697766469L; + + @SuppressWarnings("serial") public static final AllocatableValue ILLEGAL = new AllocatableValue(LIRKind.Illegal) { @Override public String toString() { @@ -36,25 +40,62 @@ } }; + private final Kind kind; + private final LIRKind lirKind; + + /** + * Initializes a new value of the specified kind. + * + * @param lirKind the kind + */ + protected Value(LIRKind lirKind) { + this.lirKind = lirKind; + if (getPlatformKind() instanceof Kind) { + this.kind = (Kind) getPlatformKind(); + } else { + this.kind = Kind.Illegal; + } + } + /** * Returns a String representation of the kind, which should be the end of all * {@link #toString()} implementation of subclasses. */ - default String getKindSuffix() { + protected final String getKindSuffix() { return "|" + getKind().getTypeChar(); } /** * Returns the kind of this value. */ - Kind getKind(); + public final Kind getKind() { + return kind; + } - LIRKind getLIRKind(); + public final LIRKind getLIRKind() { + return lirKind; + } /** * Returns the platform specific kind used to store this value. */ - PlatformKind getPlatformKind(); + public final PlatformKind getPlatformKind() { + return lirKind.getPlatformKind(); + } + + @Override + public int hashCode() { + return 41 + lirKind.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof Value) { + Value that = (Value) obj; + return kind.equals(that.kind) && lirKind.equals(that.lirKind); + } + return false; + } /** * Checks if this value is identical to {@code other}. @@ -63,7 +104,7 @@ * should be used. */ @ExcludeFromIdentityComparisonVerification - default boolean identityEquals(Value other) { + public final boolean identityEquals(Value other) { return this == other; } }