Search in sources :

Example 16 with LLVMSourceType

use of com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType in project graal by oracle.

the class DITypeExtractor method visit.

@Override
public void visit(MDCompositeType mdType) {
    final long size = mdType.getSize();
    final long align = mdType.getAlign();
    final long offset = mdType.getOffset();
    final LLVMSourceLocation location = scopeBuilder.buildLocation(mdType);
    switch(mdType.getTag()) {
        case DW_TAG_VECTOR_TYPE:
        case DW_TAG_ARRAY_TYPE:
            {
                final boolean isVector = mdType.getTag() == MDType.DwarfTag.DW_TAG_VECTOR_TYPE;
                final LLVMSourceArrayLikeType type = new LLVMSourceArrayLikeType(size, align, offset, location);
                parsedTypes.put(mdType, type);
                LLVMSourceType baseType = resolve(mdType.getBaseType());
                final List<LLVMSourceType> members = new ArrayList<>(1);
                getElements(mdType.getMembers(), members, false);
                for (int i = members.size() - 1; i > 0; i--) {
                    final long length = extractLength(members.get(i));
                    final long tmpSize = length * baseType.getSize();
                    final LLVMSourceArrayLikeType tmp = new LLVMSourceArrayLikeType(tmpSize >= 0 ? tmpSize : 0, align, 0L, location);
                    setAggregateProperties(isVector, tmp, length, baseType);
                    baseType = tmp;
                }
                setAggregateProperties(isVector, type, extractLength(members.get(0)), baseType);
                break;
            }
        case DW_TAG_CLASS_TYPE:
            {
                String name = MDNameExtractor.getName(mdType.getName());
                final LLVMSourceClassLikeType type = new LLVMSourceClassLikeType(name, size, align, offset, location);
                parsedTypes.put(mdType, type);
                final List<LLVMSourceType> members = new ArrayList<>();
                getElements(mdType.getMembers(), members, false);
                for (final LLVMSourceType member : members) {
                    if (member instanceof LLVMSourceMemberType) {
                        type.addDynamicMember((LLVMSourceMemberType) member);
                    } else if (member instanceof LLVMSourceStaticMemberType) {
                        type.addStaticMember((LLVMSourceStaticMemberType) member);
                    }
                }
                MDBaseNode mdMembers = mdType.getMembers();
                if (mdMembers instanceof MDNode) {
                    final MDNode elemListNode = (MDNode) mdMembers;
                    for (MDBaseNode elemNode : elemListNode) {
                        if (elemNode instanceof MDSubprogram) {
                            MDSubprogram mdSubprogram = (MDSubprogram) elemNode;
                            final String methodName = ((MDString) mdSubprogram.getName()).getString();
                            if (mdSubprogram.getLinkageName() instanceof MDString) {
                                final String methodLinkageName = ((MDString) mdSubprogram.getLinkageName()).getString();
                                final LLVMSourceFunctionType llvmSourceFunctionType = (LLVMSourceFunctionType) parsedTypes.get(mdSubprogram);
                                final long virtualIndex = mdSubprogram.getVirtuality() > 0 ? mdSubprogram.getVirtualIndex() : -1L;
                                if (llvmSourceFunctionType != null) {
                                    type.addMethod(methodName, methodLinkageName, llvmSourceFunctionType, virtualIndex);
                                }
                            } else {
                            /*
                                 * mdSubprogram does not have an MDString as (linkage)name, or
                                 * function could not be found. In this case, just do not add the
                                 * given mdSubprogram as a class method.
                                 */
                            }
                        }
                    }
                }
                break;
            }
        case DW_TAG_UNION_TYPE:
        case DW_TAG_STRUCTURE_TYPE:
            {
                String name = MDNameExtractor.getName(mdType.getName());
                if (mdType.getTag() == MDType.DwarfTag.DW_TAG_STRUCTURE_TYPE) {
                    name = String.format("struct %s", name);
                } else if (mdType.getTag() == MDType.DwarfTag.DW_TAG_UNION_TYPE) {
                    name = String.format("union %s", name);
                }
                final LLVMSourceStructLikeType type = new LLVMSourceStructLikeType(name, size, align, offset, location);
                parsedTypes.put(mdType, type);
                final List<LLVMSourceType> members = new ArrayList<>();
                getElements(mdType.getMembers(), members, false);
                for (final LLVMSourceType member : members) {
                    if (member instanceof LLVMSourceMemberType) {
                        type.addDynamicMember((LLVMSourceMemberType) member);
                    } else if (member instanceof LLVMSourceStaticMemberType) {
                        type.addStaticMember((LLVMSourceStaticMemberType) member);
                    }
                }
                break;
            }
        case DW_TAG_ENUMERATION_TYPE:
            {
                final String name = String.format("enum %s", MDNameExtractor.getName(mdType.getName()));
                final LLVMSourceEnumLikeType type = new LLVMSourceEnumLikeType(() -> name, size, align, offset, location);
                parsedTypes.put(mdType, type);
                final List<LLVMSourceType> members = new ArrayList<>();
                getElements(mdType.getMembers(), members, false);
                for (final LLVMSourceType member : members) {
                    type.addValue((int) member.getOffset(), member.getName());
                }
                break;
            }
        default:
            {
                parsedTypes.put(mdType, LLVMSourceType.UNKNOWN);
            }
    }
}
Also used : LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation) MDBaseNode(com.oracle.truffle.llvm.parser.metadata.MDBaseNode) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType) MDString(com.oracle.truffle.llvm.parser.metadata.MDString) LLVMSourceMemberType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceMemberType) MDNode(com.oracle.truffle.llvm.parser.metadata.MDNode) LLVMSourceStructLikeType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceStructLikeType) MDString(com.oracle.truffle.llvm.parser.metadata.MDString) LLVMSourceClassLikeType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceClassLikeType) LLVMSourceEnumLikeType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceEnumLikeType) ArrayList(java.util.ArrayList) List(java.util.List) MetadataValueList(com.oracle.truffle.llvm.parser.metadata.MetadataValueList) LLVMSourceStaticMemberType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceStaticMemberType) LLVMSourceFunctionType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceFunctionType) MDSubprogram(com.oracle.truffle.llvm.parser.metadata.MDSubprogram) LLVMSourceArrayLikeType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceArrayLikeType)

