Search in sources :

Example 21 with LLVMTruffleObject

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

the class LLVMTruffleReadBytes method doIntrinsic.

@Specialization
protected Object doIntrinsic(LLVMAddress value, @Cached("getLLVMMemory()") LLVMMemory memory, @Cached("getContextReference()") ContextReference<LLVMContext> ctxRef) {
    byte c;
    long ptr = value.getVal();
    int count = 0;
    while ((c = memory.getI8(ptr)) != 0) {
        count++;
        ptr += Byte.BYTES;
    }
    byte[] bytes = new byte[count];
    count = 0;
    ptr = value.getVal();
    while ((c = memory.getI8(ptr)) != 0) {
        bytes[count++] = c;
        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 22 with LLVMTruffleObject

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

the class LLVMTruffleWriteManagedToGlobal method doIntrinsic.

@Specialization
protected LLVMTruffleObject doIntrinsic(LLVMGlobal address, LLVMTruffleObject value, @Cached("getContextReference()") ContextReference<LLVMContext> context) {
    LLVMTruffleObject typedValue = (LLVMTruffleObject) attachType.execute(value, address.getInteropType());
    context.get().getGlobalFrame().setObject(address.getSlot(), typedValue);
    return typedValue;
}
Also used : LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 23 with LLVMTruffleObject

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

the class LLVMAddressArrayLiteralNode method foreignWriteRef.

// TODO: work around a DSL bug (GR-6493): remove cached int a and int b
@SuppressWarnings("unused")
@Specialization(guards = "addr.isManaged()")
@ExplodeLoop
protected LLVMTruffleObject foreignWriteRef(VirtualFrame frame, LLVMTruffleObject addr, @Cached("0") int a, @Cached("0") int b, @Cached("createForeignWrites()") LLVMForeignWriteNode[] foreignWrites) {
    LLVMTruffleObject currentPtr = addr;
    for (int i = 0; i < values.length; i++) {
        Object currentValue = values[i].execute(frame);
        foreignWrites[i].execute(currentPtr, currentValue);
        currentPtr = currentPtr.increment(stride);
    }
    return addr;
}
Also used : LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) Specialization(com.oracle.truffle.api.dsl.Specialization) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 24 with LLVMTruffleObject

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

the class LLVMFloatArrayLiteralNode method foreignWriteFloat.

@Specialization(guards = "addr.isManaged()")
@ExplodeLoop
protected LLVMTruffleObject foreignWriteFloat(VirtualFrame frame, LLVMTruffleObject addr, @Cached("createForeignWrite()") LLVMForeignWriteNode foreignWrite) {
    LLVMTruffleObject currentPtr = addr;
    for (int i = 0; i < values.length; i++) {
        float currentValue = LLVMTypesGen.asFloat(values[i].executeGeneric(frame));
        foreignWrite.execute(currentPtr, currentValue);
        currentPtr = currentPtr.increment(stride);
    }
    return addr;
}
Also used : LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) Specialization(com.oracle.truffle.api.dsl.Specialization) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 25 with LLVMTruffleObject

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

the class LLVMI1ArrayLiteralNode method foreignWriteI1.

@Specialization(guards = "addr.isManaged()")
@ExplodeLoop
protected LLVMTruffleObject foreignWriteI1(VirtualFrame frame, LLVMTruffleObject addr, @Cached("createForeignWrite()") LLVMForeignWriteNode foreignWrite) {
    LLVMTruffleObject currentPtr = addr;
    for (int i = 0; i < values.length; i++) {
        boolean currentValue = LLVMTypesGen.asBoolean(values[i].executeGeneric(frame));
        foreignWrite.execute(currentPtr, currentValue);
        currentPtr = currentPtr.increment(stride);
    }
    return addr;
}
Also used : LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) Specialization(com.oracle.truffle.api.dsl.Specialization) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

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