Search in sources :

Example 11 with LLVMAddress

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

the class LLVMLandingpadNode method executeGeneric.

@Override
public Object executeGeneric(VirtualFrame frame) {
    try {
        LLVMException exception = (LLVMException) frame.getObject(exceptionSlot);
        Object unwindHeader = exception.getUnwindHeader();
        LLVMStack.StackPointer stack = (LLVMStack.StackPointer) getStack.executeGeneric(frame);
        int clauseId = getEntryIdentifier(frame, stack, unwindHeader);
        if (clauseId == 0 && !cleanup) {
            throw exception;
        } else {
            LLVMAddress executeLLVMAddress = allocateLandingPadValue.execute(frame);
            LLVMAddress pair0 = executeLLVMAddress;
            getMemory().putAddress(pair0, unwindHeaderToNative.executeWithTarget(unwindHeader));
            getMemory().putI32(executeLLVMAddress.getVal() + LLVMExpressionNode.ADDRESS_SIZE_IN_BYTES, clauseId);
            return executeLLVMAddress;
        }
    } catch (FrameSlotTypeException e) {
        CompilerDirectives.transferToInterpreter();
        throw new IllegalStateException(e);
    }
}
Also used : FrameSlotTypeException(com.oracle.truffle.api.frame.FrameSlotTypeException) LLVMAddress(com.oracle.truffle.llvm.runtime.LLVMAddress) LLVMException(com.oracle.truffle.llvm.runtime.LLVMException) LLVMStack(com.oracle.truffle.llvm.runtime.memory.LLVMStack)

Example 12 with LLVMAddress

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

the class LLVMComplexDiv method executeGeneric.

@Override
public Object executeGeneric(VirtualFrame frame) {
    try {
        double a = aNode.executeDouble(frame);
        double b = bNode.executeDouble(frame);
        double c = cNode.executeDouble(frame);
        double d = dNode.executeDouble(frame);
        double denom = c * c + d * d;
        double zReal = (a * c + b * d) / denom;
        double zImag = (b * c - a * d) / denom;
        LLVMAddress allocatedMemory = alloc.executeLLVMAddress(frame);
        getMemory().putDouble(allocatedMemory, zReal);
        getMemory().putDouble(allocatedMemory.getVal() + LLVMExpressionNode.DOUBLE_SIZE_IN_BYTES, zImag);
        return allocatedMemory;
    } catch (UnexpectedResultException e) {
        CompilerDirectives.transferToInterpreter();
        throw new IllegalStateException(e);
    }
}
Also used : UnexpectedResultException(com.oracle.truffle.api.nodes.UnexpectedResultException) LLVMAddress(com.oracle.truffle.llvm.runtime.LLVMAddress)

Example 13 with LLVMAddress

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

the class NativeAllocateStringNode method alloc.

@Specialization
protected Object alloc(String s, @Cached("getLLVMMemory()") LLVMMemory memory) {
    LLVMAddress allocatedMemory = memory.allocateMemory(s.length() + 1);
    long currentPtr = allocatedMemory.getVal();
    for (byte b : s.getBytes()) {
        memory.putI8(currentPtr, b);
        currentPtr += 1;
    }
    memory.putI8(currentPtr, (byte) 0);
    return allocatedMemory;
}
Also used : LLVMAddress(com.oracle.truffle.llvm.runtime.LLVMAddress) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 14 with LLVMAddress

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

the class LLVMAddressArrayLiteralNode method writeAddress.

@Specialization
@ExplodeLoop
protected LLVMAddress writeAddress(VirtualFrame frame, LLVMAddress addr, @Cached("getLLVMMemory()") LLVMMemory memory) {
    long currentPtr = addr.getVal();
    for (int i = 0; i < values.length; i++) {
        LLVMAddress currentValue = values[i].execute(frame);
        memory.putAddress(currentPtr, currentValue);
        currentPtr += stride;
    }
    return addr;
}
Also used : LLVMAddress(com.oracle.truffle.llvm.runtime.LLVMAddress) Specialization(com.oracle.truffle.api.dsl.Specialization) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 15 with LLVMAddress

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

the class LLVMStructArrayLiteralNode method writeDouble.

@Specialization
@ExplodeLoop
protected LLVMAddress writeDouble(VirtualFrame frame, LLVMAddress addr) {
    long currentPtr = addr.getVal();
    for (int i = 0; i < values.length; i++) {
        try {
            LLVMAddress currentValue = values[i].executeLLVMAddress(frame);
            memMove.executeWithTarget(LLVMAddress.fromLong(currentPtr), currentValue, stride);
            currentPtr += stride;
        } catch (UnexpectedResultException e) {
            CompilerDirectives.transferToInterpreter();
            throw new IllegalStateException(e);
        }
    }
    return addr;
}
Also used : UnexpectedResultException(com.oracle.truffle.api.nodes.UnexpectedResultException) LLVMAddress(com.oracle.truffle.llvm.runtime.LLVMAddress) Specialization(com.oracle.truffle.api.dsl.Specialization) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Aggregations

LLVMAddress (com.oracle.truffle.llvm.runtime.LLVMAddress)18 Specialization (com.oracle.truffle.api.dsl.Specialization)6 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)3 UnexpectedResultException (com.oracle.truffle.api.nodes.UnexpectedResultException)3 LLVMTruffleObject (com.oracle.truffle.llvm.runtime.LLVMTruffleObject)3 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 FrameSlotTypeException (com.oracle.truffle.api.frame.FrameSlotTypeException)1 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)1 LLVMException (com.oracle.truffle.llvm.runtime.LLVMException)1 LLVMVarArgCompoundValue (com.oracle.truffle.llvm.runtime.LLVMVarArgCompoundValue)1 LLVM80BitFloat (com.oracle.truffle.llvm.runtime.floating.LLVM80BitFloat)1 LLVMGlobal (com.oracle.truffle.llvm.runtime.global.LLVMGlobal)1 LLVMStack (com.oracle.truffle.llvm.runtime.memory.LLVMStack)1 LLVMFloatVector (com.oracle.truffle.llvm.runtime.vector.LLVMFloatVector)1