comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLInstrumenter.java @ 16880:7661cc464239

Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map SL: Updated implementation to use new Instrumentable interface
author David Piorkowski <david.piorkowski@oracle.com>
date Thu, 21 Aug 2014 13:28:22 -0700
parents
children 54696f15ac93
comparison
equal deleted inserted replaced
16867:7af9301efe6b 16880:7661cc464239
1 /*
2 * Copyright (c) 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 static com.oracle.truffle.api.instrument.StandardSyntaxTag.*;
26
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.nodes.controlflow.*;
31 import com.oracle.truffle.sl.nodes.local.*;
32 import com.oracle.truffle.sl.runtime.*;
33
34 /**
35 * This is a general purpose visitor which traverses a completely parsed Simple AST and instruments
36 * all the nodes within it. This visitor is designed to visit the tree immediately after it has been
37 * parsed.
38 *
39 */
40 public class SLInstrumenter implements NodeVisitor {
41
42 private final SLContext context;
43
44 public SLInstrumenter(SLContext context) {
45 this.context = context;
46 }
47
48 /**
49 * Instruments and tags all relevant {@link SLStatementNode}s and {@link SLExpressionNode}s.
50 * Currently, only SLStatementNodes that are not SLExpressionNodes are tagged as statements.
51 */
52 public boolean visit(Node node) {
53 // We have to distinguish between SLExpressionNode and SLStatementNode since some of the
54 // generated factories have methods that require SLExpressionNodes as parameters. Since
55 // SLExpressionNodes are a subclass of SLStatementNode, we check if something is an
56 // SLExpressionNode first.
57 if (node instanceof SLExpressionNode && node.getParent() != null) {
58 SLExpressionNode expressionNode = (SLExpressionNode) node;
59 Probe probe = expressionNode.probe(context);
60 // probe.tagAs(STATEMENT);
61
62 if (node instanceof SLWriteLocalVariableNode)
63 probe.tagAs(ASSIGNMENT);
64
65 } else if (node instanceof SLStatementNode && node.getParent() != null) {
66
67 SLStatementNode statementNode = (SLStatementNode) node;
68 Probe probe = statementNode.probe(context);
69 probe.tagAs(STATEMENT);
70
71 if (node instanceof SLWhileNode)
72 probe.tagAs(START_LOOP);
73 }
74
75 return true;
76 }
77 }