Search in sources :

Example 1 with LLVMStack

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

the class LLVMTruffleExecute method doExecute.

@ExplodeLoop
private Object doExecute(VirtualFrame frame, TruffleObject value, LLVMContext context, LLVMGetStackNode getStack) {
    Object[] evaluatedArgs = new Object[args.length];
    for (int i = 0; i < args.length; i++) {
        evaluatedArgs[i] = prepareValuesForEscape[i].executeWithTarget(args[i].executeGeneric(frame));
    }
    try {
        LLVMStack stack = getStack.executeWithTarget(getThreadingStack(context), Thread.currentThread());
        Object rawValue;
        try (StackPointer save = stack.newFrame()) {
            rawValue = ForeignAccess.sendExecute(foreignExecute, value, evaluatedArgs);
        }
        return toLLVM.executeWithTarget(rawValue);
    } catch (UnsupportedMessageException | UnsupportedTypeException | ArityException e) {
        CompilerDirectives.transferToInterpreter();
        throw new IllegalStateException(e);
    }
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) StackPointer(com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer) ArityException(com.oracle.truffle.api.interop.ArityException) LLVMStack(com.oracle.truffle.llvm.runtime.memory.LLVMStack) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 2 with LLVMStack

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

the class LLVMForeignCallNode method callIndirect.

@Specialization(replaces = "callDirectCached")
protected Object callIndirect(LLVMFunctionDescriptor function, Object[] arguments, @Cached("create()") IndirectCallNode callNode, @Cached("createSlowPackArguments()") SlowPackForeignArgumentsNode slowPack, @Cached("create()") LLVMGetStackNode getStack, @Cached("getLLVMMemory()") LLVMMemory memory) {
    assert !(function.getType().getReturnType() instanceof StructureType);
    LLVMStack stack = getStack.executeWithTarget(function.getContext().getThreadingStack(), Thread.currentThread());
    Object result;
    try (StackPointer stackPointer = stack.newFrame()) {
        result = callNode.call(getCallTarget(function), slowPack.pack(function, memory, arguments, stackPointer));
    }
    return prepareValueForEscape.executeWithTarget(result);
}
Also used : StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) StackPointer(com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer) LLVMStack(com.oracle.truffle.llvm.runtime.memory.LLVMStack) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 3 with LLVMStack

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

the class LLVMTruffleInvoke method doInvoke.

@ExplodeLoop
private Object doInvoke(VirtualFrame frame, TruffleObject value, String id, ContextReference<LLVMContext> contextReference, LLVMGetStackNode getStack) {
    Object[] evaluatedArgs = new Object[args.length];
    for (int i = 0; i < args.length; i++) {
        evaluatedArgs[i] = prepareValuesForEscape[i].executeWithTarget(args[i].executeGeneric(frame));
    }
    try {
        LLVMContext context = contextReference.get();
        LLVMStack stack = getStack.executeWithTarget(getThreadingStack(context), Thread.currentThread());
        Object rawValue;
        try (StackPointer save = stack.newFrame()) {
            rawValue = ForeignAccess.sendInvoke(foreignInvoke, value, id, evaluatedArgs);
        }
        return toLLVM.executeWithTarget(rawValue);
    } catch (UnknownIdentifierException | UnsupportedMessageException | UnsupportedTypeException | ArityException e) {
        CompilerDirectives.transferToInterpreter();
        throw new IllegalStateException(e);
    }
}
Also used : LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) StackPointer(com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer) ArityException(com.oracle.truffle.api.interop.ArityException) LLVMStack(com.oracle.truffle.llvm.runtime.memory.LLVMStack) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 4 with LLVMStack

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

the class LLVMForeignCallNode method directCall.

private Object directCall(Object[] arguments, DirectCallNode callNode, PackForeignArgumentsNode packNode, LLVMGetStackNode getStack, LLVMContext context) {
    Object result;
    LLVMStack stack = getStack.executeWithTarget(getThreadingStack(context), Thread.currentThread());
    try (StackPointer stackPointer = stack.newFrame()) {
        result = callNode.call(packNode.pack(arguments, stackPointer));
    }
    return prepareValueForEscape.executeWithTarget(result);
}
Also used : StackPointer(com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer) LLVMStack(com.oracle.truffle.llvm.runtime.memory.LLVMStack)

Aggregations

LLVMStack (com.oracle.truffle.llvm.runtime.memory.LLVMStack)4 StackPointer (com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer)4 ArityException (com.oracle.truffle.api.interop.ArityException)2 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)2 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)2 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)2 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)2 LLVMTruffleObject (com.oracle.truffle.llvm.runtime.LLVMTruffleObject)2 Specialization (com.oracle.truffle.api.dsl.Specialization)1 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)1 LLVMContext (com.oracle.truffle.llvm.runtime.LLVMContext)1 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)1