Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/TestNodes.java @ 22219:1c0f490984d5
Merge with f47b601edbc626dcfe8b3636933b4834c89f7779
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Wed, 16 Sep 2015 15:36:22 -0700 |
parents | dc83cc1f94f2 3aad794eec0e |
children | 20380d1d41f2 |
comparison
equal
deleted
inserted
replaced
22160:0599e2df6a9f | 22219:1c0f490984d5 |
---|---|
22 * or visit www.oracle.com if you need additional information or have any | 22 * or visit www.oracle.com if you need additional information or have any |
23 * questions. | 23 * questions. |
24 */ | 24 */ |
25 package com.oracle.truffle.tools.test; | 25 package com.oracle.truffle.tools.test; |
26 | 26 |
27 import java.lang.reflect.Field; | |
28 import java.lang.reflect.InvocationTargetException; | |
29 import java.lang.reflect.Method; | |
30 | |
27 import com.oracle.truffle.api.CallTarget; | 31 import com.oracle.truffle.api.CallTarget; |
28 import com.oracle.truffle.api.Truffle; | 32 import com.oracle.truffle.api.Truffle; |
29 import com.oracle.truffle.api.TruffleLanguage; | 33 import com.oracle.truffle.api.TruffleLanguage; |
30 import com.oracle.truffle.api.frame.VirtualFrame; | 34 import com.oracle.truffle.api.frame.VirtualFrame; |
35 import com.oracle.truffle.api.instrument.Instrumenter; | |
31 import com.oracle.truffle.api.instrument.KillException; | 36 import com.oracle.truffle.api.instrument.KillException; |
32 import com.oracle.truffle.api.instrument.Probe; | 37 import com.oracle.truffle.api.instrument.Probe; |
33 import com.oracle.truffle.api.instrument.ProbeNode; | 38 import com.oracle.truffle.api.instrument.ProbeNode; |
34 import com.oracle.truffle.api.instrument.ProbeNode.WrapperNode; | 39 import com.oracle.truffle.api.instrument.ProbeNode.WrapperNode; |
35 import com.oracle.truffle.api.nodes.Node; | 40 import com.oracle.truffle.api.nodes.Node; |
37 import com.oracle.truffle.api.nodes.NodeInfo; | 42 import com.oracle.truffle.api.nodes.NodeInfo; |
38 import com.oracle.truffle.api.nodes.RootNode; | 43 import com.oracle.truffle.api.nodes.RootNode; |
39 import com.oracle.truffle.api.source.LineLocation; | 44 import com.oracle.truffle.api.source.LineLocation; |
40 import com.oracle.truffle.api.source.Source; | 45 import com.oracle.truffle.api.source.Source; |
41 import com.oracle.truffle.api.source.SourceSection; | 46 import com.oracle.truffle.api.source.SourceSection; |
47 import com.oracle.truffle.api.vm.TruffleVM; | |
42 | 48 |
43 /** | 49 /** |
44 * Nodes and an {@linkplain CallTarget executable ASTs} for testing. | 50 * Nodes and an {@linkplain CallTarget executable ASTs} for testing. |
45 */ | 51 */ |
46 class TestNodes { | 52 class TestNodes { |
53 public static final LineLocation expr13Line2 = expr13Source.createLineLocation(2); | 59 public static final LineLocation expr13Line2 = expr13Source.createLineLocation(2); |
54 | 60 |
55 /** | 61 /** |
56 * An executable addition expression that evaluates to 13. | 62 * An executable addition expression that evaluates to 13. |
57 */ | 63 */ |
58 static CallTarget createExpr13TestCallTarget() { | 64 static CallTarget createExpr13TestCallTarget(Instrumenter instrumenter) { |
59 final RootNode rootNode = createExpr13TestRootNode(); | 65 final RootNode rootNode = createExpr13TestRootNode(instrumenter); |
60 return Truffle.getRuntime().createCallTarget(rootNode); | 66 return Truffle.getRuntime().createCallTarget(rootNode); |
61 } | 67 } |
62 | 68 |
63 /** | 69 /** |
64 * Root holding an addition expression that evaluates to 13. | 70 * Root holding an addition expression that evaluates to 13. |
65 */ | 71 */ |
66 static RootNode createExpr13TestRootNode() { | 72 static RootNode createExpr13TestRootNode(Instrumenter instrumenter) { |
67 final TestLanguageNode ast = createExpr13AST(); | 73 final TestLanguageNode ast = createExpr13AST(); |
68 final TestRootNode rootNode = new TestRootNode(ast); | 74 final TestRootNode rootNode = new TestRootNode(ast, instrumenter); |
69 rootNode.adoptChildren(); | 75 rootNode.adoptChildren(); |
70 return rootNode; | 76 return rootNode; |
77 } | |
78 | |
79 static Instrumenter createInstrumenter() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { | |
80 TruffleVM vm = TruffleVM.newVM().build(); | |
81 final Field field = TruffleVM.class.getDeclaredField("instrumenter"); | |
82 field.setAccessible(true); | |
83 final Instrumenter instrument = (Instrumenter) field.get(vm); | |
84 return instrument; | |
71 } | 85 } |
72 | 86 |
73 /** | 87 /** |
74 * Addition expression that evaluates to 13, with faked source attribution. | 88 * Addition expression that evaluates to 13, with faked source attribution. |
75 */ | 89 */ |
163 * completes an AST. The root nodes serves as our entry point into a program. | 177 * completes an AST. The root nodes serves as our entry point into a program. |
164 */ | 178 */ |
165 static class TestRootNode extends RootNode { | 179 static class TestRootNode extends RootNode { |
166 @Child private TestLanguageNode body; | 180 @Child private TestLanguageNode body; |
167 | 181 |
182 private final Instrumenter instrumenter; | |
183 | |
168 /** | 184 /** |
169 * This constructor emulates the global machinery that applies registered probers to every | 185 * This constructor emulates the global machinery that applies registered probers to every |
170 * newly created AST. Global registry is not used, since that would interfere with other | 186 * newly created AST. Global registry is not used, since that would interfere with other |
171 * tests run in the same environment. | 187 * tests run in the same environment. |
172 */ | 188 */ |
173 public TestRootNode(TestLanguageNode body) { | 189 public TestRootNode(TestLanguageNode body, Instrumenter instrumenter) { |
174 super(TruffleLanguage.class, null, null); | 190 super(TruffleLanguage.class, null, null); |
191 this.instrumenter = instrumenter; | |
175 this.body = body; | 192 this.body = body; |
176 } | 193 } |
177 | 194 |
178 @Override | 195 @Override |
179 public Object execute(VirtualFrame frame) { | 196 public Object execute(VirtualFrame frame) { |
185 return true; | 202 return true; |
186 } | 203 } |
187 | 204 |
188 @Override | 205 @Override |
189 public void applyInstrumentation() { | 206 public void applyInstrumentation() { |
190 Probe.applyASTProbers(body); | 207 Method method; |
208 try { | |
209 method = Instrumenter.class.getDeclaredMethod("applyInstrumentation", Node.class); | |
210 method.setAccessible(true); | |
211 method.invoke(instrumenter, body); | |
212 } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { | |
213 throw new RuntimeException("TestNodes"); | |
214 } | |
191 } | 215 } |
192 } | 216 } |
193 | 217 |
194 static class TestValueNode extends TestLanguageNode { | 218 static class TestValueNode extends TestLanguageNode { |
195 private final int value; | 219 private final int value; |