Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLInstrumenter.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 | 54696f15ac93 |
children | 997899955e72 a1427e40deaf |
rev | line source |
---|---|
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
1 /* |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
4 * |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
8 * |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
14 * |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
18 * |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
21 * questions. |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
22 */ |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.sl.nodes.instrument; |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
24 |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
25 import static com.oracle.truffle.api.instrument.StandardSyntaxTag.*; |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
26 |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
27 import com.oracle.truffle.api.instrument.*; |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
28 import com.oracle.truffle.api.nodes.*; |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
29 import com.oracle.truffle.sl.nodes.*; |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.sl.nodes.controlflow.*; |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
31 import com.oracle.truffle.sl.nodes.local.*; |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
32 import com.oracle.truffle.sl.runtime.*; |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
33 |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
34 /** |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
35 * This is a general purpose visitor which traverses a completely parsed Simple AST and instruments |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
36 * all the nodes within it. This visitor is designed to visit the tree immediately after it has been |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
37 * parsed. |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
38 * |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
39 */ |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
40 public class SLInstrumenter implements NodeVisitor { |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
41 |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
42 private final SLContext context; |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
43 |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
44 public SLInstrumenter(SLContext context) { |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
45 this.context = context; |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
46 } |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
47 |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
48 /** |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
49 * Instruments and tags all relevant {@link SLStatementNode}s and {@link SLExpressionNode}s. |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
50 * Currently, only SLStatementNodes that are not SLExpressionNodes are tagged as statements. |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
51 */ |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
52 public boolean visit(Node node) { |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
53 // We have to distinguish between SLExpressionNode and SLStatementNode since some of the |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
54 // generated factories have methods that require SLExpressionNodes as parameters. Since |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
55 // SLExpressionNodes are a subclass of SLStatementNode, we check if something is an |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
56 // SLExpressionNode first. |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
57 if (node instanceof SLExpressionNode && node.getParent() != null) { |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
58 SLExpressionNode expressionNode = (SLExpressionNode) node; |
16882
54696f15ac93
SL/Instrumentation: Added checks for null SourceSections in SLInstrumenter
David Piorkowski <david.piorkowski@oracle.com>
parents:
16880
diff
changeset
|
59 if (expressionNode.getSourceSection() != null) { |
54696f15ac93
SL/Instrumentation: Added checks for null SourceSections in SLInstrumenter
David Piorkowski <david.piorkowski@oracle.com>
parents:
16880
diff
changeset
|
60 Probe probe = expressionNode.probe(context); |
54696f15ac93
SL/Instrumentation: Added checks for null SourceSections in SLInstrumenter
David Piorkowski <david.piorkowski@oracle.com>
parents:
16880
diff
changeset
|
61 // probe.tagAs(STATEMENT); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
62 |
16882
54696f15ac93
SL/Instrumentation: Added checks for null SourceSections in SLInstrumenter
David Piorkowski <david.piorkowski@oracle.com>
parents:
16880
diff
changeset
|
63 if (node instanceof SLWriteLocalVariableNode) |
54696f15ac93
SL/Instrumentation: Added checks for null SourceSections in SLInstrumenter
David Piorkowski <david.piorkowski@oracle.com>
parents:
16880
diff
changeset
|
64 probe.tagAs(ASSIGNMENT); |
54696f15ac93
SL/Instrumentation: Added checks for null SourceSections in SLInstrumenter
David Piorkowski <david.piorkowski@oracle.com>
parents:
16880
diff
changeset
|
65 } |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
66 } else if (node instanceof SLStatementNode && node.getParent() != null) { |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
67 |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
68 SLStatementNode statementNode = (SLStatementNode) node; |
16882
54696f15ac93
SL/Instrumentation: Added checks for null SourceSections in SLInstrumenter
David Piorkowski <david.piorkowski@oracle.com>
parents:
16880
diff
changeset
|
69 if (statementNode.getSourceSection() != null) { |
54696f15ac93
SL/Instrumentation: Added checks for null SourceSections in SLInstrumenter
David Piorkowski <david.piorkowski@oracle.com>
parents:
16880
diff
changeset
|
70 Probe probe = statementNode.probe(context); |
54696f15ac93
SL/Instrumentation: Added checks for null SourceSections in SLInstrumenter
David Piorkowski <david.piorkowski@oracle.com>
parents:
16880
diff
changeset
|
71 probe.tagAs(STATEMENT); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
72 |
16882
54696f15ac93
SL/Instrumentation: Added checks for null SourceSections in SLInstrumenter
David Piorkowski <david.piorkowski@oracle.com>
parents:
16880
diff
changeset
|
73 if (node instanceof SLWhileNode) |
54696f15ac93
SL/Instrumentation: Added checks for null SourceSections in SLInstrumenter
David Piorkowski <david.piorkowski@oracle.com>
parents:
16880
diff
changeset
|
74 probe.tagAs(START_LOOP); |
54696f15ac93
SL/Instrumentation: Added checks for null SourceSections in SLInstrumenter
David Piorkowski <david.piorkowski@oracle.com>
parents:
16880
diff
changeset
|
75 } |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
76 } |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
77 |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
78 return true; |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
79 } |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
80 } |