Search in sources :

Example 1 with PrimitiveType

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

the class LLVMGlobalRootNode method getMainFunctionType.

/**
 * Identify the signature of the main method so that crt0.c:_start can invoke the main method
 * with the correct signature. This is necessary because languages like Rust use non-standard C
 * main functions.
 */
private static int getMainFunctionType(LLVMFunctionDescriptor mainFunctionDescriptor) {
    Type returnType = mainFunctionDescriptor.getType().getReturnType();
    Type[] argumentTypes = mainFunctionDescriptor.getType().getArgumentTypes();
    if (argumentTypes.length > 0 && argumentTypes[0] instanceof PrimitiveType) {
        if (((PrimitiveType) argumentTypes[0]).getPrimitiveKind() == PrimitiveKind.I64) {
            return 1;
        }
    }
    if (returnType instanceof VoidType) {
        return 2;
    } else if (returnType instanceof PrimitiveType) {
        switch(((PrimitiveType) returnType).getPrimitiveKind()) {
            case I8:
                return 3;
            case I16:
                return 4;
            case I32:
                return 0;
            case I64:
                return 5;
        }
    }
    throw new AssertionError("Unexpected main method signature");
}
Also used : VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) Type(com.oracle.truffle.llvm.runtime.types.Type) VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType)

Example 2 with PrimitiveType

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

the class AsmFactory method getOperandStore.

private LLVMExpressionNode getOperandStore(Type type, AsmOperand operand, LLVMExpressionNode from) {
    if (operand instanceof AsmRegisterOperand) {
        AsmRegisterOperand op = (AsmRegisterOperand) operand;
        FrameSlot frame = getRegisterSlot(op.getBaseRegister());
        LLVMExpressionNode register = LLVMAMD64ReadRegisterNodeGen.create(frame);
        int shift = op.getShift();
        LLVMExpressionNode out = null;
        assert (type instanceof PointerType && op.getType() == PrimitiveType.I64) || (op.getType() instanceof PointerType && type == PrimitiveType.I64) || (type == op.getType());
        switch(((PrimitiveType) op.getType()).getPrimitiveKind()) {
            case I8:
                out = LLVMI8ToR64NodeGen.create(shift, register, from);
                break;
            case I16:
                out = LLVMI16ToR64NodeGen.create(register, from);
                break;
            case I32:
                out = LLVMI32ToR64NodeGen.create(from);
                break;
            case I64:
                out = from;
                break;
            default:
                throw new AsmParseException("unsupported operand type: " + op.getType());
        }
        return LLVMWriteI64NodeGen.create(out, frame, null);
    } else if (operand instanceof AsmArgumentOperand) {
        AsmArgumentOperand op = (AsmArgumentOperand) operand;
        Argument info = argInfo.get(op.getIndex());
        if (info.isMemory()) {
            LLVMExpressionNode address = info.getAddress();
            switch(((PrimitiveType) type).getPrimitiveKind()) {
                case I8:
                    return LLVMI8StoreNodeGen.create(address, from);
                case I16:
                    return LLVMI16StoreNodeGen.create(address, from);
                case I32:
                    return LLVMI32StoreNodeGen.create(address, from);
                case I64:
                    return LLVMI64StoreNodeGen.create(address, from);
                default:
                    throw new AsmParseException("unsupported operand type: " + type);
            }
        } else if (info.isRegister()) {
            FrameSlot frame = getRegisterSlot(info.getRegister());
            LLVMExpressionNode register = LLVMAMD64ReadRegisterNodeGen.create(frame);
            LLVMExpressionNode out = null;
            if (type instanceof PointerType || info.getType() instanceof PointerType) {
                return LLVMAMD64WriteAddressRegisterNodeGen.create(sourceLocation, from, frame);
            }
            switch(((PrimitiveType) type).getPrimitiveKind()) {
                case I8:
                    out = LLVMI8ToR64NodeGen.create(0, register, from);
                    break;
                case I16:
                    out = LLVMI16ToR64NodeGen.create(register, from);
                    break;
                case I32:
                    out = LLVMI32ToR64NodeGen.create(from);
                    break;
                case I64:
                    out = from;
                    break;
                default:
                    throw new AsmParseException("unsupported operand type: " + type);
            }
            return LLVMWriteI64NodeGen.create(out, frame, null);
        } else {
            throw new AssertionError("this should not happen; " + info);
        }
    } else if (operand instanceof AsmMemoryOperand) {
        LLVMExpressionNode address = getOperandAddress(operand);
        switch(((PrimitiveType) type).getPrimitiveKind()) {
            case I8:
                return LLVMI8StoreNodeGen.create(null, address, from);
            case I16:
                return LLVMI16StoreNodeGen.create(null, address, from);
            case I32:
                return LLVMI32StoreNodeGen.create(null, address, from);
            case I64:
                return LLVMI64StoreNodeGen.create(null, address, from);
            default:
                throw new AsmParseException("unsupported operand type: " + type);
        }
    }
    throw new AsmParseException("unsupported operand type: " + operand);
}
Also used : FrameSlot(com.oracle.truffle.api.frame.FrameSlot) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType)

