Search in sources :

Example 21 with RootCallTarget

use of com.oracle.truffle.api.RootCallTarget in project graal by oracle.

the class SuspendedEvent method isEvalRootStackFrame.

static boolean isEvalRootStackFrame(DebuggerSession session, FrameInstance instance) {
    CallTarget target = instance.getCallTarget();
    RootNode root = null;
    if (target instanceof RootCallTarget) {
        root = ((RootCallTarget) target).getRootNode();
    }
    if (root != null && session.getDebugger().getEnv().isEngineRoot(root)) {
        return true;
    }
    return false;
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) RootCallTarget(com.oracle.truffle.api.RootCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) RootCallTarget(com.oracle.truffle.api.RootCallTarget)

Example 22 with RootCallTarget

use of com.oracle.truffle.api.RootCallTarget in project graal by oracle.

the class LanguageSPITest method testParseOtherLanguage.

@Test
public void testParseOtherLanguage() {
    Context context = Context.newBuilder().build();
    eval(context, new Function<Env, Object>() {

        public Object apply(Env t) {
            assertCorrectTarget(t.parse(Source.newBuilder("").language(ContextAPITestLanguage.ID).name("").build()));
            assertCorrectTarget(t.parse(Source.newBuilder("").mimeType(ContextAPITestLanguage.MIME).name("").build()));
            // this is here for compatibility because mime types and language ids were allowed
            // in between.
            assertCorrectTarget(t.parse(Source.newBuilder("").mimeType(ContextAPITestLanguage.ID).name("").build()));
            return null;
        }

        private void assertCorrectTarget(CallTarget target) {
            Assert.assertEquals(ContextAPITestLanguage.ID, ((RootCallTarget) target).getRootNode().getLanguageInfo().getId());
        }
    });
    context.close();
}
Also used : Context(org.graalvm.polyglot.Context) LanguageContext(com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext) TruffleContext(com.oracle.truffle.api.TruffleContext) CallTarget(com.oracle.truffle.api.CallTarget) RootCallTarget(com.oracle.truffle.api.RootCallTarget) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Env(com.oracle.truffle.api.TruffleLanguage.Env) RootCallTarget(com.oracle.truffle.api.RootCallTarget) Test(org.junit.Test)

Example 23 with RootCallTarget

use of com.oracle.truffle.api.RootCallTarget in project sulong by graalvm.

the class LLVMDispatchNode method getIntrinsificationCallNode.

/*
     * Function is not defined in the user program (not available as LLVM IR). This would normally
     * result in a native call BUT there is an intrinsification available
     */
protected DirectCallNode getIntrinsificationCallNode(Intrinsic intrinsic) {
    RootCallTarget target = intrinsic.forceSplit() ? intrinsic.generateCallTarget(type) : intrinsic.cachedCallTarget(type);
    DirectCallNode directCallNode = DirectCallNode.create(target);
    if (intrinsic.forceInline()) {
        directCallNode.forceInlining();
    }
    return directCallNode;
}
Also used : RootCallTarget(com.oracle.truffle.api.RootCallTarget) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode)

Example 24 with RootCallTarget

use of com.oracle.truffle.api.RootCallTarget in project sulong by graalvm.

the class LLVMParserRuntime method parse.

