comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeCodeGenerator.java @ 14077:3ea5f337cc0d

Truffle-DSL: generate better implementations for getKind()
author Christian Humer <christian.humer@gmail.com>
date Wed, 05 Mar 2014 23:33:25 +0100
parents 2864cb92fa9a
children 0d5923064a88 5d1308c78ddc
comparison
equal deleted inserted replaced
14076:61bc19c3dcdc 14077:3ea5f337cc0d
951 } 951 }
952 952
953 if (node.getGenericSpecialization() != null && node.getGenericSpecialization().isReachable()) { 953 if (node.getGenericSpecialization() != null && node.getGenericSpecialization().isReachable()) {
954 clazz.add(createGenericExecute(node, rootGroup)); 954 clazz.add(createGenericExecute(node, rootGroup));
955 } 955 }
956
957 clazz.add(createGetKind(node, null, Kind.SPECIALIZED));
956 } 958 }
957 959
958 protected boolean needsInvokeCopyConstructorMethod() { 960 protected boolean needsInvokeCopyConstructorMethod() {
959 return getModel().getNode().isPolymorphic(); 961 return getModel().getNode().isPolymorphic();
962 }
963
964 protected CodeExecutableElement createGetKind(NodeData node, SpecializationData specialization, Kind kind) {
965 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), context.getTruffleTypes().getNodeInfoKind(), "getKind");
966
967 TypeMirror nodeInfoKind = context.getTruffleTypes().getNodeInfoKind();
968
969 CodeTreeBuilder builder = method.createBuilder();
970 if (node.isPolymorphic() && specialization == null) {
971 // assume next0 exists
972 builder.startIf().string("next0 != null && next0.getKind() == ").staticReference(nodeInfoKind, "SPECIALIZED").end();
973 builder.startBlock();
974 builder.startReturn().staticReference(nodeInfoKind, "POLYMORPHIC").end();
975 builder.end();
976 }
977
978 builder.startReturn().staticReference(nodeInfoKind, kind.name()).end();
979 return method;
960 } 980 }
961 981
962 protected CodeExecutableElement createInvokeCopyConstructor(TypeMirror baseType, SpecializationData specialization) { 982 protected CodeExecutableElement createInvokeCopyConstructor(TypeMirror baseType, SpecializationData specialization) {
963 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED), baseType, "invokeCopyConstructor"); 983 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED), baseType, "invokeCopyConstructor");
964 if (specialization == null) { 984 if (specialization == null) {
2501 if (needsInvokeCopyConstructorMethod()) { 2521 if (needsInvokeCopyConstructorMethod()) {
2502 clazz.add(createInvokeCopyConstructor(nodeGen.asType(), specialization)); 2522 clazz.add(createInvokeCopyConstructor(nodeGen.asType(), specialization));
2503 } 2523 }
2504 2524
2505 createCachedExecuteMethods(specialization); 2525 createCachedExecuteMethods(specialization);
2506 2526 clazz.add(createGetKind(specialization.getNode(), specialization, Kind.SPECIALIZED));
2507 } 2527 }
2508 2528
2509 private ExecutableElement createUpdateType(ActualParameter parameter) { 2529 private ExecutableElement createUpdateType(ActualParameter parameter) {
2510 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED), getContext().getType(void.class), createUpdateTypeName(parameter)); 2530 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED), getContext().getType(void.class), createUpdateTypeName(parameter));
2511 method.getParameters().add(new CodeVariableElement(getContext().getType(Class.class), "type")); 2531 method.getParameters().add(new CodeVariableElement(getContext().getType(Class.class), "type"));
2584 if (specialization.getNode().isPolymorphic()) { 2604 if (specialization.getNode().isPolymorphic()) {
2585 getElement().add(createUpdateTypes(nodeGen.asType())); 2605 getElement().add(createUpdateTypes(nodeGen.asType()));
2586 } 2606 }
2587 if (needsInvokeCopyConstructorMethod()) { 2607 if (needsInvokeCopyConstructorMethod()) {
2588 clazz.add(createInvokeCopyConstructor(nodeGen.asType(), specialization)); 2608 clazz.add(createInvokeCopyConstructor(nodeGen.asType(), specialization));
2609 }
2610
2611 if (specialization.isGeneric()) {
2612 clazz.add(createGetKind(specialization.getNode(), specialization, Kind.GENERIC));
2613 } else if (specialization.isUninitialized()) {
2614 clazz.add(createGetKind(specialization.getNode(), specialization, Kind.UNINITIALIZED));
2589 } 2615 }
2590 } 2616 }
2591 2617
2592 protected void createConstructors(CodeTypeElement clazz) { 2618 protected void createConstructors(CodeTypeElement clazz) {
2593 TypeElement superTypeElement = Utils.fromTypeMirror(clazz.getSuperclass()); 2619 TypeElement superTypeElement = Utils.fromTypeMirror(clazz.getSuperclass());