Search in sources :

Example 1 with IsNative

use of com.oracle.truffle.llvm.runtime.global.LLVMGlobal.IsNative in project sulong by graalvm.

the class LLVMGlobalWriteNode method slowPrimitiveWrite.

public static void slowPrimitiveWrite(LLVMContext context, LLVMMemory memory, PrimitiveType primitiveType, LLVMGlobal global, Object value) {
    MaterializedFrame frame = context.getGlobalFrame();
    FrameSlot slot = global.getSlot();
    boolean isNative = frame.getValue(slot) instanceof Native;
    long address = isNative ? ((Native) frame.getValue(slot)).getPointer() : 0;
    switch(primitiveType.getPrimitiveKind()) {
        case I1:
            if (isNative) {
                memory.putI1(address, (boolean) value);
            } else {
                frame.setBoolean(slot, (boolean) value);
            }
            return;
        case I8:
            if (isNative) {
                memory.putI8(address, (byte) value);
            } else {
                frame.setByte(slot, (byte) value);
            }
            return;
        case I16:
            if (isNative) {
                memory.putI16(address, (short) value);
            } else {
                frame.setInt(slot, (short) value);
            }
            return;
        case I32:
            if (isNative) {
                memory.putI32(address, (int) value);
            } else {
                frame.setInt(slot, (int) value);
            }
            return;
        case I64:
            if (isNative) {
                memory.putI64(address, (long) value);
            } else {
                frame.setLong(slot, (long) value);
            }
            return;
        case FLOAT:
            if (isNative) {
                memory.putFloat(address, (float) value);
            } else {
                frame.setFloat(slot, (float) value);
            }
            return;
        case DOUBLE:
            if (isNative) {
                memory.putDouble(address, (double) value);
            } else {
                frame.setDouble(slot, (double) value);
            }
            return;
    }
    CompilerDirectives.transferToInterpreter();
    throw new IllegalStateException();
}
Also used : Native(com.oracle.truffle.llvm.runtime.global.LLVMGlobal.Native) IsNative(com.oracle.truffle.llvm.runtime.global.LLVMGlobal.IsNative) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) MaterializedFrame(com.oracle.truffle.api.frame.MaterializedFrame)

Aggregations

FrameSlot (com.oracle.truffle.api.frame.FrameSlot)1 MaterializedFrame (com.oracle.truffle.api.frame.MaterializedFrame)1 IsNative (com.oracle.truffle.llvm.runtime.global.LLVMGlobal.IsNative)1 Native (com.oracle.truffle.llvm.runtime.global.LLVMGlobal.Native)1