annotate graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeCodeGenerator.java @ 14567:b1dded9c748a

Merge.
author Christian Humer <christian.humer@gmail.com>
date Mon, 17 Mar 2014 14:30:59 +0100
parents 5d1308c78ddc 0d5923064a88
children 40eedef0a586
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1 /*
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
4 *
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
8 *
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
13 * accompanied this code).
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
14 *
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
18 *
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
21 * questions.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
22 */
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
23 package com.oracle.truffle.dsl.processor.node;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
24
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
25 import static com.oracle.truffle.dsl.processor.Utils.*;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
26 import static javax.lang.model.element.Modifier.*;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
27
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
28 import java.util.*;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
29
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
30 import javax.lang.model.element.*;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
31 import javax.lang.model.type.*;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
32 import javax.lang.model.util.*;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
33
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
34 import com.oracle.truffle.api.dsl.*;
10741
00a9dbcbe431 Truffle-DSL: Fixed a bug in polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents: 10695
diff changeset
35 import com.oracle.truffle.api.nodes.*;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
36 import com.oracle.truffle.dsl.processor.*;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
37 import com.oracle.truffle.dsl.processor.ast.*;
10600
e93efe3ba5f4 Truffle-DSL: rewritten polymorphic optimization for simpler generated code.
Christian Humer <christian.humer@gmail.com>
parents: 10597
diff changeset
38 import com.oracle.truffle.dsl.processor.node.NodeChildData.Cardinality;
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
39 import com.oracle.truffle.dsl.processor.node.SpecializationGroup.TypeGuard;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
40 import com.oracle.truffle.dsl.processor.template.*;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
41 import com.oracle.truffle.dsl.processor.typesystem.*;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
42
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
43 public class NodeCodeGenerator extends CompilationUnitFactory<NodeData> {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
44
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
45 private static final String THIS_NODE_LOCAL_VAR_NAME = "thisNode";
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
46
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
47 private static final String EXECUTE_GENERIC_NAME = "executeGeneric0";
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
48 private static final String EXECUTE_SPECIALIZE_NAME = "executeAndSpecialize0";
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
49 private static final String EXECUTE_POLYMORPHIC_NAME = "executePolymorphic0";
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
50
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
51 private static final String UPDATE_TYPES_NAME = "updateTypes";
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
52
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
53 public NodeCodeGenerator(ProcessorContext context) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
54 super(context);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
55 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
56
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
57 private TypeMirror getUnexpectedValueException() {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
58 return getContext().getTruffleTypes().getUnexpectedValueException();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
59 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
60
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
61 private static String factoryClassName(NodeData node) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
62 return node.getNodeId() + "Factory";
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
63 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
64
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
65 private static String nodeSpecializationClassName(SpecializationData specialization) {
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
66 String nodeid = resolveNodeId(specialization.getNode());
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
67 String name = Utils.firstLetterUpperCase(nodeid);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
68 name += Utils.firstLetterUpperCase(specialization.getId());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
69 name += "Node";
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
70 return name;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
71 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
72
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
73 private static String nodePolymorphicClassName(NodeData node) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
74 return Utils.firstLetterUpperCase(resolveNodeId(node)) + "PolymorphicNode";
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
75 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
76
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
77 private static String resolveNodeId(NodeData node) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
78 String nodeid = node.getNodeId();
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
79 if (nodeid.endsWith("Node") && !nodeid.equals("Node")) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
80 nodeid = nodeid.substring(0, nodeid.length() - 4);
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
81 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
82 return nodeid;
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
83 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
84
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
85 private static String valueNameEvaluated(ActualParameter targetParameter) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
86 return valueName(targetParameter) + "Evaluated";
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
87 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
88
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
89 private static String implicitTypeName(ActualParameter param) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
90 return param.getLocalName() + "ImplicitType";
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
91 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
92
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
93 private static String polymorphicTypeName(ActualParameter param) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
94 return param.getLocalName() + "PolymorphicType";
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
95 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
96
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
97 private static String valueName(ActualParameter param) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
98 return param.getLocalName();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
99 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
100
13861
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
101 private static CodeTree createAccessChild(NodeExecutionData targetExecution) {
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
102 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
103 Element accessElement = targetExecution.getChild().getAccessElement();
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
104 if (accessElement == null || accessElement.getKind() == ElementKind.METHOD) {
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
105 builder.string("this.").string(targetExecution.getChild().getName());
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
106 } else if (accessElement.getKind() == ElementKind.FIELD) {
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
107 builder.string("this.").string(accessElement.getSimpleName().toString());
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
108 } else {
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
109 throw new AssertionError();
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
110 }
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
111 if (targetExecution.isIndexed()) {
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
112 builder.string("[" + targetExecution.getIndex() + "]");
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
113 }
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
114 return builder.getRoot();
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
115 }
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
116
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
117 private static String castValueName(ActualParameter parameter) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
118 return valueName(parameter) + "Cast";
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
119 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
120
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
121 private void addInternalValueParameters(CodeExecutableElement method, TemplateMethod specialization, boolean forceFrame, boolean evaluated) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
122 if (forceFrame && specialization.getSpecification().findParameterSpec("frame") != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
123 method.addParameter(new CodeVariableElement(getContext().getTruffleTypes().getFrame(), "frameValue"));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
124 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
125 for (ActualParameter parameter : specialization.getParameters()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
126 ParameterSpec spec = parameter.getSpecification();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
127 if (forceFrame && spec.getName().equals("frame")) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
128 continue;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
129 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
130 if (spec.isLocal()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
131 continue;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
132 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
133
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
134 String name = valueName(parameter);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
135 if (evaluated && spec.isSignature()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
136 name = valueNameEvaluated(parameter);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
137 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
138
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
139 method.addParameter(new CodeVariableElement(parameter.getType(), name));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
140 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
141 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
142
13532
85b485b1e8e1 Truffle-DSL: removed support for implicit parameters. not needed anymore.
Christian Humer <christian.humer@gmail.com>
parents: 13530
diff changeset
143 private void addInternalValueParameterNames(CodeTreeBuilder builder, TemplateMethod source, TemplateMethod specialization, String unexpectedValueName, boolean forceFrame,
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
144 Map<String, String> customNames) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
145 if (forceFrame && specialization.getSpecification().findParameterSpec("frame") != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
146 builder.string("frameValue");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
147 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
148 for (ActualParameter parameter : specialization.getParameters()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
149 ParameterSpec spec = parameter.getSpecification();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
150 if (forceFrame && spec.getName().equals("frame")) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
151 continue;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
152 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
153
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
154 if (parameter.getSpecification().isLocal()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
155 continue;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
156 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
157
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
158 ActualParameter sourceParameter = source.findParameter(parameter.getLocalName());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
159
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
160 if (customNames != null && customNames.containsKey(parameter.getLocalName())) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
161 builder.string(customNames.get(parameter.getLocalName()));
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
162 } else if (unexpectedValueName != null && parameter.getLocalName().equals(unexpectedValueName)) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
163 builder.cast(parameter.getType(), CodeTreeBuilder.singleString("ex.getResult()"));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
164 } else if (sourceParameter != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
165 builder.string(valueName(sourceParameter, parameter));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
166 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
167 builder.string(valueName(parameter));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
168 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
169 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
170 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
171
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
172 private String valueName(ActualParameter sourceParameter, ActualParameter targetParameter) {
13861
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
173 if (!sourceParameter.getSpecification().isSignature()) {
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
174 return valueName(targetParameter);
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
175 } else if (sourceParameter.getTypeSystemType() != null && targetParameter.getTypeSystemType() != null) {
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
176 if (sourceParameter.getTypeSystemType().needsCastTo(getContext(), targetParameter.getTypeSystemType())) {
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
177 return castValueName(targetParameter);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
178 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
179 }
13861
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
180 return valueName(targetParameter);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
181 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
182
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
183 private CodeTree createTemplateMethodCall(CodeTreeBuilder parent, CodeTree target, TemplateMethod sourceMethod, TemplateMethod targetMethod, String unexpectedValueName,
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
184 String... customSignatureValueNames) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
185 CodeTreeBuilder builder = parent.create();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
186
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
187 boolean castedValues = sourceMethod != targetMethod;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
188
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
189 builder.startGroup();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
190 ExecutableElement method = targetMethod.getMethod();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
191 if (method == null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
192 throw new UnsupportedOperationException();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
193 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
194 TypeElement targetClass = Utils.findNearestEnclosingType(method.getEnclosingElement());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
195 NodeData node = (NodeData) targetMethod.getTemplate();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
196
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
197 if (target == null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
198 boolean accessible = targetMethod.canBeAccessedByInstanceOf(getContext(), node.getNodeType());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
199 if (accessible) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
200 if (builder.findMethod().getModifiers().contains(STATIC)) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
201 if (method.getModifiers().contains(STATIC)) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
202 builder.type(targetClass.asType());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
203 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
204 builder.string(THIS_NODE_LOCAL_VAR_NAME);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
205 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
206 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
207 if (targetMethod instanceof ExecutableTypeData) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
208 builder.string("this");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
209 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
210 builder.string("super");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
211 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
212 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
213 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
214 if (method.getModifiers().contains(STATIC)) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
215 builder.type(targetClass.asType());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
216 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
217 ActualParameter parameter = null;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
218 for (ActualParameter searchParameter : targetMethod.getParameters()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
219 if (searchParameter.getSpecification().isSignature()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
220 parameter = searchParameter;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
221 break;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
222 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
223 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
224 ActualParameter sourceParameter = sourceMethod.findParameter(parameter.getLocalName());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
225
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
226 if (castedValues && sourceParameter != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
227 builder.string(valueName(sourceParameter, parameter));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
228 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
229 builder.string(valueName(parameter));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
230 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
231 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
232 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
233 builder.string(".");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
234 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
235 builder.tree(target);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
236 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
237 builder.startCall(method.getSimpleName().toString());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
238
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
239 int signatureIndex = 0;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
240
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
241 for (ActualParameter targetParameter : targetMethod.getParameters()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
242 ActualParameter valueParameter = null;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
243 if (sourceMethod != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
244 valueParameter = sourceMethod.findParameter(targetParameter.getLocalName());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
245 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
246 if (valueParameter == null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
247 valueParameter = targetParameter;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
248 }
11439
efe58aa92f86 Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents: 11320
diff changeset
249 TypeMirror targetType = targetParameter.getType();
efe58aa92f86 Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents: 11320
diff changeset
250 TypeMirror valueType = null;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
251 if (valueParameter != null) {
11439
efe58aa92f86 Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents: 11320
diff changeset
252 valueType = valueParameter.getType();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
253 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
254
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
255 if (signatureIndex < customSignatureValueNames.length && targetParameter.getSpecification().isSignature()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
256 builder.string(customSignatureValueNames[signatureIndex]);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
257 signatureIndex++;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
258 } else if (targetParameter.getSpecification().isLocal()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
259 builder.startGroup();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
260 if (builder.findMethod().getModifiers().contains(Modifier.STATIC)) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
261 builder.string(THIS_NODE_LOCAL_VAR_NAME).string(".");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
262 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
263 builder.string("this.");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
264 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
265 builder.string(targetParameter.getSpecification().getName());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
266 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
267 } else if (unexpectedValueName != null && targetParameter.getLocalName().equals(unexpectedValueName)) {
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
268 builder.cast(targetParameter.getType(), CodeTreeBuilder.singleString("ex.getResult()"));
11439
efe58aa92f86 Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents: 11320
diff changeset
269 } else if (!Utils.needsCastTo(getContext(), valueType, targetType)) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
270 builder.startGroup();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
271 builder.string(valueName(targetParameter));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
272 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
273 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
274 builder.string(castValueName(targetParameter));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
275 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
276 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
277
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
278 builder.end().end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
279
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
280 return builder.getRoot();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
281 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
282
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
283 private static String baseClassName(NodeData node) {
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
284 String nodeid = resolveNodeId(node);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
285 String name = Utils.firstLetterUpperCase(nodeid);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
286 name += "BaseNode";
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
287 return name;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
288 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
289
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
290 private static CodeTree createCallTypeSystemMethod(ProcessorContext context, CodeTreeBuilder parent, NodeData node, String methodName, CodeTree... args) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
291 CodeTreeBuilder builder = new CodeTreeBuilder(parent);
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
292 startCallTypeSystemMethod(context, builder, node.getTypeSystem(), methodName);
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
293 for (CodeTree arg : args) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
294 builder.tree(arg);
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
295 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
296 builder.end().end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
297 return builder.getRoot();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
298 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
299
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
300 private static void startCallTypeSystemMethod(ProcessorContext context, CodeTreeBuilder body, TypeSystemData typeSystem, String methodName) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
301 VariableElement singleton = TypeSystemCodeGenerator.findSingleton(context, typeSystem);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
302 assert singleton != null;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
303
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
304 body.startGroup();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
305 body.staticReference(singleton.getEnclosingElement().asType(), singleton.getSimpleName().toString());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
306 body.string(".").startCall(methodName);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
307 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
308
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
309 /**
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
310 * <pre>
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
311 * variant1 $condition != null
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
312 *
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
313 * $type $name = defaultValue($type);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
314 * if ($condition) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
315 * $name = $value;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
316 * }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
317 *
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
318 * variant2 $condition != null
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
319 * $type $name = $value;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
320 * </pre>
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
321 *
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
322 * .
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
323 */
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
324 private static CodeTree createLazyAssignment(CodeTreeBuilder parent, String name, TypeMirror type, CodeTree condition, CodeTree value) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
325 CodeTreeBuilder builder = new CodeTreeBuilder(parent);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
326 if (condition == null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
327 builder.declaration(type, name, value);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
328 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
329 builder.declaration(type, name, new CodeTreeBuilder(parent).defaultValue(type).getRoot());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
330
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
331 builder.startIf().tree(condition).end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
332 builder.startBlock();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
333 builder.startStatement();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
334 builder.string(name);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
335 builder.string(" = ");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
336 builder.tree(value);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
337 builder.end(); // statement
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
338 builder.end(); // block
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
339 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
340 return builder.getRoot();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
341 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
342
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
343 protected void emitEncounteredSynthetic(CodeTreeBuilder builder, TemplateMethod current) {
13861
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
344 CodeTreeBuilder nodes = builder.create();
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
345 CodeTreeBuilder arguments = builder.create();
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
346 nodes.startCommaGroup();
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
347 arguments.startCommaGroup();
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
348 boolean empty = true;
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
349 for (ActualParameter parameter : current.getParameters()) {
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
350 NodeExecutionData executionData = parameter.getSpecification().getExecution();
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
351 if (executionData != null) {
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
352 if (executionData.isShortCircuit()) {
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
353 nodes.nullLiteral();
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
354 arguments.string(valueName(parameter.getPreviousParameter()));
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
355 }
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
356 nodes.tree(createAccessChild(executionData));
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
357 arguments.string(valueName(parameter));
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
358 empty = false;
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
359 }
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
360 }
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
361 nodes.end();
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
362 arguments.end();
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
363
13812
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents: 13536
diff changeset
364 builder.startThrow().startNew(getContext().getType(UnsupportedSpecializationException.class));
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents: 13536
diff changeset
365 builder.string("this");
13861
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
366 builder.startNewArray(getContext().getTruffleTypes().getNodeArray(), null);
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
367
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
368 builder.tree(nodes.getRoot());
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
369 builder.end();
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
370 if (!empty) {
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
371 builder.tree(arguments.getRoot());
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
372 }
13812
f270f09616da Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents: 13536
diff changeset
373 builder.end().end();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
374 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
375
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
376 private static List<ExecutableElement> findUserConstructors(TypeMirror nodeType) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
377 List<ExecutableElement> constructors = new ArrayList<>();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
378 for (ExecutableElement constructor : ElementFilter.constructorsIn(Utils.fromTypeMirror(nodeType).getEnclosedElements())) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
379 if (constructor.getModifiers().contains(PRIVATE)) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
380 continue;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
381 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
382 if (isCopyConstructor(constructor)) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
383 continue;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
384 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
385 constructors.add(constructor);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
386 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
387
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
388 if (constructors.isEmpty()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
389 constructors.add(new CodeExecutableElement(null, Utils.getSimpleName(nodeType)));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
390 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
391
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
392 return constructors;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
393 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
394
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
395 private static ExecutableElement findCopyConstructor(TypeMirror type) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
396 for (ExecutableElement constructor : ElementFilter.constructorsIn(Utils.fromTypeMirror(type).getEnclosedElements())) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
397 if (constructor.getModifiers().contains(PRIVATE)) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
398 continue;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
399 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
400 if (isCopyConstructor(constructor)) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
401 return constructor;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
402 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
403 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
404
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
405 return null;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
406 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
407
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
408 private static boolean isCopyConstructor(ExecutableElement element) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
409 if (element.getParameters().size() != 1) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
410 return false;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
411 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
412 VariableElement var = element.getParameters().get(0);
11180
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
413 TypeElement enclosingType = Utils.findNearestEnclosingType(var);
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
414 if (Utils.typeEquals(var.asType(), enclosingType.asType())) {
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
415 return true;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
416 }
11180
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
417 List<TypeElement> types = Utils.getDirectSuperTypes(enclosingType);
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
418 for (TypeElement type : types) {
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
419 if (!(type instanceof CodeTypeElement)) {
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
420 // no copy constructors which are not generated types
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
421 return false;
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
422 }
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
423
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
424 if (Utils.typeEquals(var.asType(), type.asType())) {
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
425 return true;
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
426 }
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
427 }
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
428 return false;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
429 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
430
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
431 @Override
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
432 @SuppressWarnings("unchecked")
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
433 protected void createChildren(NodeData node) {
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
434 List<CodeTypeElement> casts = new ArrayList<>(getElement().getEnclosedElements());
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
435 getElement().getEnclosedElements().clear();
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
436
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
437 Map<NodeData, List<TypeElement>> childTypes = new LinkedHashMap<>();
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
438 for (NodeData nodeChild : node.getEnclosingNodes()) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
439 NodeCodeGenerator generator = new NodeCodeGenerator(getContext());
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
440 childTypes.put(nodeChild, generator.process(null, nodeChild).getEnclosedElements());
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
441 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
442
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
443 if (node.needsFactory() || node.getNodeDeclaringChildren().size() > 0) {
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
444 NodeFactoryFactory factory = new NodeFactoryFactory(context, childTypes);
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
445 add(factory, node);
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
446 factory.getElement().getEnclosedElements().addAll(casts);
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
447 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
448 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
449
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
450 protected CodeTree createCastType(TypeSystemData typeSystem, TypeData sourceType, TypeData targetType, boolean expect, CodeTree value) {
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
451 if (targetType == null) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
452 return value;
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
453 } else if (sourceType != null && !sourceType.needsCastTo(getContext(), targetType)) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
454 return value;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
455 }
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
456
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
457 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
458 String targetMethodName;
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
459 if (expect) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
460 targetMethodName = TypeSystemCodeGenerator.expectTypeMethodName(targetType);
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
461 } else {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
462 targetMethodName = TypeSystemCodeGenerator.asTypeMethodName(targetType);
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
463 }
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
464 startCallTypeSystemMethod(getContext(), builder, typeSystem, targetMethodName);
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
465 builder.tree(value);
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
466 builder.end().end();
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
467 return builder.getRoot();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
468 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
469
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
470 protected CodeTree createExpectType(TypeSystemData typeSystem, TypeData sourceType, TypeData targetType, CodeTree expression) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
471 return createCastType(typeSystem, sourceType, targetType, true, expression);
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
472 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
473
13275
bd5c996b5d25 Truffle-DSL: fixed wrong transferToInterpreter with transferToInterpreterAndInvalidate.
Christian Humer <christian.humer@gmail.com>
parents: 13272
diff changeset
474 public CodeTree createDeoptimize(CodeTreeBuilder parent) {
bd5c996b5d25 Truffle-DSL: fixed wrong transferToInterpreter with transferToInterpreterAndInvalidate.
Christian Humer <christian.humer@gmail.com>
parents: 13272
diff changeset
475 CodeTreeBuilder builder = new CodeTreeBuilder(parent);
bd5c996b5d25 Truffle-DSL: fixed wrong transferToInterpreter with transferToInterpreterAndInvalidate.
Christian Humer <christian.humer@gmail.com>
parents: 13272
diff changeset
476 builder.startStatement();
bd5c996b5d25 Truffle-DSL: fixed wrong transferToInterpreter with transferToInterpreterAndInvalidate.
Christian Humer <christian.humer@gmail.com>
parents: 13272
diff changeset
477 builder.startStaticCall(getContext().getTruffleTypes().getCompilerDirectives(), "transferToInterpreterAndInvalidate").end();
bd5c996b5d25 Truffle-DSL: fixed wrong transferToInterpreter with transferToInterpreterAndInvalidate.
Christian Humer <christian.humer@gmail.com>
parents: 13272
diff changeset
478 builder.end();
bd5c996b5d25 Truffle-DSL: fixed wrong transferToInterpreter with transferToInterpreterAndInvalidate.
Christian Humer <christian.humer@gmail.com>
parents: 13272
diff changeset
479 return builder.getRoot();
bd5c996b5d25 Truffle-DSL: fixed wrong transferToInterpreter with transferToInterpreterAndInvalidate.
Christian Humer <christian.humer@gmail.com>
parents: 13272
diff changeset
480 }
bd5c996b5d25 Truffle-DSL: fixed wrong transferToInterpreter with transferToInterpreterAndInvalidate.
Christian Humer <christian.humer@gmail.com>
parents: 13272
diff changeset
481
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
482 private class NodeFactoryFactory extends ClassElementFactory<NodeData> {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
483
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
484 private final Map<NodeData, List<TypeElement>> childTypes;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
485 private CodeTypeElement generatedNode;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
486
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
487 public NodeFactoryFactory(ProcessorContext context, Map<NodeData, List<TypeElement>> childElements) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
488 super(context);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
489 this.childTypes = childElements;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
490 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
491
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
492 @Override
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
493 protected CodeTypeElement create(NodeData node) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
494 Modifier visibility = Utils.getVisibility(node.getTemplateType().getModifiers());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
495 CodeTypeElement clazz = createClass(node, modifiers(), factoryClassName(node), null, false);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
496 if (visibility != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
497 clazz.getModifiers().add(visibility);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
498 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
499 clazz.getModifiers().add(Modifier.FINAL);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
500 clazz.add(createConstructorUsingFields(modifiers(PRIVATE), clazz));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
501 return clazz;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
502 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
503
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
504 @Override
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
505 protected void createChildren(NodeData node) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
506 CodeTypeElement clazz = getElement();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
507
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
508 Modifier createVisibility = Utils.getVisibility(clazz.getModifiers());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
509
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
510 CodeTypeElement polymorphicNode = null;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
511 if (node.needsFactory()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
512 NodeBaseFactory factory = new NodeBaseFactory(context);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
513 add(factory, node.getGenericSpecialization() == null ? node.getSpecializations().get(0) : node.getGenericSpecialization());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
514 generatedNode = factory.getElement();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
515
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
516 if (node.needsRewrites(context)) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
517 clazz.add(createCreateGenericMethod(node, createVisibility));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
518 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
519
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
520 createFactoryMethods(node, clazz, createVisibility);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
521
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
522 for (SpecializationData specialization : node.getSpecializations()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
523 if (!specialization.isReachable()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
524 continue;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
525 }
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
526
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
527 if (specialization.isPolymorphic() && node.isPolymorphic()) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
528 PolymorphicNodeFactory polymorphicFactory = new PolymorphicNodeFactory(getContext(), generatedNode);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
529 add(polymorphicFactory, specialization);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
530 polymorphicNode = polymorphicFactory.getElement();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
531 continue;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
532 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
533
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
534 add(new SpecializedNodeFactory(context, generatedNode), specialization);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
535 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
536
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
537 TypeMirror nodeFactory = Utils.getDeclaredType(Utils.fromTypeMirror(getContext().getType(NodeFactory.class)), node.getNodeType());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
538 clazz.getImplements().add(nodeFactory);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
539 clazz.add(createCreateNodeMethod(node));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
540 clazz.add(createGetNodeClassMethod(node));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
541 clazz.add(createGetNodeSignaturesMethod());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
542 clazz.add(createGetChildrenSignatureMethod(node));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
543 clazz.add(createGetInstanceMethod(node, createVisibility));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
544 clazz.add(createInstanceConstant(node, clazz.asType()));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
545 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
546
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
547 if (polymorphicNode != null) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
548 patchParameterType(clazz, UPDATE_TYPES_NAME, generatedNode.asType(), polymorphicNode.asType());
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
549 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
550
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
551 for (NodeData childNode : childTypes.keySet()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
552 if (childNode.getTemplateType().getModifiers().contains(Modifier.PRIVATE)) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
553 continue;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
554 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
555
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
556 for (TypeElement type : childTypes.get(childNode)) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
557 Set<Modifier> typeModifiers = ((CodeTypeElement) type).getModifiers();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
558 Modifier visibility = Utils.getVisibility(type.getModifiers());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
559 typeModifiers.clear();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
560 if (visibility != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
561 typeModifiers.add(visibility);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
562 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
563
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
564 typeModifiers.add(Modifier.STATIC);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
565 typeModifiers.add(Modifier.FINAL);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
566 clazz.add(type);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
567 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
568 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
569
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
570 List<NodeData> children = node.getNodeDeclaringChildren();
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
571 if (node.getDeclaringNode() == null && children.size() > 0) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
572 clazz.add(createGetFactories(node));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
573 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
574
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
575 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
576
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
577 private void patchParameterType(CodeTypeElement enclosingClass, String methodName, TypeMirror originalType, TypeMirror newType) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
578 for (TypeElement enclosedType : ElementFilter.typesIn(enclosingClass.getEnclosedElements())) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
579 CodeTypeElement type = (CodeTypeElement) enclosedType;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
580 ExecutableElement method = type.getMethod(methodName);
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
581 for (VariableElement v : method.getParameters()) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
582 CodeVariableElement var = (CodeVariableElement) v;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
583 if (Utils.typeEquals(var.getType(), originalType)) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
584 var.setType(newType);
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
585 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
586 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
587 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
588 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
589
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
590 private CodeExecutableElement createGetNodeClassMethod(NodeData node) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
591 TypeMirror returnType = Utils.getDeclaredType(Utils.fromTypeMirror(getContext().getType(Class.class)), node.getNodeType());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
592 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), returnType, "getNodeClass");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
593 CodeTreeBuilder builder = method.createBuilder();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
594 builder.startReturn().typeLiteral(node.getNodeType()).end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
595 return method;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
596 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
598 private CodeExecutableElement createGetNodeSignaturesMethod() {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
599 TypeElement listType = Utils.fromTypeMirror(getContext().getType(List.class));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
600 TypeMirror classType = getContext().getType(Class.class);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
601 TypeMirror returnType = Utils.getDeclaredType(listType, Utils.getDeclaredType(listType, classType));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
602 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), returnType, "getNodeSignatures");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
603 CodeTreeBuilder builder = method.createBuilder();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
604 builder.startReturn();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
605 builder.startStaticCall(getContext().getType(Arrays.class), "asList");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
606 List<ExecutableElement> constructors = findUserConstructors(generatedNode.asType());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
607 for (ExecutableElement constructor : constructors) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
608 builder.tree(createAsList(builder, Utils.asTypeMirrors(constructor.getParameters()), classType));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
609 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
610 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
611 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
612 return method;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
613 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
614
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
615 private CodeExecutableElement createGetChildrenSignatureMethod(NodeData node) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
616 Types types = getContext().getEnvironment().getTypeUtils();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
617 TypeElement listType = Utils.fromTypeMirror(getContext().getType(List.class));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
618 TypeMirror classType = getContext().getType(Class.class);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
619 TypeMirror nodeType = getContext().getTruffleTypes().getNode();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
620 TypeMirror wildcardNodeType = types.getWildcardType(nodeType, null);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
621 classType = Utils.getDeclaredType(Utils.fromTypeMirror(classType), wildcardNodeType);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
622 TypeMirror returnType = Utils.getDeclaredType(listType, classType);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
623
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
624 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), returnType, "getExecutionSignature");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
625 CodeTreeBuilder builder = method.createBuilder();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
626
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
627 List<TypeMirror> signatureTypes = new ArrayList<>();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
628 assert !node.getSpecializations().isEmpty();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
629 SpecializationData data = node.getSpecializations().get(0);
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
630
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
631 for (ActualParameter parameter : data.getSignatureParameters()) {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
632 signatureTypes.add(parameter.getSpecification().getExecution().getNodeType());
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
633 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
634
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
635 builder.startReturn().tree(createAsList(builder, signatureTypes, classType)).end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
636 return method;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
637 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
638
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
639 private CodeTree createAsList(CodeTreeBuilder parent, List<TypeMirror> types, TypeMirror elementClass) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
640 CodeTreeBuilder builder = parent.create();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
641 builder.startGroup();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
642 builder.type(getContext().getType(Arrays.class));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
643 builder.string(".<").type(elementClass).string(">");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
644 builder.startCall("asList");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
645 for (TypeMirror typeMirror : types) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
646 builder.typeLiteral(typeMirror);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
647 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
648 builder.end().end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
649 return builder.getRoot();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
650 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
651
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
652 private CodeExecutableElement createCreateNodeMethod(NodeData node) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
653 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), node.getNodeType(), "createNode");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
654 CodeVariableElement arguments = new CodeVariableElement(getContext().getType(Object.class), "arguments");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
655 method.setVarArgs(true);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
656 method.addParameter(arguments);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
657
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
658 CodeTreeBuilder builder = method.createBuilder();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
659 List<ExecutableElement> signatures = findUserConstructors(generatedNode.asType());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
660 boolean ifStarted = false;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
661
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
662 for (ExecutableElement element : signatures) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
663 ifStarted = builder.startIf(ifStarted);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
664 builder.string("arguments.length == " + element.getParameters().size());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
665
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
666 int index = 0;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
667 for (VariableElement param : element.getParameters()) {
11509
dcaf879d4a7e Truffle-DSL: fixed a compiler warning for fields of type java.lang.Object. (GRAAL-434 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11506
diff changeset
668 if (Utils.isObject(param.asType())) {
dcaf879d4a7e Truffle-DSL: fixed a compiler warning for fields of type java.lang.Object. (GRAAL-434 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11506
diff changeset
669 continue;
dcaf879d4a7e Truffle-DSL: fixed a compiler warning for fields of type java.lang.Object. (GRAAL-434 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11506
diff changeset
670 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
671 builder.string(" && ");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
672 if (!param.asType().getKind().isPrimitive()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
673 builder.string("(arguments[" + index + "] == null || ");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
674 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
675 builder.string("arguments[" + index + "] instanceof ");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
676 builder.type(Utils.boxType(getContext(), param.asType()));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
677 if (!param.asType().getKind().isPrimitive()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
678 builder.string(")");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
679 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
680 index++;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
681 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
682 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
683 builder.startBlock();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
684
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
685 builder.startReturn().startCall("create");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
686 index = 0;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
687 for (VariableElement param : element.getParameters()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
688 builder.startGroup();
11509
dcaf879d4a7e Truffle-DSL: fixed a compiler warning for fields of type java.lang.Object. (GRAAL-434 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11506
diff changeset
689 if (!Utils.isObject(param.asType())) {
dcaf879d4a7e Truffle-DSL: fixed a compiler warning for fields of type java.lang.Object. (GRAAL-434 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11506
diff changeset
690 builder.string("(").type(param.asType()).string(") ");
dcaf879d4a7e Truffle-DSL: fixed a compiler warning for fields of type java.lang.Object. (GRAAL-434 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11506
diff changeset
691 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
692 builder.string("arguments[").string(String.valueOf(index)).string("]");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
693 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
694 index++;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
695 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
696 builder.end().end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
697
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
698 builder.end(); // block
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
699 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
700
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
701 builder.startElseBlock();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
702 builder.startThrow().startNew(getContext().getType(IllegalArgumentException.class));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
703 builder.doubleQuote("Invalid create signature.");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
704 builder.end().end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
705 builder.end(); // else block
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
706 return method;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
707 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
708
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
709 private ExecutableElement createGetInstanceMethod(NodeData node, Modifier visibility) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
710 TypeElement nodeFactoryType = Utils.fromTypeMirror(getContext().getType(NodeFactory.class));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
711 TypeMirror returnType = Utils.getDeclaredType(nodeFactoryType, node.getNodeType());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
712
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
713 CodeExecutableElement method = new CodeExecutableElement(modifiers(), returnType, "getInstance");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
714 if (visibility != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
715 method.getModifiers().add(visibility);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
716 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
717 method.getModifiers().add(Modifier.STATIC);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
718
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
719 String varName = instanceVarName(node);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
720
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
721 CodeTreeBuilder builder = method.createBuilder();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
722 builder.startIf();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
723 builder.string(varName).string(" == null");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
724 builder.end().startBlock();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
725
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
726 builder.startStatement();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
727 builder.string(varName);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
728 builder.string(" = ");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
729 builder.startNew(factoryClassName(node)).end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
730 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
731
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
732 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
733 builder.startReturn().string(varName).end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
734 return method;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
735 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
736
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
737 private String instanceVarName(NodeData node) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
738 if (node.getDeclaringNode() != null) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
739 return Utils.firstLetterLowerCase(factoryClassName(node)) + "Instance";
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
740 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
741 return "instance";
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
742 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
743 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
744
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
745 private CodeVariableElement createInstanceConstant(NodeData node, TypeMirror factoryType) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
746 String varName = instanceVarName(node);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
747 CodeVariableElement var = new CodeVariableElement(modifiers(), factoryType, varName);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
748 var.getModifiers().add(Modifier.PRIVATE);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
749 var.getModifiers().add(Modifier.STATIC);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
750 return var;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
751 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
752
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
753 private ExecutableElement createGetFactories(NodeData node) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
754 List<NodeData> children = node.getNodeDeclaringChildren();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
755 if (node.needsFactory()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
756 children.add(node);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
757 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
758
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
759 List<TypeMirror> nodeTypesList = new ArrayList<>();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
760 TypeMirror prev = null;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
761 boolean allSame = true;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
762 for (NodeData child : children) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
763 nodeTypesList.add(child.getNodeType());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
764 if (prev != null && !Utils.typeEquals(child.getNodeType(), prev)) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
765 allSame = false;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
766 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
767 prev = child.getNodeType();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
768 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
769 TypeMirror commonNodeSuperType = Utils.getCommonSuperType(getContext(), nodeTypesList.toArray(new TypeMirror[nodeTypesList.size()]));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
770
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
771 Types types = getContext().getEnvironment().getTypeUtils();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
772 TypeMirror factoryType = getContext().getType(NodeFactory.class);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
773 TypeMirror baseType;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
774 if (allSame) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
775 baseType = Utils.getDeclaredType(Utils.fromTypeMirror(factoryType), commonNodeSuperType);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
776 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
777 baseType = Utils.getDeclaredType(Utils.fromTypeMirror(factoryType), types.getWildcardType(commonNodeSuperType, null));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
778 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
779 TypeMirror listType = Utils.getDeclaredType(Utils.fromTypeMirror(getContext().getType(List.class)), baseType);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
780
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
781 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, STATIC), listType, "getFactories");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
782
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
783 CodeTreeBuilder builder = method.createBuilder();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
784 builder.startReturn();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
785 builder.startStaticCall(getContext().getType(Arrays.class), "asList");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
786
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
787 for (NodeData child : children) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
788 builder.startGroup();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
789 NodeData childNode = child;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
790 List<NodeData> factories = new ArrayList<>();
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
791 while (childNode.getDeclaringNode() != null) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
792 factories.add(childNode);
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
793 childNode = childNode.getDeclaringNode();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
794 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
795 Collections.reverse(factories);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
796 for (NodeData nodeData : factories) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
797 builder.string(factoryClassName(nodeData)).string(".");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
798 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
799 builder.string("getInstance()");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
800 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
801 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
802 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
803 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
804 return method;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
805 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
806
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
807 private void createFactoryMethods(NodeData node, CodeTypeElement clazz, Modifier createVisibility) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
808 List<ExecutableElement> constructors = findUserConstructors(generatedNode.asType());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
809 for (ExecutableElement constructor : constructors) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
810 clazz.add(createCreateMethod(node, createVisibility, constructor));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
811 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
812 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
813
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
814 private CodeExecutableElement createCreateMethod(NodeData node, Modifier visibility, ExecutableElement constructor) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
815 CodeExecutableElement method = CodeExecutableElement.clone(getContext().getEnvironment(), constructor);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
816 method.setSimpleName(CodeNames.of("create"));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
817 method.getModifiers().clear();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
818 if (visibility != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
819 method.getModifiers().add(visibility);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
820 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
821 method.getModifiers().add(Modifier.STATIC);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
822 method.setReturnType(node.getNodeType());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
823
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
824 CodeTreeBuilder body = method.createBuilder();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
825 body.startReturn();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
826 if (node.getSpecializations().isEmpty()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
827 body.nullLiteral();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
828 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
829 body.startNew(nodeSpecializationClassName(node.getSpecializations().get(0)));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
830 for (VariableElement var : method.getParameters()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
831 body.string(var.getSimpleName().toString());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
832 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
833 body.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
834 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
835 body.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
836 return method;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
837 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
838
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
839 private CodeExecutableElement createCreateGenericMethod(NodeData node, Modifier visibility) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
840 CodeExecutableElement method = new CodeExecutableElement(modifiers(), node.getNodeType(), "createGeneric");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
841 if (visibility != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
842 method.getModifiers().add(visibility);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
843 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
844 method.getModifiers().add(Modifier.STATIC);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
845 method.addParameter(new CodeVariableElement(node.getNodeType(), THIS_NODE_LOCAL_VAR_NAME));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
846
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
847 CodeTreeBuilder body = method.createBuilder();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
848
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
849 SpecializationData found = null;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
850 List<SpecializationData> specializations = node.getSpecializations();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
851 for (int i = 0; i < specializations.size(); i++) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
852 if (specializations.get(i).isReachable()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
853 found = specializations.get(i);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
854 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
855 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
856
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
857 if (found == null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
858 body.startThrow().startNew(getContext().getType(UnsupportedOperationException.class)).end().end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
859 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
860 body.startReturn().startNew(nodeSpecializationClassName(found)).startGroup().cast(baseClassName(node)).string(THIS_NODE_LOCAL_VAR_NAME).end().end().end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
861 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
862 return method;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
863 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
864 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
865
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
866 private class NodeBaseFactory extends ClassElementFactory<SpecializationData> {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
867
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
868 public NodeBaseFactory(ProcessorContext context) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
869 super(context);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
870 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
871
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
872 @Override
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
873 protected CodeTypeElement create(SpecializationData specialization) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
874 NodeData node = specialization.getNode();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
875 CodeTypeElement clazz = createClass(node, modifiers(PRIVATE, ABSTRACT, STATIC), baseClassName(node), node.getNodeType(), false);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
876
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
877 for (NodeChildData child : node.getChildren()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
878 clazz.add(createChildField(child));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
879
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
880 if (child.getAccessElement() != null && child.getAccessElement().getModifiers().contains(Modifier.ABSTRACT)) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
881 ExecutableElement getter = (ExecutableElement) child.getAccessElement();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
882 CodeExecutableElement method = CodeExecutableElement.clone(getContext().getEnvironment(), getter);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
883 method.getModifiers().remove(Modifier.ABSTRACT);
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
884 CodeTreeBuilder builder = method.createBuilder();
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
885 builder.startReturn().string("this.").string(child.getName()).end();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
886 clazz.add(method);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
887 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
888 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
889
11187
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11186
diff changeset
890 for (NodeFieldData field : node.getFields()) {
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11186
diff changeset
891 if (!field.isGenerated()) {
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11186
diff changeset
892 continue;
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11186
diff changeset
893 }
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11186
diff changeset
894
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11186
diff changeset
895 clazz.add(new CodeVariableElement(modifiers(PROTECTED, FINAL), field.getType(), field.getName()));
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11186
diff changeset
896 if (field.getGetter() != null && field.getGetter().getModifiers().contains(Modifier.ABSTRACT)) {
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11186
diff changeset
897 CodeExecutableElement method = CodeExecutableElement.clone(getContext().getEnvironment(), field.getGetter());
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11186
diff changeset
898 method.getModifiers().remove(Modifier.ABSTRACT);
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11186
diff changeset
899 method.createBuilder().startReturn().string("this.").string(field.getName()).end();
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11186
diff changeset
900 clazz.add(method);
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11186
diff changeset
901 }
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11186
diff changeset
902 }
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11186
diff changeset
903
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
904 for (String assumption : node.getAssumptions()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
905 clazz.add(createAssumptionField(assumption));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
906 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
907
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
908 createConstructors(node, clazz);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
909
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
910 return clazz;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
911 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
912
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
913 @Override
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
914 protected void createChildren(SpecializationData specialization) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
915 NodeData node = specialization.getNode();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
916 CodeTypeElement clazz = getElement();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
917
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
918 SpecializationGroup rootGroup = createSpecializationGroups(node);
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
919
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
920 if (node.needsRewrites(context)) {
11180
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
921 if (node.isPolymorphic()) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
922
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
923 CodeVariableElement var = new CodeVariableElement(modifiers(PROTECTED), clazz.asType(), "next0");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
924 var.getAnnotationMirrors().add(new CodeAnnotationMirror(getContext().getTruffleTypes().getChildAnnotation()));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
925 clazz.add(var);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
926
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
927 CodeExecutableElement setter = new CodeExecutableElement(modifiers(PROTECTED), context.getType(void.class), "setNext0");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
928 setter.getParameters().add(new CodeVariableElement(clazz.asType(), "next0"));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
929 CodeTreeBuilder builder = setter.createBuilder();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
930 builder.statement("this.next0 = adoptChild(next0)");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
931 clazz.add(setter);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
932
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
933 CodeExecutableElement genericCachedExecute = createCachedExecute(node, node.getPolymorphicSpecialization());
10600
e93efe3ba5f4 Truffle-DSL: rewritten polymorphic optimization for simpler generated code.
Christian Humer <christian.humer@gmail.com>
parents: 10597
diff changeset
934 clazz.add(genericCachedExecute);
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
935
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
936 getElement().add(createUpdateTypes(clazz.asType()));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
937 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
938
12392
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
939 for (CodeExecutableElement method : createImplicitChildrenAccessors()) {
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
940 clazz.add(method);
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
941 }
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
942 clazz.add(createGenericExecuteAndSpecialize(node, rootGroup));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
943 clazz.add(createInfoMessage(node));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
944 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
945
12567
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
946 if (needsInvokeCopyConstructorMethod()) {
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
947 clazz.add(createInvokeCopyConstructor(clazz.asType(), null));
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
948 clazz.add(createCopyPolymorphicConstructor(clazz.asType()));
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
949 }
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
950
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
951 if (node.getGenericSpecialization() != null && node.getGenericSpecialization().isReachable()) {
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
952 clazz.add(createGenericExecute(node, rootGroup));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
953 }
14077
3ea5f337cc0d Truffle-DSL: generate better implementations for getKind()
Christian Humer <christian.humer@gmail.com>
parents: 14042
diff changeset
954
14564
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14077
diff changeset
955 clazz.add(createGetCost(node, null, NodeCost.MONOMORPHIC));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
956 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
957
12567
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
958 protected boolean needsInvokeCopyConstructorMethod() {
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
959 return getModel().getNode().isPolymorphic();
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
960 }
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
961
14564
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14077
diff changeset
962 protected CodeExecutableElement createGetCost(NodeData node, SpecializationData specialization, NodeCost cost) {
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14077
diff changeset
963 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), context.getTruffleTypes().getNodeCost(), "getCost");
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14077
diff changeset
964
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14077
diff changeset
965 TypeMirror nodeInfoKind = context.getTruffleTypes().getNodeCost();
14077
3ea5f337cc0d Truffle-DSL: generate better implementations for getKind()
Christian Humer <christian.humer@gmail.com>
parents: 14042
diff changeset
966
3ea5f337cc0d Truffle-DSL: generate better implementations for getKind()
Christian Humer <christian.humer@gmail.com>
parents: 14042
diff changeset
967 CodeTreeBuilder builder = method.createBuilder();
3ea5f337cc0d Truffle-DSL: generate better implementations for getKind()
Christian Humer <christian.humer@gmail.com>
parents: 14042
diff changeset
968 if (node.isPolymorphic() && specialization == null) {
3ea5f337cc0d Truffle-DSL: generate better implementations for getKind()
Christian Humer <christian.humer@gmail.com>
parents: 14042
diff changeset
969 // assume next0 exists
14564
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14077
diff changeset
970 builder.startIf().string("next0 != null && next0.getCost() == ").staticReference(nodeInfoKind, "MONOMORPHIC").end();
14077
3ea5f337cc0d Truffle-DSL: generate better implementations for getKind()
Christian Humer <christian.humer@gmail.com>
parents: 14042
diff changeset
971 builder.startBlock();
3ea5f337cc0d Truffle-DSL: generate better implementations for getKind()
Christian Humer <christian.humer@gmail.com>
parents: 14042
diff changeset
972 builder.startReturn().staticReference(nodeInfoKind, "POLYMORPHIC").end();
3ea5f337cc0d Truffle-DSL: generate better implementations for getKind()
Christian Humer <christian.humer@gmail.com>
parents: 14042
diff changeset
973 builder.end();
3ea5f337cc0d Truffle-DSL: generate better implementations for getKind()
Christian Humer <christian.humer@gmail.com>
parents: 14042
diff changeset
974 }
3ea5f337cc0d Truffle-DSL: generate better implementations for getKind()
Christian Humer <christian.humer@gmail.com>
parents: 14042
diff changeset
975
14564
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14077
diff changeset
976 builder.startReturn().staticReference(nodeInfoKind, cost.name()).end();
14077
3ea5f337cc0d Truffle-DSL: generate better implementations for getKind()
Christian Humer <christian.humer@gmail.com>
parents: 14042
diff changeset
977 return method;
3ea5f337cc0d Truffle-DSL: generate better implementations for getKind()
Christian Humer <christian.humer@gmail.com>
parents: 14042
diff changeset
978 }
3ea5f337cc0d Truffle-DSL: generate better implementations for getKind()
Christian Humer <christian.humer@gmail.com>
parents: 14042
diff changeset
979
12567
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
980 protected CodeExecutableElement createInvokeCopyConstructor(TypeMirror baseType, SpecializationData specialization) {
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
981 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED), baseType, "invokeCopyConstructor");
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
982 if (specialization == null) {
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
983 method.getModifiers().add(ABSTRACT);
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
984 } else {
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
985 CodeTreeBuilder builder = method.createBuilder();
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
986 builder.startReturn();
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
987 builder.startNew(getElement().asType());
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
988 builder.string("this");
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
989 for (ActualParameter param : getImplicitTypeParamters(specialization)) {
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
990 builder.string(implicitTypeName(param));
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
991 }
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
992 builder.end().end();
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
993 }
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
994 return method;
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
995 }
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
996
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
997 protected CodeExecutableElement createCopyPolymorphicConstructor(TypeMirror baseType) {
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
998 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, FINAL), baseType, "copyPolymorphic");
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
999 CodeTreeBuilder builder = method.createBuilder();
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1000 CodeTreeBuilder nullBuilder = builder.create();
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1001 CodeTreeBuilder oldBuilder = builder.create();
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1002 CodeTreeBuilder resetBuilder = builder.create();
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1003
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1004 for (ActualParameter param : getModel().getSignatureParameters()) {
13535
e8ef44830b50 Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 13533
diff changeset
1005 NodeExecutionData execution = param.getSpecification().getExecution();
12567
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1006
13861
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
1007 CodeTree access = createAccessChild(execution);
12567
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1008
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1009 String oldName = "old" + Utils.firstLetterUpperCase(param.getLocalName());
13535
e8ef44830b50 Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 13533
diff changeset
1010 oldBuilder.declaration(execution.getChild().getNodeData().getNodeType(), oldName, access);
13861
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
1011 nullBuilder.startStatement().tree(access).string(" = null").end();
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
1012 resetBuilder.startStatement().tree(access).string(" = ").string(oldName).end();
12567
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1013 }
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1014
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1015 builder.tree(oldBuilder.getRoot());
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1016 builder.tree(nullBuilder.getRoot());
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1017
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1018 builder.startStatement().type(baseType).string(" copy = ");
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1019 builder.startCall("invokeCopyConstructor").end();
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1020 builder.end();
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1021
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1022 builder.tree(resetBuilder.getRoot());
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1023 builder.startReturn().string("copy").end();
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1024 return method;
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1025 }
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1026
12392
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
1027 private List<CodeExecutableElement> createImplicitChildrenAccessors() {
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
1028 NodeData node = getModel().getNode();
12503
d7f8dd4fe876 minor reformatting based on 'mx eclipseformat'
Doug Simon <doug.simon@oracle.com>
parents: 12403
diff changeset
1029 // Map<NodeChildData, Set<TypeData>> expectTypes = new HashMap<>();
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1030 @SuppressWarnings("unchecked")
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1031 List<Set<TypeData>> expectTypes = Arrays.<Set<TypeData>> asList(new Set[node.getGenericSpecialization().getParameters().size()]);
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1032
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1033 for (ExecutableTypeData executableType : node.getExecutableTypes()) {
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1034 for (int i = 0; i < executableType.getEvaluatedCount(); i++) {
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1035 ActualParameter parameter = executableType.getSignatureParameter(i);
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1036 if (i >= expectTypes.size()) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1037 break;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1038 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1039 Set<TypeData> types = expectTypes.get(i);
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1040 if (types == null) {
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1041 types = new TreeSet<>();
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1042 expectTypes.set(i, types);
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1043 }
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1044 types.add(parameter.getTypeSystemType());
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1045 }
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1046 }
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1047
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1048 List<CodeExecutableElement> methods = new ArrayList<>();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1049 @SuppressWarnings("unchecked")
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1050 List<Set<TypeData>> visitedList = Arrays.<Set<TypeData>> asList(new Set[node.getGenericSpecialization().getParameters().size()]);
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1051 for (SpecializationData spec : node.getSpecializations()) {
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1052 int signatureIndex = -1;
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1053 for (ActualParameter param : spec.getParameters()) {
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1054 if (!param.getSpecification().isSignature()) {
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1055 continue;
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1056 }
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1057 signatureIndex++;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1058 Set<TypeData> visitedTypeData = visitedList.get(signatureIndex);
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1059 if (visitedTypeData == null) {
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1060 visitedTypeData = new TreeSet<>();
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1061 visitedList.set(signatureIndex, visitedTypeData);
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1062 }
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1063
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1064 if (visitedTypeData.contains(param.getTypeSystemType())) {
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1065 continue;
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1066 }
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1067 visitedTypeData.add(param.getTypeSystemType());
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1068
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1069 Set<TypeData> expect = expectTypes.get(signatureIndex);
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1070 if (expect == null) {
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1071 expect = Collections.emptySet();
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1072 }
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1073
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1074 methods.addAll(createExecuteChilds(param, expect));
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1075 }
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1076 }
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1077 return methods;
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1078 }
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
1079
10690
a0309f88306c Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents: 10689
diff changeset
1080 private CodeTree truffleBooleanOption(CodeTreeBuilder parent, String name) {
a0309f88306c Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents: 10689
diff changeset
1081 CodeTreeBuilder builder = parent.create();
a0309f88306c Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents: 10689
diff changeset
1082 builder.staticReference(getContext().getTruffleTypes().getTruffleOptions(), name);
a0309f88306c Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents: 10689
diff changeset
1083 return builder.getRoot();
a0309f88306c Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents: 10689
diff changeset
1084 }
a0309f88306c Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents: 10689
diff changeset
1085
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1086 private Element createInfoMessage(NodeData node) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1087 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, STATIC), getContext().getType(String.class), "createInfo0");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1088 method.addParameter(new CodeVariableElement(getContext().getType(String.class), "message"));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1089 addInternalValueParameters(method, node.getGenericSpecialization(), false, false);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1090
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1091 CodeTreeBuilder builder = method.createBuilder();
10690
a0309f88306c Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents: 10689
diff changeset
1092
a0309f88306c Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents: 10689
diff changeset
1093 builder.startIf().tree(truffleBooleanOption(builder, TruffleTypes.OPTION_DETAILED_REWRITE_REASONS)).end();
a0309f88306c Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents: 10689
diff changeset
1094 builder.startBlock();
a0309f88306c Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents: 10689
diff changeset
1095
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1096 builder.startStatement().string("StringBuilder builder = new StringBuilder(message)").end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1097 builder.startStatement().startCall("builder", "append").doubleQuote(" (").end().end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1098
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1099 String sep = null;
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1100 for (ActualParameter parameter : node.getGenericSpecialization().getSignatureParameters()) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1101 builder.startStatement();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1102 builder.string("builder");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1103 if (sep != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1104 builder.startCall(".append").doubleQuote(sep).end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1105 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1106 builder.startCall(".append").doubleQuote(parameter.getLocalName()).end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1107 builder.startCall(".append").doubleQuote(" = ").end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1108 builder.startCall(".append").string(parameter.getLocalName()).end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1109 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1110
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1111 if (!Utils.isPrimitive(parameter.getType())) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1112 builder.startIf().string(parameter.getLocalName() + " != null").end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1113 builder.startBlock();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1114 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1115 builder.startStatement();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1116 if (Utils.isPrimitive(parameter.getType())) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1117 builder.startCall("builder.append").doubleQuote(" (" + Utils.getSimpleName(parameter.getType()) + ")").end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1118 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1119 builder.startCall("builder.append").doubleQuote(" (").end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1120 builder.startCall(".append").string(parameter.getLocalName() + ".getClass().getSimpleName()").end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1121 builder.startCall(".append").doubleQuote(")").end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1122 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1123 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1124 if (!Utils.isPrimitive(parameter.getType())) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1125 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1126 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1127
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1128 sep = ", ";
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1129 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1130
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1131 builder.startStatement().startCall("builder", "append").doubleQuote(")").end().end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1132 builder.startReturn().string("builder.toString()").end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1133
10690
a0309f88306c Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents: 10689
diff changeset
1134 builder.end();
a0309f88306c Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents: 10689
diff changeset
1135 builder.startElseBlock();
a0309f88306c Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents: 10689
diff changeset
1136 builder.startReturn().string("message").end();
a0309f88306c Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents: 10689
diff changeset
1137 builder.end();
a0309f88306c Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents: 10689
diff changeset
1138
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1139 return method;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1140 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1141
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1142 private CodeExecutableElement createCachedExecute(NodeData node, SpecializationData polymorph) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1143 CodeExecutableElement cachedExecute = new CodeExecutableElement(modifiers(PROTECTED, ABSTRACT), polymorph.getReturnType().getType(), EXECUTE_POLYMORPHIC_NAME);
13530
0576e9a0358e Truffle-DSL: minor cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 13528
diff changeset
1144 addInternalValueParameters(cachedExecute, polymorph, true, false);
10741
00a9dbcbe431 Truffle-DSL: Fixed a bug in polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents: 10695
diff changeset
1145
00a9dbcbe431 Truffle-DSL: Fixed a bug in polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents: 10695
diff changeset
1146 ExecutableTypeData sourceExecutableType = node.findExecutableType(polymorph.getReturnType().getTypeSystemType(), 0);
00a9dbcbe431 Truffle-DSL: Fixed a bug in polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents: 10695
diff changeset
1147 boolean sourceThrowsUnexpected = sourceExecutableType != null && sourceExecutableType.hasUnexpectedValue(getContext());
13535
e8ef44830b50 Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 13533
diff changeset
1148 if (sourceThrowsUnexpected && sourceExecutableType.getType().equals(node.getGenericSpecialization().getReturnType().getTypeSystemType())) {
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1149 sourceThrowsUnexpected = false;
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1150 }
10741
00a9dbcbe431 Truffle-DSL: Fixed a bug in polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents: 10695
diff changeset
1151 if (sourceThrowsUnexpected) {
00a9dbcbe431 Truffle-DSL: Fixed a bug in polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents: 10695
diff changeset
1152 cachedExecute.getThrownTypes().add(getContext().getType(UnexpectedResultException.class));
00a9dbcbe431 Truffle-DSL: Fixed a bug in polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents: 10695
diff changeset
1153 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1154 return cachedExecute;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1155
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1156 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1157
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1158 private void createConstructors(NodeData node, CodeTypeElement clazz) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1159 List<ExecutableElement> constructors = findUserConstructors(node.getNodeType());
11742
85b846b31690 Truffle-DSL: automatically generate copy constructor if super constructor expects only SourceSection parameter.
Andreas Woess <andreas.woess@jku.at>
parents: 11603
diff changeset
1160 ExecutableElement sourceSectionConstructor = null;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1161 if (constructors.isEmpty()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1162 clazz.add(createUserConstructor(clazz, null));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1163 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1164 for (ExecutableElement constructor : constructors) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1165 clazz.add(createUserConstructor(clazz, constructor));
11742
85b846b31690 Truffle-DSL: automatically generate copy constructor if super constructor expects only SourceSection parameter.
Andreas Woess <andreas.woess@jku.at>
parents: 11603
diff changeset
1166 if (NodeParser.isSourceSectionConstructor(context, constructor)) {
85b846b31690 Truffle-DSL: automatically generate copy constructor if super constructor expects only SourceSection parameter.
Andreas Woess <andreas.woess@jku.at>
parents: 11603
diff changeset
1167 sourceSectionConstructor = constructor;
85b846b31690 Truffle-DSL: automatically generate copy constructor if super constructor expects only SourceSection parameter.
Andreas Woess <andreas.woess@jku.at>
parents: 11603
diff changeset
1168 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1169 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1170 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1171 if (node.needsRewrites(getContext())) {
11742
85b846b31690 Truffle-DSL: automatically generate copy constructor if super constructor expects only SourceSection parameter.
Andreas Woess <andreas.woess@jku.at>
parents: 11603
diff changeset
1172 clazz.add(createCopyConstructor(clazz, findCopyConstructor(node.getNodeType()), sourceSectionConstructor));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1173 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1174 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1175
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1176 private CodeExecutableElement createUserConstructor(CodeTypeElement type, ExecutableElement superConstructor) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1177 CodeExecutableElement method = new CodeExecutableElement(null, type.getSimpleName().toString());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1178 CodeTreeBuilder builder = method.createBuilder();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1179
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1180 NodeData node = getModel().getNode();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1181
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1182 if (superConstructor != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1183 for (VariableElement param : superConstructor.getParameters()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1184 method.getParameters().add(CodeVariableElement.clone(param));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1185 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1186 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1187
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1188 if (superConstructor != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1189 builder.startStatement().startSuperCall();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1190 for (VariableElement param : superConstructor.getParameters()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1191 builder.string(param.getSimpleName().toString());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1192 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1193 builder.end().end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1194 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1195
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1196 for (VariableElement var : type.getFields()) {
13533
b466199f19e1 Truffle-DSL: fixed bug when using @CreateCast with children arrays.
Christian Humer <christian.humer@gmail.com>
parents: 13532
diff changeset
1197 NodeChildData child = node.findChild(var.getSimpleName().toString());
b466199f19e1 Truffle-DSL: fixed bug when using @CreateCast with children arrays.
Christian Humer <christian.humer@gmail.com>
parents: 13532
diff changeset
1198
b466199f19e1 Truffle-DSL: fixed bug when using @CreateCast with children arrays.
Christian Humer <christian.humer@gmail.com>
parents: 13532
diff changeset
1199 if (child != null) {
13536
419b3ea1bdd1 Truffle-DSL: removed try-catch hack for polymorphic invocations.
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1200 method.getParameters().add(new CodeVariableElement(child.getOriginalType(), child.getName()));
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1201 } else {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1202 method.getParameters().add(new CodeVariableElement(var.asType(), var.getSimpleName().toString()));
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1203 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1204
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1205 builder.startStatement();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1206 String fieldName = var.getSimpleName().toString();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1207
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1208 CodeTree init = createStaticCast(builder, child, fieldName);
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1209 init = createAdoptChild(builder, var.asType(), init);
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1210
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1211 builder.string("this.").string(fieldName).string(" = ").tree(init);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1212 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1213 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1214 return method;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1215 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1216
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1217 private CodeTree createStaticCast(CodeTreeBuilder parent, NodeChildData child, String fieldName) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1218 NodeData parentNode = getModel().getNode();
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1219 if (child != null) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1220 CreateCastData createCast = parentNode.findCast(child.getName());
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1221 if (createCast != null) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1222 return createTemplateMethodCall(parent, null, parentNode.getGenericSpecialization(), createCast, null, fieldName);
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1223 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1224 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1225 return CodeTreeBuilder.singleString(fieldName);
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1226 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1227
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1228 private CodeTree createAdoptChild(CodeTreeBuilder parent, TypeMirror type, CodeTree value) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1229 CodeTreeBuilder builder = new CodeTreeBuilder(parent);
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1230 if (Utils.isAssignable(getContext(), type, getContext().getTruffleTypes().getNode())) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1231 builder.string("adoptChild(").tree(value).string(")");
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1232 } else if (Utils.isAssignable(getContext(), type, getContext().getTruffleTypes().getNodeArray())) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1233 builder.string("adoptChildren(").tree(value).string(")");
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1234 } else {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1235 builder.tree(value);
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1236 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1237 return builder.getRoot();
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1238 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1239
11742
85b846b31690 Truffle-DSL: automatically generate copy constructor if super constructor expects only SourceSection parameter.
Andreas Woess <andreas.woess@jku.at>
parents: 11603
diff changeset
1240 private CodeExecutableElement createCopyConstructor(CodeTypeElement type, ExecutableElement superConstructor, ExecutableElement sourceSectionConstructor) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1241 CodeExecutableElement method = new CodeExecutableElement(null, type.getSimpleName().toString());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1242 CodeTreeBuilder builder = method.createBuilder();
11180
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
1243 method.getParameters().add(new CodeVariableElement(type.asType(), "copy"));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1244
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1245 if (superConstructor != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1246 builder.startStatement().startSuperCall().string("copy").end().end();
11742
85b846b31690 Truffle-DSL: automatically generate copy constructor if super constructor expects only SourceSection parameter.
Andreas Woess <andreas.woess@jku.at>
parents: 11603
diff changeset
1247 } else if (sourceSectionConstructor != null) {
85b846b31690 Truffle-DSL: automatically generate copy constructor if super constructor expects only SourceSection parameter.
Andreas Woess <andreas.woess@jku.at>
parents: 11603
diff changeset
1248 builder.startStatement().startSuperCall().string("copy.getSourceSection()").end().end();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1249 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1250
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1251 for (VariableElement var : type.getFields()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1252 builder.startStatement();
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1253 final String varName = var.getSimpleName().toString();
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1254 final TypeMirror varType = var.asType();
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1255
11743
c287d13cb8b0 Truffle-DSL: use clone() for copying node arrays in copy constructor.
Andreas Woess <andreas.woess@jku.at>
parents: 11742
diff changeset
1256 String copyAccess = "copy." + varName;
c287d13cb8b0 Truffle-DSL: use clone() for copying node arrays in copy constructor.
Andreas Woess <andreas.woess@jku.at>
parents: 11742
diff changeset
1257 if (Utils.isAssignable(getContext(), varType, getContext().getTruffleTypes().getNodeArray())) {
c287d13cb8b0 Truffle-DSL: use clone() for copying node arrays in copy constructor.
Andreas Woess <andreas.woess@jku.at>
parents: 11742
diff changeset
1258 copyAccess += ".clone()";
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1259 }
11743
c287d13cb8b0 Truffle-DSL: use clone() for copying node arrays in copy constructor.
Andreas Woess <andreas.woess@jku.at>
parents: 11742
diff changeset
1260 CodeTree init = createAdoptChild(builder, varType, CodeTreeBuilder.singleString(copyAccess));
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1261 builder.startStatement().string("this.").string(varName).string(" = ").tree(init).end();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1262 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1263
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1264 return method;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1265 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1266
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1267 private CodeVariableElement createAssumptionField(String assumption) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1268 CodeVariableElement var = new CodeVariableElement(getContext().getTruffleTypes().getAssumption(), assumption);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1269 var.getModifiers().add(Modifier.FINAL);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1270 return var;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1271 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1272
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1273 private CodeVariableElement createChildField(NodeChildData child) {
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1274 TypeMirror type = child.getNodeType();
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1275 CodeVariableElement var = new CodeVariableElement(type, child.getName());
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1276 var.getModifiers().add(Modifier.PROTECTED);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1277
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1278 DeclaredType annotationType;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1279 if (child.getCardinality() == Cardinality.MANY) {
10602
b8fe1fe004ec Truffle-DSL: fixed bugs in the generated polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents: 10600
diff changeset
1280 var.getModifiers().add(Modifier.FINAL);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1281 annotationType = getContext().getTruffleTypes().getChildrenAnnotation();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1282 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1283 annotationType = getContext().getTruffleTypes().getChildAnnotation();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1284 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1285
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1286 var.getAnnotationMirrors().add(new CodeAnnotationMirror(annotationType));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1287 return var;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1288 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1289
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1290 private CodeExecutableElement createGenericExecuteAndSpecialize(final NodeData node, SpecializationGroup rootGroup) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1291 TypeMirror genericReturnType = node.getGenericSpecialization().getReturnType().getType();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1292 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED), genericReturnType, EXECUTE_SPECIALIZE_NAME);
11185
5daaa0821406 Truffle-DSL: Changed executeAndSpecialize to use an int as minimumState instead of a class.
Christian Humer <christian.humer@gmail.com>
parents: 11180
diff changeset
1293 method.addParameter(new CodeVariableElement(getContext().getType(int.class), "minimumState"));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1294 addInternalValueParameters(method, node.getGenericSpecialization(), true, false);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1295 method.addParameter(new CodeVariableElement(getContext().getType(String.class), "reason"));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1296
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1297 CodeTreeBuilder builder = method.createBuilder();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1298 builder.startStatement();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1299 builder.startStaticCall(getContext().getTruffleTypes().getCompilerAsserts(), "neverPartOfCompilation").end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1300 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1301
11197
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1302 String currentNode = "this";
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1303 for (SpecializationData specialization : node.getSpecializations()) {
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1304 if (!specialization.getExceptions().isEmpty()) {
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1305 currentNode = "current";
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1306 builder.declaration(baseClassName(node), currentNode, "this");
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1307 break;
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1308 }
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1309 }
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1310
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1311 builder.startStatement().string("String message = ").startCall("createInfo0").string("reason");
13532
85b485b1e8e1 Truffle-DSL: removed support for implicit parameters. not needed anymore.
Christian Humer <christian.humer@gmail.com>
parents: 13530
diff changeset
1312 addInternalValueParameterNames(builder, node.getGenericSpecialization(), node.getGenericSpecialization(), null, false, null);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1313 builder.end().end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1314
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1315 final String currentNodeVar = currentNode;
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1316 builder.tree(createExecuteTree(builder, node.getGenericSpecialization(), rootGroup, true, new CodeBlock<SpecializationData>() {
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1317
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1318 public CodeTree create(CodeTreeBuilder b, SpecializationData current) {
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1319 return createGenericInvokeAndSpecialize(b, node.getGenericSpecialization(), current, currentNodeVar);
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1320 }
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1321 }, null, false, true, false));
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1322
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1323 boolean firstUnreachable = true;
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1324 for (SpecializationData current : node.getSpecializations()) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1325 if (current.isReachable()) {
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1326 continue;
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1327 }
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1328 if (firstUnreachable) {
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1329 emitEncounteredSynthetic(builder, current);
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1330 firstUnreachable = false;
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1331 }
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1332 }
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1333 emitUnreachableSpecializations(builder, node);
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1334
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1335 return method;
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1336 }
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1337
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1338 private SpecializationGroup createSpecializationGroups(final NodeData node) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1339 List<SpecializationData> specializations = node.getSpecializations();
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1340 List<SpecializationData> filteredSpecializations = new ArrayList<>();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1341 for (SpecializationData current : specializations) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1342 if (current.isUninitialized() || current.isPolymorphic() || !current.isReachable()) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1343 continue;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1344 }
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1345 filteredSpecializations.add(current);
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1346 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1347
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1348 return SpecializationGroup.create(filteredSpecializations);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1349 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1350
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1351 private CodeExecutableElement createGenericExecute(NodeData node, SpecializationGroup group) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1352 TypeMirror genericReturnType = node.getGenericSpecialization().getReturnType().getType();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1353 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED), genericReturnType, EXECUTE_GENERIC_NAME);
10689
3ae117e62905 Removed frame argument for generic cases if not needed.
Christian Humer <christian.humer@gmail.com>
parents: 10602
diff changeset
1354
12635
ba6593e52d22 Truffle-DSL: fixed additional wrong @SlowPath usage on generic. (GRAAL-490 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12567
diff changeset
1355 if (!node.needsFrame(getContext())) {
12399
980db6c0bcd3 Truffle-DSL: fixed invalid @SlowPath on generic execute methods. (GRAAL-490 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12398
diff changeset
1356 method.getAnnotationMirrors().add(new CodeAnnotationMirror(getContext().getTruffleTypes().getSlowPath()));
980db6c0bcd3 Truffle-DSL: fixed invalid @SlowPath on generic execute methods. (GRAAL-490 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12398
diff changeset
1357 }
12635
ba6593e52d22 Truffle-DSL: fixed additional wrong @SlowPath usage on generic. (GRAAL-490 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12567
diff changeset
1358 addInternalValueParameters(method, node.getGenericSpecialization(), node.needsFrame(getContext()), false);
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1359 final CodeTreeBuilder builder = method.createBuilder();
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1360
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1361 builder.tree(createExecuteTree(builder, node.getGenericSpecialization(), group, false, new CodeBlock<SpecializationData>() {
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1362
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1363 public CodeTree create(CodeTreeBuilder b, SpecializationData current) {
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1364 return createGenericInvoke(builder, current.getNode().getGenericSpecialization(), current);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1365 }
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1366 }, null, false, true, false));
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1367
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1368 emitUnreachableSpecializations(builder, node);
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1369
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1370 return method;
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1371 }
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1372
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1373 private void emitUnreachableSpecializations(final CodeTreeBuilder builder, NodeData node) {
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1374 for (SpecializationData current : node.getSpecializations()) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1375 if (current.isReachable()) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1376 continue;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1377 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1378 builder.string("// unreachable ").string(current.getId()).newLine();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1379 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1380 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1381
11443
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1382 protected CodeTree createExecuteTree(CodeTreeBuilder outerParent, final SpecializationData source, final SpecializationGroup group, final boolean checkMinimumState,
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1383 final CodeBlock<SpecializationData> guardedblock, final CodeTree elseBlock, boolean forceElse, final boolean emitAssumptions, final boolean typedCasts) {
11443
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1384 return guard(outerParent, source, group, checkMinimumState, new CodeBlock<Integer>() {
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1385
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1386 public CodeTree create(CodeTreeBuilder parent, Integer ifCount) {
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1387 CodeTreeBuilder builder = parent.create();
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1388
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1389 if (group.getSpecialization() != null) {
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1390 builder.tree(guardedblock.create(builder, group.getSpecialization()));
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1391
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1392 assert group.getChildren().isEmpty() : "missed a specialization";
11443
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1393
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1394 } else {
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1395 for (SpecializationGroup childGroup : group.getChildren()) {
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1396 builder.tree(createExecuteTree(builder, source, childGroup, checkMinimumState, guardedblock, null, false, emitAssumptions, typedCasts));
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1397 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1398 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1399
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1400 return builder.getRoot();
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1401 }
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1402 }, elseBlock, forceElse, emitAssumptions, typedCasts);
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1403 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1404
11443
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1405 private CodeTree guard(CodeTreeBuilder parent, SpecializationData source, SpecializationGroup group, boolean checkMinimumState, CodeBlock<Integer> bodyBlock, CodeTree elseBlock,
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1406 boolean forceElse, boolean emitAssumptions, boolean typedCasts) {
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1407 CodeTreeBuilder builder = parent.create();
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1408
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1409 int ifCount = emitGuards(builder, source, group, checkMinimumState, emitAssumptions, typedCasts);
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1410
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1411 if (isReachableGroup(group, ifCount, checkMinimumState)) {
11443
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1412 builder.tree(bodyBlock.create(builder, ifCount));
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1413 }
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1414
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1415 builder.end(ifCount);
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1416
11443
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1417 if (elseBlock != null) {
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1418 if (ifCount > 0 || forceElse) {
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1419 builder.tree(elseBlock);
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1420 }
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1421 }
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1422
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1423 return builder.getRoot();
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1424 }
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1425
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1426 private boolean isReachableGroup(SpecializationGroup group, int ifCount, boolean checkMinimumState) {
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1427 if (ifCount != 0) {
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1428 return true;
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1429 }
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1430 SpecializationGroup previous = group.getPreviousGroup();
12401
85dcc7f59c34 Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents: 12399
diff changeset
1431 if (previous == null || previous.findElseConnectableGuards(checkMinimumState).isEmpty()) {
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1432 return true;
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1433 }
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1434
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1435 /*
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1436 * Hacky else case. In this case the specialization is not reachable due to previous
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1437 * else branch. This is only true if the minimum state is not checked.
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1438 */
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1439 if (previous.getGuards().size() == 1 && previous.getTypeGuards().isEmpty() && previous.getAssumptions().isEmpty() && !checkMinimumState &&
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1440 (previous.getParent() == null || previous.getMaxSpecializationIndex() != previous.getParent().getMaxSpecializationIndex())) {
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1441 return false;
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1442 }
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1443
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1444 return true;
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1445 }
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1446
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1447 private int emitGuards(CodeTreeBuilder builder, SpecializationData source, SpecializationGroup group, boolean checkMinimumState, boolean emitAssumptions, boolean typedCasts) {
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1448 NodeData node = source.getNode();
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1449
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1450 CodeTreeBuilder guardsBuilder = builder.create();
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1451 CodeTreeBuilder castBuilder = builder.create();
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1452 CodeTreeBuilder guardsCastBuilder = builder.create();
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1453
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1454 String guardsAnd = "";
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1455 String guardsCastAnd = "";
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1456
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1457 boolean minimumState = checkMinimumState;
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1458 if (minimumState) {
12401
85dcc7f59c34 Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents: 12399
diff changeset
1459 int groupMaxIndex = group.getUncheckedSpecializationIndex();
85dcc7f59c34 Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents: 12399
diff changeset
1460
85dcc7f59c34 Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents: 12399
diff changeset
1461 if (groupMaxIndex > -1) {
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1462 guardsBuilder.string(guardsAnd);
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1463 guardsBuilder.string("minimumState < " + groupMaxIndex);
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1464 guardsAnd = " && ";
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1465 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1466 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1467
11443
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1468 if (emitAssumptions) {
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1469 for (String assumption : group.getAssumptions()) {
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1470 guardsBuilder.string(guardsAnd);
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1471 guardsBuilder.string("this");
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1472 guardsBuilder.string(".").string(assumption).string(".isValid()");
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1473 guardsAnd = " && ";
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1474 }
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1475 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1476
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1477 for (TypeGuard typeGuard : group.getTypeGuards()) {
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1478 ActualParameter valueParam = source.getSignatureParameter(typeGuard.getSignatureIndex());
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1479
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1480 if (valueParam == null) {
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1481 /*
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1482 * If used inside a execute evaluated method then the value param may not exist.
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1483 * In that case we assume that the value is executed generic or of the current
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1484 * specialization.
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1485 */
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1486 if (group.getSpecialization() != null) {
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1487 valueParam = group.getSpecialization().getSignatureParameter(typeGuard.getSignatureIndex());
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1488 } else {
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1489 valueParam = node.getGenericSpecialization().getSignatureParameter(typeGuard.getSignatureIndex());
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1490 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1491 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1492
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1493 NodeExecutionData execution = valueParam.getSpecification().getExecution();
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1494 CodeTree implicitGuard = createTypeGuard(guardsBuilder, execution, valueParam, typeGuard.getType(), typedCasts);
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1495 if (implicitGuard != null) {
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1496 guardsBuilder.string(guardsAnd);
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1497 guardsBuilder.tree(implicitGuard);
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1498 guardsAnd = " && ";
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1499 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1500
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1501 CodeTree cast = createCast(castBuilder, execution, valueParam, typeGuard.getType(), checkMinimumState, typedCasts);
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1502 if (cast != null) {
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1503 castBuilder.tree(cast);
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1504 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1505 }
12401
85dcc7f59c34 Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents: 12399
diff changeset
1506 List<GuardData> elseGuards = group.findElseConnectableGuards(checkMinimumState);
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1507
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1508 for (GuardData guard : group.getGuards()) {
11442
2868b55001d4 Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents: 11439
diff changeset
1509 if (elseGuards.contains(guard)) {
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1510 continue;
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1511 }
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1512
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1513 if (needsTypeGuard(source, group, guard)) {
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1514 guardsCastBuilder.tree(createMethodGuard(builder, guardsCastAnd, source, guard));
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1515 guardsCastAnd = " && ";
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1516 } else {
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1517 guardsBuilder.tree(createMethodGuard(builder, guardsAnd, source, guard));
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1518 guardsAnd = " && ";
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1519 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1520 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1521
11442
2868b55001d4 Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents: 11439
diff changeset
1522 int ifCount = startGuardIf(builder, guardsBuilder, 0, elseGuards);
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1523 builder.tree(castBuilder.getRoot());
11442
2868b55001d4 Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents: 11439
diff changeset
1524 ifCount = startGuardIf(builder, guardsCastBuilder, ifCount, elseGuards);
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1525 return ifCount;
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1526 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1527
11442
2868b55001d4 Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents: 11439
diff changeset
1528 private int startGuardIf(CodeTreeBuilder builder, CodeTreeBuilder conditionBuilder, int ifCount, List<GuardData> elseGuard) {
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1529 int newIfCount = ifCount;
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1530
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1531 if (!conditionBuilder.isEmpty()) {
11442
2868b55001d4 Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents: 11439
diff changeset
1532 if (ifCount == 0 && !elseGuard.isEmpty()) {
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1533 builder.startElseIf();
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1534 } else {
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1535 builder.startIf();
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1536 }
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1537 builder.tree(conditionBuilder.getRoot());
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1538 builder.end().startBlock();
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1539 newIfCount++;
11442
2868b55001d4 Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents: 11439
diff changeset
1540 } else if (ifCount == 0 && !elseGuard.isEmpty()) {
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1541 builder.startElseBlock();
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1542 newIfCount++;
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1543 }
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1544 return newIfCount;
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1545 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1546
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1547 private boolean needsTypeGuard(SpecializationData source, SpecializationGroup group, GuardData guard) {
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1548 int signatureIndex = 0;
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1549 for (ActualParameter parameter : guard.getParameters()) {
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1550 if (!parameter.getSpecification().isSignature()) {
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1551 continue;
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1552 }
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1553
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1554 TypeGuard typeGuard = group.findTypeGuard(signatureIndex);
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1555 if (typeGuard != null) {
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1556 TypeData requiredType = typeGuard.getType();
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1557
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1558 ActualParameter sourceParameter = source.findParameter(parameter.getLocalName());
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1559 if (sourceParameter == null) {
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1560 sourceParameter = source.getNode().getGenericSpecialization().findParameter(parameter.getLocalName());
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1561 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1562
11443
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1563 if (Utils.needsCastTo(getContext(), sourceParameter.getType(), requiredType.getPrimitiveType())) {
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1564 return true;
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1565 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1566 }
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1567
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1568 signatureIndex++;
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1569 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1570 return false;
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1571 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1572
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1573 private CodeTree createTypeGuard(CodeTreeBuilder parent, NodeExecutionData execution, ActualParameter source, TypeData targetType, boolean typedCasts) {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1574 NodeData node = execution.getChild().getNodeData();
11443
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1575
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1576 CodeTreeBuilder builder = new CodeTreeBuilder(parent);
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1577
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1578 TypeData sourceType = source.getTypeSystemType();
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1579
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1580 if (!sourceType.needsCastTo(getContext(), targetType)) {
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1581 return null;
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1582 }
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1583
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1584 builder.startGroup();
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1585
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1586 if (execution.isShortCircuit()) {
11443
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1587 ActualParameter shortCircuit = source.getPreviousParameter();
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1588 assert shortCircuit != null;
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1589 builder.string("(");
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1590 builder.string("!").string(valueName(shortCircuit));
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1591 builder.string(" || ");
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1592 }
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1593
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1594 String castMethodName;
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1595 String castTypeName = null;
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1596 List<TypeData> types = getModel().getNode().getTypeSystem().lookupSourceTypes(targetType);
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1597 if (types.size() > 1) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1598 castMethodName = TypeSystemCodeGenerator.isImplicitTypeMethodName(targetType);
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1599 if (typedCasts) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1600 castTypeName = implicitTypeName(source);
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1601 }
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1602 } else {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1603 castMethodName = TypeSystemCodeGenerator.isTypeMethodName(targetType);
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1604 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1605
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1606 startCallTypeSystemMethod(getContext(), builder, node.getTypeSystem(), castMethodName);
11443
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1607 builder.string(valueName(source));
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1608 if (castTypeName != null) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1609 builder.string(castTypeName);
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1610 }
11443
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1611 builder.end().end(); // call
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1612
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1613 if (execution.isShortCircuit()) {
11443
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1614 builder.string(")");
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1615 }
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1616
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1617 builder.end(); // group
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1618
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1619 return builder.getRoot();
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1620 }
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1621
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1622 // TODO merge redundancies with #createTypeGuard
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1623 private CodeTree createCast(CodeTreeBuilder parent, NodeExecutionData execution, ActualParameter source, TypeData targetType, boolean checkMinimumState, boolean typedCasts) {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1624 NodeData node = execution.getChild().getNodeData();
11443
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1625 TypeData sourceType = source.getTypeSystemType();
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1626
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1627 if (!sourceType.needsCastTo(getContext(), targetType)) {
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1628 return null;
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1629 }
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1630
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1631 CodeTree condition = null;
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1632 if (execution.isShortCircuit()) {
11443
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1633 ActualParameter shortCircuit = source.getPreviousParameter();
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1634 assert shortCircuit != null;
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1635 condition = CodeTreeBuilder.singleString(valueName(shortCircuit));
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1636 }
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1637
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1638 String castMethodName;
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1639 String castTypeName = null;
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1640 List<TypeData> types = getModel().getNode().getTypeSystem().lookupSourceTypes(targetType);
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1641 if (types.size() > 1) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1642 castMethodName = TypeSystemCodeGenerator.asImplicitTypeMethodName(targetType);
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1643 if (typedCasts) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1644 castTypeName = implicitTypeName(source);
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1645 }
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1646 } else {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1647 castMethodName = TypeSystemCodeGenerator.asTypeMethodName(targetType);
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1648 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1649
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1650 List<CodeTree> args = new ArrayList<>();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1651 args.add(CodeTreeBuilder.singleString(valueName(source)));
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1652 if (castTypeName != null) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1653 args.add(CodeTreeBuilder.singleString(castTypeName));
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1654 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1655
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1656 CodeTree value = createCallTypeSystemMethod(context, parent, node, castMethodName, args.toArray(new CodeTree[0]));
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1657
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1658 CodeTreeBuilder builder = parent.create();
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1659 builder.tree(createLazyAssignment(parent, castValueName(source), targetType.getPrimitiveType(), condition, value));
11603
152b4146f05b Truffle-DSL: fix implicit cast bug.
Andreas Woess <andreas.woess@jku.at>
parents: 11554
diff changeset
1660 if (checkMinimumState && types.size() > 1) {
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1661 CodeTree castType = createCallTypeSystemMethod(context, parent, node, TypeSystemCodeGenerator.getImplicitClass(targetType), CodeTreeBuilder.singleString(valueName(source)));
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1662 builder.tree(createLazyAssignment(builder, implicitTypeName(source), getContext().getType(Class.class), condition, castType));
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1663 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1664
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1665 return builder.getRoot();
11443
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1666 }
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
1667
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1668 private CodeTree createMethodGuard(CodeTreeBuilder parent, String prefix, SpecializationData source, GuardData guard) {
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1669 CodeTreeBuilder builder = parent.create();
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1670 builder.string(prefix);
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1671 if (guard.isNegated()) {
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1672 builder.string("!");
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1673 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1674 builder.tree(createTemplateMethodCall(builder, null, source, guard, null));
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1675 return builder.getRoot();
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1676 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1677
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1678 protected CodeTree createGenericInvoke(CodeTreeBuilder parent, SpecializationData source, SpecializationData current) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1679 CodeTreeBuilder builder = new CodeTreeBuilder(parent);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1680
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1681 if (current.getMethod() == null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1682 emitEncounteredSynthetic(builder, current);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1683 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1684 builder.startReturn().tree(createTemplateMethodCall(builder, null, source, current, null)).end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1685 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1686
11197
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1687 return encloseThrowsWithFallThrough(current, builder.getRoot());
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1688 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1689
11197
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1690 protected CodeTree createGenericInvokeAndSpecialize(CodeTreeBuilder parent, SpecializationData source, SpecializationData current, String currentNodeVar) {
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1691 CodeTreeBuilder builder = parent.create();
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1692 CodeTreeBuilder prefix = parent.create();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1693
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1694 NodeData node = current.getNode();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1695
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1696 if (current.isGeneric() && node.isPolymorphic()) {
11197
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1697 builder.startIf().string(currentNodeVar).string(".next0 == null && minimumState > 0").end().startBlock();
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1698 builder.tree(createRewritePolymorphic(builder, node, currentNodeVar));
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1699 builder.end();
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1700 builder.startElseBlock();
11197
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1701 builder.tree(createRewriteGeneric(builder, source, current, currentNodeVar));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1702 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1703 } else {
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1704 if (current.getExceptions().isEmpty()) {
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1705 builder.tree(createGenericInvoke(builder, source, current, createReplaceCall(builder, current, currentNodeVar, currentNodeVar, null), null));
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1706 } else {
11197
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1707 builder.startStatement().string(currentNodeVar).string(" = ").tree(createReplaceCall(builder, current, currentNodeVar, currentNodeVar, null)).end();
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1708 builder.tree(createGenericInvoke(builder, source, current, null, CodeTreeBuilder.singleString(currentNodeVar)));
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1709 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1710 }
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1711 CodeTreeBuilder root = parent.create();
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1712 root.tree(prefix.getRoot());
11197
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1713 root.tree(encloseThrowsWithFallThrough(current, builder.getRoot()));
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1714 return root.getRoot();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1715 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1716
11197
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1717 private CodeTree createRewriteGeneric(CodeTreeBuilder parent, SpecializationData source, SpecializationData current, String currentNode) {
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1718 NodeData node = current.getNode();
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1719
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1720 CodeTreeBuilder builder = parent.create();
11197
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1721 builder.declaration(getContext().getTruffleTypes().getNode(), "root", currentNode);
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1722 builder.startIf().string(currentNode).string(".next0 != null").end().startBlock();
11320
80de3bbfa8b9 Truffle-DSL: fixed inconsistent children for polymorphic -> generic rewrites. (GRAAL-425)
Christian Humer <christian.humer@gmail.com>
parents: 11201
diff changeset
1723 /*
80de3bbfa8b9 Truffle-DSL: fixed inconsistent children for polymorphic -> generic rewrites. (GRAAL-425)
Christian Humer <christian.humer@gmail.com>
parents: 11201
diff changeset
1724 * Communicates to the caller of executeAndSpecialize that it was rewritten to generic.
80de3bbfa8b9 Truffle-DSL: fixed inconsistent children for polymorphic -> generic rewrites. (GRAAL-425)
Christian Humer <christian.humer@gmail.com>
parents: 11201
diff changeset
1725 * Its important that this is used instead of the currentNode since the caller is this.
80de3bbfa8b9 Truffle-DSL: fixed inconsistent children for polymorphic -> generic rewrites. (GRAAL-425)
Christian Humer <christian.humer@gmail.com>
parents: 11201
diff changeset
1726 * CurrentNode may not be this anymore at this place.
80de3bbfa8b9 Truffle-DSL: fixed inconsistent children for polymorphic -> generic rewrites. (GRAAL-425)
Christian Humer <christian.humer@gmail.com>
parents: 11201
diff changeset
1727 */
80de3bbfa8b9 Truffle-DSL: fixed inconsistent children for polymorphic -> generic rewrites. (GRAAL-425)
Christian Humer <christian.humer@gmail.com>
parents: 11201
diff changeset
1728 builder.statement("this.next0 = null");
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1729 builder.tree(createFindRoot(builder, node, false));
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1730 builder.end();
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1731 builder.end();
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1732 builder.tree(createGenericInvoke(builder, source, current, createReplaceCall(builder, current, "root", "(" + baseClassName(node) + ") root", null), null));
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1733 return builder.getRoot();
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1734 }
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1735
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1736 protected CodeTree createFindRoot(CodeTreeBuilder parent, NodeData node, boolean countDepth) {
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1737 CodeTreeBuilder builder = parent.create();
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1738 builder.startDoBlock();
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1739 builder.startAssert().string("root != null").string(" : ").doubleQuote("No polymorphic parent node.").end();
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1740 builder.startStatement().string("root = ").string("root.getParent()").end();
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1741 if (countDepth) {
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1742 builder.statement("depth++");
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1743 }
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1744 builder.end();
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1745 builder.startDoWhile();
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1746 builder.string("!").startParantheses().instanceOf("root", nodePolymorphicClassName(node)).end();
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1747 builder.end();
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1748 return builder.getRoot();
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1749 }
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1750
11197
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1751 private CodeTree encloseThrowsWithFallThrough(SpecializationData current, CodeTree tree) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1752 if (current.getExceptions().isEmpty()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1753 return tree;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1754 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1755 CodeTreeBuilder builder = new CodeTreeBuilder(null);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1756
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1757 builder.startTryBlock();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1758 builder.tree(tree);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1759 for (SpecializationThrowsData exception : current.getExceptions()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1760 builder.end().startCatchBlock(exception.getJavaClass(), "rewriteEx");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1761 builder.string("// fall through").newLine();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1762 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1763 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1764
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1765 return builder.getRoot();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1766 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1767
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1768 protected CodeTree createGenericInvoke(CodeTreeBuilder parent, SpecializationData source, SpecializationData current, CodeTree replaceCall, CodeTree replaceVar) {
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1769 assert replaceCall == null || replaceVar == null;
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1770 CodeTreeBuilder builder = parent.create();
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1771 CodeTree replace = replaceVar;
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1772 if (replace == null) {
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1773 replace = replaceCall;
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1774 }
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1775 if (current.isGeneric()) {
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1776 builder.startReturn().tree(replace).string(".").startCall(EXECUTE_GENERIC_NAME);
13532
85b485b1e8e1 Truffle-DSL: removed support for implicit parameters. not needed anymore.
Christian Humer <christian.humer@gmail.com>
parents: 13530
diff changeset
1777 addInternalValueParameterNames(builder, source, current, null, current.getNode().needsFrame(getContext()), null);
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1778 builder.end().end();
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1779 } else if (current.getMethod() == null) {
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1780 if (replaceCall != null) {
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1781 builder.statement(replaceCall);
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1782 }
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1783 emitEncounteredSynthetic(builder, current);
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1784 } else if (!current.canBeAccessedByInstanceOf(getContext(), source.getNode().getNodeType())) {
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1785 if (replaceCall != null) {
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1786 builder.statement(replaceCall);
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1787 }
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1788 builder.startReturn().tree(createTemplateMethodCall(parent, null, source, current, null)).end();
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1789 } else {
11201
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1790 replace.add(new CodeTree(CodeTreeKind.STRING, null, "."));
7fc3e1fb3965 Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents: 11197
diff changeset
1791 builder.startReturn().tree(createTemplateMethodCall(parent, replace, source, current, null)).end();
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1792 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1793 return builder.getRoot();
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1794 }
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1795
11197
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1796 protected CodeTree createReplaceCall(CodeTreeBuilder builder, SpecializationData current, String target, String source, String message) {
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1797 String className = nodeSpecializationClassName(current);
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1798 CodeTreeBuilder replaceCall = builder.create();
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1799 if (target != null) {
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1800 replaceCall.startCall(target, "replace");
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1801 } else {
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1802 replaceCall.startCall("replace");
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1803 }
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1804 replaceCall.startGroup().startNew(className).string(source);
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1805 for (ActualParameter param : current.getSignatureParameters()) {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1806 NodeChildData child = param.getSpecification().getExecution().getChild();
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1807 List<TypeData> types = child.getNodeData().getTypeSystem().lookupSourceTypes(param.getTypeSystemType());
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1808 if (types.size() > 1) {
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1809 replaceCall.string(implicitTypeName(param));
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1810 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1811 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1812 replaceCall.end().end();
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1813
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1814 if (message == null) {
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1815 replaceCall.string("message");
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1816 } else {
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1817 replaceCall.doubleQuote(message);
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1818 }
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1819 replaceCall.end();
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
1820 return replaceCall.getRoot();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1821 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1822
11197
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1823 private CodeTree createRewritePolymorphic(CodeTreeBuilder parent, NodeData node, String currentNode) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1824 String polyClassName = nodePolymorphicClassName(node);
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1825 String uninitializedName = nodeSpecializationClassName(node.getUninitializedSpecialization());
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1826 CodeTreeBuilder builder = parent.create();
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1827
12567
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1828 builder.declaration(getElement().asType(), "currentCopy", currentNode + ".copyPolymorphic()");
11197
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1829 builder.declaration(polyClassName, "polymorphic", builder.create().startNew(polyClassName).string(currentNode).end());
3479ab380552 Truffle-DSL: More elegant solution for rewrite with exception in executeAndSpecialize0.
Christian Humer <christian.humer@gmail.com>
parents: 11195
diff changeset
1830 builder.startStatement().startCall(currentNode, "replace").string("polymorphic").string("message").end().end();
12567
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1831 builder.startStatement().startCall("polymorphic", "setNext0").string("currentCopy").end().end();
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1832 builder.startStatement().startCall("currentCopy", "setNext0").startNew(uninitializedName).string(currentNode).end().end().end();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1833
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1834 builder.startReturn();
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1835 builder.startCall("currentCopy.next0", EXECUTE_POLYMORPHIC_NAME);
13532
85b485b1e8e1 Truffle-DSL: removed support for implicit parameters. not needed anymore.
Christian Humer <christian.humer@gmail.com>
parents: 13530
diff changeset
1836 addInternalValueParameterNames(builder, node.getGenericSpecialization(), node.getGenericSpecialization(), null, true, null);
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1837 builder.end();
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
1838 builder.end();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1839
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1840 return builder.getRoot();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1841 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1842
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1843 protected CodeTree createCastingExecute(CodeTreeBuilder parent, SpecializationData specialization, ExecutableTypeData executable, ExecutableTypeData castExecutable) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1844 TypeData type = executable.getType();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1845 CodeTreeBuilder builder = new CodeTreeBuilder(parent);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1846 NodeData node = specialization.getNode();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1847
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1848 ExecutableTypeData castedType = node.findExecutableType(type, 0);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1849 TypeData primaryType = castExecutable.getType();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1850
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1851 boolean needsTry = castExecutable.hasUnexpectedValue(getContext());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1852 boolean returnVoid = type.isVoid();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1853
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1854 List<ActualParameter> executeParameters = new ArrayList<>();
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1855 for (ActualParameter sourceParameter : executable.getSignatureParameters()) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1856 ActualParameter targetParameter = castExecutable.findParameter(sourceParameter.getLocalName());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1857 if (targetParameter != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1858 executeParameters.add(targetParameter);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1859 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1860 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1861
11445
5fbd1ba4a5f3 Truffle-DSL: execute evaluated methods can now be declared using any type in the typesystem as parameters.
Christian Humer <christian.humer@gmail.com>
parents: 11443
diff changeset
1862 // execute names are enforced no cast
5fbd1ba4a5f3 Truffle-DSL: execute evaluated methods can now be declared using any type in the typesystem as parameters.
Christian Humer <christian.humer@gmail.com>
parents: 11443
diff changeset
1863 String[] executeParameterNames = new String[executeParameters.size()];
5fbd1ba4a5f3 Truffle-DSL: execute evaluated methods can now be declared using any type in the typesystem as parameters.
Christian Humer <christian.humer@gmail.com>
parents: 11443
diff changeset
1864 for (int i = 0; i < executeParameterNames.length; i++) {
5fbd1ba4a5f3 Truffle-DSL: execute evaluated methods can now be declared using any type in the typesystem as parameters.
Christian Humer <christian.humer@gmail.com>
parents: 11443
diff changeset
1865 executeParameterNames[i] = valueName(executeParameters.get(i));
5fbd1ba4a5f3 Truffle-DSL: execute evaluated methods can now be declared using any type in the typesystem as parameters.
Christian Humer <christian.humer@gmail.com>
parents: 11443
diff changeset
1866 }
5fbd1ba4a5f3 Truffle-DSL: execute evaluated methods can now be declared using any type in the typesystem as parameters.
Christian Humer <christian.humer@gmail.com>
parents: 11443
diff changeset
1867
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1868 builder.tree(createExecuteChildren(builder, executable, specialization, executeParameters, null));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1869
11445
5fbd1ba4a5f3 Truffle-DSL: execute evaluated methods can now be declared using any type in the typesystem as parameters.
Christian Humer <christian.humer@gmail.com>
parents: 11443
diff changeset
1870 CodeTree primaryExecuteCall = createTemplateMethodCall(builder, null, executable, castExecutable, null, executeParameterNames);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1871 if (needsTry) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1872 if (!returnVoid) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1873 builder.declaration(primaryType.getPrimitiveType(), "value");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1874 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1875 builder.startTryBlock();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1876
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1877 if (returnVoid) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1878 builder.statement(primaryExecuteCall);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1879 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1880 builder.startStatement();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1881 builder.string("value = ");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1882 builder.tree(primaryExecuteCall);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1883 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1884 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1885
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1886 builder.end().startCatchBlock(getUnexpectedValueException(), "ex");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1887 if (returnVoid) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1888 builder.string("// ignore").newLine();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1889 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1890 builder.startReturn();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1891 builder.tree(createExpectExecutableType(node, specialization.getNode().getTypeSystem().getGenericTypeData(), castedType, CodeTreeBuilder.singleString("ex.getResult()")));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1892 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1893 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1894 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1895
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1896 if (!returnVoid) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1897 builder.startReturn();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1898 builder.tree(createExpectExecutableType(node, castExecutable.getReturnType().getTypeSystemType(), executable, CodeTreeBuilder.singleString("value")));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1899 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1900 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1901 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1902 if (returnVoid) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1903 builder.statement(primaryExecuteCall);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1904 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1905 builder.startReturn();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1906 builder.tree(createExpectExecutableType(node, castExecutable.getReturnType().getTypeSystemType(), executable, primaryExecuteCall));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1907 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1908 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1909 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1910
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1911 return builder.getRoot();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1912 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1913
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1914 protected CodeTree createExpectExecutableType(NodeData node, TypeData sourceType, ExecutableTypeData castedType, CodeTree value) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1915 boolean hasUnexpected = castedType.hasUnexpectedValue(getContext());
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1916 return createCastType(node.getTypeSystem(), sourceType, castedType.getType(), hasUnexpected, value);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1917 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1918
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1919 protected CodeTree createExecuteChildren(CodeTreeBuilder parent, ExecutableTypeData sourceExecutable, SpecializationData specialization, List<ActualParameter> targetParameters,
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1920 ActualParameter unexpectedParameter) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1921 CodeTreeBuilder builder = parent.create();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1922 for (ActualParameter targetParameter : targetParameters) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1923 if (!targetParameter.getSpecification().isSignature()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1924 continue;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1925 }
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1926 NodeExecutionData execution = targetParameter.getSpecification().getExecution();
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1927 CodeTree executionExpressions = createExecuteChild(builder, execution, sourceExecutable, targetParameter, unexpectedParameter);
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1928 CodeTree unexpectedTree = createCatchUnexpectedTree(builder, executionExpressions, specialization, sourceExecutable, targetParameter, execution.isShortCircuit(), unexpectedParameter);
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1929 CodeTree shortCircuitTree = createShortCircuitTree(builder, unexpectedTree, specialization, targetParameter, unexpectedParameter);
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1930
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1931 if (shortCircuitTree == executionExpressions) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1932 if (containsNewLine(executionExpressions)) {
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1933 builder.declaration(targetParameter.getType(), valueName(targetParameter));
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1934 builder.tree(shortCircuitTree);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1935 } else {
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1936 builder.startStatement().type(targetParameter.getType()).string(" ").tree(shortCircuitTree).end();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1937 }
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1938 } else {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1939 builder.tree(shortCircuitTree);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1940 }
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1941
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1942 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1943 return builder.getRoot();
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1944 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
1945
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1946 private ExecutableTypeData resolveExecutableType(NodeExecutionData execution, TypeData type) {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1947 ExecutableTypeData targetExecutable = execution.getChild().findExecutableType(getContext(), type);
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1948 if (targetExecutable == null) {
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1949 targetExecutable = execution.getChild().findAnyGenericExecutableType(getContext());
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1950 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1951 return targetExecutable;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1952 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1953
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1954 private CodeTree createExecuteChild(CodeTreeBuilder parent, NodeExecutionData execution, ExecutableTypeData sourceExecutable, ActualParameter targetParameter,
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1955 ActualParameter unexpectedParameter) {
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1956 SpecializationData specialization = getModel();
12398
c78612fb0120 Truffle-DSL. fixed some issues with new generation strategy.
Christian Humer <christian.humer@gmail.com>
parents: 12395
diff changeset
1957 TreeSet<TypeData> possiblePolymorphicTypes = lookupPolymorphicTargetTypes(targetParameter);
c78612fb0120 Truffle-DSL. fixed some issues with new generation strategy.
Christian Humer <christian.humer@gmail.com>
parents: 12395
diff changeset
1958 if (specialization.isPolymorphic() && targetParameter.getTypeSystemType().isGeneric() && unexpectedParameter == null && possiblePolymorphicTypes.size() > 1) {
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1959
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1960 CodeTreeBuilder builder = parent.create();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1961
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1962 boolean elseIf = false;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1963 for (TypeData possiblePolymoprhicType : possiblePolymorphicTypes) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1964 if (possiblePolymoprhicType.isGeneric()) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1965 continue;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1966 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1967 elseIf = builder.startIf(elseIf);
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1968
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1969 ActualParameter sourceParameter = sourceExecutable.findParameter(targetParameter.getLocalName());
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1970 TypeData sourceType = sourceParameter != null ? sourceParameter.getTypeSystemType() : null;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1971 builder.string(polymorphicTypeName(targetParameter)).string(" == ").typeLiteral(possiblePolymoprhicType.getPrimitiveType());
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1972 builder.end().startBlock();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1973 builder.startStatement();
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1974 builder.tree(createExecuteChildExpression(parent, execution, sourceType, new ActualParameter(targetParameter, possiblePolymoprhicType), unexpectedParameter, null));
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1975 builder.end();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1976 builder.end();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1977 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1978
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1979 builder.startElseBlock();
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1980 builder.startStatement().tree(createExecuteChildImplicit(parent, execution, sourceExecutable, targetParameter, unexpectedParameter)).end();
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1981 builder.end();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1982
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1983 return builder.getRoot();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1984 } else {
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1985 return createExecuteChildImplicit(parent, execution, sourceExecutable, targetParameter, unexpectedParameter);
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1986 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1987 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
1988
12567
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1989 protected final List<ActualParameter> getImplicitTypeParamters(SpecializationData model) {
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1990 List<ActualParameter> parameter = new ArrayList<>();
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1991 for (ActualParameter param : model.getSignatureParameters()) {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
1992 NodeChildData child = param.getSpecification().getExecution().getChild();
12567
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1993 List<TypeData> types = child.getNodeData().getTypeSystem().lookupSourceTypes(param.getTypeSystemType());
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1994 if (types.size() > 1) {
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1995 parameter.add(param);
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1996 }
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1997 }
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1998 return parameter;
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
1999 }
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
2000
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2001 protected final TreeSet<TypeData> lookupPolymorphicTargetTypes(ActualParameter param) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2002 SpecializationData specialization = getModel();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2003 TreeSet<TypeData> possiblePolymorphicTypes = new TreeSet<>();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2004 for (SpecializationData otherSpecialization : specialization.getNode().getSpecializations()) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2005 if (!otherSpecialization.isSpecialized()) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2006 continue;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2007 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2008 ActualParameter otherParameter = otherSpecialization.findParameter(param.getLocalName());
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2009 if (otherParameter != null) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2010 possiblePolymorphicTypes.add(otherParameter.getTypeSystemType());
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2011 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2012 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2013 return possiblePolymorphicTypes;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2014 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2015
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2016 private CodeTree createExecuteChildImplicit(CodeTreeBuilder parent, NodeExecutionData execution, ExecutableTypeData sourceExecutable, ActualParameter param, ActualParameter unexpectedParameter) {
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2017 CodeTreeBuilder builder = parent.create();
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2018 ActualParameter sourceParameter = sourceExecutable.findParameter(param.getLocalName());
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2019 String childExecuteName = createExecuteChildMethodName(param, sourceParameter != null);
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2020 if (childExecuteName != null) {
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2021 builder.string(valueName(param));
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2022 builder.string(" = ");
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2023 builder.startCall(childExecuteName);
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2024
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2025 for (ActualParameter parameters : sourceExecutable.getParameters()) {
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2026 if (parameters.getSpecification().isSignature()) {
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2027 continue;
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2028 }
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2029 builder.string(parameters.getLocalName());
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2030 }
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2031
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2032 if (sourceParameter != null) {
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2033 builder.string(valueNameEvaluated(sourceParameter));
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2034 }
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2035
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2036 builder.string(implicitTypeName(param));
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2037
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2038 builder.end();
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2039 } else {
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2040 List<TypeData> sourceTypes = execution.getChild().getNodeData().getTypeSystem().lookupSourceTypes(param.getTypeSystemType());
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2041 TypeData expectType = sourceParameter != null ? sourceParameter.getTypeSystemType() : null;
12392
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2042 if (sourceTypes.size() > 1) {
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2043 builder.tree(createExecuteChildImplicitExpressions(parent, param, expectType));
12392
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2044 } else {
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2045 builder.tree(createExecuteChildExpression(parent, execution, expectType, param, unexpectedParameter, null));
12392
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2046 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2047 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2048 return builder.getRoot();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2049 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2050
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2051 private String createExecuteChildMethodName(ActualParameter param, boolean expect) {
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2052 NodeExecutionData execution = param.getSpecification().getExecution();
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2053 NodeChildData child = execution.getChild();
12392
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2054 if (child.getExecuteWith().size() > 0) {
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2055 return null;
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2056 }
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2057 List<TypeData> sourceTypes = child.getNodeData().getTypeSystem().lookupSourceTypes(param.getTypeSystemType());
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2058 if (sourceTypes.size() <= 1) {
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2059 return null;
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2060 }
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2061 String prefix = expect ? "expect" : "execute";
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2062 String suffix = execution.getIndex() > -1 ? String.valueOf(execution.getIndex()) : "";
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2063 return prefix + Utils.firstLetterUpperCase(child.getName()) + Utils.firstLetterUpperCase(Utils.getSimpleName(param.getType())) + suffix;
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2064 }
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2065
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2066 private List<CodeExecutableElement> createExecuteChilds(ActualParameter param, Set<TypeData> expectTypes) {
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2067 CodeExecutableElement executeMethod = createExecuteChild(param, null);
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2068 if (executeMethod == null) {
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2069 return Collections.emptyList();
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2070 }
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2071 List<CodeExecutableElement> childs = new ArrayList<>();
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2072 childs.add(executeMethod);
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2073
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2074 for (TypeData expectType : expectTypes) {
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2075 CodeExecutableElement method = createExecuteChild(param, expectType);
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2076 if (method != null) {
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2077 childs.add(method);
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2078 }
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2079 }
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2080 return childs;
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2081 }
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2082
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2083 private CodeExecutableElement createExecuteChild(ActualParameter param, TypeData expectType) {
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2084 String childExecuteName = createExecuteChildMethodName(param, expectType != null);
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2085 if (childExecuteName == null) {
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2086 return null;
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2087 }
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2088
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2089 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, expectType != null ? STATIC : FINAL), param.getType(), childExecuteName);
12392
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2090 method.getThrownTypes().add(getContext().getTruffleTypes().getUnexpectedValueException());
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2091 method.addParameter(new CodeVariableElement(getContext().getTruffleTypes().getFrame(), "frameValue"));
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2092 if (expectType != null) {
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2093 method.addParameter(new CodeVariableElement(expectType.getPrimitiveType(), valueNameEvaluated(param)));
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2094 }
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2095 method.addParameter(new CodeVariableElement(getContext().getType(Class.class), implicitTypeName(param)));
12392
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2096
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2097 CodeTreeBuilder builder = method.createBuilder();
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2098 builder.declaration(param.getType(), valueName(param));
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2099 builder.tree(createExecuteChildImplicitExpressions(builder, param, expectType));
12392
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2100 builder.startReturn().string(valueName(param)).end();
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2101
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2102 return method;
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2103 }
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2104
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2105 private CodeTree createExecuteChildImplicitExpressions(CodeTreeBuilder parent, ActualParameter targetParameter, TypeData expectType) {
12392
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2106 CodeTreeBuilder builder = parent.create();
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2107 NodeData node = getModel().getNode();
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2108 NodeExecutionData execution = targetParameter.getSpecification().getExecution();
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2109 List<TypeData> sourceTypes = node.getTypeSystem().lookupSourceTypes(targetParameter.getTypeSystemType());
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2110 boolean elseIf = false;
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2111 int index = 0;
12392
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2112 for (TypeData sourceType : sourceTypes) {
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2113 if (index < sourceTypes.size() - 1) {
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2114 elseIf = builder.startIf(elseIf);
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2115 builder.string(implicitTypeName(targetParameter)).string(" == ").typeLiteral(sourceType.getPrimitiveType());
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2116 builder.end();
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2117 builder.startBlock();
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2118 } else {
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2119 builder.startElseBlock();
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2120 }
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2121
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2122 ExecutableTypeData implictExecutableTypeData = execution.getChild().findExecutableType(getContext(), sourceType);
12392
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2123 if (implictExecutableTypeData == null) {
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2124 /*
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2125 * For children with executeWith.size() > 0 an executable type may not exist so
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2126 * use the generic executable type which is guaranteed to exist. An expect call
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2127 * is inserted automatically by #createExecuteExpression.
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2128 */
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2129 implictExecutableTypeData = execution.getChild().getNodeData().findExecutableType(node.getTypeSystem().getGenericTypeData(), execution.getChild().getExecuteWith().size());
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2130 }
12392
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2131
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2132 ImplicitCastData cast = execution.getChild().getNodeData().getTypeSystem().lookupCast(sourceType, targetParameter.getTypeSystemType());
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2133 CodeTree execute = createExecuteChildExpression(builder, execution, expectType, targetParameter, null, cast);
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2134 builder.statement(execute);
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2135 builder.end();
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2136 index++;
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2137 }
12392
4e26955b6da2 Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents: 12391
diff changeset
2138 return builder.getRoot();
12391
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2139 }
7aa2a8c69ba3 TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11743
diff changeset
2140
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2141 private CodeTree createExecuteChildExpression(CodeTreeBuilder parent, NodeExecutionData execution, TypeData sourceParameterType, ActualParameter targetParameter,
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2142 ActualParameter unexpectedParameter, ImplicitCastData cast) {
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2143 // assignments: targetType <- castTargetType <- castSourceType <- sourceType
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2144 TypeData sourceType = sourceParameterType;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2145 TypeData targetType = targetParameter.getTypeSystemType();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2146 TypeData castSourceType = targetType;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2147 TypeData castTargetType = targetType;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2148
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2149 if (cast != null) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2150 castSourceType = cast.getSourceType();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2151 castTargetType = cast.getTargetType();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2152 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2153
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2154 CodeTree expression;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2155 if (sourceType == null) {
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2156 ExecutableTypeData targetExecutable = resolveExecutableType(execution, castSourceType);
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2157 expression = createExecuteChildExpression(parent, execution, targetExecutable, unexpectedParameter);
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2158 sourceType = targetExecutable.getType();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2159 } else {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2160 expression = CodeTreeBuilder.singleString(valueNameEvaluated(targetParameter));
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2161 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2162
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2163 // target = expectTargetType(implicitCast(expectCastSourceType(source)))
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2164 TypeSystemData typeSystem = execution.getChild().getNodeData().getTypeSystem();
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2165 expression = createExpectType(typeSystem, sourceType, castSourceType, expression);
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2166 expression = createImplicitCast(parent, typeSystem, cast, expression);
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2167 expression = createExpectType(typeSystem, castTargetType, targetType, expression);
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2168
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2169 CodeTreeBuilder builder = parent.create();
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2170 builder.string(valueName(targetParameter));
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2171 builder.string(" = ");
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2172 builder.tree(expression);
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2173 return builder.getRoot();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2174 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2175
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2176 private CodeTree createImplicitCast(CodeTreeBuilder parent, TypeSystemData typeSystem, ImplicitCastData cast, CodeTree expression) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2177 if (cast == null) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2178 return expression;
11554
5d5007c9a5aa Truffle-DSL: fixed a if bug target parameters and executes accidently do not match.
Christian Humer <christian.humer@gmail.com>
parents: 11545
diff changeset
2179 }
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2180 CodeTreeBuilder builder = parent.create();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2181 startCallTypeSystemMethod(getContext(), builder, typeSystem, cast.getMethodName());
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2182 builder.tree(expression);
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2183 builder.end().end();
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2184 return builder.getRoot();
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2185 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2186
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2187 private boolean containsNewLine(CodeTree tree) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2188 if (tree.getCodeKind() == CodeTreeKind.NEW_LINE) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2189 return true;
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2190 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2191
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2192 for (CodeTree codeTree : tree.getEnclosedElements()) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2193 if (containsNewLine(codeTree)) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2194 return true;
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2195 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2196 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2197 return false;
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2198 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2199
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2200 private boolean hasUnexpected(ActualParameter sourceParameter, ActualParameter targetParameter, ActualParameter unexpectedParameter) {
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2201 NodeExecutionData execution = targetParameter.getSpecification().getExecution();
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2202
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2203 if (getModel().isPolymorphic() && targetParameter.getTypeSystemType().isGeneric() && unexpectedParameter == null) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2204 // check for other polymorphic types
12398
c78612fb0120 Truffle-DSL. fixed some issues with new generation strategy.
Christian Humer <christian.humer@gmail.com>
parents: 12395
diff changeset
2205 TreeSet<TypeData> polymorphicTargetTypes = lookupPolymorphicTargetTypes(targetParameter);
c78612fb0120 Truffle-DSL. fixed some issues with new generation strategy.
Christian Humer <christian.humer@gmail.com>
parents: 12395
diff changeset
2206 if (polymorphicTargetTypes.size() > 1) {
c78612fb0120 Truffle-DSL. fixed some issues with new generation strategy.
Christian Humer <christian.humer@gmail.com>
parents: 12395
diff changeset
2207 for (TypeData polymorphicTargetType : polymorphicTargetTypes) {
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2208 if (hasUnexpectedType(execution, sourceParameter, polymorphicTargetType)) {
12398
c78612fb0120 Truffle-DSL. fixed some issues with new generation strategy.
Christian Humer <christian.humer@gmail.com>
parents: 12395
diff changeset
2209 return true;
c78612fb0120 Truffle-DSL. fixed some issues with new generation strategy.
Christian Humer <christian.humer@gmail.com>
parents: 12395
diff changeset
2210 }
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2211 }
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2212 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2213 }
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2214
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2215 if (hasUnexpectedType(execution, sourceParameter, targetParameter.getTypeSystemType())) {
11554
5d5007c9a5aa Truffle-DSL: fixed a if bug target parameters and executes accidently do not match.
Christian Humer <christian.humer@gmail.com>
parents: 11545
diff changeset
2216 return true;
5d5007c9a5aa Truffle-DSL: fixed a if bug target parameters and executes accidently do not match.
Christian Humer <christian.humer@gmail.com>
parents: 11545
diff changeset
2217 }
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2218 return false;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2219 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2220
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2221 private boolean hasUnexpectedType(NodeExecutionData execution, ActualParameter sourceParameter, TypeData targetType) {
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2222 List<TypeData> implicitSourceTypes = getModel().getNode().getTypeSystem().lookupSourceTypes(targetType);
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2223
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2224 for (TypeData implicitSourceType : implicitSourceTypes) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2225 TypeData sourceType;
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2226 ExecutableTypeData targetExecutable = resolveExecutableType(execution, implicitSourceType);
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2227 if (sourceParameter != null) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2228 sourceType = sourceParameter.getTypeSystemType();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2229 } else {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2230 if (targetExecutable.hasUnexpectedValue(getContext())) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2231 return true;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2232 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2233 sourceType = targetExecutable.getType();
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2234 }
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2235
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2236 ImplicitCastData cast = getModel().getNode().getTypeSystem().lookupCast(implicitSourceType, targetType);
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2237 if (cast != null) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2238 if (cast.getSourceType().needsCastTo(getContext(), targetType)) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2239 return true;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2240 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2241 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2242
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2243 if (sourceType.needsCastTo(getContext(), targetType)) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2244 return true;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2245 }
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2246 }
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2247 return false;
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2248 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2249
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2250 private CodeTree createCatchUnexpectedTree(CodeTreeBuilder parent, CodeTree body, SpecializationData specialization, ExecutableTypeData currentExecutable, ActualParameter param,
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2251 boolean shortCircuit, ActualParameter unexpectedParameter) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2252 CodeTreeBuilder builder = new CodeTreeBuilder(parent);
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2253 ActualParameter sourceParameter = currentExecutable.findParameter(param.getLocalName());
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2254 boolean unexpected = hasUnexpected(sourceParameter, param, unexpectedParameter);
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2255 if (!unexpected) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2256 return body;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2257 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2258
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2259 if (!shortCircuit) {
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2260 builder.declaration(param.getType(), valueName(param));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2261 }
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2262 builder.startTryBlock();
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2263
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2264 if (containsNewLine(body)) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2265 builder.tree(body);
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2266 } else {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2267 builder.statement(body);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2268 }
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2269
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2270 builder.end().startCatchBlock(getUnexpectedValueException(), "ex");
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2271 SpecializationData generic = specialization.getNode().getGenericSpecialization();
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2272 ActualParameter genericParameter = generic.findParameter(param.getLocalName());
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2273
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2274 List<ActualParameter> genericParameters = generic.getParametersAfter(genericParameter);
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2275 builder.tree(createExecuteChildren(parent, currentExecutable, generic, genericParameters, genericParameter));
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2276 if (specialization.isPolymorphic()) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2277 builder.tree(createReturnOptimizeTypes(builder, currentExecutable, specialization, param));
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2278 } else {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2279 builder.tree(createReturnExecuteAndSpecialize(builder, currentExecutable, specialization, param,
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2280 "Expected " + param.getLocalName() + " instanceof " + Utils.getSimpleName(param.getType())));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2281 }
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2282 builder.end(); // catch block
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2283
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2284 return builder.getRoot();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2285 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2286
10602
b8fe1fe004ec Truffle-DSL: fixed bugs in the generated polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents: 10600
diff changeset
2287 private CodeTree createReturnOptimizeTypes(CodeTreeBuilder parent, ExecutableTypeData currentExecutable, SpecializationData specialization, ActualParameter param) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2288 NodeData node = specialization.getNode();
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
2289 SpecializationData polymorphic = node.getPolymorphicSpecialization();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2290
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2291 CodeTreeBuilder builder = new CodeTreeBuilder(parent);
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2292 builder.startStatement().string(polymorphicTypeName(param)).string(" = ").typeLiteral(getContext().getType(Object.class)).end();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2293
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2294 builder.startReturn();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2295
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2296 CodeTreeBuilder execute = new CodeTreeBuilder(builder);
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
2297 execute.startCall("next0", EXECUTE_POLYMORPHIC_NAME);
13532
85b485b1e8e1 Truffle-DSL: removed support for implicit parameters. not needed anymore.
Christian Humer <christian.humer@gmail.com>
parents: 13530
diff changeset
2298 addInternalValueParameterNames(execute, specialization, polymorphic, param.getLocalName(), true, null);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2299 execute.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2300
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
2301 TypeData sourceType = polymorphic.getReturnType().getTypeSystemType();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2302
10602
b8fe1fe004ec Truffle-DSL: fixed bugs in the generated polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents: 10600
diff changeset
2303 builder.tree(createExpectExecutableType(node, sourceType, currentExecutable, execute.getRoot()));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2304
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2305 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2306 return builder.getRoot();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2307 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2308
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2309 private CodeTree createExecuteChildExpression(CodeTreeBuilder parent, NodeExecutionData targetExecution, ExecutableTypeData targetExecutable, ActualParameter unexpectedParameter) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2310 CodeTreeBuilder builder = new CodeTreeBuilder(parent);
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2311 if (targetExecution != null) {
13861
28479abd1a69 Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents: 13812
diff changeset
2312 builder.tree(createAccessChild(targetExecution));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2313 builder.string(".");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2314 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2315
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2316 builder.startCall(targetExecutable.getMethodName());
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2317
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2318 // TODO this should be merged with #createTemplateMethodCall
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2319 int index = 0;
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2320 for (ActualParameter parameter : targetExecutable.getParameters()) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2321
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2322 if (!parameter.getSpecification().isSignature()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2323 builder.string(parameter.getLocalName());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2324 } else {
10602
b8fe1fe004ec Truffle-DSL: fixed bugs in the generated polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents: 10600
diff changeset
2325
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2326 if (index < targetExecution.getChild().getExecuteWith().size()) {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2327 NodeChildData child = targetExecution.getChild().getExecuteWith().get(index);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2328
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2329 ParameterSpec spec = getModel().getSpecification().findParameterSpec(child.getName());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2330 List<ActualParameter> specializationParams = getModel().findParameters(spec);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2331
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2332 if (specializationParams.isEmpty()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2333 builder.defaultValue(parameter.getType());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2334 continue;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2335 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2336
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2337 ActualParameter specializationParam = specializationParams.get(0);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2338
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2339 TypeData targetType = parameter.getTypeSystemType();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2340 TypeData sourceType = specializationParam.getTypeSystemType();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2341 String localName = specializationParam.getLocalName();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2342
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2343 if (unexpectedParameter != null && unexpectedParameter.getLocalName().equals(specializationParam.getLocalName())) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2344 localName = "ex.getResult()";
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2345 sourceType = getModel().getNode().getTypeSystem().getGenericTypeData();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2346 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2347
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2348 CodeTree value = CodeTreeBuilder.singleString(localName);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2349
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2350 if (sourceType.needsCastTo(getContext(), targetType)) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2351 value = createCallTypeSystemMethod(getContext(), builder, getModel().getNode(), TypeSystemCodeGenerator.asTypeMethodName(targetType), value);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2352 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2353 builder.tree(value);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2354 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2355 builder.defaultValue(parameter.getType());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2356 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2357 index++;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2358 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2359 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2360
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2361 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2362
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2363 return builder.getRoot();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2364 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2365
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2366 private CodeTree createShortCircuitTree(CodeTreeBuilder parent, CodeTree body, SpecializationData specialization, ActualParameter parameter, ActualParameter exceptionParam) {
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2367 NodeExecutionData execution = parameter.getSpecification().getExecution();
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2368 if (execution == null || !execution.isShortCircuit()) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2369 return body;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2370 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2371
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2372 CodeTreeBuilder builder = new CodeTreeBuilder(parent);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2373 ActualParameter shortCircuitParam = specialization.getPreviousParam(parameter);
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2374 builder.tree(createShortCircuitValue(builder, specialization, execution, shortCircuitParam, exceptionParam));
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2375 builder.declaration(parameter.getType(), valueName(parameter), CodeTreeBuilder.createBuilder().defaultValue(parameter.getType()));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2376 builder.startIf().string(shortCircuitParam.getLocalName()).end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2377 builder.startBlock();
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2378
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2379 if (containsNewLine(body)) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2380 builder.tree(body);
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2381 } else {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2382 builder.statement(body);
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2383 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2384 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2385
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2386 return builder.getRoot();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2387 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2388
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2389 private CodeTree createShortCircuitValue(CodeTreeBuilder parent, SpecializationData specialization, NodeExecutionData execution, ActualParameter shortCircuitParam,
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2390 ActualParameter exceptionParam) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2391 CodeTreeBuilder builder = new CodeTreeBuilder(parent);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2392 int shortCircuitIndex = 0;
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2393 for (NodeExecutionData otherExectuion : specialization.getNode().getChildExecutions()) {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2394 if (otherExectuion.isShortCircuit()) {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2395 if (otherExectuion == execution) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2396 break;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2397 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2398 shortCircuitIndex++;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2399 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2400 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2401
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2402 builder.startStatement().type(shortCircuitParam.getType()).string(" ").string(valueName(shortCircuitParam)).string(" = ");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2403 ShortCircuitData shortCircuitData = specialization.getShortCircuits().get(shortCircuitIndex);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2404 builder.tree(createTemplateMethodCall(builder, null, specialization, shortCircuitData, exceptionParam != null ? exceptionParam.getLocalName() : null));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2405 builder.end(); // statement
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2406
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2407 return builder.getRoot();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2408 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2409
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
2410 protected CodeTree createReturnExecuteAndSpecialize(CodeTreeBuilder parent, ExecutableTypeData executable, SpecializationData current, ActualParameter exceptionParam, String reason) {
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
2411 NodeData node = current.getNode();
11185
5daaa0821406 Truffle-DSL: Changed executeAndSpecialize to use an int as minimumState instead of a class.
Christian Humer <christian.humer@gmail.com>
parents: 11180
diff changeset
2412 SpecializationData generic = node.getGenericSpecialization();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2413 CodeTreeBuilder specializeCall = new CodeTreeBuilder(parent);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2414 specializeCall.startCall(EXECUTE_SPECIALIZE_NAME);
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
2415 specializeCall.string(String.valueOf(node.getSpecializations().indexOf(current)));
13532
85b485b1e8e1 Truffle-DSL: removed support for implicit parameters. not needed anymore.
Christian Humer <christian.humer@gmail.com>
parents: 13530
diff changeset
2416 addInternalValueParameterNames(specializeCall, generic, node.getGenericSpecialization(), exceptionParam != null ? exceptionParam.getLocalName() : null, true, null);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2417 specializeCall.doubleQuote(reason);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2418 specializeCall.end().end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2419
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2420 CodeTreeBuilder builder = new CodeTreeBuilder(parent);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2421
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2422 builder.startReturn();
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
2423 builder.tree(createExpectExecutableType(node, generic.getReturnType().getTypeSystemType(), executable, specializeCall.getRoot()));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2424 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2425
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2426 return builder.getRoot();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2427 }
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2428
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2429 protected final CodeExecutableElement createUpdateTypes(TypeMirror polymorphicType) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2430 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED), getContext().getType(void.class), UPDATE_TYPES_NAME);
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2431 method.getParameters().add(new CodeVariableElement(polymorphicType, "polymorphic"));
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2432 CodeTreeBuilder builder = method.createBuilder();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2433
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2434 if (getModel().isPolymorphic()) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2435 builder.startStatement();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2436 builder.startCall("next0", "updateTypes").string("polymorphic").end();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2437 builder.end();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2438 } else if (getModel().isSpecialized()) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2439 for (ActualParameter parameter : getModel().getParameters()) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2440 if (!parameter.getSpecification().isSignature()) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2441 continue;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2442 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2443 if (lookupPolymorphicTargetTypes(parameter).size() <= 1) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2444 continue;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2445 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2446 builder.startStatement();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2447 builder.startCall("polymorphic", createUpdateTypeName(parameter));
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2448 builder.typeLiteral(parameter.getType());
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2449 builder.end().end();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2450 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2451
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2452 builder.startStatement().startCall("super", UPDATE_TYPES_NAME).string("polymorphic").end().end();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2453 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2454 return method;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2455 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2456
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2457 protected String createUpdateTypeName(ActualParameter parameter) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2458 return "update" + Utils.firstLetterUpperCase(parameter.getLocalName()) + "Type";
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2459 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2460 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2461
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2462 private class PolymorphicNodeFactory extends SpecializedNodeFactory {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2463
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2464 public PolymorphicNodeFactory(ProcessorContext context, CodeTypeElement nodeGen) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2465 super(context, nodeGen);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2466 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2467
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2468 @Override
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2469 public CodeTypeElement create(SpecializationData polymorph) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2470 NodeData node = polymorph.getNode();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2471 TypeMirror baseType = node.getNodeType();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2472 if (nodeGen != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2473 baseType = nodeGen.asType();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2474 }
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
2475 CodeTypeElement clazz = createClass(node, modifiers(PRIVATE, STATIC, FINAL), nodePolymorphicClassName(node), baseType, false);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2476
14564
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14077
diff changeset
2477 clazz.getAnnotationMirrors().add(createNodeInfo(node, NodeCost.NONE));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2478
13530
0576e9a0358e Truffle-DSL: minor cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 13528
diff changeset
2479 for (ActualParameter polymorphParameter : polymorph.getSignatureParameters()) {
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2480 if (!polymorphParameter.getTypeSystemType().isGeneric()) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2481 continue;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2482 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2483 Set<TypeData> types = new HashSet<>();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2484 for (SpecializationData specialization : node.getSpecializations()) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2485 if (!specialization.isSpecialized()) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2486 continue;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2487 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2488 ActualParameter parameter = specialization.findParameter(polymorphParameter.getLocalName());
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2489 assert parameter != null;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2490 types.add(parameter.getTypeSystemType());
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2491 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2492 CodeVariableElement var = new CodeVariableElement(modifiers(PRIVATE), getContext().getType(Class.class), polymorphicTypeName(polymorphParameter));
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2493 var.getAnnotationMirrors().add(new CodeAnnotationMirror(getContext().getTruffleTypes().getCompilationFinal()));
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2494 clazz.add(var);
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2495 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2496
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2497 return clazz;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2498 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2499
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2500 @Override
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2501 protected void createChildren(SpecializationData specialization) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2502 CodeTypeElement clazz = getElement();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2503
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2504 createConstructors(clazz);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2505 createExecuteMethods(specialization);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2506
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2507 getElement().add(createUpdateTypes(nodeGen.asType()));
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2508
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2509 for (ActualParameter parameter : specialization.getParameters()) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2510 if (!parameter.getSpecification().isSignature()) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2511 continue;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2512 }
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2513 if (lookupPolymorphicTargetTypes(parameter).size() <= 1) {
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2514 continue;
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2515 }
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2516 getElement().add(createUpdateType(parameter));
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2517 }
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2518
12567
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
2519 if (needsInvokeCopyConstructorMethod()) {
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
2520 clazz.add(createInvokeCopyConstructor(nodeGen.asType(), specialization));
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
2521 }
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
2522
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2523 createCachedExecuteMethods(specialization);
14564
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14077
diff changeset
2524 clazz.add(createGetCost(specialization.getNode(), specialization, NodeCost.NONE));
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2525 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2526
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2527 private ExecutableElement createUpdateType(ActualParameter parameter) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2528 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED), getContext().getType(void.class), createUpdateTypeName(parameter));
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2529 method.getParameters().add(new CodeVariableElement(getContext().getType(Class.class), "type"));
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2530 CodeTreeBuilder builder = method.createBuilder();
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2531
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2532 String fieldName = polymorphicTypeName(parameter);
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2533 builder.startIf().string(fieldName).isNull().end().startBlock();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2534 builder.startStatement().string(fieldName).string(" = ").string("type").end();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2535 builder.end();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2536 builder.startElseIf().string(fieldName).string(" != ").string("type").end();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2537 builder.startBlock();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2538 builder.startStatement().string(fieldName).string(" = ").typeLiteral(getContext().getType(Object.class)).end();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2539 builder.end();
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2540
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2541 return method;
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2542 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2543
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2544 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2545
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2546 private class SpecializedNodeFactory extends NodeBaseFactory {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2547
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2548 protected final CodeTypeElement nodeGen;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2549
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2550 public SpecializedNodeFactory(ProcessorContext context, CodeTypeElement nodeGen) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2551 super(context);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2552 this.nodeGen = nodeGen;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2553 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2554
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2555 @Override
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2556 public CodeTypeElement create(SpecializationData specialization) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2557 NodeData node = specialization.getNode();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2558 TypeMirror baseType = node.getNodeType();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2559 if (nodeGen != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2560 baseType = nodeGen.asType();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2561 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2562 CodeTypeElement clazz = createClass(node, modifiers(PRIVATE, STATIC, FINAL), nodeSpecializationClassName(specialization), baseType, false);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2563
14564
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14077
diff changeset
2564 NodeCost cost;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2565 if (specialization.isGeneric()) {
14564
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14077
diff changeset
2566 cost = NodeCost.MEGAMORPHIC;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2567 } else if (specialization.isUninitialized()) {
14564
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14077
diff changeset
2568 cost = NodeCost.UNINITIALIZED;
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
2569 } else if (specialization.isPolymorphic()) {
14564
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14077
diff changeset
2570 cost = NodeCost.NONE;
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
2571 } else if (specialization.isSpecialized()) {
14564
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14077
diff changeset
2572 cost = NodeCost.MONOMORPHIC;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2573 } else {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
2574 throw new AssertionError();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2575 }
14564
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14077
diff changeset
2576 clazz.getAnnotationMirrors().add(createNodeInfo(node, cost));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2577
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2578 return clazz;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2579 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2580
14564
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14077
diff changeset
2581 protected CodeAnnotationMirror createNodeInfo(NodeData node, NodeCost cost) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2582 String shortName = node.getShortName();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2583 CodeAnnotationMirror nodeInfoMirror = new CodeAnnotationMirror(getContext().getTruffleTypes().getNodeInfoAnnotation());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2584 if (shortName != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2585 nodeInfoMirror.setElementValue(nodeInfoMirror.findExecutableElement("shortName"), new CodeAnnotationValue(shortName));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2586 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2587
14564
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14077
diff changeset
2588 DeclaredType nodeinfoCost = getContext().getTruffleTypes().getNodeCost();
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14077
diff changeset
2589 VariableElement varKind = Utils.findVariableElement(nodeinfoCost, cost.name());
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14077
diff changeset
2590
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14077
diff changeset
2591 nodeInfoMirror.setElementValue(nodeInfoMirror.findExecutableElement("cost"), new CodeAnnotationValue(varKind));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2592 return nodeInfoMirror;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2593 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2594
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2595 @Override
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2596 protected void createChildren(SpecializationData specialization) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2597 CodeTypeElement clazz = getElement();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2598 createConstructors(clazz);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2599
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2600 createExecuteMethods(specialization);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2601 createCachedExecuteMethods(specialization);
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2602 if (specialization.getNode().isPolymorphic()) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2603 getElement().add(createUpdateTypes(nodeGen.asType()));
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2604 }
12567
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
2605 if (needsInvokeCopyConstructorMethod()) {
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
2606 clazz.add(createInvokeCopyConstructor(nodeGen.asType(), specialization));
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
2607 }
14077
3ea5f337cc0d Truffle-DSL: generate better implementations for getKind()
Christian Humer <christian.humer@gmail.com>
parents: 14042
diff changeset
2608
3ea5f337cc0d Truffle-DSL: generate better implementations for getKind()
Christian Humer <christian.humer@gmail.com>
parents: 14042
diff changeset
2609 if (specialization.isGeneric()) {
14564
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14077
diff changeset
2610 clazz.add(createGetCost(specialization.getNode(), specialization, NodeCost.MEGAMORPHIC));
14077
3ea5f337cc0d Truffle-DSL: generate better implementations for getKind()
Christian Humer <christian.humer@gmail.com>
parents: 14042
diff changeset
2611 } else if (specialization.isUninitialized()) {
14564
5d1308c78ddc Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents: 14077
diff changeset
2612 clazz.add(createGetCost(specialization.getNode(), specialization, NodeCost.UNINITIALIZED));
14077
3ea5f337cc0d Truffle-DSL: generate better implementations for getKind()
Christian Humer <christian.humer@gmail.com>
parents: 14042
diff changeset
2613 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2614 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2615
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2616 protected void createConstructors(CodeTypeElement clazz) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2617 TypeElement superTypeElement = Utils.fromTypeMirror(clazz.getSuperclass());
11180
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
2618 SpecializationData specialization = getModel();
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
2619 NodeData node = specialization.getNode();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2620 for (ExecutableElement constructor : ElementFilter.constructorsIn(superTypeElement.getEnclosedElements())) {
11180
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
2621 if (specialization.isUninitialized()) {
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
2622 // ignore copy constructors for uninitialized if not polymorphic
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
2623 if (isCopyConstructor(constructor) && !node.isPolymorphic()) {
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
2624 continue;
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
2625 }
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
2626 } else if (node.getUninitializedSpecialization() != null) {
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
2627 // ignore others than copy constructors for specialized nodes
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
2628 if (!isCopyConstructor(constructor)) {
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
2629 continue;
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
2630 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2631 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2632
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2633 CodeExecutableElement superConstructor = createSuperConstructor(clazz, constructor);
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2634 CodeTree body = superConstructor.getBodyTree();
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2635 CodeTreeBuilder builder = superConstructor.createBuilder();
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2636 builder.tree(body);
11180
a9cb98ff8fd9 Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents: 10859
diff changeset
2637
12637
9b23caa3ad31 Truffle-DSL: fixed generated generic node adopted the polymorphic chain when transiting from polymorphic to generic.
Christian Humer <christian.humer@gmail.com>
parents: 12635
diff changeset
2638 if (node.isPolymorphic()) {
9b23caa3ad31 Truffle-DSL: fixed generated generic node adopted the polymorphic chain when transiting from polymorphic to generic.
Christian Humer <christian.humer@gmail.com>
parents: 12635
diff changeset
2639 if (specialization.isSpecialized() || specialization.isPolymorphic()) {
9b23caa3ad31 Truffle-DSL: fixed generated generic node adopted the polymorphic chain when transiting from polymorphic to generic.
Christian Humer <christian.humer@gmail.com>
parents: 12635
diff changeset
2640 builder.statement("this.next0 = adoptChild(copy.next0)");
9b23caa3ad31 Truffle-DSL: fixed generated generic node adopted the polymorphic chain when transiting from polymorphic to generic.
Christian Humer <christian.humer@gmail.com>
parents: 12635
diff changeset
2641 }
9b23caa3ad31 Truffle-DSL: fixed generated generic node adopted the polymorphic chain when transiting from polymorphic to generic.
Christian Humer <christian.humer@gmail.com>
parents: 12635
diff changeset
2642 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2643 if (superConstructor != null) {
12567
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
2644 for (ActualParameter param : getImplicitTypeParamters(getModel())) {
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
2645 clazz.add(new CodeVariableElement(modifiers(PRIVATE, FINAL), getContext().getType(Class.class), implicitTypeName(param)));
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
2646 superConstructor.getParameters().add(new CodeVariableElement(getContext().getType(Class.class), implicitTypeName(param)));
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
2647
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
2648 builder.startStatement();
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
2649 builder.string("this.").string(implicitTypeName(param)).string(" = ").string(implicitTypeName(param));
0d3e4d940925 Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 12503
diff changeset
2650 builder.end();
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2651 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2652
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2653 clazz.add(superConstructor);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2654 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2655 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2656 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2657
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2658 protected void createExecuteMethods(SpecializationData specialization) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2659 NodeData node = specialization.getNode();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2660 CodeTypeElement clazz = getElement();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2661
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2662 for (ExecutableTypeData execType : node.getExecutableTypes()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2663 if (execType.isFinal()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2664 continue;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2665 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2666 CodeExecutableElement executeMethod = createExecutableTypeOverride(execType, true);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2667 clazz.add(executeMethod);
13271
2b9fcffd6f36 Truffle-DSL: added support for generating execute methods with java varargs.
Christian Humer <christian.humer@gmail.com>
parents: 12637
diff changeset
2668 CodeTreeBuilder builder = executeMethod.getBuilder();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2669 CodeTree result = createExecuteBody(builder, specialization, execType);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2670 if (result != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2671 builder.tree(result);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2672 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2673 clazz.remove(executeMethod);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2674 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2675 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2676 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2677
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2678 protected void createCachedExecuteMethods(SpecializationData specialization) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2679 NodeData node = specialization.getNode();
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2680 if (!node.isPolymorphic()) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2681 return;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2682 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2683
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2684 CodeTypeElement clazz = getElement();
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2685
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
2686 final SpecializationData polymorphic = node.getPolymorphicSpecialization();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
2687 ExecutableElement executeCached = nodeGen.getMethod(EXECUTE_POLYMORPHIC_NAME);
13530
0576e9a0358e Truffle-DSL: minor cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 13528
diff changeset
2688 CodeExecutableElement executeMethod = CodeExecutableElement.clone(getContext().getEnvironment(), executeCached);
0576e9a0358e Truffle-DSL: minor cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 13528
diff changeset
2689 executeMethod.getModifiers().remove(Modifier.ABSTRACT);
0576e9a0358e Truffle-DSL: minor cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 13528
diff changeset
2690 CodeTreeBuilder builder = executeMethod.createBuilder();
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2691
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2692 if (specialization.isGeneric() || specialization.isPolymorphic()) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2693 builder.startThrow().startNew(getContext().getType(AssertionError.class));
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2694 builder.doubleQuote("Should not be reached.");
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2695 builder.end().end();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2696 } else if (specialization.isUninitialized()) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2697 builder.tree(createAppendPolymorphic(builder, specialization));
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2698 } else {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2699 CodeTreeBuilder elseBuilder = new CodeTreeBuilder(builder);
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
2700 elseBuilder.startReturn().startCall("this.next0", EXECUTE_POLYMORPHIC_NAME);
13532
85b485b1e8e1 Truffle-DSL: removed support for implicit parameters. not needed anymore.
Christian Humer <christian.humer@gmail.com>
parents: 13530
diff changeset
2701 addInternalValueParameterNames(elseBuilder, polymorphic, polymorphic, null, true, null);
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2702 elseBuilder.end().end();
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2703
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2704 boolean forceElse = specialization.getExceptions().size() > 0;
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2705 builder.tree(createExecuteTree(builder, polymorphic, SpecializationGroup.create(specialization), false, new CodeBlock<SpecializationData>() {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2706
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2707 public CodeTree create(CodeTreeBuilder b, SpecializationData current) {
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2708 return createGenericInvoke(b, polymorphic, current);
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2709 }
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2710 }, elseBuilder.getRoot(), forceElse, true, true));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2711 }
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2712 clazz.add(executeMethod);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2713 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2714
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2715 private CodeTree createAppendPolymorphic(CodeTreeBuilder parent, SpecializationData specialization) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2716 NodeData node = specialization.getNode();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2717
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2718 CodeTreeBuilder builder = new CodeTreeBuilder(parent);
13275
bd5c996b5d25 Truffle-DSL: fixed wrong transferToInterpreter with transferToInterpreterAndInvalidate.
Christian Humer <christian.humer@gmail.com>
parents: 13272
diff changeset
2719 builder.tree(createDeoptimize(builder));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2720
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
2721 builder.declaration(getContext().getTruffleTypes().getNode(), "root", "this");
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2722 builder.declaration(getContext().getType(int.class), "depth", "0");
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
2723 builder.tree(createFindRoot(builder, node, true));
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
2724 builder.newLine();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2725
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
2726 builder.startIf().string("depth > ").string(String.valueOf(node.getPolymorphicDepth())).end();
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
2727 builder.startBlock();
11320
80de3bbfa8b9 Truffle-DSL: fixed inconsistent children for polymorphic -> generic rewrites. (GRAAL-425)
Christian Humer <christian.humer@gmail.com>
parents: 11201
diff changeset
2728 String message = "Polymorphic limit reached (" + node.getPolymorphicDepth() + ")";
80de3bbfa8b9 Truffle-DSL: fixed inconsistent children for polymorphic -> generic rewrites. (GRAAL-425)
Christian Humer <christian.humer@gmail.com>
parents: 11201
diff changeset
2729 String castRoot = "(" + baseClassName(node) + ") root";
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
2730 builder.tree(createGenericInvoke(builder, node.getPolymorphicSpecialization(), node.getGenericSpecialization(),
11320
80de3bbfa8b9 Truffle-DSL: fixed inconsistent children for polymorphic -> generic rewrites. (GRAAL-425)
Christian Humer <christian.humer@gmail.com>
parents: 11201
diff changeset
2731 createReplaceCall(builder, node.getGenericSpecialization(), "root", castRoot, message), null));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2732 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2733
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
2734 builder.startElseBlock();
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
2735 builder.startStatement().startCall("setNext0");
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2736 builder.startNew(nodeSpecializationClassName(node.getUninitializedSpecialization())).string("this").end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2737 builder.end().end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2738
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2739 CodeTreeBuilder specializeCall = new CodeTreeBuilder(builder);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2740 specializeCall.startCall(EXECUTE_SPECIALIZE_NAME);
11185
5daaa0821406 Truffle-DSL: Changed executeAndSpecialize to use an int as minimumState instead of a class.
Christian Humer <christian.humer@gmail.com>
parents: 11180
diff changeset
2741 specializeCall.string("0");
13532
85b485b1e8e1 Truffle-DSL: removed support for implicit parameters. not needed anymore.
Christian Humer <christian.humer@gmail.com>
parents: 13530
diff changeset
2742 addInternalValueParameterNames(specializeCall, specialization, node.getGenericSpecialization(), null, true, null);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2743 specializeCall.startGroup().doubleQuote("Uninitialized polymorphic (").string(" + depth + ").doubleQuote("/" + node.getPolymorphicDepth() + ")").end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2744 specializeCall.end().end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2745
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2746 builder.declaration(node.getGenericSpecialization().getReturnType().getType(), "result", specializeCall.getRoot());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2747
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
2748 CodeTree root = builder.create().cast(nodePolymorphicClassName(node)).string("root").getRoot();
11320
80de3bbfa8b9 Truffle-DSL: fixed inconsistent children for polymorphic -> generic rewrites. (GRAAL-425)
Christian Humer <christian.humer@gmail.com>
parents: 11201
diff changeset
2749 builder.startIf().string("this.next0 != null").end().startBlock();
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2750 builder.startStatement().string("(").tree(root).string(").").startCall(UPDATE_TYPES_NAME).tree(root).end().end();
11320
80de3bbfa8b9 Truffle-DSL: fixed inconsistent children for polymorphic -> generic rewrites. (GRAAL-425)
Christian Humer <christian.humer@gmail.com>
parents: 11201
diff changeset
2751 builder.end();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2752
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2753 if (Utils.isVoid(builder.findMethod().getReturnType())) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2754 builder.returnStatement();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2755 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2756 builder.startReturn().string("result").end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2757 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2758
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2759 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2760
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2761 return builder.getRoot();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2762 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2763
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2764 private CodeTree createExecuteBody(CodeTreeBuilder parent, SpecializationData specialization, ExecutableTypeData execType) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2765 CodeTreeBuilder builder = new CodeTreeBuilder(parent);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2766
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2767 List<ExecutableTypeData> primaryExecutes = findFunctionalExecutableType(specialization, execType.getEvaluatedCount());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2768
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2769 if (primaryExecutes.contains(execType) || primaryExecutes.isEmpty()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2770 builder.tree(createFunctionalExecute(builder, specialization, execType));
11506
e6645c18d154 Truffle-DSL: reduced generated code size by not generating primarily unused primitive type execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 11445
diff changeset
2771 } else if (needsCastingExecuteMethod(execType)) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2772 assert !primaryExecutes.isEmpty();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2773 builder.tree(createCastingExecute(builder, specialization, execType, primaryExecutes.get(0)));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2774 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2775 return null;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2776 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2777
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2778 return builder.getRoot();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2779 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2780
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2781 private CodeExecutableElement createExecutableTypeOverride(ExecutableTypeData execType, boolean evaluated) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2782 CodeExecutableElement method = CodeExecutableElement.clone(getContext().getEnvironment(), execType.getMethod());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2783
13271
2b9fcffd6f36 Truffle-DSL: added support for generating execute methods with java varargs.
Christian Humer <christian.humer@gmail.com>
parents: 12637
diff changeset
2784 CodeTreeBuilder builder = method.createBuilder();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2785 int i = 0;
13271
2b9fcffd6f36 Truffle-DSL: added support for generating execute methods with java varargs.
Christian Humer <christian.humer@gmail.com>
parents: 12637
diff changeset
2786 int signatureIndex = -1;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2787 for (VariableElement param : method.getParameters()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2788 CodeVariableElement var = CodeVariableElement.clone(param);
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2789 ActualParameter actualParameter = i < execType.getParameters().size() ? execType.getParameters().get(i) : null;
13271
2b9fcffd6f36 Truffle-DSL: added support for generating execute methods with java varargs.
Christian Humer <christian.humer@gmail.com>
parents: 12637
diff changeset
2790 String name;
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2791 if (actualParameter != null) {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2792 if (actualParameter.getSpecification().isSignature()) {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2793 signatureIndex++;
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2794 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2795
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2796 if (evaluated && actualParameter.getSpecification().isSignature()) {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2797 name = valueNameEvaluated(actualParameter);
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2798 } else {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2799 name = valueName(actualParameter);
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2800 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2801
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2802 int varArgCount = getModel().getSignatureSize() - signatureIndex;
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2803 if (evaluated && actualParameter.isTypeVarArgs()) {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2804 ActualParameter baseVarArgs = actualParameter;
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2805 name = valueName(baseVarArgs) + "Args";
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2806
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2807 builder.startAssert().string(name).string(" != null").end();
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2808 builder.startAssert().string(name).string(".length == ").string(String.valueOf(varArgCount)).end();
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2809 if (varArgCount > 0) {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2810 List<ActualParameter> varArgsParameter = execType.getParameters().subList(i, execType.getParameters().size());
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2811 for (ActualParameter varArg : varArgsParameter) {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2812 if (varArgCount <= 0) {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2813 break;
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2814 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2815 TypeMirror type = baseVarArgs.getType();
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2816 if (type.getKind() == TypeKind.ARRAY) {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2817 type = ((ArrayType) type).getComponentType();
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2818 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2819 builder.declaration(type, valueNameEvaluated(varArg), name + "[" + varArg.getTypeVarArgsIndex() + "]");
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2820 varArgCount--;
13272
0b8335a4fb13 Truffle-DSL: more testing for generating execute methods with varargs.
Christian Humer <christian.humer@gmail.com>
parents: 13271
diff changeset
2821 }
13271
2b9fcffd6f36 Truffle-DSL: added support for generating execute methods with java varargs.
Christian Humer <christian.humer@gmail.com>
parents: 12637
diff changeset
2822 }
2b9fcffd6f36 Truffle-DSL: added support for generating execute methods with java varargs.
Christian Humer <christian.humer@gmail.com>
parents: 12637
diff changeset
2823 }
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2824 } else {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents: 13275
diff changeset
2825 name = "arg" + i;
13271
2b9fcffd6f36 Truffle-DSL: added support for generating execute methods with java varargs.
Christian Humer <christian.humer@gmail.com>
parents: 12637
diff changeset
2826 }
2b9fcffd6f36 Truffle-DSL: added support for generating execute methods with java varargs.
Christian Humer <christian.humer@gmail.com>
parents: 12637
diff changeset
2827 var.setName(name);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2828 method.getParameters().set(i, var);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2829 i++;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2830 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2831
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2832 method.getAnnotationMirrors().clear();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2833 method.getModifiers().remove(Modifier.ABSTRACT);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2834 return method;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2835 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2836
11506
e6645c18d154 Truffle-DSL: reduced generated code size by not generating primarily unused primitive type execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 11445
diff changeset
2837 private boolean needsCastingExecuteMethod(ExecutableTypeData execType) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2838 if (execType.isAbstract()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2839 return true;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2840 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2841 if (execType.getType().isGeneric()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2842 return true;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2843 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2844 return false;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2845 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2846
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2847 private List<ExecutableTypeData> findFunctionalExecutableType(SpecializationData specialization, int evaluatedCount) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2848 TypeData primaryType = specialization.getReturnType().getTypeSystemType();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2849 List<ExecutableTypeData> otherTypes = specialization.getNode().getExecutableTypes(evaluatedCount);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2850
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2851 List<ExecutableTypeData> filteredTypes = new ArrayList<>();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2852 for (ExecutableTypeData compareType : otherTypes) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2853 if (!Utils.typeEquals(compareType.getType().getPrimitiveType(), primaryType.getPrimitiveType())) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2854 continue;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2855 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2856 filteredTypes.add(compareType);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2857 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2858
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2859 // no direct matches found use generic where the type is Object
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2860 if (filteredTypes.isEmpty()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2861 for (ExecutableTypeData compareType : otherTypes) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2862 if (compareType.getType().isGeneric() && !compareType.hasUnexpectedValue(getContext())) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2863 filteredTypes.add(compareType);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2864 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2865 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2866 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2867
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2868 if (filteredTypes.isEmpty()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2869 for (ExecutableTypeData compareType : otherTypes) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2870 if (compareType.getType().isGeneric()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2871 filteredTypes.add(compareType);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2872 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2873 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2874 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2875
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2876 return filteredTypes;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2877 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2878
11443
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
2879 private CodeTree createFunctionalExecute(CodeTreeBuilder parent, final SpecializationData specialization, final ExecutableTypeData executable) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2880 CodeTreeBuilder builder = new CodeTreeBuilder(parent);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2881 if (specialization.isUninitialized()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2882 builder.tree(createDeoptimize(builder));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2883 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2884
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11509
diff changeset
2885 builder.tree(createExecuteChildren(builder, executable, specialization, specialization.getParameters(), null));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2886
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2887 CodeTree returnSpecialized = null;
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
2888
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
2889 if (specialization.findNextSpecialization() != null) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2890 CodeTreeBuilder returnBuilder = new CodeTreeBuilder(builder);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2891 returnBuilder.tree(createDeoptimize(builder));
11190
4eb23800c907 Truffle-DSL: Implemented support for negated guards (GRAAL-371 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11187
diff changeset
2892 returnBuilder.tree(createReturnExecuteAndSpecialize(builder, executable, specialization, null, "One of guards " + specialization.getGuardDefinitions() + " failed"));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2893 returnSpecialized = returnBuilder.getRoot();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2894 }
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
2895
11443
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
2896 builder.tree(createExecuteTree(builder, specialization, SpecializationGroup.create(specialization), false, new CodeBlock<SpecializationData>() {
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
2897
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
2898 public CodeTree create(CodeTreeBuilder b, SpecializationData current) {
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
2899 return createExecute(b, executable, specialization);
b33783cbd8ce Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents: 11442
diff changeset
2900 }
12395
8e8347ecabbc Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents: 12392
diff changeset
2901 }, returnSpecialized, false, false, false));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2902
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2903 return builder.getRoot();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2904 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2905
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2906 private CodeTree createExecute(CodeTreeBuilder parent, ExecutableTypeData executable, SpecializationData specialization) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2907 NodeData node = specialization.getNode();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2908 CodeTreeBuilder builder = new CodeTreeBuilder(parent);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2909 if (!specialization.getExceptions().isEmpty() || !specialization.getAssumptions().isEmpty()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2910 builder.startTryBlock();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2911 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2912
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2913 for (String assumption : specialization.getAssumptions()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2914 builder.startStatement();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2915 builder.string("this.").string(assumption).string(".check()");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2916 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2917 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2918
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2919 CodeTreeBuilder returnBuilder = new CodeTreeBuilder(parent);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2920 if (specialization.isPolymorphic()) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
2921 returnBuilder.startCall("next0", EXECUTE_POLYMORPHIC_NAME);
13532
85b485b1e8e1 Truffle-DSL: removed support for implicit parameters. not needed anymore.
Christian Humer <christian.humer@gmail.com>
parents: 13530
diff changeset
2922 addInternalValueParameterNames(returnBuilder, specialization, specialization, null, true, null);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2923 returnBuilder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2924 } else if (specialization.isUninitialized()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2925 returnBuilder.startCall("super", EXECUTE_SPECIALIZE_NAME);
11185
5daaa0821406 Truffle-DSL: Changed executeAndSpecialize to use an int as minimumState instead of a class.
Christian Humer <christian.humer@gmail.com>
parents: 11180
diff changeset
2926 returnBuilder.string("0");
13532
85b485b1e8e1 Truffle-DSL: removed support for implicit parameters. not needed anymore.
Christian Humer <christian.humer@gmail.com>
parents: 13530
diff changeset
2927 addInternalValueParameterNames(returnBuilder, specialization, specialization, null, true, null);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2928 returnBuilder.doubleQuote("Uninitialized monomorphic");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2929 returnBuilder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2930 } else if (specialization.getMethod() == null && !node.needsRewrites(context)) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2931 emitEncounteredSynthetic(builder, specialization);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2932 } else if (specialization.isGeneric()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2933 returnBuilder.startCall("super", EXECUTE_GENERIC_NAME);
13532
85b485b1e8e1 Truffle-DSL: removed support for implicit parameters. not needed anymore.
Christian Humer <christian.humer@gmail.com>
parents: 13530
diff changeset
2934 addInternalValueParameterNames(returnBuilder, specialization, specialization, null, node.needsFrame(getContext()), null);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2935 returnBuilder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2936 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2937 returnBuilder.tree(createTemplateMethodCall(returnBuilder, null, specialization, specialization, null));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2938 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2939
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2940 if (!returnBuilder.isEmpty()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2941 TypeData targetType = node.getTypeSystem().findTypeData(builder.findMethod().getReturnType());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2942 TypeData sourceType = specialization.getReturnType().getTypeSystemType();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2943
10741
00a9dbcbe431 Truffle-DSL: Fixed a bug in polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents: 10695
diff changeset
2944 builder.startReturn();
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2945 if (targetType == null || sourceType == null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2946 builder.tree(returnBuilder.getRoot());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2947 } else if (sourceType.needsCastTo(getContext(), targetType)) {
13536
419b3ea1bdd1 Truffle-DSL: removed try-catch hack for polymorphic invocations.
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
2948 String castMethodName = TypeSystemCodeGenerator.expectTypeMethodName(targetType);
419b3ea1bdd1 Truffle-DSL: removed try-catch hack for polymorphic invocations.
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
2949 if (!executable.hasUnexpectedValue(context)) {
419b3ea1bdd1 Truffle-DSL: removed try-catch hack for polymorphic invocations.
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
2950 castMethodName = TypeSystemCodeGenerator.asTypeMethodName(targetType);
419b3ea1bdd1 Truffle-DSL: removed try-catch hack for polymorphic invocations.
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
2951 }
419b3ea1bdd1 Truffle-DSL: removed try-catch hack for polymorphic invocations.
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
2952 builder.tree(createCallTypeSystemMethod(context, parent, node, castMethodName, returnBuilder.getRoot()));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2953 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2954 builder.tree(returnBuilder.getRoot());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2955 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2956 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2957 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2958
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2959 if (!specialization.getExceptions().isEmpty()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2960 for (SpecializationThrowsData exception : specialization.getExceptions()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2961 builder.end().startCatchBlock(exception.getJavaClass(), "ex");
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2962 builder.tree(createDeoptimize(builder));
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
2963 builder.tree(createReturnExecuteAndSpecialize(parent, executable, specialization, null, "Thrown " + Utils.getSimpleName(exception.getJavaClass())));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2964 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2965 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2966 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2967 if (!specialization.getAssumptions().isEmpty()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2968 builder.end().startCatchBlock(getContext().getTruffleTypes().getInvalidAssumption(), "ex");
11186
4a9936bb03a4 Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11185
diff changeset
2969 builder.tree(createReturnExecuteAndSpecialize(parent, executable, specialization, null, "Assumption failed"));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2970 builder.end();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2971 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2972
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2973 return builder.getRoot();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2974 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2975
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2976 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2977
11195
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
2978 private interface CodeBlock<T> {
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
2979
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
2980 CodeTree create(CodeTreeBuilder parent, T value);
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
2981
4f52b08bd2f9 Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents: 11190
diff changeset
2982 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2983 }