Search in sources :

Example 1 with LLVMSourceStaticMemberType

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

the class DebugInfoModuleProcessor method processModule.

public static void processModule(ModelModule irModel, Source bitcodeSource, MetadataValueList metadata) {
    MDUpgrade.perform(metadata);
    final DebugInfoCache cache = new DebugInfoCache(metadata, irModel.getSourceStaticMembers());
    final Map<LLVMSourceSymbol, SymbolImpl> globals = irModel.getSourceGlobals();
    final Map<LLVMSourceStaticMemberType, SymbolImpl> staticMembers = irModel.getSourceStaticMembers();
    irModel.accept(new SymbolProcessor(cache, bitcodeSource, globals, staticMembers));
    final MDBaseNode cuNode = metadata.getNamedNode(MDNamedNode.COMPILEUNIT_NAME);
    final MetadataProcessor mdParser = new MetadataProcessor(cache, globals, staticMembers);
    if (cuNode != null) {
        cuNode.accept(mdParser);
    }
    irModel.setFunctionProcessor(new DebugInfoFunctionProcessor(cache));
}
Also used : SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) LLVMSourceSymbol(com.oracle.truffle.llvm.runtime.debug.LLVMSourceSymbol) MDBaseNode(com.oracle.truffle.llvm.parser.metadata.MDBaseNode) LLVMSourceStaticMemberType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceStaticMemberType)

Example 2 with LLVMSourceStaticMemberType

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

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, align, 0L, location);
                    setAggregateProperties(isVector, tmp, length, baseType);
                    baseType = tmp;
                }
                setAggregateProperties(isVector, type, extractLength(members.get(0)), baseType);
                break;
            }
        case DW_TAG_CLASS_TYPE:
        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 : LLVMSourceStructLikeType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceStructLikeType) LLVMSourceEnumLikeType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceEnumLikeType) LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation) ArrayList(java.util.ArrayList) List(java.util.List) MetadataValueList(com.oracle.truffle.llvm.parser.metadata.MetadataValueList) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceType) MDString(com.oracle.truffle.llvm.parser.metadata.MDString) LLVMSourceMemberType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceMemberType) LLVMSourceStaticMemberType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceStaticMemberType) LLVMSourceArrayLikeType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceArrayLikeType)

Example 3 with LLVMSourceStaticMemberType

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

the class DITypeExtractor method visit.