Example 3 with PrimitiveType

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

the class AsmFactory method getOperandLoad.

private LLVMExpressionNode getOperandLoad(Type typeHint, AsmOperand operand) {
    Type type = typeHint == null ? operand.getType() : typeHint;
    if (operand instanceof AsmRegisterOperand) {
        AsmRegisterOperand op = (AsmRegisterOperand) operand;
        FrameSlot frame = getRegisterSlot(op.getBaseRegister());
        LLVMExpressionNode register = LLVMAMD64ReadRegisterNodeGen.create(frame);
        int shift = op.getShift();
        assert type instanceof PointerType || type == op.getType();
        if (type instanceof PointerType) {
            switch(((PrimitiveType) op.getType()).getPrimitiveKind()) {
                case I8:
                    return LLVMToI8NoZeroExtNodeGen.create(register);
                case I16:
                    return LLVMToI16NoZeroExtNodeGen.create(register);
                case I32:
                    return LLVMToI32NoZeroExtNodeGen.create(register);
                case I64:
                    return LLVMAMD64ReadAddressNodeGen.create(frame);
                default:
                    throw new AsmParseException("unsupported operand type: " + type);
            }
        }
        switch(((PrimitiveType) op.getType()).getPrimitiveKind()) {
            case I8:
                return LLVMAMD64I64ToI8NodeGen.create(shift, register);
            case I16:
                return LLVMToI16NoZeroExtNodeGen.create(register);
            case I32:
                return LLVMToI32NoZeroExtNodeGen.create(register);
            case I64:
                return register;
            default:
                throw new AsmParseException("unsupported operand type: " + type);
        }
    } else if (operand instanceof AsmImmediateOperand) {
        AsmImmediateOperand op = (AsmImmediateOperand) operand;
        if (op.isLabel()) {
            throw new AsmParseException("labels not supported");
        } else {
            switch(((PrimitiveType) type).getPrimitiveKind()) {
                case I8:
                    return LLVMAMD64I8NodeGen.create((byte) op.getValue());
                case I16:
                    return LLVMAMD64I16NodeGen.create((short) op.getValue());
                case I32:
                    return LLVMAMD64I32NodeGen.create((int) op.getValue());
                case I64:
                    return LLVMAMD64I64NodeGen.create(op.getValue());
                default:
                    throw new AsmParseException("unsupported operand type: " + type);
            }
        }
    } else if (operand instanceof AsmArgumentOperand) {
        AsmArgumentOperand op = (AsmArgumentOperand) operand;
        Argument info = argInfo.get(op.getIndex());
        FrameSlot frame = getArgumentSlot(op.getIndex(), type);
        if (info.isMemory()) {
            if (type instanceof PointerType) {
                return LLVMAddressDirectLoadNodeGen.create(LLVMAddressReadNodeGen.create(frame));
            }
            switch(((PrimitiveType) type).getPrimitiveKind()) {
                case I8:
                    return LLVMI8LoadNodeGen.create(LLVMAddressReadNodeGen.create(frame));
                case I16:
                    return LLVMI16LoadNodeGen.create(LLVMAddressReadNodeGen.create(frame));
                case I32:
                    return LLVMI32LoadNodeGen.create(LLVMAddressReadNodeGen.create(frame));
                case I64:
                    return LLVMI64LoadNodeGen.create(LLVMAddressReadNodeGen.create(frame));
                default:
                    throw new AsmParseException("unsupported operand type: " + type);
            }
        } else if (info.isRegister()) {
            frame = getRegisterSlot(info.getRegister());
            if (type instanceof PointerType) {
                return LLVMAMD64ReadAddressNodeGen.create(frame);
            }
            LLVMExpressionNode register = LLVMAMD64ReadRegisterNodeGen.create(frame);
            switch(((PrimitiveType) type).getPrimitiveKind()) {
                case I8:
                    return LLVMToI8NoZeroExtNodeGen.create(register);
                case I16:
                    return LLVMToI16NoZeroExtNodeGen.create(register);
                case I32:
                    return LLVMToI32NoZeroExtNodeGen.create(register);
                case I64:
                    return LLVMToI64NoZeroExtNodeGen.create(register);
                default:
                    throw new AsmParseException("unsupported operand type: " + type);
            }
        } else {
            // constraint "0"-"9"
            if (type instanceof PointerType) {
                return LLVMAMD64ReadAddressNodeGen.create(frame);
            }
            LLVMExpressionNode register = LLVMAMD64ReadRegisterNodeGen.create(frame);
            switch(((PrimitiveType) type).getPrimitiveKind()) {
                case I8:
                    return LLVMToI8NoZeroExtNodeGen.create(register);
                case I16:
                    return LLVMToI16NoZeroExtNodeGen.create(register);
                case I32:
                    return LLVMToI32NoZeroExtNodeGen.create(register);
                case I64:
                    return LLVMToI64NoZeroExtNodeGen.create(register);
                default:
                    throw new AsmParseException("unsupported operand type: " + type);
            }
        }
    } else if (operand instanceof AsmMemoryOperand) {
        LLVMExpressionNode address = getOperandAddress(operand);
        LLVMExpressionNode addr = LLVMToAddressNodeGen.create(address);
        if (type instanceof PrimitiveType) {
            switch(((PrimitiveType) type).getPrimitiveKind()) {
                case I8:
                    return LLVMI8LoadNodeGen.create(addr);
                case I16:
                    return LLVMI16LoadNodeGen.create(addr);
                case I32:
                    return LLVMI32LoadNodeGen.create(addr);
                case I64:
                    return LLVMI64LoadNodeGen.create(addr);
                default:
                    throw new AsmParseException("unsupported operand type: " + type);
            }
        } else if (type instanceof PointerType) {
            return LLVMAddressDirectLoadNodeGen.create(addr);
        } else {
            throw new AsmParseException("unsupported operand type: " + type);
        }
    }
    throw new AsmParseException("unsupported operand: " + operand);
}
Also used : PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) Type(com.oracle.truffle.llvm.runtime.types.Type) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType)

