changeset 19715:ff556250415e

Merge.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Mon, 09 Mar 2015 12:03:59 +0100
parents b503dd4e723c (current diff) 2f5d4df2af90 (diff)
children 1a9bfa2c3cc9
files
diffstat 1 files changed, 47 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeGenFactory.java	Mon Mar 09 12:03:48 2015 +0100
+++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeGenFactory.java	Mon Mar 09 12:03:59 2015 +0100
@@ -867,18 +867,27 @@
             locals.addReferencesTo(executeBuilder);
             executeBuilder.end();
 
+            boolean hasExecutedUnexpected = executedType != null && !executedType.isGeneric() && !executedType.isVoid();
+
             CodeTreeBuilder contentBuilder = builder.create();
             contentBuilder.startReturn();
-            contentBuilder.tree(TypeSystemCodeGenerator.expect(executedType, returnType, executeBuilder.build()));
+            if (!hasExecutedUnexpected) {
+                if (executedType == null || executedType.needsCastTo(returnType)) {
+                    contentBuilder.cast(returnType.getPrimitiveType(), executeBuilder.build());
+                } else {
+                    contentBuilder.tree(executeBuilder.build());
+                }
+            } else {
+                contentBuilder.tree(TypeSystemCodeGenerator.expect(executedType, returnType, executeBuilder.build()));
+            }
             contentBuilder.end();
             // try catch assert if unexpected value is not expected
             CodeTree content = contentBuilder.build();
-            if (!execType.hasUnexpectedValue(context) && !returnType.isGeneric() && !returnType.isVoid()) {
+            if (!execType.hasUnexpectedValue(context) && hasExecutedUnexpected) {
                 content = wrapTryCatchUnexpected(content);
             }
             builder.tree(content);
         }
-
         return method;
     }
 
@@ -1078,7 +1087,7 @@
                 String varName = name + specialization.getIndex();
                 TypeMirror type = assumption.getExpression().getResolvedType();
                 builder.declaration(type, varName, assumptions);
-                currentValues.set(name, new LocalVariable(null, type, varName, null));
+                currentValues.set(name, new LocalVariable(null, type, varName, null, null));
             }
 
             builder.startIf();
@@ -1244,8 +1253,11 @@
             for (Parameter p : specialization.getSignatureParameters()) {
                 CodeVariableElement var = createImplicitProfileParameter(p.getSpecification().getExecution(), p.getTypeSystemType());
                 if (var != null) {
-                    // we need the original name here
-                    builder.tree(LocalVariable.fromParameter(p).createReference());
+                    LocalVariable variable = currentValues.get(p.getLocalName());
+                    if (variable == null) {
+                        throw new AssertionError("Could not bind cached value " + p.getLocalName() + ": " + currentValues);
+                    }
+                    builder.tree(variable.original().createReference());
                 }
             }
             for (CacheExpression cache : specialization.getCaches()) {
@@ -2282,7 +2294,7 @@
         String varName = name + specialization.getIndex();
         TypeMirror type = cache.getParameter().getType();
         builder.declaration(type, varName, initializer);
-        currentValues.set(name, new LocalVariable(null, type, varName, null));
+        currentValues.set(name, new LocalVariable(null, type, varName, null, null));
     }
 
     public static final class LocalContext {
@@ -2298,13 +2310,13 @@
             for (CacheExpression cache : specialization.getCaches()) {
                 Parameter cacheParameter = cache.getParameter();
                 String name = cacheParameter.getVariableElement().getSimpleName().toString();
-                set(cacheParameter.getLocalName(), new LocalVariable(cacheParameter.getTypeSystemType(), cacheParameter.getType(), name, CodeTreeBuilder.singleString("this." + name)));
+                set(cacheParameter.getLocalName(), new LocalVariable(cacheParameter.getTypeSystemType(), cacheParameter.getType(), name, CodeTreeBuilder.singleString("this." + name), null));
             }
 
             for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) {
                 String name = assumptionName(assumption);
                 TypeMirror type = assumption.getExpression().getResolvedType();
-                set(name, new LocalVariable(null, type, name, CodeTreeBuilder.singleString("this." + name)));
+                set(name, new LocalVariable(null, type, name, CodeTreeBuilder.singleString("this." + name), null));
             }
         }
 
