Search in sources :

Example 6 with LLVMAddress

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

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

the class LLVMComplexMul 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 ac = a * c;
        double bd = b * d;
        double ad = a * d;
        double bc = b * c;
        double zReal = ac - bd;
        double zImag = ad + bc;
        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 8 with LLVMAddress

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

the class LLVMMemory method allocateCString.

public LLVMAddress allocateCString(String string) {
    LLVMAddress baseAddress = allocateMemory(string.length() + 1);
    long currentAddress = baseAddress.getVal();
    for (int i = 0; i < string.length(); i++) {
        byte c = (byte) string.charAt(i);
        putI8(currentAddress, c);
        currentAddress++;
    }
    putI8(currentAddress, (byte) 0);
    return baseAddress;
}
Also used : LLVMAddress(com.oracle.truffle.llvm.runtime.LLVMAddress)

Example 9 with LLVMAddress

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

the class StructLiteralNode method doLLVMAddress.

@ExplodeLoop
@Specialization
protected LLVMAddress doLLVMAddress(VirtualFrame frame, LLVMAddress address) {
    for (int i = 0; i < offsets.length; i++) {
        LLVMAddress currentAddr = address.increment(offsets[i]);
        Object value = values[i] == null ? null : values[i].executeGeneric(frame);
        elementWriteNodes[i].executeWithTarget(currentAddr, value);
    }
    return address;
}
Also used : LLVMAddress(com.oracle.truffle.llvm.runtime.LLVMAddress) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) Specialization(com.oracle.truffle.api.dsl.Specialization) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 10 with LLVMAddress

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

the class LLVMSignal method setSignalHandler.

@TruffleBoundary
private static LLVMAddress setSignalHandler(LLVMContext context, Signal signal, LLVMAddress function) {
    int signalId = signal.getNumber();
    LLVMAddress returnFunction = context.getSigDfl();
    try {
        LLVMSignalHandler newSignalHandler = new LLVMSignalHandler(context, signal, function);
        synchronized (registeredSignals) {
            if (registeredSignals.containsKey(signalId)) {
                LLVMSignalHandler currentFunction = registeredSignals.get(signalId);
                if (currentFunction.isRunning()) {
                    returnFunction = currentFunction.getFunction();
                    /*
                         * the new signal handler already manages this signal, so we can safely
                         * deactivate the old one.
                         */
                    currentFunction.setStopped();
                }
            }
            registeredSignals.put(signalId, newSignalHandler);
        }
    } catch (IllegalArgumentException e) {
        System.err.println("could not register signal with id " + signalId + " (" + signal + ")");
        return context.getSigErr();
    }
    return returnFunction;
}
Also used : LLVMAddress(com.oracle.truffle.llvm.runtime.LLVMAddress) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

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