Skip to content
Snippets Groups Projects
Commit 3e460be5 authored by Mick Jordan's avatar Mick Jordan
Browse files

add optional tracing of REngine.makeCallTarget

parent 7d560a6a
No related branches found
No related tags found
No related merge requests found
......@@ -33,6 +33,7 @@ import com.oracle.truffle.api.frame.*;
import com.oracle.truffle.api.nodes.*;
import com.oracle.truffle.api.source.*;
import com.oracle.truffle.r.nodes.*;
import com.oracle.truffle.r.nodes.access.*;
import com.oracle.truffle.r.nodes.builtin.*;
import com.oracle.truffle.r.nodes.function.*;
import com.oracle.truffle.r.options.*;
......@@ -335,6 +336,8 @@ public final class REngine implements RContext.Engine {
return result;
}
private static boolean traceMakeCallTarget;
/**
* Wraps the Truffle AST in {@code node} in an anonymous function and returns a
* {@link RootCallTarget} for it. We define the
......@@ -350,12 +353,33 @@ public final class REngine implements RContext.Engine {
*/
@SlowPath
private static RootCallTarget makeCallTarget(RNode body) {
if (traceMakeCallTarget) {
doTraceMakeCallTarget(body);
}
REnvironment.FunctionDefinition rootNodeEnvironment = new REnvironment.FunctionDefinition(REnvironment.emptyEnv());
FunctionDefinitionNode rootNode = new FunctionDefinitionNode(null, rootNodeEnvironment, body, FormalArguments.NO_ARGS, "<wrapper>", true);
RootCallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
return callTarget;
}
private static void doTraceMakeCallTarget(RNode body) {
String nodeClassName = body.getClass().getSimpleName();
SourceSection ss = body.getSourceSection();
String trace;
if (ss == null) {
System.console();
if (body instanceof ConstantNode) {
trace = ((ConstantNode) body).getValue().toString();
} else {
trace = "not constant/no source";
}
} else {
trace = ss.toString();
}
RContext.getInstance().getConsoleHandler().printf("makeCallTarget: node: %s, %s%n", nodeClassName, trace);
}
/**
* Execute {@code callTarget} in {@code frame}, optionally printing any result. N.B.
* {@code callTarget.call} will create a new {@link VirtualFrame} called, say, {@code newFrame},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment