Search in sources :

Example 1 with LLVMThreadingStack

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

the class LLVMContext method initialize.

@SuppressWarnings("unchecked")
void initialize(ContextExtension[] contextExtens) {
    contextState = State.INITIALIZED;
    assert this.threadingStack == null;
    this.contextExtensions = contextExtens;
    if (traceIREnabled()) {
        if (!env.getOptions().get(SulongEngineOption.LL_DEBUG)) {
            traceIRLog("Trace IR logging is enabled, but \'--llvm.llDebug=true\' is not set");
        }
        LLVMTracerInstrument.attach(env);
    }
    this.threadingStack = new LLVMThreadingStack(Thread.currentThread(), parseStackSize(env.getOptions().get(SulongEngineOption.STACK_SIZE)));
    String languageHome = language.getLLVMLanguageHome();
    if (languageHome != null) {
        PlatformCapability<?> sysContextExt = language.getCapability(PlatformCapability.class);
        internalLibraryPath = Paths.get(languageHome).resolve(sysContextExt.getSulongLibrariesPath());
        internalLibraryPathFile = env.getInternalTruffleFile(internalLibraryPath.toUri());
        // add internal library location also to the external library lookup path
        addLibraryPath(internalLibraryPath.toString());
    }
    for (ContextExtension ext : contextExtensions) {
        ext.initialize(this);
    }
    try {
        /*
             * The default internal libraries are parsed in reverse dependency order, but not
             * initialised. (For C: libsulong / For C++: libsulong, libsulong++) The truffle cache
             * and the llvm language cache will return the call target of future parsing of these
             * libraries.
             */
        String[] sulongLibraryNames = language.getCapability(PlatformCapability.class).getSulongDefaultLibraries();
        for (int i = sulongLibraryNames.length - 1; i >= 0; i--) {
            TruffleFile file = InternalLibraryLocator.INSTANCE.locateLibrary(this, sulongLibraryNames[i], "<default bitcode library>");
            Source librarySource = Source.newBuilder("llvm", file).internal(isInternalLibraryFile(file)).build();
            sourceCache.put(IDGenerater.INVALID_ID, librarySource);
            env.parseInternal(librarySource);
        }
        setLibsulongAuxFunction(SULONG_INIT_CONTEXT);
        setLibsulongAuxFunction(SULONG_DISPOSE_CONTEXT);
        setLibsulongAuxFunction(START_METHOD_NAME);
        CallTarget builtinsLibrary = env.parseInternal(Source.newBuilder("llvm", env.getInternalTruffleFile(internalLibraryPath.resolve(language.getCapability(PlatformCapability.class).getBuiltinsLibrary()).toUri())).internal(true).build());
        builtinsLibrary.call();
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
Also used : LLVMThreadingStack(com.oracle.truffle.llvm.runtime.memory.LLVMThreadingStack) CallTarget(com.oracle.truffle.api.CallTarget) RootCallTarget(com.oracle.truffle.api.RootCallTarget) TruffleFile(com.oracle.truffle.api.TruffleFile) IOException(java.io.IOException) TruffleSafepoint(com.oracle.truffle.api.TruffleSafepoint) Source(com.oracle.truffle.api.source.Source)

Example 2 with LLVMThreadingStack

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

the class LLVMForeignCallNode method execute.

@Override
public Object execute(VirtualFrame frame) {
    Object result;
    LLVMThreadingStack threadingStack = LLVMContext.get(this).getThreadingStack();
    LLVMStack stack = getStack.executeWithTarget(threadingStack, Thread.currentThread());
    try {
        result = doCall(frame, stack);
    } catch (ArityException ex) {
        throw silenceException(RuntimeException.class, ex);
    } catch (TypeOverflowException ex) {
        throw silenceException(RuntimeException.class, ex);
    }
    return prepareValueForEscape.executeWithType(result, returnBaseType);
}
Also used : LLVMThreadingStack(com.oracle.truffle.llvm.runtime.memory.LLVMThreadingStack) TypeOverflowException(com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException) ArityException(com.oracle.truffle.api.interop.ArityException) LLVMStack(com.oracle.truffle.llvm.runtime.memory.LLVMStack)

Aggregations

LLVMThreadingStack (com.oracle.truffle.llvm.runtime.memory.LLVMThreadingStack)2 CallTarget (com.oracle.truffle.api.CallTarget)1 RootCallTarget (com.oracle.truffle.api.RootCallTarget)1 TruffleFile (com.oracle.truffle.api.TruffleFile)1 TruffleSafepoint (com.oracle.truffle.api.TruffleSafepoint)1 ArityException (com.oracle.truffle.api.interop.ArityException)1 Source (com.oracle.truffle.api.source.Source)1 LLVMStack (com.oracle.truffle.llvm.runtime.memory.LLVMStack)1 TypeOverflowException (com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException)1 IOException (java.io.IOException)1