comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLStatementWrapper.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 com.oracle.truffle.api.CompilerDirectives.SlowPath;
26 import com.oracle.truffle.api.frame.*;
27 import com.oracle.truffle.api.instrument.*;
28 import com.oracle.truffle.api.nodes.*;
29 import com.oracle.truffle.sl.nodes.*;
30 import com.oracle.truffle.sl.runtime.*;
31
32 /**
33 * SLStatmentWrapper is a Truffle AST node that gets inserted as the parent to the node that it is
34 * wrapping. Any debugging instruments are attached to this wrapper through {@link Probe}s (which
35 * themselves contain the instruments). It is through this mechanism that tools can interact
36 * directly with the AST. <br/>
37 * SLStatmentWrapper specifically wraps {@link SLStatementWrapper}s and overrides the executeVoid
38 * function of {@link SLStatementNode} to operate on the child of the wrapper instead of the wrapper
39 * itself.
40 *
41 */
42 public final class SLStatementWrapper extends SLStatementNode implements Wrapper {
43
44 @Child private SLStatementNode child;
45
46 private final Probe probe;
47
48 public SLStatementWrapper(SLContext context, SLStatementNode child) {
49 super(child.getSourceSection());
50 assert !(child instanceof SLStatementWrapper);
51 this.child = insert(child);
52 this.probe = context.getProbe(child.getSourceSection());
53 }
54
55 @Override
56 public SLStatementNode getNonWrapperNode() {
57 return child;
58 }
59
60 public Node getChild() {
61 return child;
62 }
63
64 public Probe getProbe() {
65 return probe;
66 }
67
68 @SlowPath
69 public boolean isTaggedAs(SyntaxTag tag) {
70 return probe.isTaggedAs(tag);
71 }
72
73 @SlowPath
74 public Iterable<SyntaxTag> getSyntaxTags() {
75 return probe.getSyntaxTags();
76 }
77
78 @SlowPath
79 public void tagAs(SyntaxTag tag) {
80 probe.tagAs(tag);
81 }
82
83 @Override
84 public void executeVoid(VirtualFrame frame) {
85 this.tagAs(StandardSyntaxTag.STATEMENT);
86 probe.enter(child, frame);
87
88 try {
89 child.executeVoid(frame);
90 probe.leave(child, frame);
91 } catch (KillException e) {
92 throw (e);
93 } catch (Exception e) {
94 probe.leaveExceptional(child, frame, e);
95 throw (e);
96 }
97
98 }
99 }