@@ -2336,11 +2348,11 @@
 
         @SuppressWarnings("static-method")
         public LocalVariable createValue(NodeExecutionData execution, TypeData type) {
-            return new LocalVariable(type, type.getPrimitiveType(), valueName(execution), null);
+            return new LocalVariable(type, type.getPrimitiveType(), valueName(execution), null, null);
         }
 
         public LocalVariable createShortCircuitValue(NodeExecutionData execution) {
-            return new LocalVariable(factory.typeSystem.getBooleanType(), factory.getType(boolean.class), shortCircuitName(execution), null);
+            return new LocalVariable(factory.typeSystem.getBooleanType(), factory.getType(boolean.class), shortCircuitName(execution), null, null);
         }
 
         private static String valueName(NodeExecutionData execution) {
@@ -2411,11 +2423,11 @@
         }
 
         private void loadValues(int evaluatedArguments, int varargsThreshold) {
-            values.put(FRAME_VALUE, new LocalVariable(null, factory.getType(Frame.class), FRAME_VALUE, null));
+            values.put(FRAME_VALUE, new LocalVariable(null, factory.getType(Frame.class), FRAME_VALUE, null, null));
 
             for (NodeFieldData field : factory.node.getFields()) {
                 String fieldName = fieldValueName(field);
-                values.put(fieldName, new LocalVariable(null, field.getType(), fieldName, factory.accessParent(field.getName())));
+                values.put(fieldName, new LocalVariable(null, field.getType(), fieldName, factory.accessParent(field.getName()), null));
             }
 
             boolean varargs = needsVarargs(false, varargsThreshold);
@@ -2430,13 +2442,13 @@
                     if (varargs) {
                         shortCircuit = shortCircuit.accessWith(createReadVarargs(i));
                     }
-                    values.put(shortCircuit.getName(), shortCircuit);
+                    values.put(shortCircuit.getName(), shortCircuit.makeOriginal());
                 }
                 LocalVariable value = createValue(execution, factory.genericType);
                 if (varargs) {
                     value = value.accessWith(createReadVarargs(i));
                 }
-                values.put(value.getName(), value);
+                values.put(value.getName(), value.makeOriginal());
             }
         }
 
@@ -2519,6 +2531,7 @@
         private final TypeMirror typeMirror;
         private final CodeTree accessorTree;
         private final String name;
+        private final LocalVariable previous;
 
         public static LocalVariable fromParameter(Parameter parameter) {
             NodeExecutionData execution = parameter.getSpecification().getExecution();
@@ -2528,15 +2541,16 @@
             } else {
                 name = createName(execution);
             }
-            return new LocalVariable(parameter.getTypeSystemType(), parameter.getType(), name, null);
+            return new LocalVariable(parameter.getTypeSystemType(), parameter.getType(), name, null, null);
         }
 
-        private LocalVariable(TypeData type, TypeMirror typeMirror, String name, CodeTree accessorTree) {
+        private LocalVariable(TypeData type, TypeMirror typeMirror, String name, CodeTree accessorTree, LocalVariable previous) {
             Objects.requireNonNull(typeMirror);
             this.typeMirror = typeMirror;
             this.accessorTree = accessorTree;
             this.type = type;
             this.name = name;
+            this.previous = previous;
         }
 
         public TypeData getType() {
@@ -2583,19 +2597,31 @@
         }
 
         public LocalVariable newType(TypeData newType) {
-            return new LocalVariable(newType, newType.getPrimitiveType(), name, accessorTree);
+            return new LocalVariable(newType, newType.getPrimitiveType(), name, accessorTree, this);
         }
 
         public LocalVariable newType(TypeMirror newType) {
-            return new LocalVariable(type, newType, name, accessorTree);
+            return new LocalVariable(type, newType, name, accessorTree, this);
         }
 
         public LocalVariable accessWith(CodeTree tree) {
-            return new LocalVariable(type, typeMirror, name, tree);
+            return new LocalVariable(type, typeMirror, name, tree, this);
         }
 
         public LocalVariable nextName() {
-            return new LocalVariable(type, typeMirror, createNextName(name), accessorTree);
+            return new LocalVariable(type, typeMirror, createNextName(name), accessorTree, this);
+        }
+
+        public LocalVariable makeOriginal() {
+            return new LocalVariable(type, typeMirror, name, accessorTree, null);
+        }
+
+        public LocalVariable original() {
+            LocalVariable variable = this;
+            while (variable.previous != null) {
+                variable = variable.previous;
+            }
+            return variable;
         }
 
         public LocalVariable makeGeneric() {