@Override
public void visit(MDDerivedType 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_MEMBER:
            {
                if (Flags.ARTIFICIAL.isAllFlags(mdType.getFlags())) {
                    parsedTypes.put(mdType, LLVMSourceType.VOID);
                    break;
                }
                final String name = MDNameExtractor.getName(mdType.getName());
                if (Flags.STATIC_MEMBER.isSetIn(mdType.getFlags())) {
                    final LLVMSourceStaticMemberType type = new LLVMSourceStaticMemberType(name, size, align, location);
                    parsedTypes.put(mdType, type);
                    final LLVMSourceType baseType = resolve(mdType.getBaseType());
                    type.setElementType(baseType);
                    if (mdType.getExtraData() instanceof MDValue) {
                        staticMembers.put(type, ((MDValue) mdType.getExtraData()).getValue());
                    }
                    break;
                }
                final LLVMSourceMemberType type = new LLVMSourceMemberType(name, size, align, offset, location);
                parsedTypes.put(mdType, type);
                LLVMSourceType baseType = resolve(mdType.getBaseType());
                if (Flags.BITFIELD.isSetIn(mdType.getFlags()) || (baseType != UNKNOWN && baseType.getSize() != size)) {
                    final LLVMSourceDecoratorType decorator = new LLVMSourceDecoratorType(size, align, offset, Function.identity(), location);
                    decorator.setBaseType(baseType);
                    baseType = decorator;
                }
                type.setElementType(baseType);
                break;
            }
        case DW_TAG_REFERENCE_TYPE:
        case DW_TAG_POINTER_TYPE:
            {
                final boolean isSafeToDereference = Flags.OBJECT_POINTER.isSetIn(mdType.getFlags());
                final boolean isReference = mdType.getTag() == MDType.DwarfTag.DW_TAG_REFERENCE_TYPE;
                final LLVMSourcePointerType type = new LLVMSourcePointerType(size, align, offset, isSafeToDereference, isReference, location);
                parsedTypes.put(mdType, type);
                // LLVM does not specify a void type, if this is indicated, the reference is simply
                // null
                final LLVMSourceType baseType = resolve(mdType.getBaseType(), LLVMSourceType.VOID);
                type.setBaseType(baseType);
                type.setName(() -> {
                    final String baseName = baseType.getName();
                    final String sym = isReference ? " &" : "*";
                    if (!baseType.isPointer() && baseName.contains(" ")) {
                        return String.format("(%s)%s", baseName, sym);
                    } else {
                        return String.format("%s%s", baseName, sym);
                    }
                });
                break;
            }
        case DW_TAG_TYPEDEF:
        case DW_TAG_VOLATILE_TYPE:
        case DW_TAG_CONST_TYPE:
            {
                final Function<String, String> decorator;
                switch(mdType.getTag()) {
                    case DW_TAG_VOLATILE_TYPE:
                        decorator = s -> String.format("volatile %s", s);
                        break;
                    case DW_TAG_CONST_TYPE:
                        decorator = s -> String.format("const %s", s);
                        break;
                    case DW_TAG_TYPEDEF:
                        {
                            final String name = MDNameExtractor.getName(mdType.getName());
                            decorator = s -> name;
                            break;
                        }
                    default:
                        decorator = Function.identity();
                }
                final LLVMSourceDecoratorType type = new LLVMSourceDecoratorType(size, align, offset, decorator, location);
                parsedTypes.put(mdType, type);
                final LLVMSourceType baseType = resolve(mdType.getBaseType());
                type.setBaseType(baseType);
                type.setSize(baseType.getSize());
                break;
            }
        case DW_TAG_INHERITANCE:
            {
                final LLVMSourceMemberType type = new LLVMSourceMemberType("super", size, align, offset, location);
                parsedTypes.put(mdType, type);
                final LLVMSourceType baseType = resolve(mdType.getBaseType());
                type.setElementType(baseType);
                type.setName(() -> String.format("super (%s)", baseType.getName()));
                break;
            }
        default:
            {
                parsedTypes.put(mdType, LLVMSourceType.UNKNOWN);
            }
    }
}
Also used : MDGlobalVariable(com.oracle.truffle.llvm.parser.metadata.MDGlobalVariable) LLVMSourcePointerType(com.oracle.truffle.llvm.runtime.debug.LLVMSourcePointerType) LLVMSourceStructLikeType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceStructLikeType) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary) LLVMSourceFunctionType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceFunctionType) HashMap(java.util.HashMap) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) MDSubprogram(com.oracle.truffle.llvm.parser.metadata.MDSubprogram) Map(java.util.Map) MDSubroutine(com.oracle.truffle.llvm.parser.metadata.MDSubroutine) MDVoidNode(com.oracle.truffle.llvm.parser.metadata.MDVoidNode) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceType) MDString(com.oracle.truffle.llvm.parser.metadata.MDString) Flags(com.oracle.truffle.llvm.parser.metadata.Flags) MetadataVisitor(com.oracle.truffle.llvm.parser.metadata.MetadataVisitor) MDEnumerator(com.oracle.truffle.llvm.parser.metadata.MDEnumerator) MDValue(com.oracle.truffle.llvm.parser.metadata.MDValue) MDBaseNode(com.oracle.truffle.llvm.parser.metadata.MDBaseNode) LLVMSourceStaticMemberType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceStaticMemberType) MDDerivedType(com.oracle.truffle.llvm.parser.metadata.MDDerivedType) SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) LLVMSourceEnumLikeType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceEnumLikeType) UNKNOWN(com.oracle.truffle.llvm.runtime.debug.LLVMSourceType.UNKNOWN) MDCompositeType(com.oracle.truffle.llvm.parser.metadata.MDCompositeType) MDType(com.oracle.truffle.llvm.parser.metadata.MDType) LLVMSourceDecoratorType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceDecoratorType) MDBasicType(com.oracle.truffle.llvm.parser.metadata.MDBasicType) List(java.util.List) MDSubrange(com.oracle.truffle.llvm.parser.metadata.MDSubrange) MetadataValueList(com.oracle.truffle.llvm.parser.metadata.MetadataValueList) LLVMSourceArrayLikeType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceArrayLikeType) LLVMSourceBasicType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceBasicType) MDLocalVariable(com.oracle.truffle.llvm.parser.metadata.MDLocalVariable) LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation) MDNode(com.oracle.truffle.llvm.parser.metadata.MDNode) LLVMSourceMemberType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceMemberType) MDGlobalVariableExpression(com.oracle.truffle.llvm.parser.metadata.MDGlobalVariableExpression) Function(java.util.function.Function) LLVMSourceDecoratorType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceDecoratorType) MDValue(com.oracle.truffle.llvm.parser.metadata.MDValue) LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation) LLVMSourcePointerType(com.oracle.truffle.llvm.runtime.debug.LLVMSourcePointerType) MDString(com.oracle.truffle.llvm.parser.metadata.MDString) LLVMSourceStaticMemberType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceStaticMemberType) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceType) LLVMSourceMemberType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceMemberType)

