changeset 16903:3ca8ba1bfc21

bind a generated Node class to the NodeClass instance of the generated-from Node class
author Doug Simon <doug.simon@oracle.com>
date Sat, 23 Aug 2014 16:53:47 +0200
parents 0583d157992a
children e86071cdba96
files graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java
diffstat 1 files changed, 17 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java	Sat Aug 23 00:50:44 2014 +0200
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java	Sat Aug 23 16:53:47 2014 +0200
@@ -54,7 +54,9 @@
      */
     @SuppressWarnings("unchecked")
     public static NodeClass get(Class<?> c) {
-        Class<? extends Node> key = (Class<? extends Node>) c;
+        GeneratedNode gen = c.getAnnotation(GeneratedNode.class);
+        Class<? extends Node> key = gen == null ? (Class<? extends Node>) c : (Class<? extends Node>) gen.value();
+
         NodeClass value = (NodeClass) allClasses.get(key);
         // The fact that {@link ConcurrentHashMap#put} and {@link ConcurrentHashMap#get}
         // are used makes the double-checked locking idiom work.
@@ -162,6 +164,8 @@
             if (!info.nameTemplate().isEmpty()) {
                 newNameTemplate = info.nameTemplate();
             }
+        } else {
+            System.out.println("No NodeInfo for " + clazz);
         }
         EnumSet<InputType> newAllowedUsageTypes = EnumSet.noneOf(InputType.class);
         Class<?> current = clazz;
@@ -229,6 +233,12 @@
         fieldTypes.putAll(scanner.fieldTypes);
     }
 
+    private boolean isNodeClassFor(Node n) {
+        GeneratedNode gen = n.getClass().getAnnotation(GeneratedNode.class);
+        assert gen != null;
+        return gen.value() == getClazz();
+    }
+
     public String shortName() {
         return shortName;
     }
@@ -1199,7 +1209,7 @@
      * @param newNode the node to which the inputs should be copied.
      */
     public void copyInputs(Node node, Node newNode) {
-        assert node.getClass() == getClazz() && newNode.getClass() == getClazz();
+        assert isNodeClassFor(node) && isNodeClassFor(newNode);
 
         int index = 0;
         while (index < directInputCount) {
@@ -1221,7 +1231,7 @@
      * @param newNode the node to which the successors should be copied.
      */
     public void copySuccessors(Node node, Node newNode) {
-        assert node.getClass() == getClazz() && newNode.getClass() == getClazz();
+        assert isNodeClassFor(node) && isNodeClassFor(newNode);
 
         int index = 0;
         while (index < directSuccessorCount) {
@@ -1240,7 +1250,7 @@
     }
 
     public boolean inputsEqual(Node node, Node other) {
-        assert node.getClass() == getClazz() && other.getClass() == getClazz();
+        assert isNodeClassFor(node) && isNodeClassFor(other);
         int index = 0;
         while (index < directInputCount) {
             if (getNode(other, inputOffsets[index]) != getNode(node, inputOffsets[index])) {
@@ -1259,7 +1269,7 @@
     }
 
     public boolean successorsEqual(Node node, Node other) {
-        assert node.getClass() == getClazz() && other.getClass() == getClazz();
+        assert isNodeClassFor(node) && isNodeClassFor(other);
         int index = 0;
         while (index < directSuccessorCount) {
             if (getNode(other, successorOffsets[index]) != getNode(node, successorOffsets[index])) {
@@ -1278,7 +1288,7 @@
     }
 
     public boolean inputContains(Node node, Node other) {
-        assert node.getClass() == getClazz();
+        assert isNodeClassFor(node);
 
         int index = 0;
         while (index < directInputCount) {
@@ -1298,7 +1308,7 @@
     }
 
     public boolean successorContains(Node node, Node other) {
-        assert node.getClass() == getClazz();
+        assert isNodeClassFor(node);
 
         int index = 0;
         while (index < directSuccessorCount) {