Example 4 with PrimitiveType

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

the class LLVMContext method getGlobalFrameSlot.

public FrameSlot getGlobalFrameSlot(Object symbol, Type type) {
    FrameSlotKind kind;
    if (type instanceof PrimitiveType) {
        switch(((PrimitiveType) type).getPrimitiveKind()) {
            case DOUBLE:
                kind = FrameSlotKind.Double;
                break;
            case FLOAT:
                kind = FrameSlotKind.Float;
                break;
            case HALF:
            case I16:
            case I32:
                kind = FrameSlotKind.Int;
                break;
            case I1:
                kind = FrameSlotKind.Boolean;
                break;
            case I64:
                kind = FrameSlotKind.Long;
                break;
            case I8:
                kind = FrameSlotKind.Byte;
                break;
            default:
                kind = FrameSlotKind.Object;
                break;
        }
    } else {
        kind = FrameSlotKind.Object;
    }
    FrameSlot frameSlot = globalFrameDescriptor.findOrAddFrameSlot(symbol, type, kind);
    return frameSlot;
}
Also used : FrameSlotKind(com.oracle.truffle.api.frame.FrameSlotKind) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType)

Example 5 with PrimitiveType

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

the class BasicNodeFactory method createVectorLiteralNode.

@Override
public LLVMExpressionNode createVectorLiteralNode(LLVMParserRuntime runtime, List<LLVMExpressionNode> listValues, Type type) {
    LLVMExpressionNode[] vals = listValues.toArray(new LLVMExpressionNode[listValues.size()]);
    Type llvmType = ((VectorType) type).getElementType();
    if (llvmType instanceof PrimitiveType) {
        switch(((PrimitiveType) llvmType).getPrimitiveKind()) {
            case I1:
                return LLVMVectorI1LiteralNodeGen.create(vals);
            case I8:
                return LLVMVectorI8LiteralNodeGen.create(vals);
            case I16:
                return LLVMVectorI16LiteralNodeGen.create(vals);
            case I32:
                return LLVMVectorI32LiteralNodeGen.create(vals);
            case I64:
                return LLVMVectorI64LiteralNodeGen.create(vals);
            case FLOAT:
                return LLVMVectorFloatLiteralNodeGen.create(vals);
            case DOUBLE:
                return LLVMVectorDoubleLiteralNodeGen.create(vals);
            default:
                throw new AssertionError();
        }
    } else if (llvmType instanceof PointerType) {
        if (((PointerType) llvmType).getPointeeType() instanceof FunctionType) {
            return LLVMVectorFunctionLiteralNodeGen.create(vals);
        } else {
            return LLVMVectorAddressLiteralNodeGen.create(vals);
        }
    } else {
        throw new AssertionError(llvmType + " not yet supported");
    }
}
Also used : LLVMSourcePointerType(com.oracle.truffle.llvm.runtime.debug.LLVMSourcePointerType) VariableBitWidthType(com.oracle.truffle.llvm.runtime.types.VariableBitWidthType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) LLVMConversionType(com.oracle.truffle.llvm.parser.instructions.LLVMConversionType) MetaType(com.oracle.truffle.llvm.runtime.types.MetaType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) LLVMInteropType(com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType) LLVMArithmeticInstructionType(com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType) Type(com.oracle.truffle.llvm.runtime.types.Type) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) LLVMSourcePointerType(com.oracle.truffle.llvm.runtime.debug.LLVMSourcePointerType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType)

Aggregations

PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)16 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)12 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)11 Type (com.oracle.truffle.llvm.runtime.types.Type)8 VoidType (com.oracle.truffle.llvm.runtime.types.VoidType)8 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)7 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)7 PrimitiveKind (com.oracle.truffle.llvm.runtime.types.PrimitiveType.PrimitiveKind)5 LLVMUnsupportedInlineAssemblerNode (com.oracle.truffle.llvm.nodes.others.LLVMUnsupportedInlineAssemblerNode)3 VariableBitWidthType (com.oracle.truffle.llvm.runtime.types.VariableBitWidthType)3 VectorType (com.oracle.truffle.llvm.runtime.types.VectorType)3 FrameSlotKind (com.oracle.truffle.api.frame.FrameSlotKind)2 LLVMAMD64Target (com.oracle.truffle.llvm.nodes.asm.support.LLVMAMD64Target)2 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)2 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)2 LLVMSourcePointerType (com.oracle.truffle.llvm.runtime.debug.LLVMSourcePointerType)2 LLVMSourceType (com.oracle.truffle.llvm.runtime.debug.LLVMSourceType)2 LLVMInteropType (com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType)2 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)2 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)2