Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/serial/PostOrderSerializer.java @ 20129:5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Thu, 02 Apr 2015 01:22:41 +0200 |
parents | 45fff0246a43 |
children |
comparison
equal
deleted
inserted
replaced
20128:7ad60a16bbb0 | 20129:5b7db8941fd7 |
---|---|
28 import java.nio.*; | 28 import java.nio.*; |
29 | 29 |
30 import sun.misc.*; | 30 import sun.misc.*; |
31 | 31 |
32 import com.oracle.truffle.api.nodes.*; | 32 import com.oracle.truffle.api.nodes.*; |
33 import com.oracle.truffle.api.nodes.NodeUtil.NodeClass; | 33 import com.oracle.truffle.api.nodes.NodeFieldAccessor.NodeFieldKind; |
34 import com.oracle.truffle.api.nodes.NodeUtil.NodeField; | |
35 import com.oracle.truffle.api.nodes.NodeUtil.NodeFieldKind; | |
36 import com.oracle.truffle.api.source.*; | 34 import com.oracle.truffle.api.source.*; |
37 | 35 |
38 /** | 36 /** |
39 * Experimental API. May change without notice. | 37 * Experimental API. May change without notice. |
40 */ | 38 */ |
77 buffer.put(VariableLengthIntBuffer.NULL); | 75 buffer.put(VariableLengthIntBuffer.NULL); |
78 return; | 76 return; |
79 } | 77 } |
80 Class<? extends Node> nodeClass = node.getClass(); | 78 Class<? extends Node> nodeClass = node.getClass(); |
81 | 79 |
82 NodeField[] nodeFields = NodeClass.get(nodeClass).getFields(); | 80 NodeFieldAccessor[] nodeFields = NodeClass.get(nodeClass).getFields(); |
83 serializeChildFields(buffer, node, nodeFields); | 81 serializeChildFields(buffer, node, nodeFields); |
84 serializeChildrenFields(buffer, node, nodeFields); | 82 serializeChildrenFields(buffer, node, nodeFields); |
85 buffer.put(cp.putClass(node.getClass())); | 83 buffer.put(cp.putClass(node.getClass())); |
86 serializeDataFields(buffer, node, nodeFields); | 84 serializeDataFields(buffer, node, nodeFields); |
87 } | 85 } |
88 | 86 |
89 private void serializeDataFields(VariableLengthIntBuffer buffer, Node node, NodeField[] nodeFields) throws UnsupportedConstantPoolTypeException { | 87 private void serializeDataFields(VariableLengthIntBuffer buffer, Node node, NodeFieldAccessor[] nodeFields) throws UnsupportedConstantPoolTypeException { |
90 for (int i = 0; i < nodeFields.length; i++) { | 88 for (int i = 0; i < nodeFields.length; i++) { |
91 NodeField field = nodeFields[i]; | 89 NodeFieldAccessor field = nodeFields[i]; |
92 if (field.getKind() == NodeFieldKind.DATA) { | 90 if (field.getKind() == NodeFieldKind.DATA) { |
93 Class<?> fieldClass = field.getType(); | 91 Class<?> fieldClass = field.getType(); |
94 long offset = field.getOffset(); | 92 long offset = field.getOffset(); |
95 int cpi; | 93 int cpi; |
96 | 94 |
146 } else { | 144 } else { |
147 return cp.putObject(fieldClass, value); | 145 return cp.putObject(fieldClass, value); |
148 } | 146 } |
149 } | 147 } |
150 | 148 |
151 private void serializeChildrenFields(VariableLengthIntBuffer buffer, Node nodeInstance, NodeField[] nodeFields) throws UnsupportedConstantPoolTypeException { | 149 private void serializeChildrenFields(VariableLengthIntBuffer buffer, Node nodeInstance, NodeFieldAccessor[] nodeFields) throws UnsupportedConstantPoolTypeException { |
152 for (int i = 0; i < nodeFields.length; i++) { | 150 for (int i = 0; i < nodeFields.length; i++) { |
153 NodeField field = nodeFields[i]; | 151 NodeFieldAccessor field = nodeFields[i]; |
154 if (field.getKind() == NodeFieldKind.CHILDREN) { | 152 if (field.getKind() == NodeFieldKind.CHILDREN) { |
155 Object childArrayObject = unsafe.getObject(nodeInstance, field.getOffset()); | 153 Object childArrayObject = unsafe.getObject(nodeInstance, field.getOffset()); |
156 if (childArrayObject != null && !(childArrayObject instanceof Node[])) { | 154 if (childArrayObject != null && !(childArrayObject instanceof Node[])) { |
157 throw new AssertionError("Node children must be instanceof Node[]"); | 155 throw new AssertionError("Node children must be instanceof Node[]"); |
158 } | 156 } |
171 } | 169 } |
172 } | 170 } |
173 } | 171 } |
174 } | 172 } |
175 | 173 |
176 private void serializeChildFields(VariableLengthIntBuffer buffer, Node nodeInstance, NodeField[] nodeFields) throws UnsupportedConstantPoolTypeException { | 174 private void serializeChildFields(VariableLengthIntBuffer buffer, Node nodeInstance, NodeFieldAccessor[] nodeFields) throws UnsupportedConstantPoolTypeException { |
177 for (int i = 0; i < nodeFields.length; i++) { | 175 for (int i = 0; i < nodeFields.length; i++) { |
178 NodeField field = nodeFields[i]; | 176 NodeFieldAccessor field = nodeFields[i]; |
179 if (field.getKind() == NodeFieldKind.CHILD) { | 177 if (field.getKind() == NodeFieldKind.CHILD) { |
180 Object childObject = unsafe.getObject(nodeInstance, field.getOffset()); | 178 Object childObject = unsafe.getObject(nodeInstance, field.getOffset()); |
181 if (childObject != null && !(childObject instanceof Node)) { | 179 if (childObject != null && !(childObject instanceof Node)) { |
182 throw new AssertionError("Node children must be instanceof Node"); | 180 throw new AssertionError("Node children must be instanceof Node"); |
183 } | 181 } |