public static LLVMParserResult parse(Source source, ExternalLibrary library, BitcodeParserResult parserResult, LLVMLanguage language, LLVMContext context, NodeFactory nodeFactory) {
    ModelModule model = parserResult.getModel();
    TargetDataLayout layout = model.getTargetDataLayout();
    assert layout != null;
    LLVMModelVisitor module = new LLVMModelVisitor();
    model.accept(module);
    DataLayoutConverter.DataSpecConverterImpl targetDataLayout = DataLayoutConverter.getConverter(layout.getDataLayout());
    context.setDataLayoutConverter(targetDataLayout);
    LLVMParserRuntime runtime = new LLVMParserRuntime(source, library, language, context, nodeFactory, module.getAliases());
    runtime.registerFunctions(model);
    LLVMSymbolReadResolver symbolResolver = new LLVMSymbolReadResolver(runtime, runtime.getGlobalFrameDescriptor());
    LLVMExpressionNode[] globals = runtime.createGlobalVariableInitializationNodes(symbolResolver, module.getGlobals());
    RootNode globalVarInits = nodeFactory.createStaticInitsRootNode(runtime, globals);
    RootCallTarget globalVarInitsTarget = Truffle.getRuntime().createCallTarget(globalVarInits);
    LLVMExpressionNode[] deallocs = runtime.getDeallocations();
    RootNode globalVarDeallocs = nodeFactory.createStaticInitsRootNode(runtime, deallocs);
    RootCallTarget globalVarDeallocsTarget = Truffle.getRuntime().createCallTarget(globalVarDeallocs);
    RootCallTarget constructorFunctions = runtime.getConstructors(module.getGlobals());
    RootCallTarget destructorFunctions = runtime.getDestructors(module.getGlobals());
    if (context.getEnv().getOptions().get(SulongEngineOption.ENABLE_LVI)) {
        final LLVMSourceContext sourceContext = context.getSourceContext();
        model.getSourceGlobals().forEach((symbol, irValue) -> {
            final LLVMExpressionNode node = symbolResolver.resolve(irValue);
            final LLVMDebugValue value = nodeFactory.createDebugStaticValue(node);
            sourceContext.registerStatic(symbol, value);
        });
        model.getSourceStaticMembers().forEach(((type, symbol) -> {
            final LLVMExpressionNode node = symbolResolver.resolve(symbol);
            final LLVMDebugValue value = nodeFactory.createDebugStaticValue(node);
            type.setValue(value);
        }));
    }
    RootCallTarget mainFunctionCallTarget = null;
    if (runtime.getScope().functionExists("@main")) {
        LLVMFunctionDescriptor mainDescriptor = runtime.getScope().getFunctionDescriptor("@main");
        LLVMFunctionDescriptor startDescriptor = runtime.getScope().getFunctionDescriptor("@_start");
        RootCallTarget startCallTarget = startDescriptor.getLLVMIRFunction();
        String applicationPath = source.getPath() == null ? "" : source.getPath().toString();
        RootNode globalFunction = nodeFactory.createGlobalRootNode(runtime, startCallTarget, mainDescriptor, applicationPath);
        RootCallTarget globalFunctionRoot = Truffle.getRuntime().createCallTarget(globalFunction);
        RootNode globalRootNode = nodeFactory.createGlobalRootNodeWrapping(runtime, globalFunctionRoot, startDescriptor.getType().getReturnType());
        mainFunctionCallTarget = Truffle.getRuntime().createCallTarget(globalRootNode);
    }
    return new LLVMParserResult(runtime.getScope(), mainFunctionCallTarget, globalVarInitsTarget, globalVarDeallocsTarget, constructorFunctions, destructorFunctions);
}
Also used : GlobalVariable(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalVariable) DataLayoutConverter(com.oracle.truffle.llvm.runtime.datalayout.DataLayoutConverter) GlobalConstant(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalConstant) GlobalValueSymbol(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol) RootCallTarget(com.oracle.truffle.api.RootCallTarget) FunctionDefinition(com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition) Pair(com.oracle.truffle.llvm.parser.util.Pair) Linkage(com.oracle.truffle.llvm.parser.model.enums.Linkage) LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) SulongEngineOption(com.oracle.truffle.llvm.runtime.options.SulongEngineOption) LLVMSymbolReadResolver(com.oracle.truffle.llvm.parser.nodes.LLVMSymbolReadResolver) ArrayList(java.util.ArrayList) FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) LLVMFunctionDescriptor(com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor) Type(com.oracle.truffle.llvm.runtime.types.Type) ModelModule(com.oracle.truffle.llvm.parser.model.ModelModule) LLVMSourceContext(com.oracle.truffle.llvm.runtime.debug.LLVMSourceContext) LLVMLanguage(com.oracle.truffle.llvm.runtime.LLVMLanguage) Map(java.util.Map) RootNode(com.oracle.truffle.api.nodes.RootNode) ArrayConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.aggregate.ArrayConstant) LLVMSourceSymbol(com.oracle.truffle.llvm.runtime.debug.LLVMSourceSymbol) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) ExternalLibrary(com.oracle.truffle.llvm.runtime.LLVMContext.ExternalLibrary) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) LLVMStack(com.oracle.truffle.llvm.runtime.memory.LLVMStack) SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) TargetDataLayout(com.oracle.truffle.llvm.parser.model.target.TargetDataLayout) LLVMDebugValue(com.oracle.truffle.llvm.runtime.debug.LLVMDebugValue) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) LLVMScope(com.oracle.truffle.llvm.runtime.LLVMScope) List(java.util.List) Source(com.oracle.truffle.api.source.Source) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) StructureConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.aggregate.StructureConstant) GlobalAlias(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalAlias) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) Truffle(com.oracle.truffle.api.Truffle) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) Comparator(java.util.Comparator) RootNode(com.oracle.truffle.api.nodes.RootNode) TargetDataLayout(com.oracle.truffle.llvm.parser.model.target.TargetDataLayout) DataLayoutConverter(com.oracle.truffle.llvm.runtime.datalayout.DataLayoutConverter) LLVMSymbolReadResolver(com.oracle.truffle.llvm.parser.nodes.LLVMSymbolReadResolver) ModelModule(com.oracle.truffle.llvm.parser.model.ModelModule) LLVMFunctionDescriptor(com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) LLVMDebugValue(com.oracle.truffle.llvm.runtime.debug.LLVMDebugValue) RootCallTarget(com.oracle.truffle.api.RootCallTarget) LLVMSourceContext(com.oracle.truffle.llvm.runtime.debug.LLVMSourceContext)

