Mercurial > hg > graal-jvmci-8
diff graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeCodeGenerator.java @ 8251:cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Wed, 13 Mar 2013 11:32:43 +0100 |
parents | c4c3f50fa9c2 |
children | 0905d796944a |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeCodeGenerator.java Tue Mar 12 11:38:52 2013 +0100 +++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeCodeGenerator.java Wed Mar 13 11:32:43 2013 +0100 @@ -34,7 +34,8 @@ import com.oracle.truffle.api.codegen.*; import com.oracle.truffle.codegen.processor.*; import com.oracle.truffle.codegen.processor.ast.*; -import com.oracle.truffle.codegen.processor.node.NodeFieldData.*; +import com.oracle.truffle.codegen.processor.node.NodeFieldData.ExecutionKind; +import com.oracle.truffle.codegen.processor.node.NodeFieldData.FieldKind; import com.oracle.truffle.codegen.processor.template.*; import com.oracle.truffle.codegen.processor.typesystem.*; @@ -145,7 +146,9 @@ private void startCallOperationMethod(CodeTreeBuilder body, TemplateMethod templateMethod, boolean castedValues) { body.startGroup(); ExecutableElement method = templateMethod.getMethod(); - + if (method == null) { + throw new IllegalStateException("Cannot call synthtetic operation methods."); + } TypeElement targetClass = Utils.findNearestEnclosingType(method.getEnclosingElement()); NodeData node = (NodeData) templateMethod.getTemplate(); @@ -419,6 +422,10 @@ return builder.getRoot(); } + private void emitEncounteredSynthetic(CodeTreeBuilder builder) { + builder.startThrow().startNew(getContext().getType(UnsupportedOperationException.class)).end().end(); + } + @Override protected void createChildren(NodeData node) { Map<NodeData, List<TypeElement>> childTypes = new LinkedHashMap<>(); @@ -987,11 +994,15 @@ builder.startTryBlock(); } - builder.startReturn(); - startCallOperationMethod(builder, specialization, true); - addValueParameterNamesWithCasts(builder, specialization.getNode().getGenericSpecialization(), specialization, false); - builder.end().end(); // start call operation - builder.end(); // return + if (specialization.isSynthetic()) { + emitEncounteredSynthetic(builder); + } else { + builder.startReturn(); + startCallOperationMethod(builder, specialization, true); + addValueParameterNamesWithCasts(builder, specialization.getNode().getGenericSpecialization(), specialization, false); + builder.end().end(); // start call operation + builder.end(); // return + } if (!specialization.getExceptions().isEmpty()) { for (SpecializationThrowsData exception : specialization.getExceptions()) { @@ -1005,6 +1016,7 @@ builder.end(); } } + } private class SpecializedNodeFactory extends ClassElementFactory<SpecializationData> { @@ -1197,7 +1209,9 @@ builder.startTryBlock(); } - if ((specialization.isUninitialized() || specialization.isGeneric()) && node.needsRewrites(getContext())) { + if (specialization.getMethod() == null) { + emitEncounteredSynthetic(builder); + } else if (specialization.isUninitialized() || specialization.isGeneric()) { builder.startReturn().startCall(factoryClassName(node), generatedGenericMethodName(null)); builder.string("this"); addValueParameterNames(builder, specialization, null, true, true); @@ -1205,12 +1219,9 @@ } else { builder.startReturn(); - if (specialization.isUninitialized()) { - startCallOperationMethod(builder, specialization.getNode().getGenericSpecialization(), false); - } else { - startCallOperationMethod(builder, specialization, false); - } + startCallOperationMethod(builder, specialization, false); addValueParameterNames(builder, specialization, null, false, false); + builder.end().end(); // operation call builder.end(); // return }