Search in sources :

Example 6 with FunctionType

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

the class Function method setupScope.

public void setupScope() {
    scope.startLocalScope(function);
    final FunctionType functionType = function.getType();
    for (Type argType : functionType.getArgumentTypes()) {
        scope.addSymbol(function.createParameter(argType), argType);
    }
}
Also used : PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) Type(com.oracle.truffle.llvm.runtime.types.Type) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType)

Example 7 with FunctionType

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

the class Module method createFunction.

private void createFunction(long[] args) {
    final int recordOffset = useStrTab() ? STRTAB_RECORD_OFFSET : 0;
    Type type = types.get(args[FUNCTION_TYPE + recordOffset]);
    if (type instanceof PointerType) {
        type = ((PointerType) type).getPointeeType();
    }
    final FunctionType functionType = (FunctionType) type;
    final boolean isPrototype = args[FUNCTION_ISPROTOTYPE + recordOffset] != 0;
    final Linkage linkage = Linkage.decode(args[FUNCTION_LINKAGE + recordOffset]);
    final AttributesCodeEntry paramAttr = paramAttributes.getCodeEntry(args[FUNCTION_PARAMATTR + recordOffset]);
    if (isPrototype) {
        final FunctionDeclaration function = new FunctionDeclaration(functionType, linkage, paramAttr);
        module.addFunctionDeclaration(function);
        scope.addSymbol(function, function.getType());
        if (useStrTab()) {
            readNameFromStrTab(args, function);
        }
    } else {
        final FunctionDefinition function = new FunctionDefinition(functionType, linkage, paramAttr);
        module.addFunctionDefinition(function);
        scope.addSymbol(function, function.getType());
        if (useStrTab()) {
            readNameFromStrTab(args, function);
        }
        functionQueue.addLast(function);
    }
}
Also used : FunctionDeclaration(com.oracle.truffle.llvm.parser.model.functions.FunctionDeclaration) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) Type(com.oracle.truffle.llvm.runtime.types.Type) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) Linkage(com.oracle.truffle.llvm.parser.model.enums.Linkage) AttributesCodeEntry(com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionDefinition(com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition)

Example 8 with FunctionType

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

the class LLVMParserRuntime method resolveStructor.

private LLVMExpressionNode[] resolveStructor(GlobalValueSymbol globalVar, Comparator<Pair<Integer, ?>> priorityComparator) {
    if (!(globalVar.getValue() instanceof ArrayConstant)) {
        // array globals of length 0 may be initialized with scalar null
        return LLVMExpressionNode.NO_EXPRESSIONS;
    }
    final Object globalVariableDescriptor = scope.getGlobalVariable(globalVar.getName());
    final ArrayConstant arrayConstant = (ArrayConstant) globalVar.getValue();
    final int elemCount = arrayConstant.getElementCount();
    final StructureType elementType = (StructureType) arrayConstant.getType().getElementType();
    final int structSize = getContext().getByteSize(elementType);
    final FunctionType functionType = (FunctionType) ((PointerType) elementType.getElementType(1)).getPointeeType();
    final int indexedTypeLength = getContext().getByteAlignment(functionType);
    final ArrayList<Pair<Integer, LLVMExpressionNode>> structors = new ArrayList<>(elemCount);
    for (int i = 0; i < elemCount; i++) {
        final LLVMExpressionNode globalVarAddress = nodeFactory.createLiteral(this, globalVariableDescriptor, new PointerType(globalVar.getType()));
        final LLVMExpressionNode iNode = nodeFactory.createLiteral(this, i, PrimitiveType.I32);
        final LLVMExpressionNode structPointer = nodeFactory.createTypedElementPointer(this, globalVarAddress, iNode, structSize, elementType);
        final LLVMExpressionNode loadedStruct = nodeFactory.createLoad(this, elementType, structPointer);
        final LLVMExpressionNode oneLiteralNode = nodeFactory.createLiteral(this, 1, PrimitiveType.I32);
        final LLVMExpressionNode functionLoadTarget = nodeFactory.createTypedElementPointer(this, loadedStruct, oneLiteralNode, indexedTypeLength, functionType);
        final LLVMExpressionNode loadedFunction = nodeFactory.createLoad(this, functionType, functionLoadTarget);
        final LLVMExpressionNode[] argNodes = new LLVMExpressionNode[] { nodeFactory.createFrameRead(this, PointerType.VOID, rootFrame.findFrameSlot(LLVMStack.FRAME_ID)) };
        final LLVMExpressionNode functionCall = nodeFactory.createFunctionCall(this, loadedFunction, argNodes, functionType, null);
        final StructureConstant structorDefinition = (StructureConstant) arrayConstant.getElement(i);
        final SymbolImpl prioritySymbol = structorDefinition.getElement(0);
        final Integer priority = LLVMSymbolReadResolver.evaluateIntegerConstant(prioritySymbol);
        structors.add(new Pair<>(priority != null ? priority : LEAST_CONSTRUCTOR_PRIORITY, functionCall));
    }
    return structors.stream().sorted(priorityComparator).map(Pair::getSecond).toArray(LLVMExpressionNode[]::new);
}
Also used : FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) ArrayList(java.util.ArrayList) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) StructureConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.aggregate.StructureConstant) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) ArrayConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.aggregate.ArrayConstant) Pair(com.oracle.truffle.llvm.parser.util.Pair)

