Mercurial > hg > truffle
comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLExpressionWrapperNode.java @ 18485:e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Sun, 23 Nov 2014 16:07:23 -0800 |
parents | |
children | ccb97347d874 |
comparison
equal
deleted
inserted
replaced
18484:e97e1f07a3d6 | 18485:e3c95cbbb50c |
---|---|
1 /* | |
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.truffle.sl.nodes.instrument; | |
24 | |
25 import java.math.*; | |
26 | |
27 import com.oracle.truffle.api.frame.*; | |
28 import com.oracle.truffle.api.instrument.*; | |
29 import com.oracle.truffle.api.instrument.ProbeNode.WrapperNode; | |
30 import com.oracle.truffle.api.nodes.*; | |
31 import com.oracle.truffle.sl.nodes.*; | |
32 import com.oracle.truffle.sl.runtime.*; | |
33 | |
34 /** | |
35 * A Truffle node that can be inserted into a Simple AST (assumed not to have executed yet) to | |
36 * enable "instrumentation" of an {@link SLExpressionNode}. Tools wishing to interact with AST | |
37 * execution may attach {@link Instrument}s to the {@link Probe} uniquely associated with the | |
38 * wrapper, and to which this wrapper routes execution events. | |
39 */ | |
40 @NodeInfo(cost = NodeCost.NONE) | |
41 public final class SLExpressionWrapperNode extends SLExpressionNode implements WrapperNode { | |
42 @Child private SLExpressionNode child; | |
43 @Child private ProbeNode probeNode; | |
44 | |
45 /** | |
46 * Constructor. | |
47 * | |
48 * @param child The {@link SLExpressionNode} that this wrapper is wrapping | |
49 */ | |
50 public SLExpressionWrapperNode(SLExpressionNode child) { | |
51 super(child.getSourceSection()); | |
52 assert !(child instanceof SLExpressionWrapperNode); | |
53 this.child = child; | |
54 } | |
55 | |
56 public String instrumentationInfo() { | |
57 return "Wrapper node for SL Expressions"; | |
58 } | |
59 | |
60 @Override | |
61 public SLExpressionNode getNonWrapperNode() { | |
62 return child; | |
63 } | |
64 | |
65 public void insertProbe(ProbeNode newProbeNode) { | |
66 this.probeNode = newProbeNode; | |
67 } | |
68 | |
69 public Probe getProbe() { | |
70 try { | |
71 return probeNode.getProbe(); | |
72 } catch (IllegalStateException e) { | |
73 throw new IllegalStateException("A lite-Probed wrapper has no explicit Probe"); | |
74 } | |
75 } | |
76 | |
77 public Node getChild() { | |
78 return child; | |
79 } | |
80 | |
81 @Override | |
82 public Object executeGeneric(VirtualFrame frame) { | |
83 | |
84 probeNode.enter(child, frame); | |
85 Object result; | |
86 | |
87 try { | |
88 result = child.executeGeneric(frame); | |
89 probeNode.returnValue(child, frame, result); | |
90 } catch (Exception e) { | |
91 probeNode.returnExceptional(child, frame, e); | |
92 throw (e); | |
93 } | |
94 return result; | |
95 } | |
96 | |
97 @Override | |
98 public long executeLong(VirtualFrame frame) throws UnexpectedResultException { | |
99 return SLTypesGen.SLTYPES.expectLong(executeGeneric(frame)); | |
100 } | |
101 | |
102 @Override | |
103 public BigInteger executeBigInteger(VirtualFrame frame) throws UnexpectedResultException { | |
104 return SLTypesGen.SLTYPES.expectBigInteger(executeGeneric(frame)); | |
105 } | |
106 | |
107 @Override | |
108 public boolean executeBoolean(VirtualFrame frame) throws UnexpectedResultException { | |
109 return SLTypesGen.SLTYPES.expectBoolean(executeGeneric(frame)); | |
110 } | |
111 | |
112 @Override | |
113 public String executeString(VirtualFrame frame) throws UnexpectedResultException { | |
114 return SLTypesGen.SLTYPES.expectString(executeGeneric(frame)); | |
115 } | |
116 | |
117 @Override | |
118 public SLFunction executeFunction(VirtualFrame frame) throws UnexpectedResultException { | |
119 probeNode.enter(child, frame); | |
120 SLFunction result; | |
121 | |
122 try { | |
123 result = child.executeFunction(frame); | |
124 probeNode.returnValue(child, frame, result); | |
125 } catch (Exception e) { | |
126 probeNode.returnExceptional(child, frame, e); | |
127 throw (e); | |
128 } | |
129 return result; | |
130 } | |
131 | |
132 @Override | |
133 public SLNull executeNull(VirtualFrame frame) throws UnexpectedResultException { | |
134 return SLTypesGen.SLTYPES.expectSLNull(executeGeneric(frame)); | |
135 } | |
136 | |
137 @Override | |
138 public Probe probe() { | |
139 throw new IllegalStateException("Cannot call probe() on a wrapper."); | |
140 } | |
141 | |
142 @Override | |
143 public void probeLite(TruffleEventReceiver eventReceiver) { | |
144 throw new IllegalStateException("Cannot call probeLite() on a wrapper."); | |
145 } | |
146 } |