Example 17 with LLVMSourceType

use of com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType in project graal by oracle.

the class DITypeExtractor method visit.

@Override
public void visit(MDGlobalVariableExpression mdGlobalExpression) {
    final LLVMSourceType type = resolve(mdGlobalExpression.getGlobalVariable());
    parsedTypes.put(mdGlobalExpression, type);
}
Also used : LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType)

Aggregations

LLVMSourceType (com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType)17 LLVMSourceLocation (com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation)5 LLVMSourceFunctionType (com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceFunctionType)5 MDBaseNode (com.oracle.truffle.llvm.parser.metadata.MDBaseNode)4 LLVMSourceStaticMemberType (com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceStaticMemberType)4 MDString (com.oracle.truffle.llvm.parser.metadata.MDString)3 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)3 LLVMSourcePointerType (com.oracle.truffle.llvm.runtime.debug.type.LLVMSourcePointerType)3 ArrayList (java.util.ArrayList)3 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)2 MDCompositeType (com.oracle.truffle.llvm.parser.metadata.MDCompositeType)2 MDGlobalVariable (com.oracle.truffle.llvm.parser.metadata.MDGlobalVariable)2 MDGlobalVariableExpression (com.oracle.truffle.llvm.parser.metadata.MDGlobalVariableExpression)2 MDLocalVariable (com.oracle.truffle.llvm.parser.metadata.MDLocalVariable)2 MDNode (com.oracle.truffle.llvm.parser.metadata.MDNode)2 MDSubprogram (com.oracle.truffle.llvm.parser.metadata.MDSubprogram)2 MDValue (com.oracle.truffle.llvm.parser.metadata.MDValue)2 MetadataValueList (com.oracle.truffle.llvm.parser.metadata.MetadataValueList)2 FunctionDefinition (com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition)2 FunctionParameter (com.oracle.truffle.llvm.parser.model.functions.FunctionParameter)2