Search in sources :

Example 1 with NativeContextExtension

use of com.oracle.truffle.llvm.runtime.NativeContextExtension in project graal by oracle.

the class ParserDriver method createNativeTruffleFile.

@TruffleBoundary
private TruffleFile createNativeTruffleFile(String libName, String libPath) {
    NativeContextExtension nativeContextExtension = context.getContextExtensionOrNull(NativeContextExtension.class);
    if (nativeContextExtension != null) {
        TruffleFile file = DefaultLibraryLocator.INSTANCE.locate(context, libName, "<native library>");
        if (file == null) {
            // Unable to locate the library -> will go to native
            LibraryLocator.traceDelegateNative(context, libPath);
            file = context.getEnv().getInternalTruffleFile(libPath);
        }
        return file;
    }
    return null;
}
Also used : TruffleFile(com.oracle.truffle.api.TruffleFile) NativeContextExtension(com.oracle.truffle.llvm.runtime.NativeContextExtension) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 2 with NativeContextExtension

use of com.oracle.truffle.llvm.runtime.NativeContextExtension in project graal by oracle.

the class LoadNativeNode method parseAndInitialiseNativeLib.

@TruffleBoundary
private Object parseAndInitialiseNativeLib(LLVMContext context) {
    NativeContextExtension nativeContextExtension = context.getContextExtensionOrNull(NativeContextExtension.class);
    if (nativeContextExtension != null) {
        CallTarget callTarget = nativeContextExtension.parseNativeLibrary(path, context);
        Object nfiLibrary = callTarget.call();
        nativeContextExtension.addLibraryHandles(nfiLibrary);
        return nfiLibrary;
    }
    return null;
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) NativeContextExtension(com.oracle.truffle.llvm.runtime.NativeContextExtension) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 3 with NativeContextExtension

use of com.oracle.truffle.llvm.runtime.NativeContextExtension in project graal by oracle.

the class InitializeExternalNode method execute.

/*
     * (PLi): Need to be careful of native functions/globals that are not in the nfi context (i.e.
     * __xstat). Ideally they will be added to the symbol table as unresolved/undefined
     * functions/globals.
     */
public void execute(LLVMContext context, LLVMScopeChain localScope, LLVMDLOpen.RTLDFlags rtldFlags) {
    LLVMScopeChain globalScope = context.getGlobalScopeChain();
    LLVMIntrinsicProvider intrinsicProvider = getLanguage().getCapability(LLVMIntrinsicProvider.class);
    NativeContextExtension nativeContextExtension = getNativeContextExtension(context);
    for (int i = 0; i < globals.length; i++) {
        LLVMGlobal global = globals[i];
        LLVMPointer pointer = allocExternalSymbol.execute(localScope, globalScope, intrinsicProvider, nativeContextExtension, context, rtldFlags, global);
        if (pointer == null) {
            continue;
        }
        context.initializeSymbol(globals[i], pointer);
    }
    for (int i = 0; i < functions.length; i++) {
        LLVMFunction function = functions[i];
        LLVMPointer pointer = allocExternalSymbol.execute(localScope, globalScope, intrinsicProvider, nativeContextExtension, context, rtldFlags, function);
        if (pointer == null) {
            continue;
        }
        context.initializeSymbol(functions[i], pointer);
    }
}
Also used : LLVMFunction(com.oracle.truffle.llvm.runtime.LLVMFunction) LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) LLVMScopeChain(com.oracle.truffle.llvm.runtime.LLVMScopeChain) LLVMGlobal(com.oracle.truffle.llvm.runtime.global.LLVMGlobal) LLVMIntrinsicProvider(com.oracle.truffle.llvm.runtime.LLVMIntrinsicProvider) NativeContextExtension(com.oracle.truffle.llvm.runtime.NativeContextExtension)

Example 4 with NativeContextExtension

use of com.oracle.truffle.llvm.runtime.NativeContextExtension in project graal by oracle.

the class LoadDependencyNode method createNativeTruffleFile.

@TruffleBoundary
private TruffleFile createNativeTruffleFile(String libName, String libPath) {
    LLVMContext context = getContext();
    NativeContextExtension nativeContextExtension = context.getContextExtensionOrNull(NativeContextExtension.class);
    if (nativeContextExtension != null) {
        TruffleFile file = DefaultLibraryLocator.INSTANCE.locate(context, libName, "<native library>");
        if (file == null) {
            // Unable to locate the library -> will go to native
            LibraryLocator.traceDelegateNative(context, libPath);
            file = context.getEnv().getInternalTruffleFile(libPath);
        }
        return file;
    }
    return null;
}
Also used : LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) TruffleFile(com.oracle.truffle.api.TruffleFile) NativeContextExtension(com.oracle.truffle.llvm.runtime.NativeContextExtension) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

NativeContextExtension (com.oracle.truffle.llvm.runtime.NativeContextExtension)4 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)3 TruffleFile (com.oracle.truffle.api.TruffleFile)2 CallTarget (com.oracle.truffle.api.CallTarget)1 LLVMContext (com.oracle.truffle.llvm.runtime.LLVMContext)1 LLVMFunction (com.oracle.truffle.llvm.runtime.LLVMFunction)1 LLVMIntrinsicProvider (com.oracle.truffle.llvm.runtime.LLVMIntrinsicProvider)1 LLVMScopeChain (com.oracle.truffle.llvm.runtime.LLVMScopeChain)1 LLVMGlobal (com.oracle.truffle.llvm.runtime.global.LLVMGlobal)1 LLVMPointer (com.oracle.truffle.llvm.runtime.pointer.LLVMPointer)1