Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeCodeGenerator.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 | d81ff782fa1a |
comparison
equal
deleted
inserted
replaced
8241:91982900acee | 8242:ac4e8c16ffdf |
---|---|
69 } | 69 } |
70 | 70 |
71 private static String specializationId(SpecializationData specialization) { | 71 private static String specializationId(SpecializationData specialization) { |
72 String name = ""; | 72 String name = ""; |
73 NodeData node = specialization.getNode(); | 73 NodeData node = specialization.getNode(); |
74 if (node.getSpecializations().length > 1) { | 74 if (node.getSpecializations().size() > 1) { |
75 name = specialization.getMethodName(); | 75 name = specialization.getMethodName(); |
76 if (name.startsWith("do")) { | 76 if (name.startsWith("do")) { |
77 name = name.substring(2); | 77 name = name.substring(2); |
78 } | 78 } |
79 } | 79 } |
478 Modifier createVisibility = Utils.getVisibility(clazz.getModifiers()); | 478 Modifier createVisibility = Utils.getVisibility(clazz.getModifiers()); |
479 | 479 |
480 if (node.needsFactory()) { | 480 if (node.needsFactory()) { |
481 createFactoryMethods(node, clazz, createVisibility); | 481 createFactoryMethods(node, clazz, createVisibility); |
482 | 482 |
483 if (node.getSpecializations().length > 1) { | 483 if (node.getSpecializations().size() > 1) { |
484 clazz.add(createCreateSpecializedMethod(node, createVisibility)); | 484 clazz.add(createCreateSpecializedMethod(node, createVisibility)); |
485 } | 485 } |
486 | 486 |
487 if (node.needsRewrites(getContext())) { | 487 if (node.needsRewrites(getContext())) { |
488 clazz.add(createSpecializeMethod(node)); | 488 clazz.add(createSpecializeMethod(node)); |
779 method.getModifiers().add(Modifier.STATIC); | 779 method.getModifiers().add(Modifier.STATIC); |
780 method.setReturnType(node.getNodeType()); | 780 method.setReturnType(node.getNodeType()); |
781 | 781 |
782 CodeTreeBuilder body = method.createBuilder(); | 782 CodeTreeBuilder body = method.createBuilder(); |
783 body.startReturn(); | 783 body.startReturn(); |
784 if (node.getSpecializations().length == 0) { | 784 if (node.getSpecializations().isEmpty()) { |
785 body.null_(); | 785 body.null_(); |
786 } else { | 786 } else { |
787 body.startNew(nodeClassName(node.getSpecializations()[0])); | 787 body.startNew(nodeClassName(node.getSpecializations().get(0))); |
788 for (VariableElement var : method.getParameters()) { | 788 for (VariableElement var : method.getParameters()) { |
789 body.string(var.getSimpleName().toString()); | 789 body.string(var.getSimpleName().toString()); |
790 } | 790 } |
791 body.end(); | 791 body.end(); |
792 } | 792 } |
834 method.addParameter(new CodeVariableElement(node.getNodeType(), THIS_NODE_LOCAL_VAR_NAME)); | 834 method.addParameter(new CodeVariableElement(node.getNodeType(), THIS_NODE_LOCAL_VAR_NAME)); |
835 method.addParameter(new CodeVariableElement(getContext().getType(Class.class), "minimumState")); | 835 method.addParameter(new CodeVariableElement(getContext().getType(Class.class), "minimumState")); |
836 addValueParameters(method, node.getGenericSpecialization(), false); | 836 addValueParameters(method, node.getGenericSpecialization(), false); |
837 | 837 |
838 CodeTreeBuilder body = method.createBuilder(); | 838 CodeTreeBuilder body = method.createBuilder(); |
839 body.startStatement().string("boolean allowed = (minimumState == ").string(nodeClassName(node.getSpecializations()[0])).string(".class)").end(); | 839 body.startStatement().string("boolean allowed = (minimumState == ").string(nodeClassName(node.getSpecializations().get(0))).string(".class)").end(); |
840 | 840 |
841 for (int i = 1; i < node.getSpecializations().length; i++) { | 841 for (int i = 1; i < node.getSpecializations().size(); i++) { |
842 SpecializationData specialization = node.getSpecializations()[i]; | 842 SpecializationData specialization = node.getSpecializations().get(i); |
843 body.startStatement().string("allowed = allowed || (minimumState == ").string(nodeClassName(specialization)).string(".class)").end(); | 843 body.startStatement().string("allowed = allowed || (minimumState == ").string(nodeClassName(specialization)).string(".class)").end(); |
844 | 844 |
845 CodeTreeBuilder guarded = new CodeTreeBuilder(body); | 845 CodeTreeBuilder guarded = new CodeTreeBuilder(body); |
846 guarded.startReturn().startNew(nodeClassName(specialization)); | 846 guarded.startReturn().startNew(nodeClassName(specialization)); |
847 guarded.string(THIS_NODE_LOCAL_VAR_NAME); | 847 guarded.string(THIS_NODE_LOCAL_VAR_NAME); |
857 private List<CodeExecutableElement> createGeneratedGenericMethod(NodeData node) { | 857 private List<CodeExecutableElement> createGeneratedGenericMethod(NodeData node) { |
858 TypeMirror genericReturnType = node.getGenericSpecialization().getReturnType().getActualType(); | 858 TypeMirror genericReturnType = node.getGenericSpecialization().getReturnType().getActualType(); |
859 if (node.getGenericSpecialization().isUseSpecializationsForGeneric()) { | 859 if (node.getGenericSpecialization().isUseSpecializationsForGeneric()) { |
860 List<CodeExecutableElement> methods = new ArrayList<>(); | 860 List<CodeExecutableElement> methods = new ArrayList<>(); |
861 | 861 |
862 SpecializationData[] specializations = node.getSpecializations(); | 862 List<SpecializationData> specializations = node.getSpecializations(); |
863 SpecializationData prev = null; | 863 SpecializationData prev = null; |
864 for (int i = 0; i < specializations.length; i++) { | 864 for (int i = 0; i < specializations.size(); i++) { |
865 SpecializationData current = specializations[i]; | 865 SpecializationData current = specializations.get(i); |
866 SpecializationData next = i + 1 < specializations.length ? specializations[i + 1] : null; | 866 SpecializationData next = i + 1 < specializations.size() ? specializations.get(i + 1) : null; |
867 if (prev == null || current.isUninitialized()) { | 867 if (prev == null || current.isUninitialized()) { |
868 prev = current; | 868 prev = current; |
869 continue; | 869 continue; |
870 } else { | 870 } else { |
871 String methodName = generatedGenericMethodName(current); | 871 String methodName = generatedGenericMethodName(current); |
1193 | 1193 |
1194 builder.string(valueName(param)); | 1194 builder.string(valueName(param)); |
1195 builder.string(" = "); | 1195 builder.string(" = "); |
1196 ExecutableTypeData genericExecutableType = field.getNodeData().findGenericExecutableType(getContext(), param.getActualTypeData(node.getTypeSystem())); | 1196 ExecutableTypeData genericExecutableType = field.getNodeData().findGenericExecutableType(getContext(), param.getActualTypeData(node.getTypeSystem())); |
1197 if (genericExecutableType == null) { | 1197 if (genericExecutableType == null) { |
1198 throw new AssertionError("Must have generic executable type. Parser validation most likely failed. " + Arrays.toString(field.getNodeData().getExecutableTypes())); | 1198 throw new AssertionError("Must have generic executable type. Parser validation most likely failed. " + (field.getNodeData().getExecutableTypes())); |
1199 } | 1199 } |
1200 buildExecute(builder, param, field, genericExecutableType); | 1200 buildExecute(builder, param, field, genericExecutableType); |
1201 builder.end(); | 1201 builder.end(); |
1202 | 1202 |
1203 endShortCircuit(builder, shortCircuit); | 1203 endShortCircuit(builder, shortCircuit); |