Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeCodeGenerator.java @ 18761:a665483c3881
Truffle-DSL: new node layout implementation.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 29 Dec 2014 23:38:54 +0100 |
parents | 59bf50cc5a32 |
children | 674c8a6d5e6c |
comparison
equal
deleted
inserted
replaced
18760:6fa3999631d8 | 18761:a665483c3881 |
---|---|
93 } | 93 } |
94 return factoryElement; | 94 return factoryElement; |
95 } else { | 95 } else { |
96 // wrap all types into the first node | 96 // wrap all types into the first node |
97 CodeTypeElement first = generatedNodes.get(0); | 97 CodeTypeElement first = generatedNodes.get(0); |
98 CodeTypeElement last = generatedNodes.get(1); | 98 CodeTypeElement second = first; |
99 | 99 if (generatedNodes.size() > 1) { |
100 for (CodeTypeElement generatedNode : generatedNodes) { | 100 second = generatedNodes.get(1); |
101 if (first != generatedNode) { | 101 for (CodeTypeElement generatedNode : generatedNodes) { |
102 first.add(makeInnerClass(generatedNode)); | 102 if (first != generatedNode) { |
103 first.add(makeInnerClass(generatedNode)); | |
104 } | |
103 } | 105 } |
104 } | 106 } |
107 new NodeFactoryFactory(context, node, second).createFactoryMethods(first, ElementUtils.getVisibility(node.getTemplateType().getModifiers())); | |
105 ElementUtils.setVisibility(first.getModifiers(), ElementUtils.getVisibility(node.getTemplateType().getModifiers())); | 108 ElementUtils.setVisibility(first.getModifiers(), ElementUtils.getVisibility(node.getTemplateType().getModifiers())); |
106 for (ExecutableElement constructor : ElementFilter.constructorsIn(first.getEnclosedElements())) { | 109 for (ExecutableElement constructor : ElementFilter.constructorsIn(first.getEnclosedElements())) { |
107 ElementUtils.setVisibility(((CodeExecutableElement) constructor).getModifiers(), Modifier.PRIVATE); | 110 ElementUtils.setVisibility(((CodeExecutableElement) constructor).getModifiers(), Modifier.PRIVATE); |
108 } | 111 } |
109 | 112 |
110 NodeFactoryFactory.createFactoryMethods(context, node, first, last, ElementUtils.getVisibility(node.getTemplateType().getModifiers())); | |
111 return first; | 113 return first; |
112 } | 114 } |
113 } | 115 } |
114 | 116 |
115 private static CodeTypeElement createContainer(NodeData node) { | 117 private static CodeTypeElement createContainer(NodeData node) { |
116 CodeTypeElement container; | 118 CodeTypeElement container; |
117 Modifier visibility = ElementUtils.getVisibility(node.getTemplateType().getModifiers()); | 119 Modifier visibility = ElementUtils.getVisibility(node.getTemplateType().getModifiers()); |
118 String containerName = NodeFactoryFactory.factoryClassName(node); | 120 String containerName = NodeFactoryFactory.factoryClassName(node); |
119 container = GeneratorUtils.createClass(node, modifiers(), containerName, null, false); | 121 container = GeneratorUtils.createClass(node, null, modifiers(), containerName, null); |
120 if (visibility != null) { | 122 if (visibility != null) { |
121 container.getModifiers().add(visibility); | 123 container.getModifiers().add(visibility); |
122 } | 124 } |
123 container.getModifiers().add(Modifier.FINAL); | 125 container.getModifiers().add(Modifier.FINAL); |
124 | 126 |
131 | 133 |
132 private static List<CodeTypeElement> generateNodes(ProcessorContext context, NodeData node) { | 134 private static List<CodeTypeElement> generateNodes(ProcessorContext context, NodeData node) { |
133 if (!node.needsFactory()) { | 135 if (!node.needsFactory()) { |
134 return Collections.emptyList(); | 136 return Collections.emptyList(); |
135 } | 137 } |
138 if (node.getTypeSystem().getOptions().useNewLayout()) { | |
139 return Arrays.asList(new NodeGenFactory(context, node).create()); | |
140 } else { | |
141 return generateNodesOld(context, node); | |
142 } | |
143 } | |
144 | |
145 private static List<CodeTypeElement> generateNodesOld(ProcessorContext context, NodeData node) { | |
136 List<CodeTypeElement> nodeTypes = new ArrayList<>(); | 146 List<CodeTypeElement> nodeTypes = new ArrayList<>(); |
137 SpecializationData generic = node.getGenericSpecialization() == null ? node.getSpecializations().get(0) : node.getGenericSpecialization(); | 147 SpecializationData generic = node.getGenericSpecialization() == null ? node.getSpecializations().get(0) : node.getGenericSpecialization(); |
138 CodeTypeElement baseNode = new NodeBaseFactory(context, node, generic).create(); | 148 CodeTypeElement baseNode = new NodeBaseFactory(context, node, generic).create(); |
139 nodeTypes.add(baseNode); | 149 nodeTypes.add(baseNode); |
140 | 150 |
141 for (SpecializationData specialization : node.getSpecializations()) { | 151 for (SpecializationData specialization : node.getSpecializations()) { |
142 if (!specialization.isReachable() || specialization.isGeneric()) { | 152 if (!specialization.isReachable() || specialization.isFallback()) { |
143 continue; | 153 continue; |
144 } | 154 } |
145 if (specialization.isPolymorphic() && node.isPolymorphic(context)) { | 155 if (specialization.isPolymorphic() && node.isPolymorphic(context)) { |
146 nodeTypes.add(new PolymorphicNodeFactory(context, node, specialization, baseNode).create()); | 156 nodeTypes.add(new PolymorphicNodeFactory(context, node, specialization, baseNode).create()); |
147 continue; | 157 continue; |