Example 25 with RootCallTarget

use of com.oracle.truffle.api.RootCallTarget in project sulong by graalvm.

the class LLVMParserRuntime method getStructor.

private RootCallTarget getStructor(String name, List<GlobalValueSymbol> globals, Comparator<Pair<Integer, ?>> priorityComparator) {
    for (GlobalValueSymbol globalValueSymbol : globals) {
        if (globalValueSymbol.getName().equals(name)) {
            final LLVMExpressionNode[] targets = resolveStructor(globalValueSymbol, priorityComparator);
            final RootCallTarget constructorFunctionsRootCallTarget = Truffle.getRuntime().createCallTarget(nodeFactory.createStaticInitsRootNode(this, targets));
            return constructorFunctionsRootCallTarget;
        }
    }
    return null;
}
Also used : LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) GlobalValueSymbol(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol) RootCallTarget(com.oracle.truffle.api.RootCallTarget)

Aggregations

RootCallTarget (com.oracle.truffle.api.RootCallTarget)26 RootNode (com.oracle.truffle.api.nodes.RootNode)8 CallTarget (com.oracle.truffle.api.CallTarget)4 DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)4 Source (com.oracle.truffle.api.source.Source)4 Test (org.junit.Test)4 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)3 StackPointer (com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer)3 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)2 SourceSection (com.oracle.truffle.api.source.SourceSection)2 GlobalValueSymbol (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol)2 LLVMContext (com.oracle.truffle.llvm.runtime.LLVMContext)2 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)2 OptimizedDirectCallNode (org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode)2 RootTestNode (org.graalvm.compiler.truffle.test.nodes.RootTestNode)2 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 Truffle (com.oracle.truffle.api.Truffle)1 TruffleContext (com.oracle.truffle.api.TruffleContext)1 Env (com.oracle.truffle.api.TruffleLanguage.Env)1 ControlFlowException (com.oracle.truffle.api.nodes.ControlFlowException)1