annotate graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLInstrumenter.java @ 16958:997899955e72

Instrumentation: removed ExecutionContext parameter from probe method in Instrumentable SL/Instrumentation: SLRootNode's now store SLContext. New method added to SLStatementNode to find the root node and get its SLContext
author David Piorkowski <david.piorkowski@oracle.com>
date Tue, 26 Aug 2014 11:00:30 -0700
parents 54696f15ac93
children f0c3de09f12a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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 * 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
35 * 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
36 * parsed.
7661cc464239 Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff changeset
37 *
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 public class SLInstrumenter implements NodeVisitor {
7661cc464239 Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff changeset
40
16958
997899955e72 Instrumentation: removed ExecutionContext parameter from probe method in Instrumentable
David Piorkowski <david.piorkowski@oracle.com>
parents: 16882
diff changeset
41 public SLInstrumenter() {
16880
7661cc464239 Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff changeset
42 }
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 /**
7661cc464239 Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff changeset
45 * 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
46 * 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
47 */
7661cc464239 Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff changeset
48 public boolean visit(Node node) {
7661cc464239 Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff changeset
49 // 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
50 // 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
51 // 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
52 // SLExpressionNode first.
7661cc464239 Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff changeset
53 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
54 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
55 if (expressionNode.getSourceSection() != null) {
16958
997899955e72 Instrumentation: removed ExecutionContext parameter from probe method in Instrumentable
David Piorkowski <david.piorkowski@oracle.com>
parents: 16882
diff changeset
56 Probe probe = expressionNode.probe();
16882
54696f15ac93 SL/Instrumentation: Added checks for null SourceSections in SLInstrumenter
David Piorkowski <david.piorkowski@oracle.com>
parents: 16880
diff changeset
57 // probe.tagAs(STATEMENT);
16880
7661cc464239 Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff changeset
58
16882
54696f15ac93 SL/Instrumentation: Added checks for null SourceSections in SLInstrumenter
David Piorkowski <david.piorkowski@oracle.com>
parents: 16880
diff changeset
59 if (node instanceof SLWriteLocalVariableNode)
54696f15ac93 SL/Instrumentation: Added checks for null SourceSections in SLInstrumenter
David Piorkowski <david.piorkowski@oracle.com>
parents: 16880
diff changeset
60 probe.tagAs(ASSIGNMENT);
54696f15ac93 SL/Instrumentation: Added checks for null SourceSections in SLInstrumenter
David Piorkowski <david.piorkowski@oracle.com>
parents: 16880
diff changeset
61 }
16880
7661cc464239 Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff changeset
62 } 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
63
7661cc464239 Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff changeset
64 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
65 if (statementNode.getSourceSection() != null) {
16958
997899955e72 Instrumentation: removed ExecutionContext parameter from probe method in Instrumentable
David Piorkowski <david.piorkowski@oracle.com>
parents: 16882
diff changeset
66 Probe probe = statementNode.probe();
16882
54696f15ac93 SL/Instrumentation: Added checks for null SourceSections in SLInstrumenter
David Piorkowski <david.piorkowski@oracle.com>
parents: 16880
diff changeset
67 probe.tagAs(STATEMENT);
16880
7661cc464239 Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff changeset
68
16882
54696f15ac93 SL/Instrumentation: Added checks for null SourceSections in SLInstrumenter
David Piorkowski <david.piorkowski@oracle.com>
parents: 16880
diff changeset
69 if (node instanceof SLWhileNode)
54696f15ac93 SL/Instrumentation: Added checks for null SourceSections in SLInstrumenter
David Piorkowski <david.piorkowski@oracle.com>
parents: 16880
diff changeset
70 probe.tagAs(START_LOOP);
54696f15ac93 SL/Instrumentation: Added checks for null SourceSections in SLInstrumenter
David Piorkowski <david.piorkowski@oracle.com>
parents: 16880
diff changeset
71 }
16880
7661cc464239 Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff changeset
72 }
7661cc464239 Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff changeset
73
7661cc464239 Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff changeset
74 return true;
7661cc464239 Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff changeset
75 }
7661cc464239 Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff changeset
76 }