< prev index next >

src/jdk.vm.ci/share/classes/jdk.vm.ci.code/src/jdk/vm/ci/code/ValueUtil.java

Print this page




   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.code;
  24 
  25 import java.util.*;

  26 
  27 import jdk.vm.ci.meta.*;




  28 
  29 /**
  30  * Utility class for working with the {@link Value} class and its subclasses.
  31  */
  32 public final class ValueUtil {
  33 
  34     public static boolean isIllegal(Value value) {
  35         assert value != null;
  36         return Value.ILLEGAL.equals(value);
  37     }
  38 
  39     public static boolean isIllegalJavaValue(JavaValue value) {
  40         assert value != null;
  41         return Value.ILLEGAL.equals(value);
  42     }
  43 
  44     public static boolean isLegal(Value value) {
  45         return !isIllegal(value);
  46     }
  47 
  48     public static boolean isVirtualObject(JavaValue value) {
  49         assert value != null;
  50         return value instanceof VirtualObject;
  51     }
  52 
  53     public static VirtualObject asVirtualObject(JavaValue value) {
  54         assert value != null;
  55         return (VirtualObject) value;
  56     }
  57 
  58     public static boolean isConstantJavaValue(JavaValue value) {
  59         assert value != null;
  60         return value instanceof JavaConstant;
  61     }
  62 





  63     public static boolean isAllocatableValue(Value value) {
  64         assert value != null;
  65         return value instanceof AllocatableValue;
  66     }
  67 
  68     public static AllocatableValue asAllocatableValue(Value value) {
  69         assert value != null;
  70         return (AllocatableValue) value;
  71     }
  72 
  73     public static boolean isStackSlot(Value value) {
  74         assert value != null;
  75         return value instanceof StackSlot;
  76     }
  77 
  78     public static StackSlot asStackSlot(Value value) {
  79         assert value != null;
  80         return (StackSlot) value;
  81     }
  82 
  83     public static boolean isStackSlotValue(Value value) {
  84         assert value != null;
  85         return value instanceof StackSlotValue;
  86     }
  87 
  88     public static StackSlotValue asStackSlotValue(Value value) {
  89         assert value != null;
  90         return (StackSlotValue) value;
  91     }
  92 
  93     public static boolean isVirtualStackSlot(Value value) {
  94         assert value != null;
  95         return value instanceof VirtualStackSlot;
  96     }
  97 
  98     public static VirtualStackSlot asVirtualStackSlot(Value value) {
  99         assert value != null;
 100         return (VirtualStackSlot) value;
 101     }
 102 
 103     public static boolean isRegister(Value value) {
 104         assert value != null;
 105         return value instanceof RegisterValue;
 106     }
 107 
 108     public static Register asRegister(Value value) {
 109         return asRegisterValue(value).getRegister();
 110     }
 111 
 112     public static RegisterValue asRegisterValue(Value value) {
 113         assert value != null;
 114         return (RegisterValue) value;
 115     }
 116 
 117     public static Register asRegister(Value value, PlatformKind kind) {
 118         if (value.getPlatformKind() != kind) {
 119             throw new InternalError("needed: " + kind + " got: " + value.getPlatformKind());
 120         } else {
 121             return asRegister(value);
 122         }




   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.code;
  24 
  25 import java.util.ArrayList;
  26 import java.util.List;
  27 
  28 import jdk.vm.ci.meta.AllocatableValue;
  29 import jdk.vm.ci.meta.JavaConstant;
  30 import jdk.vm.ci.meta.JavaValue;
  31 import jdk.vm.ci.meta.PlatformKind;
  32 import jdk.vm.ci.meta.Value;
  33 
  34 /**
  35  * Utility class for working with the {@link Value} class and its subclasses.
  36  */
  37 public final class ValueUtil {
  38 
  39     public static boolean isIllegal(Value value) {
  40         assert value != null;
  41         return Value.ILLEGAL.equals(value);
  42     }
  43 
  44     public static boolean isIllegalJavaValue(JavaValue value) {
  45         assert value != null;
  46         return Value.ILLEGAL.equals(value);
  47     }
  48 
  49     public static boolean isLegal(Value value) {
  50         return !isIllegal(value);
  51     }
  52 
  53     public static boolean isVirtualObject(JavaValue value) {
  54         assert value != null;
  55         return value instanceof VirtualObject;
  56     }
  57 
  58     public static VirtualObject asVirtualObject(JavaValue value) {
  59         assert value != null;
  60         return (VirtualObject) value;
  61     }
  62 
  63     public static boolean isConstantJavaValue(JavaValue value) {
  64         assert value != null;
  65         return value instanceof JavaConstant;
  66     }
  67 
  68     public static JavaConstant asConstantJavaValue(JavaValue value) {
  69         assert value != null;
  70         return (JavaConstant) value;
  71     }
  72 
  73     public static boolean isAllocatableValue(Value value) {
  74         assert value != null;
  75         return value instanceof AllocatableValue;
  76     }
  77 
  78     public static AllocatableValue asAllocatableValue(Value value) {
  79         assert value != null;
  80         return (AllocatableValue) value;
  81     }
  82 
  83     public static boolean isStackSlot(Value value) {
  84         assert value != null;
  85         return value instanceof StackSlot;
  86     }
  87 
  88     public static StackSlot asStackSlot(Value value) {
  89         assert value != null;
  90         return (StackSlot) value;
  91     }
  92 




















  93     public static boolean isRegister(Value value) {
  94         assert value != null;
  95         return value instanceof RegisterValue;
  96     }
  97 
  98     public static Register asRegister(Value value) {
  99         return asRegisterValue(value).getRegister();
 100     }
 101 
 102     public static RegisterValue asRegisterValue(Value value) {
 103         assert value != null;
 104         return (RegisterValue) value;
 105     }
 106 
 107     public static Register asRegister(Value value, PlatformKind kind) {
 108         if (value.getPlatformKind() != kind) {
 109             throw new InternalError("needed: " + kind + " got: " + value.getPlatformKind());
 110         } else {
 111             return asRegister(value);
 112         }


< prev index next >