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