Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLStatementWrapper.java @ 16913:b879421229db
SL: better toString for SL nodes.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Sat, 23 Aug 2014 19:31:33 +0200 |
parents | 7661cc464239 |
children | a1427e40deaf |
rev | line source |
---|---|
16595
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
1 /* |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
4 * |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
8 * |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
14 * |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
18 * |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
21 * questions. |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
22 */ |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.sl.nodes.instrument; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
24 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
25 import com.oracle.truffle.api.CompilerDirectives.SlowPath; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
26 import com.oracle.truffle.api.frame.*; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
27 import com.oracle.truffle.api.instrument.*; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
28 import com.oracle.truffle.api.nodes.*; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
29 import com.oracle.truffle.sl.nodes.*; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.sl.runtime.*; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
31 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
32 /** |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
33 * SLStatmentWrapper is a Truffle AST node that gets inserted as the parent to the node that it is |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
34 * wrapping. Any debugging instruments are attached to this wrapper through {@link Probe}s (which |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
35 * themselves contain the instruments). It is through this mechanism that tools can interact |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
36 * directly with the AST. <br/> |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
37 * SLStatmentWrapper specifically wraps {@link SLStatementWrapper}s and overrides the executeVoid |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
38 * function of {@link SLStatementNode} to operate on the child of the wrapper instead of the wrapper |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
39 * itself. |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
40 * |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
41 */ |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
42 public final class SLStatementWrapper extends SLStatementNode implements Wrapper { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
43 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
44 @Child private SLStatementNode child; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
45 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
46 private final Probe probe; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
47 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
48 public SLStatementWrapper(SLContext context, SLStatementNode child) { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
49 super(child.getSourceSection()); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
50 assert !(child instanceof SLStatementWrapper); |
16856
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
16595
diff
changeset
|
51 this.probe = context.createProbe(child.getSourceSection()); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16856
diff
changeset
|
52 this.child = child; |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16856
diff
changeset
|
53 // The child should only be inserted after a replace, so we defer inserting the child to the |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16856
diff
changeset
|
54 // creator of the wrapper. |
16595
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
55 } |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
56 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
57 @Override |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
58 public SLStatementNode getNonWrapperNode() { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
59 return child; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
60 } |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
61 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
62 public Node getChild() { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
63 return child; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
64 } |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
65 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
66 public Probe getProbe() { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
67 return probe; |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
68 } |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
69 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
70 @SlowPath |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
71 public boolean isTaggedAs(SyntaxTag tag) { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
72 return probe.isTaggedAs(tag); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
73 } |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
74 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
75 @SlowPath |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
76 public Iterable<SyntaxTag> getSyntaxTags() { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
77 return probe.getSyntaxTags(); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
78 } |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
79 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
80 @SlowPath |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
81 public void tagAs(SyntaxTag tag) { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
82 probe.tagAs(tag); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
83 } |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
84 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
85 @Override |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
86 public void executeVoid(VirtualFrame frame) { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
87 this.tagAs(StandardSyntaxTag.STATEMENT); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
88 probe.enter(child, frame); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
89 |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
90 try { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
91 child.executeVoid(frame); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
92 probe.leave(child, frame); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
93 } catch (KillException e) { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
94 throw (e); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
95 } catch (Exception e) { |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
96 probe.leaveExceptional(child, frame, e); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
97 throw (e); |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
98 } |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16856
diff
changeset
|
99 } |
16595
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
100 |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16856
diff
changeset
|
101 /** |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16856
diff
changeset
|
102 * Sets the parent pointer of this wrapper's child. |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16856
diff
changeset
|
103 */ |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16856
diff
changeset
|
104 public void insertChild() { |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16856
diff
changeset
|
105 insert(this.child); |
16595
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
106 } |
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
107 } |