comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLExpressionWrapper.java @ 16595:618d92152d3c

SL: Added support for instrumentation.
author David Piorkowski <david.piorkowski@oracle.com>
date Thu, 24 Jul 2014 16:14:44 -0700
parents
children 7833417c8172
comparison
equal deleted inserted replaced
16592:8084d44c78d3 16595:618d92152d3c
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.CompilerDirectives.*;
28 import com.oracle.truffle.api.frame.*;
29 import com.oracle.truffle.api.instrument.*;
30 import com.oracle.truffle.api.nodes.*;
31 import com.oracle.truffle.sl.nodes.*;
32 import com.oracle.truffle.sl.runtime.*;
33
34 /**
35 * SLExpressionWrapper is a Truffle AST node that gets inserted as the parent to the node that it is
36 * wrapping. Any debugging instruments are attached to this wrapper through {@link Probe}s (which
37 * themselves contain the instruments. It is through this mechanism that tools can interact directly
38 * with the AST. <br/>
39 * {@link SLExpressionWrapper} specifically wraps {@link SLExpressionNode}s and overrides the
40 * various execute functions in {@link SLExpressionNode} to operate on the child of the wrapper
41 * instead of the wrapper itself.
42 *
43 */
44 public final class SLExpressionWrapper extends SLExpressionNode implements Wrapper {
45 @Child private SLExpressionNode child;
46
47 private final Probe probe;
48
49 public SLExpressionWrapper(SLContext context, SLExpressionNode child) {
50 super(child.getSourceSection());
51 assert !(child instanceof SLExpressionWrapper);
52 this.child = insert(child);
53 this.probe = context.getProbe(child.getSourceSection());
54 }
55
56 @Override
57 public SLExpressionNode getNonWrapperNode() {
58 return child;
59 }
60
61 @Override
62 public Node getChild() {
63 return child;
64 }
65
66 @Override
67 public Probe getProbe() {
68 return probe;
69 }
70
71 @Override
72 @SlowPath
73 public boolean isTaggedAs(SyntaxTag tag) {
74 return probe.isTaggedAs(tag);
75 }
76
77 @Override
78 @SlowPath
79 public Iterable<SyntaxTag> getSyntaxTags() {
80 return probe.getSyntaxTags();
81 }
82
83 @SlowPath
84 public void tagAs(SyntaxTag tag) {
85 probe.tagAs(tag);
86 }
87
88 @Override
89 public Object executeGeneric(VirtualFrame frame) {
90 this.tagAs(StandardSyntaxTag.STATEMENT);
91 probe.enter(child, frame);
92 Object result;
93
94 try {
95 result = child.executeGeneric(frame);
96 probe.leave(child, frame, result);
97 } catch (Exception e) {
98 probe.leaveExceptional(child, frame, e);
99 throw (e);
100 }
101 return result;
102 }
103
104 @Override
105 public long executeLong(VirtualFrame frame) throws UnexpectedResultException {
106 this.tagAs(StandardSyntaxTag.STATEMENT);
107 return SLTypesGen.SLTYPES.expectLong(executeGeneric(frame));
108 }
109
110 @Override
111 public BigInteger executeBigInteger(VirtualFrame frame) throws UnexpectedResultException {
112 this.tagAs(StandardSyntaxTag.STATEMENT);
113 return SLTypesGen.SLTYPES.expectBigInteger(executeGeneric(frame));
114 }
115
116 @Override
117 public boolean executeBoolean(VirtualFrame frame) throws UnexpectedResultException {
118 this.tagAs(StandardSyntaxTag.STATEMENT);
119 return SLTypesGen.SLTYPES.expectBoolean(executeGeneric(frame));
120 }
121
122 @Override
123 public String executeString(VirtualFrame frame) throws UnexpectedResultException {
124 this.tagAs(StandardSyntaxTag.STATEMENT);
125 return SLTypesGen.SLTYPES.expectString(executeGeneric(frame));
126 }
127
128 @Override
129 public SLFunction executeFunction(VirtualFrame frame) throws UnexpectedResultException {
130 this.tagAs(StandardSyntaxTag.STATEMENT);
131 probe.enter(child, frame);
132 SLFunction result;
133
134 try {
135 result = child.executeFunction(frame);
136 probe.leave(child, frame, result);
137 } catch (Exception e) {
138 probe.leaveExceptional(child, frame, e);
139 throw (e);
140 }
141 return result;
142 }
143
144 @Override
145 public SLNull executeNull(VirtualFrame frame) throws UnexpectedResultException {
146 return SLTypesGen.SLTYPES.expectSLNull(executeGeneric(frame));
147 }
148 }