# HG changeset patch # User Christian Humer # Date 1394058805 -3600 # Node ID 3ea5f337cc0da12c9da722ebe290794c370f0356 # Parent 61bc19c3dcdc6a9a4d13a654d1bfcaded6258418 Truffle-DSL: generate better implementations for getKind() diff -r 61bc19c3dcdc -r 3ea5f337cc0d graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeCodeGenerator.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeCodeGenerator.java Wed Mar 05 23:33:25 2014 +0100 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeCodeGenerator.java Wed Mar 05 23:33:25 2014 +0100 @@ -953,12 +953,32 @@ if (node.getGenericSpecialization() != null && node.getGenericSpecialization().isReachable()) { clazz.add(createGenericExecute(node, rootGroup)); } + + clazz.add(createGetKind(node, null, Kind.SPECIALIZED)); } protected boolean needsInvokeCopyConstructorMethod() { return getModel().getNode().isPolymorphic(); } + protected CodeExecutableElement createGetKind(NodeData node, SpecializationData specialization, Kind kind) { + CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), context.getTruffleTypes().getNodeInfoKind(), "getKind"); + + TypeMirror nodeInfoKind = context.getTruffleTypes().getNodeInfoKind(); + + CodeTreeBuilder builder = method.createBuilder(); + if (node.isPolymorphic() && specialization == null) { + // assume next0 exists + builder.startIf().string("next0 != null && next0.getKind() == ").staticReference(nodeInfoKind, "SPECIALIZED").end(); + builder.startBlock(); + builder.startReturn().staticReference(nodeInfoKind, "POLYMORPHIC").end(); + builder.end(); + } + + builder.startReturn().staticReference(nodeInfoKind, kind.name()).end(); + return method; + } + protected CodeExecutableElement createInvokeCopyConstructor(TypeMirror baseType, SpecializationData specialization) { CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED), baseType, "invokeCopyConstructor"); if (specialization == null) { @@ -2503,7 +2523,7 @@ } createCachedExecuteMethods(specialization); - + clazz.add(createGetKind(specialization.getNode(), specialization, Kind.SPECIALIZED)); } private ExecutableElement createUpdateType(ActualParameter parameter) { @@ -2587,6 +2607,12 @@ if (needsInvokeCopyConstructorMethod()) { clazz.add(createInvokeCopyConstructor(nodeGen.asType(), specialization)); } + + if (specialization.isGeneric()) { + clazz.add(createGetKind(specialization.getNode(), specialization, Kind.GENERIC)); + } else if (specialization.isUninitialized()) { + clazz.add(createGetKind(specialization.getNode(), specialization, Kind.UNINITIALIZED)); + } } protected void createConstructors(CodeTypeElement clazz) {