Search in sources :

Example 1 with LLVMContext

use of com.oracle.truffle.llvm.runtime.LLVMContext in project sulong by graalvm.

the class LLVMDispatchNode method getSignature.

private String getSignature() {
    if (signature == null) {
        CompilerDirectives.transferToInterpreterAndInvalidate();
        try {
            LLVMContext context = getContextReference().get();
            NFIContextExtension nfiContextExtension = context.getContextExtension(NFIContextExtension.class);
            this.signature = nfiContextExtension.getNativeSignature(type, LLVMCallNode.USER_ARGUMENT_OFFSET);
        } catch (UnsupportedNativeTypeException ex) {
            throw new AssertionError(ex);
        }
    }
    return signature;
}
Also used : LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) UnsupportedNativeTypeException(com.oracle.truffle.llvm.runtime.NFIContextExtension.UnsupportedNativeTypeException) NFIContextExtension(com.oracle.truffle.llvm.runtime.NFIContextExtension)

Example 2 with LLVMContext

use of com.oracle.truffle.llvm.runtime.LLVMContext in project sulong by graalvm.

the class LLVMGlobalRootNode method execute.

@Override
@ExplodeLoop
public Object execute(VirtualFrame frame) {
    try (StackPointer basePointer = getContext().getThreadingStack().getStack().newFrame()) {
        try {
            TruffleObject appPath = (TruffleObject) ctxRef.get().getEnv().asGuestValue(applicationPath.getBytes());
            LLVMTruffleObject applicationPathObj = new LLVMTruffleObject(LLVMTypedForeignObject.createUnknown(appPath));
            Object[] realArgs = new Object[] { basePointer, mainFunctionType, applicationPathObj };
            Object result = startFunction.call(realArgs);
            getContext().awaitThreadTermination();
            return result;
        } catch (LLVMExitException e) {
            LLVMContext context = getContext();
            // if any variant of exit or abort was called, we know that all the necessary
            // cleanup was already done
            context.setCleanupNecessary(false);
            context.awaitThreadTermination();
            return e.getReturnCode();
        } catch (SulongRuntimeException e) {
            CompilerDirectives.transferToInterpreter();
            throw e;
        } catch (GuestLanguageRuntimeException e) {
            CompilerDirectives.transferToInterpreter();
            return e.handleExit();
        } finally {
            // if not done already, we want at least call a shutdown command
            getContext().shutdownThreads();
        }
    }
}
Also used : LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) SulongRuntimeException(com.oracle.truffle.llvm.runtime.SulongRuntimeException) GuestLanguageRuntimeException(com.oracle.truffle.llvm.runtime.GuestLanguageRuntimeException) LLVMExitException(com.oracle.truffle.llvm.runtime.LLVMExitException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) LLVMTypedForeignObject(com.oracle.truffle.llvm.runtime.interop.LLVMTypedForeignObject) StackPointer(com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 3 with LLVMContext

use of com.oracle.truffle.llvm.runtime.LLVMContext in project sulong by graalvm.

the class LLVMNativeDispatchNode method identityFunction.

@TruffleBoundary
protected TruffleObject identityFunction() {
    LLVMContext context = getContextReference().get();
    NFIContextExtension nfiContextExtension = context.getContextExtension(NFIContextExtension.class);
    String signature;
    try {
        signature = nfiContextExtension.getNativeSignature(type, LLVMCallNode.USER_ARGUMENT_OFFSET);
    } catch (UnsupportedNativeTypeException e) {
        throw new IllegalStateException(e);
    }
    return nfiContextExtension.getNativeFunction(context, "@identity", String.format("(POINTER):%s", signature));
}
Also used : LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) UnsupportedNativeTypeException(com.oracle.truffle.llvm.runtime.NFIContextExtension.UnsupportedNativeTypeException) NFIContextExtension(com.oracle.truffle.llvm.runtime.NFIContextExtension) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 4 with LLVMContext

use of com.oracle.truffle.llvm.runtime.LLVMContext in project sulong by graalvm.

the class LLVMPolyglotExport method doExport.

@Specialization
protected Object doExport(Object name, Object value, @Cached("getContextReference()") ContextReference<LLVMContext> ctxRef) {
    String symbolName = readString.executeWithTarget(name);
    LLVMContext ctx = ctxRef.get();
    Object escaped = escape.executeWithTarget(value);
    try {
        ForeignAccess.sendWrite(write, (TruffleObject) ctx.getEnv().getPolyglotBindings(), symbolName, escaped);
    } catch (InteropException ex) {
        throw ex.raise();
    }
    return null;
}
Also used : LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) InteropException(com.oracle.truffle.api.interop.InteropException) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 5 with LLVMContext

use of com.oracle.truffle.llvm.runtime.LLVMContext in project sulong by graalvm.

the class LLVMRunDestructorFunctions method runDestructorFunctions.

@TruffleBoundary
private void runDestructorFunctions() {
    // is only executed once per context so it will be executed in the interpreter only
    LLVMContext context = getContextReference().get();
    RootCallTarget[] targets = context.getDestructorFunctions().toArray(new RootCallTarget[0]);
    for (RootCallTarget target : targets) {
        try (StackPointer stackPointer = context.getThreadingStack().getStack().newFrame()) {
            callNode.call(target, new Object[] { stackPointer });
        }
    }
}
Also used : LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) StackPointer(com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer) RootCallTarget(com.oracle.truffle.api.RootCallTarget) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

LLVMContext (com.oracle.truffle.llvm.runtime.LLVMContext)11 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)4 NFIContextExtension (com.oracle.truffle.llvm.runtime.NFIContextExtension)4 StackPointer (com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer)3 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)2 RootCallTarget (com.oracle.truffle.api.RootCallTarget)2 Specialization (com.oracle.truffle.api.dsl.Specialization)2 InteropException (com.oracle.truffle.api.interop.InteropException)2 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)2 Source (com.oracle.truffle.api.source.Source)2 LLVMTruffleObject (com.oracle.truffle.llvm.runtime.LLVMTruffleObject)2 UnsupportedNativeTypeException (com.oracle.truffle.llvm.runtime.NFIContextExtension.UnsupportedNativeTypeException)2 LLVMStack (com.oracle.truffle.llvm.runtime.memory.LLVMStack)2 Truffle (com.oracle.truffle.api.Truffle)1 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)1 ArityException (com.oracle.truffle.api.interop.ArityException)1 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)1 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)1 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)1 RootNode (com.oracle.truffle.api.nodes.RootNode)1