Example 9 with FunctionType

use of com.oracle.truffle.llvm.runtime.types.FunctionType 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)

Example 10 with FunctionType

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

the class Types method record.

@Override
public void record(long id, long[] args) {
    TypesRecord record = TypesRecord.decode(id);
    Type type;
    switch(record) {
        case NUMBER_OF_ENTRIES:
            table = new Type[(int) args[0]];
            return;
        case VOID:
            type = VoidType.INSTANCE;
            break;
        case FLOAT:
            type = PrimitiveType.FLOAT;
            break;
        case DOUBLE:
            type = PrimitiveType.DOUBLE;
            break;
        case LABEL:
            type = MetaType.LABEL;
            break;
        case OPAQUE:
            if (structName != null) {
                type = new OpaqueType(LLVMIdentifier.toLocalIdentifier(structName));
                structName = null;
                module.addGlobalType(type);
            } else {
                type = new OpaqueType();
            }
            break;
        case INTEGER:
            type = Type.getIntegerType((int) args[0]);
            break;
        case POINTER:
            {
                final PointerType pointerType = new PointerType(null);
                setType((int) args[0], pointerType::setPointeeType);
                type = pointerType;
                break;
            }
        case FUNCTION_OLD:
            {
                final FunctionType functionType = new FunctionType(null, toTypes(args, 3, args.length), args[0] != 0);
                setType((int) args[2], functionType::setReturnType);
                type = functionType;
                break;
            }
        case HALF:
            type = PrimitiveType.HALF;
            break;
        case ARRAY:
            {
                final ArrayType arrayType = new ArrayType(null, (int) args[0]);
                setType((int) args[1], arrayType::setElementType);
                type = arrayType;
                break;
            }
        case VECTOR:
            {
                final VectorType vectorType = new VectorType(null, (int) args[0]);
                setType((int) args[1], vectorType::setElementType);
                type = vectorType;
                break;
            }
        case X86_FP80:
            type = PrimitiveType.X86_FP80;
            break;
        case FP128:
            type = PrimitiveType.F128;
            break;
        case PPC_FP128:
            type = PrimitiveType.PPC_FP128;
            break;
        case METADATA:
            type = MetaType.METADATA;
            break;
        case X86_MMX:
            type = MetaType.X86MMX;
            break;
        case STRUCT_NAME:
            {
                structName = Records.toString(args);
                return;
            }
        case STRUCT_ANON:
        case STRUCT_NAMED:
            {
                final boolean isPacked = args[0] != 0;
                final Type[] members = toTypes(args, 1, args.length);
                if (structName != null) {
                    type = new StructureType(LLVMIdentifier.toTypeIdentifier(structName), isPacked, members);
                    structName = null;
                    module.addGlobalType(type);
                } else {
                    type = new StructureType(isPacked, members);
                }
                break;
            }
        case FUNCTION:
            {
                final FunctionType functionType = new FunctionType(null, toTypes(args, 2, args.length), args[0] != 0);
                setType((int) args[1], functionType::setReturnType);
                type = functionType;
                break;
            }
        case TOKEN:
            type = MetaType.TOKEN;
            break;
        default:
            type = MetaType.UNKNOWN;
            break;
    }
    if (table[size] != null) {
        ((UnresolvedType) table[size]).dependent.accept(type);
    }
    table[size++] = type;
}
Also used : ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) OpaqueType(com.oracle.truffle.llvm.runtime.types.OpaqueType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) LLVMInteropType(com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType) MetaType(com.oracle.truffle.llvm.runtime.types.MetaType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) OpaqueType(com.oracle.truffle.llvm.runtime.types.OpaqueType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) Type(com.oracle.truffle.llvm.runtime.types.Type) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) TypesRecord(com.oracle.truffle.llvm.parser.records.TypesRecord) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType)

Aggregations

FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)14 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)12 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)11 Type (com.oracle.truffle.llvm.runtime.types.Type)11 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)10 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)10 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)9 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)6 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)6 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)6 VectorType (com.oracle.truffle.llvm.runtime.types.VectorType)6 VoidType (com.oracle.truffle.llvm.runtime.types.VoidType)6 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)5 AttributesGroup (com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup)4 LLVMSourceLocation (com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation)4 AttributesCodeEntry (com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry)3 LLVMInteropType (com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType)3 MetaType (com.oracle.truffle.llvm.runtime.types.MetaType)3 ArrayList (java.util.ArrayList)3 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)2