comparison truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLStandardASTProber.java @ 22219:1c0f490984d5

Merge with f47b601edbc626dcfe8b3636933b4834c89f7779
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Wed, 16 Sep 2015 15:36:22 -0700
parents dc83cc1f94f2 3aad794eec0e
children ffb52d4126bb
comparison
equal deleted inserted replaced
22160:0599e2df6a9f 22219:1c0f490984d5
38 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 38 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 * SOFTWARE. 39 * SOFTWARE.
40 */ 40 */
41 package com.oracle.truffle.sl.nodes.instrument; 41 package com.oracle.truffle.sl.nodes.instrument;
42 42
43 import com.oracle.truffle.api.instrument.ASTProber;
44 import com.oracle.truffle.api.instrument.InstrumentationNode;
45 import com.oracle.truffle.api.instrument.Probe;
46 import static com.oracle.truffle.api.instrument.StandardSyntaxTag.ASSIGNMENT; 43 import static com.oracle.truffle.api.instrument.StandardSyntaxTag.ASSIGNMENT;
47 import static com.oracle.truffle.api.instrument.StandardSyntaxTag.START_LOOP; 44 import static com.oracle.truffle.api.instrument.StandardSyntaxTag.START_LOOP;
48 import static com.oracle.truffle.api.instrument.StandardSyntaxTag.STATEMENT; 45 import static com.oracle.truffle.api.instrument.StandardSyntaxTag.STATEMENT;
46
47 import com.oracle.truffle.api.instrument.ASTProber;
48 import com.oracle.truffle.api.instrument.InstrumentationNode;
49 import com.oracle.truffle.api.instrument.Instrumenter;
50 import com.oracle.truffle.api.instrument.Probe;
49 import com.oracle.truffle.api.nodes.Node; 51 import com.oracle.truffle.api.nodes.Node;
50 import com.oracle.truffle.api.nodes.NodeVisitor; 52 import com.oracle.truffle.api.nodes.NodeVisitor;
51 import com.oracle.truffle.sl.nodes.SLExpressionNode; 53 import com.oracle.truffle.sl.nodes.SLExpressionNode;
52 import com.oracle.truffle.sl.nodes.SLStatementNode; 54 import com.oracle.truffle.sl.nodes.SLStatementNode;
53 import com.oracle.truffle.sl.nodes.controlflow.SLWhileNode; 55 import com.oracle.truffle.sl.nodes.controlflow.SLWhileNode;
55 57
56 /** 58 /**
57 * A visitor which traverses a completely parsed Simple AST (presumed not yet executed) and enables 59 * A visitor which traverses a completely parsed Simple AST (presumed not yet executed) and enables
58 * instrumentation at a few standard kinds of nodes. 60 * instrumentation at a few standard kinds of nodes.
59 */ 61 */
60 public class SLStandardASTProber implements NodeVisitor, ASTProber { 62 public class SLStandardASTProber implements ASTProber {
61 63
62 /** 64 public void probeAST(final Instrumenter instrumenter, Node startNode) {
63 * {@inheritDoc} 65 startNode.accept(new NodeVisitor() {
64 * <p>
65 * Instruments and tags all relevant {@link SLStatementNode}s and {@link SLExpressionNode}s.
66 * Currently, only SLStatementNodes that are not SLExpressionNodes are tagged as statements.
67 */
68 public boolean visit(Node node) {
69 66
70 if (!(node instanceof InstrumentationNode) && node instanceof SLStatementNode && node.getParent() != null && node.getSourceSection() != null) { 67 /**
71 // All SL nodes are instrumentable, but treat expressions specially 68 * Instruments and tags all relevant {@link SLStatementNode}s and
69 * {@link SLExpressionNode}s. Currently, only SLStatementNodes that are not
70 * SLExpressionNodes are tagged as statements.
71 */
72 public boolean visit(Node node) {
72 73
73 if (node instanceof SLExpressionNode) { 74 if (!(node instanceof InstrumentationNode) && node instanceof SLStatementNode && node.getParent() != null && node.getSourceSection() != null) {
74 SLExpressionNode expressionNode = (SLExpressionNode) node; 75 // All SL nodes are instrumentable, but treat expressions specially
75 Probe probe = expressionNode.probe(); 76
76 if (node instanceof SLWriteLocalVariableNode) { 77 if (node instanceof SLExpressionNode) {
77 probe.tagAs(STATEMENT, null); 78 SLExpressionNode expressionNode = (SLExpressionNode) node;
78 probe.tagAs(ASSIGNMENT, null); 79 final Probe probe = instrumenter.probe(expressionNode);
80 if (node instanceof SLWriteLocalVariableNode) {
81 probe.tagAs(STATEMENT, null);
82 probe.tagAs(ASSIGNMENT, null);
83 }
84 } else {
85 SLStatementNode statementNode = (SLStatementNode) node;
86 final Probe probe = instrumenter.probe(statementNode);
87 probe.tagAs(STATEMENT, null);
88 if (node instanceof SLWhileNode) {
89 probe.tagAs(START_LOOP, null);
90 }
91 }
79 } 92 }
80 } else { 93 return true;
81 SLStatementNode statementNode = (SLStatementNode) node;
82 Probe probe = statementNode.probe();
83 probe.tagAs(STATEMENT, null);
84 if (node instanceof SLWhileNode) {
85 probe.tagAs(START_LOOP, null);
86 }
87 } 94 }
88 } 95 });
89 return true;
90 }
91
92 public void probeAST(Node node) {
93 node.accept(this);
94 } 96 }
95 } 97 }