Search in sources :

Example 1 with LLVMTruffleObject

use of com.oracle.truffle.llvm.runtime.LLVMTruffleObject 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 2 with LLVMTruffleObject

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

the class LLVMToFunctionNode method doTruffleObject.

@Specialization
protected Object doTruffleObject(LLVMTruffleObject from, @Cached("create()") LLVMAsForeignNode asForeign) {
    TruffleObject foreign = asForeign.execute(from);
    if (ForeignAccess.sendIsNull(isNull, foreign)) {
        return LLVMAddress.fromLong(0);
    } else if (ForeignAccess.sendIsExecutable(isExecutable, foreign)) {
        return from;
    }
    CompilerDirectives.transferToInterpreter();
    throw new IllegalStateException("Not a function");
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 3 with LLVMTruffleObject

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

the class LLVMTruffleHandleToManaged method doIntrinsic.

@Specialization
protected LLVMTruffleObject doIntrinsic(Object rawHandle, @Cached("getContextReference()") ContextReference<LLVMContext> context, @Cached("createToNativeWithTarget()") LLVMToNativeNode forceAddressNode) {
    LLVMAddress handle = forceAddressNode.executeWithTarget(rawHandle);
    TruffleObject object = context.get().getManagedObjectForHandle(handle);
    return new LLVMTruffleObject(object);
}
Also used : LLVMAddress(com.oracle.truffle.llvm.runtime.LLVMAddress) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 4 with LLVMTruffleObject

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

the class LLVMTruffleReadNBytes method doIntrinsic.

@Specialization
protected Object doIntrinsic(LLVMAddress value, int n, @Cached("getLLVMMemory()") LLVMMemory memory, @Cached("getContextReference()") ContextReference<LLVMContext> ctxRef) {
    int count = n < 0 ? 0 : n;
    byte[] bytes = new byte[count];
    long ptr = value.getVal();
    for (int i = 0; i < count; i++) {
        bytes[i] = memory.getI8(ptr);
        ptr += Byte.BYTES;
    }
    TruffleObject ret = (TruffleObject) ctxRef.get().getEnv().asGuestValue(bytes);
    return new LLVMTruffleObject(LLVMTypedForeignObject.createUnknown(ret));
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 5 with LLVMTruffleObject

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

the class LLVMTruffleReadNString method interop.

@Specialization
protected Object interop(LLVMTruffleObject objectWithOffset, int n, @Cached("createForeignReadNode()") Node foreignRead, @Cached("createToByteNode()") ForeignToLLVM toLLVM) {
    long offset = objectWithOffset.getOffset();
    TruffleObject object = objectWithOffset.getObject();
    char[] chars = new char[n];
    for (int i = 0; i < n; i++) {
        Object rawValue;
        try {
            rawValue = ForeignAccess.sendRead(foreignRead, object, offset + i);
        } catch (UnknownIdentifierException | UnsupportedMessageException e) {
            CompilerDirectives.transferToInterpreter();
            throw new IllegalStateException(e);
        }
        byte byteValue = (byte) toLLVM.executeWithTarget(rawValue);
        chars[i] = (char) Byte.toUnsignedInt(byteValue);
    }
    return new String(chars);
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) Specialization(com.oracle.truffle.api.dsl.Specialization)

Aggregations

LLVMTruffleObject (com.oracle.truffle.llvm.runtime.LLVMTruffleObject)35 Specialization (com.oracle.truffle.api.dsl.Specialization)33 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)22 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)10 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)5 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)2 UnexpectedResultException (com.oracle.truffle.api.nodes.UnexpectedResultException)2 LLVMAddress (com.oracle.truffle.llvm.runtime.LLVMAddress)2 LLVM80BitFloat (com.oracle.truffle.llvm.runtime.floating.LLVM80BitFloat)2 LLVMTypedForeignObject (com.oracle.truffle.llvm.runtime.interop.LLVMTypedForeignObject)2 GuestLanguageRuntimeException (com.oracle.truffle.llvm.runtime.GuestLanguageRuntimeException)1 LLVMContext (com.oracle.truffle.llvm.runtime.LLVMContext)1 LLVMExitException (com.oracle.truffle.llvm.runtime.LLVMExitException)1 LLVMFunctionDescriptor (com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor)1 LLVMVarArgCompoundValue (com.oracle.truffle.llvm.runtime.LLVMVarArgCompoundValue)1 SulongRuntimeException (com.oracle.truffle.llvm.runtime.SulongRuntimeException)1 LLVMGlobal (com.oracle.truffle.llvm.runtime.global.LLVMGlobal)1 StackPointer (com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer)1 LLVMFloatVector (com.oracle.truffle.llvm.runtime.vector.LLVMFloatVector)1