Search in sources :

Example 16 with Specialization

use of com.oracle.truffle.api.dsl.Specialization in project sulong by graalvm.

the class LLVMNativeDispatchNode method doGeneric.

@Specialization
protected Object doGeneric(LLVMAddress function, Object[] arguments, @Cached("getContextReference()") ContextReference<LLVMContext> context, @Cached("identityFunction()") TruffleObject identity, @Cached("createToNativeNodes()") LLVMNativeConvertNode[] toNative, @Cached("createFromNativeNode()") LLVMNativeConvertNode fromNative, @Cached("nativeCallStatisticsEnabled(context)") boolean statistics) {
    Object[] nativeArgs = prepareNativeArguments(arguments, toNative);
    Object returnValue;
    try (StackPointer save = ((StackPointer) arguments[0]).newFrame()) {
        returnValue = LLVMNativeCallUtils.callNativeFunction(statistics, context, nativeCallNode, dispatchIdentity(identity, function.getVal()), nativeArgs, null);
    }
    return fromNative.executeConvert(returnValue);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) StackPointer(com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 17 with Specialization

use of com.oracle.truffle.api.dsl.Specialization in project sulong by graalvm.

the class LLVMX86_64VAStart method vaStart.

@Specialization
protected Object vaStart(VirtualFrame frame, Object targetAddress) {
    final Object[] arguments = getArgumentsArray(frame);
    final int vaLength = arguments.length - numberOfExplicitArguments;
    Object regSaveArea = stackAllocationNode.executeWithTarget(frame, X86_64BitVarArgs.FP_LIMIT);
    int overflowArgAreaSize = computeOverflowArgAreaSize(arguments);
    Object overflowArgArea = stackAllocationNode.executeWithTarget(frame, overflowArgAreaSize);
    int gpOffset = calculateUsedGpArea(arguments);
    int fpOffset = X86_64BitVarArgs.GP_LIMIT + calculateUsedFpArea(arguments);
    initializeVaList(targetAddress, gpOffset, fpOffset, overflowArgArea, regSaveArea);
    // reconstruct register_save_area and overflow_arg_area according to AMD64 ABI
    if (vaLength > 0) {
        int overflowOffset = 0;
        for (int i = 0; i < vaLength; i++) {
            final Object object = arguments[numberOfExplicitArguments + i];
            final VarArgArea area = getVarArgArea(object);
            if (area == VarArgArea.GP_AREA && gpOffset < X86_64BitVarArgs.GP_LIMIT) {
                storeArgument(regSaveArea, gpOffset, memmove, pointerArithmeticRegSaveArea, i64RegSaveAreaStore, i32RegSaveAreaStore, fp80bitRegSaveAreaStore, object);
                gpOffset += X86_64BitVarArgs.GP_STEP;
            } else if (area == VarArgArea.FP_AREA && fpOffset < X86_64BitVarArgs.FP_LIMIT) {
                storeArgument(regSaveArea, fpOffset, memmove, pointerArithmeticRegSaveArea, i64RegSaveAreaStore, i32RegSaveAreaStore, fp80bitRegSaveAreaStore, object);
                fpOffset += X86_64BitVarArgs.FP_STEP;
            } else {
                assert overflowArgAreaSize >= overflowOffset;
                overflowOffset += storeArgument(overflowArgArea, overflowOffset, memmove, pointerArithmeticOverflowArea, i64OverflowArgAreaStore, i32OverflowArgAreaStore, fp80bitOverflowArgAreaStore, object);
            }
        }
    }
    return null;
}
Also used : LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 18 with Specialization

use of com.oracle.truffle.api.dsl.Specialization in project sulong by graalvm.

the class LLVMPanic method doOp.

@Specialization
protected Object doOp(LLVMGlobal panicLocVar, @Cached("createToNativeWithTarget()") LLVMToNativeNode globalAccess, @Cached("createPanicLocation()") PanicLocType panicLoc, @Cached("getLLVMMemory()") LLVMMemory memory) {
    LLVMAddress addr = globalAccess.executeWithTarget(panicLocVar);
    CompilerDirectives.transferToInterpreter();
    throw panicLoc.read(memory, addr.getVal());
}
Also used : LLVMAddress(com.oracle.truffle.llvm.runtime.LLVMAddress) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 19 with Specialization

use of com.oracle.truffle.api.dsl.Specialization 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 20 with Specialization

use of com.oracle.truffle.api.dsl.Specialization 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)

Aggregations

Specialization (com.oracle.truffle.api.dsl.Specialization)73 LLVMTruffleObject (com.oracle.truffle.llvm.runtime.LLVMTruffleObject)35 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)27 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)16 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)6 UnexpectedResultException (com.oracle.truffle.api.nodes.UnexpectedResultException)6 LLVMAddress (com.oracle.truffle.llvm.runtime.LLVMAddress)6 StackPointer (com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer)6 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)5 FileValue (cz.cuni.mff.d3s.trupple.language.runtime.customvalues.FileValue)3 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)3 Frame (com.oracle.truffle.api.frame.Frame)2 InteropException (com.oracle.truffle.api.interop.InteropException)2 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)2 LLVMFunctionDescriptor (com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor)2 LLVM80BitFloat (com.oracle.truffle.llvm.runtime.floating.LLVM80BitFloat)2 SLRootNode (com.oracle.truffle.sl.nodes.SLRootNode)2 GenericArrayType (java.lang.reflect.GenericArrayType)2 Type (java.lang.reflect.Type)2 Assumption (com.oracle.truffle.api.Assumption)1