diff graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeCodeGenerator.java @ 8252:0905d796944a

Refactored codegen error model to make error redirection a lot easier.
author Christian Humer <christian.humer@gmail.com>
date Wed, 13 Mar 2013 19:58:28 +0100
parents cb70ed101b5f
children 4dc7034317ec
line wrap: on
line diff
--- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeCodeGenerator.java	Wed Mar 13 11:32:43 2013 +0100
+++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeCodeGenerator.java	Wed Mar 13 19:58:28 2013 +0100
@@ -182,13 +182,17 @@
         body.startCall(method.getSimpleName().toString());
     }
 
-    private static String generatedGenericMethodName(SpecializationData specialization) {
+    private String generatedGenericMethodName(SpecializationData specialization) {
         final String prefix = "generic";
 
         if (specialization == null) {
             return prefix;
         }
 
+        if (!specialization.getNode().getGenericSpecialization().isUseSpecializationsForGeneric() || !specialization.getNode().needsRewrites(context)) {
+            return prefix;
+        }
+
         SpecializationData prev = null;
         for (SpecializationData current : specialization.getNode().getSpecializations()) {
             if (specialization == current) {
@@ -250,26 +254,25 @@
         }
 
         if (implicitGuards == null && explicitGuards == null && conditionPrefix != null && !conditionPrefix.isEmpty()) {
-            builder.startIf().string(conditionPrefix).end().startBlock();
+            builder.startIf();
+            builder.string(conditionPrefix);
+            builder.end().startBlock();
             ifCount++;
         }
 
         builder.tree(guardedStatements);
 
         builder.end(ifCount);
-        if (ifCount > 0 && elseStatements != null) {
-            builder.startElseBlock();
+        if (elseStatements != null && ifCount > 0) {
             builder.tree(elseStatements);
-            builder.end();
         }
-
         return builder.getRoot();
     }
 
     private CodeTree createExplicitGuards(CodeTreeBuilder parent, String conditionPrefix, SpecializationData valueSpecialization, SpecializationData guardedSpecialization, boolean onSpecialization) {
         CodeTreeBuilder builder = new CodeTreeBuilder(parent);
         String andOperator = conditionPrefix != null ? conditionPrefix + " && " : "";
-        if (guardedSpecialization.getGuards().length > 0) {
+        if (guardedSpecialization.getGuards().size() > 0) {
             // Explicitly specified guards
             for (SpecializationGuardData guard : guardedSpecialization.getGuards()) {
                 if ((guard.isOnSpecialization() && onSpecialization) || (guard.isOnExecution() && !onSpecialization)) {
@@ -514,9 +517,11 @@
                     clazz.add(createCreateSpecializedMethod(node, createVisibility));
                 }
 
-                if (node.needsRewrites(getContext())) {
+                if (node.needsRewrites(context)) {
                     clazz.add(createSpecializeMethod(node));
+                }
 
+                if (node.getGenericSpecialization() != null) {
                     List<CodeExecutableElement> genericMethods = createGeneratedGenericMethod(node);
                     for (CodeExecutableElement method : genericMethods) {
                         clazz.add(method);
@@ -600,7 +605,7 @@
             classType = types.getDeclaredType(Utils.fromTypeMirror(classType), wildcardNodeType);
             TypeMirror returnType = types.getDeclaredType(listType, classType);
 
-            CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), returnType, "getChildrenSignature");
+            CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), returnType, "getExecutionSignature");
             CodeTreeBuilder builder = method.createBuilder();
 
             List<TypeMirror> signatureTypes = new ArrayList<>();
@@ -934,7 +939,7 @@
 
         private List<CodeExecutableElement> createGeneratedGenericMethod(NodeData node) {
             TypeMirror genericReturnType = node.getGenericSpecialization().getReturnType().getActualType();
-            if (node.getGenericSpecialization().isUseSpecializationsForGeneric()) {
+            if (node.getGenericSpecialization().isUseSpecializationsForGeneric() && node.needsRewrites(context)) {
                 List<CodeExecutableElement> methods = new ArrayList<>();
 
                 List<SpecializationData> specializations = node.getSpecializations();
@@ -974,18 +979,20 @@
             CodeTree invokeMethod = invokeMethodBuilder.getRoot();
 
             if (next != null) {
-                invokeMethod = createGuardAndCast(builder, null, current.getNode().getGenericSpecialization(), current, false, invokeMethod, null);
+                CodeTreeBuilder nextBuilder = builder.create();
+
+                nextBuilder.startReturn().startCall(generatedGenericMethodName(next));
+                nextBuilder.string(THIS_NODE_LOCAL_VAR_NAME);
+                addValueParameterNames(nextBuilder, next, null, true, true);
+                nextBuilder.end().end();
+
+                invokeMethod = createGuardAndCast(builder, null, current.getNode().getGenericSpecialization(), current, false, invokeMethod, nextBuilder.getRoot());
             }
 
             builder.tree(invokeMethod);
 
             if (next != null) {
                 builder.end();
-
-                builder.startReturn().startCall(generatedGenericMethodName(next));
-                builder.string(THIS_NODE_LOCAL_VAR_NAME);
-                addValueParameterNames(builder, next, null, true, true);
-                builder.end().end();
             }
         }
 
@@ -1209,7 +1216,7 @@
                 builder.startTryBlock();
             }
 
-            if (specialization.getMethod() == null) {
+            if (specialization.getMethod() == null && !node.needsRewrites(context)) {
                 emitEncounteredSynthetic(builder);
             } else if (specialization.isUninitialized() || specialization.isGeneric()) {
                 builder.startReturn().startCall(factoryClassName(node), generatedGenericMethodName(null));
@@ -1349,7 +1356,7 @@
             }
 
             builder.startStatement().type(shortCircuitParam.getActualType()).string(" ").string(valueName(shortCircuitParam)).string(" = ");
-            ShortCircuitData shortCircuitData = specialization.getShortCircuits()[shortCircuitIndex];
+            ShortCircuitData shortCircuitData = specialization.getShortCircuits().get(shortCircuitIndex);
 
             startCallOperationMethod(builder, shortCircuitData, false);
             addValueParameterNames(builder, shortCircuitData, exceptionParam != null ? exceptionParam.getName() : null, false, false);