diff graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLStatementNode.java @ 18485:e3c95cbbb50c

Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Sun, 23 Nov 2014 16:07:23 -0800
parents c88ab4f1f04a
children d1c1cd2530d7
line wrap: on
line diff
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLStatementNode.java	Fri Nov 21 13:16:02 2014 +0100
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLStatementNode.java	Sun Nov 23 16:07:23 2014 -0800
@@ -26,10 +26,10 @@
 
 import com.oracle.truffle.api.frame.*;
 import com.oracle.truffle.api.instrument.*;
+import com.oracle.truffle.api.instrument.ProbeNode.*;
 import com.oracle.truffle.api.nodes.*;
 import com.oracle.truffle.api.source.*;
 import com.oracle.truffle.sl.nodes.instrument.*;
-import com.oracle.truffle.sl.runtime.*;
 
 /**
  * The base class of all Truffle nodes for SL. All nodes (even expressions) can be used as
@@ -90,28 +90,40 @@
         Node parent = getParent();
 
         if (parent == null) {
-            throw new IllegalStateException("Cannot probe a node without a parent");
+            throw new IllegalStateException("Cannot call probe() on a node without a parent.");
         }
 
-        if (parent instanceof SLStatementWrapper) {
-            return ((SLStatementWrapper) parent).getProbe();
+        if (parent instanceof SLStatementWrapperNode) {
+            return ((SLStatementWrapperNode) parent).getProbe();
         }
 
         // Create a new wrapper/probe with this node as its child.
-        final SLStatementWrapper wrapper = new SLStatementWrapper(getRootNodeSLContext(this), this);
+        final SLStatementWrapperNode wrapper = new SLStatementWrapperNode(this);
+
+        // Connect it to a Probe
+        final Probe probe = ProbeNode.insertProbe(wrapper);
 
         // Replace this node in the AST with the wrapper
         this.replace(wrapper);
 
-        return wrapper.getProbe();
+        return probe;
     }
 
-    protected SLContext getRootNodeSLContext(Node node) {
-        assert node != null;
+    @Override
+    public void probeLite(TruffleEventReceiver eventReceiver) {
+        Node parent = getParent();
+
+        if (parent == null) {
+            throw new IllegalStateException("Cannot call probeLite() on a node without a parent");
+        }
 
-        if (node instanceof SLRootNode) {
-            return ((SLRootNode) node).getSLContext();
+        if (parent instanceof SLStatementWrapperNode) {
+            throw new IllegalStateException("Cannot call probeLite() on a node that already has a wrapper.");
         }
-        return getRootNodeSLContext(node.getParent());
+
+        final SLStatementWrapperNode wrapper = new SLStatementWrapperNode(this);
+        ProbeNode.insertProbeLite(wrapper, eventReceiver);
+
+        this.replace(wrapper);
     }
 }