Search in sources :

Example 1 with SLRootNode

use of com.oracle.truffle.sl.nodes.SLRootNode in project graal by oracle.

the class SLContext method installBuiltin.

public void installBuiltin(NodeFactory<? extends SLBuiltinNode> factory) {
    /*
         * The builtin node factory is a class that is automatically generated by the Truffle DSL.
         * The signature returned by the factory reflects the signature of the @Specialization
         *
         * methods in the builtin classes.
         */
    int argumentCount = factory.getExecutionSignature().size();
    SLExpressionNode[] argumentNodes = new SLExpressionNode[argumentCount];
    /*
         * Builtin functions are like normal functions, i.e., the arguments are passed in as an
         * Object[] array encapsulated in SLArguments. A SLReadArgumentNode extracts a parameter
         * from this array.
         */
    for (int i = 0; i < argumentCount; i++) {
        argumentNodes[i] = new SLReadArgumentNode(i);
    }
    /* Instantiate the builtin node. This node performs the actual functionality. */
    SLBuiltinNode builtinBodyNode = factory.createNode((Object) argumentNodes);
    builtinBodyNode.addRootTag();
    /* The name of the builtin function is specified via an annotation on the node class. */
    String name = lookupNodeInfo(builtinBodyNode.getClass()).shortName();
    builtinBodyNode.setUnavailableSourceSection();
    /* Wrap the builtin in a RootNode. Truffle requires all AST to start with a RootNode. */
    SLRootNode rootNode = new SLRootNode(language, new FrameDescriptor(), builtinBodyNode, BUILTIN_SOURCE.createUnavailableSection(), name);
    /* Register the builtin function in our function registry. */
    getFunctionRegistry().register(name, Truffle.getRuntime().createCallTarget(rootNode));
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) SLExpressionNode(com.oracle.truffle.sl.nodes.SLExpressionNode) SLReadArgumentNode(com.oracle.truffle.sl.nodes.local.SLReadArgumentNode) SLRootNode(com.oracle.truffle.sl.nodes.SLRootNode) SLBuiltinNode(com.oracle.truffle.sl.builtins.SLBuiltinNode)

Example 2 with SLRootNode

use of com.oracle.truffle.sl.nodes.SLRootNode in project graal by oracle.

the class SLDisableSplittingBuiltin method disableSplitting.

@Specialization
@TruffleBoundary
public SLNull disableSplitting(@SuppressWarnings("unused") SLNull argument) {
    RootNode parentRoot = Truffle.getRuntime().getCallerFrame().getCallNode().getRootNode();
    ((SLRootNode) parentRoot).setCloningAllowed(false);
    return SLNull.SINGLETON;
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) SLRootNode(com.oracle.truffle.sl.nodes.SLRootNode) SLRootNode(com.oracle.truffle.sl.nodes.SLRootNode) Specialization(com.oracle.truffle.api.dsl.Specialization) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 3 with SLRootNode

use of com.oracle.truffle.sl.nodes.SLRootNode in project graal by oracle.

the class SLDisableSplittingBuiltin method disableSplitting.

@Specialization
@TruffleBoundary
public SLFunction disableSplitting(SLFunction function) {
    OptimizedCallTarget target = (OptimizedCallTarget) function.getCallTarget();
    ((SLRootNode) target.getRootNode()).setCloningAllowed(false);
    return function;
}
Also used : OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) SLRootNode(com.oracle.truffle.sl.nodes.SLRootNode) Specialization(com.oracle.truffle.api.dsl.Specialization) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 4 with SLRootNode

use of com.oracle.truffle.sl.nodes.SLRootNode in project graal by oracle.

the class SLNodeFactory method finishFunction.

public void finishFunction(SLStatementNode bodyNode) {
    if (bodyNode == null) {
        // a state update that would otherwise be performed by finishBlock
        lexicalScope = lexicalScope.outer;
    } else {
        methodNodes.add(bodyNode);
        final int bodyEndPos = bodyNode.getSourceEndIndex();
        final SourceSection functionSrc = source.createSection(functionStartPos, bodyEndPos - functionStartPos);
        final SLStatementNode methodBlock = finishBlock(methodNodes, functionBodyStartPos, bodyEndPos - functionBodyStartPos);
        assert lexicalScope == null : "Wrong scoping of blocks in parser";
        final SLFunctionBodyNode functionBodyNode = new SLFunctionBodyNode(methodBlock);
        functionBodyNode.setSourceSection(functionSrc.getCharIndex(), functionSrc.getCharLength());
        final SLRootNode rootNode = new SLRootNode(language, frameDescriptor, functionBodyNode, functionSrc, functionName);
        allFunctions.put(functionName, Truffle.getRuntime().createCallTarget(rootNode));
    }
    functionStartPos = 0;
    functionName = null;
    functionBodyStartPos = 0;
    parameterCount = 0;
    frameDescriptor = null;
    lexicalScope = null;
}
Also used : SLFunctionBodyNode(com.oracle.truffle.sl.nodes.controlflow.SLFunctionBodyNode) SourceSection(com.oracle.truffle.api.source.SourceSection) SLRootNode(com.oracle.truffle.sl.nodes.SLRootNode) SLStatementNode(com.oracle.truffle.sl.nodes.SLStatementNode)

Aggregations

SLRootNode (com.oracle.truffle.sl.nodes.SLRootNode)4 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)2 Specialization (com.oracle.truffle.api.dsl.Specialization)2 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)1 RootNode (com.oracle.truffle.api.nodes.RootNode)1 SourceSection (com.oracle.truffle.api.source.SourceSection)1 SLBuiltinNode (com.oracle.truffle.sl.builtins.SLBuiltinNode)1 SLExpressionNode (com.oracle.truffle.sl.nodes.SLExpressionNode)1 SLStatementNode (com.oracle.truffle.sl.nodes.SLStatementNode)1 SLFunctionBodyNode (com.oracle.truffle.sl.nodes.controlflow.SLFunctionBodyNode)1 SLReadArgumentNode (com.oracle.truffle.sl.nodes.local.SLReadArgumentNode)1 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)1