comparison graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeData.java @ 8242:ac4e8c16ffdf

Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
author Christian Humer <christian.humer@gmail.com>
date Mon, 04 Mar 2013 15:14:11 +0100
parents 6b74ffe38183
children 703c09f8640c
comparison
equal deleted inserted replaced
8241:91982900acee 8242:ac4e8c16ffdf
33 import com.oracle.truffle.codegen.processor.template.*; 33 import com.oracle.truffle.codegen.processor.template.*;
34 import com.oracle.truffle.codegen.processor.typesystem.*; 34 import com.oracle.truffle.codegen.processor.typesystem.*;
35 35
36 public class NodeData extends Template { 36 public class NodeData extends Template {
37 37
38 private NodeData parent; 38 private NodeData declaringNode;
39 private List<NodeData> declaredChildren; 39 private List<NodeData> declaredChildren;
40 40
41 private final TypeSystemData typeSystem; 41 private final TypeSystemData typeSystem;
42 42 private List<NodeFieldData> fields;
43 private NodeFieldData[] fields;
44 private SpecializationData[] specializations;
45 private TemplateMethod[] specializationListeners;
46 private GuardData[] guards;
47 private ExecutableTypeData[] executableTypes;
48
49 private TypeMirror nodeType; 43 private TypeMirror nodeType;
44
45 private List<SpecializationData> specializations;
46 private List<SpecializationListenerData> specializationListeners;
47 private List<GuardData> guards;
48 private List<ExecutableTypeData> executableTypes;
49 private List<ShortCircuitData> shortCircuits;
50 50
51 public NodeData(TypeElement type, TypeSystemData typeSystem) { 51 public NodeData(TypeElement type, TypeSystemData typeSystem) {
52 super(type, null); 52 super(type, null);
53 this.typeSystem = typeSystem; 53 this.typeSystem = typeSystem;
54 } 54 }
93 93
94 void setDeclaredChildren(List<NodeData> declaredChildren) { 94 void setDeclaredChildren(List<NodeData> declaredChildren) {
95 this.declaredChildren = declaredChildren; 95 this.declaredChildren = declaredChildren;
96 96
97 for (NodeData child : declaredChildren) { 97 for (NodeData child : declaredChildren) {
98 child.parent = this; 98 child.declaringNode = this;
99 } 99 }
100 } 100 }
101 101
102 public NodeData getParent() { 102 public NodeData getParent() {
103 return parent; 103 return declaringNode;
104 } 104 }
105 105
106 public List<NodeData> getDeclaredChildren() { 106 public List<NodeData> getDeclaredChildren() {
107 return declaredChildren; 107 return declaredChildren;
108 } 108 }
119 if (specialization.getShortCircuits() != null) { 119 if (specialization.getShortCircuits() != null) {
120 methods.addAll(Arrays.asList(specialization.getShortCircuits())); 120 methods.addAll(Arrays.asList(specialization.getShortCircuits()));
121 } 121 }
122 } 122 }
123 123
124 methods.addAll(Arrays.asList(getSpecializationListeners())); 124 methods.addAll(getSpecializationListeners());
125 methods.addAll(Arrays.asList(getExecutableTypes())); 125 methods.addAll(getExecutableTypes());
126 methods.addAll(Arrays.asList(getGuards())); 126 methods.addAll(getGuards());
127 methods.addAll(getShortCircuits());
127 128
128 return methods; 129 return methods;
129 }
130
131 public TemplateMethod[] getSpecializationListeners() {
132 return specializationListeners;
133 } 130 }
134 131
135 public List<GuardData> findGuards(String name) { 132 public List<GuardData> findGuards(String name) {
136 List<GuardData> foundGuards = new ArrayList<>(); 133 List<GuardData> foundGuards = new ArrayList<>();
137 for (GuardData guardData : getGuards()) { 134 for (GuardData guardData : getGuards()) {
138 if (guardData.getMethodName().equals(name)) { 135 if (guardData.getMethodName().equals(name)) {
139 foundGuards.add(guardData); 136 foundGuards.add(guardData);
140 } 137 }
141 } 138 }
142 return foundGuards; 139 return foundGuards;
143 }
144
145 public ExecutableTypeData[] getExecutableTypes() {
146 return executableTypes;
147 } 140 }
148 141
149 public ExecutableTypeData findGenericExecutableType(ProcessorContext context, TypeData type) { 142 public ExecutableTypeData findGenericExecutableType(ProcessorContext context, TypeData type) {
150 List<ExecutableTypeData> types = findGenericExecutableTypes(context); 143 List<ExecutableTypeData> types = findGenericExecutableTypes(context);
151 for (ExecutableTypeData availableType : types) { 144 for (ExecutableTypeData availableType : types) {
187 } 180 }
188 } 181 }
189 return result; 182 return result;
190 } 183 }
191 184
192 public TypeMirror[] getExecutablePrimitiveTypeMirrors() { 185 public List<TypeMirror> getExecutablePrimitiveTypeMirrors() {
193 TypeMirror[] typeMirrors = new TypeMirror[executableTypes.length]; 186 List<TypeMirror> typeMirrors = new ArrayList<>();
194 for (int i = 0; i < executableTypes.length; i++) { 187 for (ExecutableTypeData executableType : executableTypes) {
195 typeMirrors[i] = executableTypes[i].getType().getPrimitiveType(); 188 typeMirrors.add(executableType.getType().getPrimitiveType());
196 } 189 }
197 return typeMirrors; 190 return typeMirrors;
198 }
199
200 void setExecutableTypes(ExecutableTypeData[] declaredExecuableTypes) {
201 this.executableTypes = declaredExecuableTypes;
202 }
203
204 void setFields(NodeFieldData[] fields) {
205 this.fields = fields;
206 }
207
208 void setSpecializations(SpecializationData[] specializations) {
209 this.specializations = specializations;
210 }
211
212 void setSpecializationListeners(TemplateMethod[] specializationListeners) {
213 this.specializationListeners = specializationListeners;
214 }
215
216 void setGuards(GuardData[] guards) {
217 this.guards = guards;
218 }
219
220 public GuardData[] getGuards() {
221 return guards;
222 } 191 }
223 192
224 public NodeFieldData[] filterFields(FieldKind fieldKind, ExecutionKind usage) { 193 public NodeFieldData[] filterFields(FieldKind fieldKind, ExecutionKind usage) {
225 List<NodeFieldData> filteredFields = new ArrayList<>(); 194 List<NodeFieldData> filteredFields = new ArrayList<>();
226 NodeFieldData[] resolvedFields = getFields(); 195 for (NodeFieldData field : getFields()) {
227 if (fields != null) { 196 if (usage == null || field.getExecutionKind() == usage) {
228 for (NodeFieldData field : resolvedFields) { 197 if (fieldKind == null || field.getKind() == fieldKind) {
229 if (usage == null || field.getExecutionKind() == usage) { 198 filteredFields.add(field);
230 if (fieldKind == null || field.getKind() == fieldKind) {
231 filteredFields.add(field);
232 }
233 } 199 }
234 } 200 }
235 } 201 }
236 return filteredFields.toArray(new NodeFieldData[filteredFields.size()]); 202 return filteredFields.toArray(new NodeFieldData[filteredFields.size()]);
237 } 203 }
256 needsRewrites = true; 222 needsRewrites = true;
257 break; 223 break;
258 } 224 }
259 } 225 }
260 226
261 needsRewrites &= specializations.length >= 2; 227 needsRewrites &= specializations.size() >= 2;
262 return needsRewrites; 228 return needsRewrites;
263 } 229 }
264 230
265 public SpecializationData getGenericSpecialization() { 231 public SpecializationData getGenericSpecialization() {
266 for (SpecializationData specialization : specializations) { 232 for (SpecializationData specialization : specializations) {
277 } else { 243 } else {
278 return null; 244 return null;
279 } 245 }
280 } 246 }
281 247
282 public NodeFieldData[] getFields() {
283 return fields;
284 }
285
286 public NodeFieldData[] getDeclaredFields() {
287 return fields;
288 }
289
290 public SpecializationData[] getSpecializations() {
291 return specializations;
292 }
293
294 public String dump() { 248 public String dump() {
295 StringBuilder b = new StringBuilder(); 249 StringBuilder b = new StringBuilder();
296 b.append(String.format("[name = %s\n" + " typeSystem = %s\n" + " fields = %s\n" + " types = %s\n" + " specializations = %s\n" + " guards = %s\n" + "]", 250 b.append(String.format("[name = %s\n" + " typeSystem = %s\n" + " fields = %s\n" + " types = %s\n" + " specializations = %s\n" + " guards = %s\n" + "]",
297 Utils.getQualifiedName(getTemplateType()), getTypeSystem(), dumpList(fields), dumpList(getExecutableTypes()), dumpList(getSpecializations()), dumpList(guards))); 251 Utils.getQualifiedName(getTemplateType()), getTypeSystem(), dumpList(fields), dumpList(getExecutableTypes()), dumpList(getSpecializations()), dumpList(guards)));
298 return b.toString(); 252 return b.toString();
299 } 253 }
300 254
301 private static String dumpList(Object[] array) { 255 private static String dumpList(List<?> array) {
302 if (array == null) { 256 if (array == null) {
303 return "null"; 257 return "null";
304 } 258 }
305 259
306 StringBuilder b = new StringBuilder(); 260 StringBuilder b = new StringBuilder();
322 } 276 }
323 } 277 }
324 return null; 278 return null;
325 } 279 }
326 280
281 public List<NodeFieldData> getFields() {
282 return fields;
283 }
284
285 void setFields(List<NodeFieldData> fields) {
286 this.fields = fields;
287 }
288
289 public List<SpecializationData> getSpecializations() {
290 return specializations;
291 }
292
293 public List<SpecializationListenerData> getSpecializationListeners() {
294 return specializationListeners;
295 }
296
297 public List<GuardData> getGuards() {
298 return guards;
299 }
300
301 public List<ExecutableTypeData> getExecutableTypes() {
302 return executableTypes;
303 }
304
305 public List<ShortCircuitData> getShortCircuits() {
306 return shortCircuits;
307 }
308
309 void setSpecializations(List<SpecializationData> specializations) {
310 this.specializations = specializations;
311 for (SpecializationData specialization : specializations) {
312 specialization.setNode(this);
313 }
314 }
315
316 void setSpecializationListeners(List<SpecializationListenerData> specializationListeners) {
317 this.specializationListeners = specializationListeners;
318 }
319
320 void setGuards(List<GuardData> guards) {
321 this.guards = guards;
322 }
323
324 void setExecutableTypes(List<ExecutableTypeData> executableTypes) {
325 this.executableTypes = executableTypes;
326 }
327
328 void setShortCircuits(List<ShortCircuitData> shortCircuits) {
329 this.shortCircuits = shortCircuits;
330 }
331
327 } 332 }