1 /* 2 * Copyright (c) 2015, 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 org.graalvm.compiler.core.common.type; 24 25 import org.graalvm.compiler.core.common.LIRKind; 26 import org.graalvm.compiler.core.common.spi.LIRKindTool; 27 import org.graalvm.compiler.debug.GraalError; 28 29 import jdk.vm.ci.meta.Constant; 30 import jdk.vm.ci.meta.MemoryAccessProvider; 31 import jdk.vm.ci.meta.MetaAccessProvider; 32 import jdk.vm.ci.meta.PrimitiveConstant; 33 import jdk.vm.ci.meta.ResolvedJavaType; 34 35 /** 36 * Type describing pointers to raw memory. This stamp is used for example for direct pointers to 37 * fields or array elements. 38 */ 39 public class RawPointerStamp extends AbstractPointerStamp { 40 41 protected RawPointerStamp() { 42 super(false, false); 43 } 44 45 @Override 46 public LIRKind getLIRKind(LIRKindTool tool) { 47 return tool.getWordKind(); 48 } 49 50 @Override 51 protected AbstractPointerStamp copyWith(boolean newNonNull, boolean newAlwaysNull) { 52 // RawPointerStamp is a singleton 53 assert newNonNull == nonNull() && newAlwaysNull == alwaysNull(); 54 return this; 55 } 56 57 @Override 58 public Stamp meet(Stamp other) { 59 assert isCompatible(other); 60 return this; 61 } 62 63 @Override 64 public Stamp improveWith(Stamp other) { 65 return this; 66 } 67 68 @Override 69 public Stamp join(Stamp other) { 70 assert isCompatible(other); 71 return this; 72 } 73 74 @Override 75 public Stamp unrestricted() { 76 return this; 77 } 78 79 @Override 80 public Stamp empty() { 81 // there is no empty pointer stamp 82 return this; 83 } 84 85 @Override 86 public boolean hasValues() { 87 return true; 88 } 89 90 @Override 91 public ResolvedJavaType javaType(MetaAccessProvider metaAccess) { 92 throw GraalError.shouldNotReachHere("pointer has no Java type"); 93 } 94 95 @Override 96 public Stamp constant(Constant c, MetaAccessProvider meta) { 97 return this; 98 } 99 100 @Override 101 public boolean isCompatible(Stamp other) { 102 return other instanceof RawPointerStamp; 103 } 104 105 @Override 106 public boolean isCompatible(Constant constant) { 107 if (constant instanceof PrimitiveConstant) { 108 return ((PrimitiveConstant) constant).getJavaKind().isNumericInteger(); 109 } else { 110 return constant instanceof DataPointerConstant; 111 } 112 } 113 114 @Override 115 public Constant readConstant(MemoryAccessProvider provider, Constant base, long displacement) { 116 throw GraalError.shouldNotReachHere("can't read raw pointer"); 117 } 118 119 @Override 120 public String toString() { 121 return "void*"; 122 } 123 }