Example 4 with LLVMSourceStaticMemberType

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

the class DITypeExtractor method visit.

@Override
public void visit(MDGlobalVariable mdGlobal) {
    final LLVMSourceType type = resolve(mdGlobal.getType());
    parsedTypes.put(mdGlobal, type);
    if (mdGlobal.getStaticMemberDeclaration() != MDVoidNode.INSTANCE && mdGlobal.getVariable() instanceof MDValue) {
        final LLVMSourceType declType = resolve(mdGlobal.getStaticMemberDeclaration());
        final SymbolImpl symbol = ((MDValue) mdGlobal.getVariable()).getValue();
        if (declType instanceof LLVMSourceStaticMemberType) {
            staticMembers.put((LLVMSourceStaticMemberType) declType, symbol);
        }
    }
}
Also used : SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) MDValue(com.oracle.truffle.llvm.parser.metadata.MDValue) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceType) LLVMSourceStaticMemberType(com.oracle.truffle.llvm.runtime.debug.LLVMSourceStaticMemberType)

Aggregations

LLVMSourceStaticMemberType (com.oracle.truffle.llvm.runtime.debug.LLVMSourceStaticMemberType)4 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)3 LLVMSourceType (com.oracle.truffle.llvm.runtime.debug.LLVMSourceType)3 MDBaseNode (com.oracle.truffle.llvm.parser.metadata.MDBaseNode)2 MDString (com.oracle.truffle.llvm.parser.metadata.MDString)2 MDValue (com.oracle.truffle.llvm.parser.metadata.MDValue)2 MetadataValueList (com.oracle.truffle.llvm.parser.metadata.MetadataValueList)2 LLVMSourceArrayLikeType (com.oracle.truffle.llvm.runtime.debug.LLVMSourceArrayLikeType)2 LLVMSourceEnumLikeType (com.oracle.truffle.llvm.runtime.debug.LLVMSourceEnumLikeType)2 LLVMSourceMemberType (com.oracle.truffle.llvm.runtime.debug.LLVMSourceMemberType)2 LLVMSourceStructLikeType (com.oracle.truffle.llvm.runtime.debug.LLVMSourceStructLikeType)2 LLVMSourceLocation (com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 Flags (com.oracle.truffle.llvm.parser.metadata.Flags)1 MDBasicType (com.oracle.truffle.llvm.parser.metadata.MDBasicType)1 MDCompositeType (com.oracle.truffle.llvm.parser.metadata.MDCompositeType)1 MDDerivedType (com.oracle.truffle.llvm.parser.metadata.MDDerivedType)1 MDEnumerator (com.oracle.truffle.llvm.parser.metadata.MDEnumerator)1