1 /* 2 * Copyright (c) 2014, 2014, 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 org.graalvm.compiler.core.common.type; 24 25 import jdk.vm.ci.meta.Constant; 26 import jdk.vm.ci.meta.MemoryAccessProvider; 27 28 /** 29 * Type describing primitive values. 30 */ 31 public abstract class PrimitiveStamp extends ArithmeticStamp { 32 33 private final int bits; 34 35 protected PrimitiveStamp(int bits, ArithmeticOpTable ops) { 36 super(ops); 37 this.bits = bits; 38 } 39 40 /** 41 * The width in bits of the value described by this stamp. 42 */ 43 public int getBits() { 44 return bits; 45 } 46 47 public static int getBits(Stamp stamp) { 48 if (stamp instanceof PrimitiveStamp) { 49 return ((PrimitiveStamp) stamp).getBits(); 50 } else { 51 return 0; 52 } 53 } 54 55 @Override 56 public Constant readConstant(MemoryAccessProvider provider, Constant base, long displacement) { 57 return provider.readPrimitiveConstant(getStackKind(), base, displacement, getBits()); 58 } 59 60 @Override 61 public int hashCode() { 62 final int prime = 31; 63 int result = super.hashCode(); 64 result = prime * result + bits; 65 return result; 66 } 67 68 @Override 69 public boolean equals(Object obj) { 70 if (this == obj) { 71 return true; 72 } 73 if (!(obj instanceof PrimitiveStamp)) { 74 return false; 75 } 76 PrimitiveStamp other = (PrimitiveStamp) obj; 77 if (bits != other.bits) { 78 return false; 79 } 80 return super.equals(obj); 81 } 82 }