Search in sources :

Example 1 with LLVMSourcePointerType

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

the class DebugExprType method getTypeFromSymbolTableMetaObject.

@TruffleBoundary
public static DebugExprType getTypeFromSymbolTableMetaObject(Object metaObj) {
    if (metaObj instanceof LLVMSourceBasicType) {
        LLVMSourceBasicType basicType = (LLVMSourceBasicType) metaObj;
        LLVMSourceBasicType.Kind typeKind = basicType.getKind();
        long typeSize = basicType.getSize();
        switch(typeKind) {
            case BOOLEAN:
                return DebugExprType.getIntType(1, false);
            case SIGNED:
                return DebugExprType.getIntType(typeSize, true);
            case UNSIGNED:
                return DebugExprType.getIntType(typeSize, false);
            case SIGNED_CHAR:
                return DebugExprType.getIntType(8, true);
            case UNSIGNED_CHAR:
                return DebugExprType.getIntType(8, false);
            case FLOATING:
                return DebugExprType.getFloatType(typeSize);
            default:
                return DebugExprType.getVoidType();
        }
    } else if (metaObj instanceof LLVMSourceArrayLikeType) {
        LLVMSourceArrayLikeType arrayType = (LLVMSourceArrayLikeType) metaObj;
        DebugExprType innerType = getTypeFromSymbolTableMetaObject(arrayType.getElementType(0));
        return new DebugExprType(Kind.ARRAY, innerType, arrayType.getElementCount());
    } else if (metaObj instanceof LLVMSourceDecoratorType) {
        return getTypeFromSymbolTableMetaObject(((LLVMSourceDecoratorType) metaObj).getActualType());
    } else if (metaObj instanceof LLVMSourceStructLikeType) {
        return new DebugExprType(Kind.STRUCT, null);
    } else if (metaObj instanceof LLVMSourcePointerType) {
        LLVMSourcePointerType pointerType = (LLVMSourcePointerType) metaObj;
        DebugExprType baseType = getTypeFromSymbolTableMetaObject(pointerType.getBaseType());
        return new DebugExprType(Kind.POINTER, baseType);
    } else {
        return DebugExprType.getVoidType();
    }
}
Also used : LLVMSourceStructLikeType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceStructLikeType) LLVMSourceDecoratorType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceDecoratorType) LLVMSourceBasicType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceBasicType) LLVMSourcePointerType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourcePointerType) LLVMSourceArrayLikeType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceArrayLikeType) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 2 with LLVMSourcePointerType

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

the class DebugExprDereferenceNode method getMemberAndType.

@TruffleBoundary
private Pair<Object, DebugExprType> getMemberAndType(Object executedPointerNode) {
    if (executedPointerNode == null) {
        throw DebugExprException.create(this, "debugObject to dereference is null");
    }
    try {
        LLVMDebuggerValue llvmDebuggerValue = (LLVMDebuggerValue) executedPointerNode;
        Object metaObj = llvmDebuggerValue.resolveMetaObject();
        DebugExprType pointerType = DebugExprType.getTypeFromSymbolTableMetaObject(metaObj);
        if (!pointerType.isPointer()) {
            throw DebugExprException.create(this, llvmDebuggerValue + " is no pointer");
        }
        LLVMSourcePointerType llvmSourcePointerType = (LLVMSourcePointerType) metaObj;
        LLVMSourceType llvmSourceType = llvmSourcePointerType.getBaseType();
        LLVMDebugObject llvmPointerObject = (LLVMDebugObject) executedPointerNode;
        Object llvmPointerValue = llvmPointerObject.getValue();
        Builder builder = CommonNodeFactory.createDebugDeclarationBuilder();
        LLVMDebugValue dereferencedValue = builder.build(llvmPointerValue);
        LLVMDebugObject llvmDebugObject = LLVMDebugObject.create(llvmSourceType, 0L, dereferencedValue, null);
        DebugExprType type = pointerType.getInnerType();
        return Pair.create(type.parse(llvmDebugObject), type);
    } catch (ClassCastException e) {
    // throw cast exception of executedPointerNode (2 lines below)
    }
    throw DebugExprException.create(this, executedPointerNode + " cannot be casted to pointer ");
}
Also used : DebugExprType(com.oracle.truffle.llvm.runtime.debug.debugexpr.parser.DebugExprType) LLVMDebugObject(com.oracle.truffle.llvm.runtime.debug.value.LLVMDebugObject) Builder(com.oracle.truffle.llvm.runtime.debug.value.LLVMDebugValue.Builder) LLVMDebuggerValue(com.oracle.truffle.llvm.runtime.debug.LLVMDebuggerValue) LLVMDebugObject(com.oracle.truffle.llvm.runtime.debug.value.LLVMDebugObject) LLVMSourcePointerType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourcePointerType) LLVMDebugValue(com.oracle.truffle.llvm.runtime.debug.value.LLVMDebugValue) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 3 with LLVMSourcePointerType

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

the class DITypeExtractor method visit.

@Override
public void visit(MDLocalVariable mdLocal) {
    LLVMSourceType type = resolve(mdLocal.getType());
    if (Flags.OBJECT_POINTER.isSetIn(mdLocal.getFlags()) && type instanceof LLVMSourcePointerType) {
        // llvm does not set the objectpointer flag on this pointer type even though it sets
        // it on the pointer type that is used in the function type descriptor
        final LLVMSourcePointerType oldPointer = (LLVMSourcePointerType) type;
        final LLVMSourcePointerType newPointer = new LLVMSourcePointerType(oldPointer.getSize(), oldPointer.getAlign(), oldPointer.getOffset(), true, oldPointer.isReference(), type.getLocation());
        newPointer.setBaseType(oldPointer.getBaseType());
        newPointer.setName(oldPointer::getName);
        type = newPointer;
    }
    parsedTypes.put(mdLocal, type);
}
Also used : LLVMSourcePointerType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourcePointerType) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType)

Example 4 with LLVMSourcePointerType

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

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:
            {
                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 LLVMSourceInheritanceType inheritanceType = new LLVMSourceInheritanceType("super", size, align, offset, location);
                parsedTypes.put(mdType, inheritanceType);
                final LLVMSourceType baseType = resolve(mdType.getBaseType());
                inheritanceType.setElementType(baseType);
                inheritanceType.setName(() -> String.format("super (%s)", baseType.getName()));
                inheritanceType.setVirtual(Flags.VIRTUAL.isSetIn(mdType.getFlags()));
                break;
            }
        default:
            {
                parsedTypes.put(mdType, LLVMSourceType.UNKNOWN);
            }
    }
}
Also used : MDGlobalVariable(com.oracle.truffle.llvm.parser.metadata.MDGlobalVariable) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary) FunctionDefinition(com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition) UNKNOWN(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType.UNKNOWN) HashMap(java.util.HashMap) Function(java.util.function.Function) Supplier(java.util.function.Supplier) LLVMSymbolReadResolver(com.oracle.truffle.llvm.parser.nodes.LLVMSymbolReadResolver) LLVMSourceTypeFactory(com.oracle.truffle.llvm.runtime.debug.value.LLVMSourceTypeFactory) ArrayList(java.util.ArrayList) MDSubprogram(com.oracle.truffle.llvm.parser.metadata.MDSubprogram) LLVMSourceFunctionType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceFunctionType) LLVMSourceBasicType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceBasicType) LLVMLanguage(com.oracle.truffle.llvm.runtime.LLVMLanguage) Map(java.util.Map) MDSubroutine(com.oracle.truffle.llvm.parser.metadata.MDSubroutine) FunctionParameter(com.oracle.truffle.llvm.parser.model.functions.FunctionParameter) LLVMSourceStructLikeType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceStructLikeType) MDVoidNode(com.oracle.truffle.llvm.parser.metadata.MDVoidNode) MDString(com.oracle.truffle.llvm.parser.metadata.MDString) Flags(com.oracle.truffle.llvm.parser.metadata.Flags) MetadataVisitor(com.oracle.truffle.llvm.parser.metadata.MetadataVisitor) DataLayout(com.oracle.truffle.llvm.runtime.datalayout.DataLayout) MDEnumerator(com.oracle.truffle.llvm.parser.metadata.MDEnumerator) MDValue(com.oracle.truffle.llvm.parser.metadata.MDValue) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType) LLVMSourceArrayLikeType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceArrayLikeType) LLVMSourceStaticMemberType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceStaticMemberType) MDBaseNode(com.oracle.truffle.llvm.parser.metadata.MDBaseNode) MDDerivedType(com.oracle.truffle.llvm.parser.metadata.MDDerivedType) SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) MDCompositeType(com.oracle.truffle.llvm.parser.metadata.MDCompositeType) MDType(com.oracle.truffle.llvm.parser.metadata.MDType) MDBasicType(com.oracle.truffle.llvm.parser.metadata.MDBasicType) LLVMSourceEnumLikeType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceEnumLikeType) List(java.util.List) MDSubrange(com.oracle.truffle.llvm.parser.metadata.MDSubrange) MetadataValueList(com.oracle.truffle.llvm.parser.metadata.MetadataValueList) LLVMSourceMemberType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceMemberType) LLVMSourceClassLikeType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceClassLikeType) MDLocalVariable(com.oracle.truffle.llvm.parser.metadata.MDLocalVariable) LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation) LLVMSourceInheritanceType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceInheritanceType) MDNode(com.oracle.truffle.llvm.parser.metadata.MDNode) LLVMSourceDecoratorType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceDecoratorType) MDGlobalVariableExpression(com.oracle.truffle.llvm.parser.metadata.MDGlobalVariableExpression) LLVMSourcePointerType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourcePointerType) Function(java.util.function.Function) LLVMSourceDecoratorType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceDecoratorType) LLVMSourceInheritanceType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceInheritanceType) MDValue(com.oracle.truffle.llvm.parser.metadata.MDValue) LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation) LLVMSourcePointerType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourcePointerType) MDString(com.oracle.truffle.llvm.parser.metadata.MDString) LLVMSourceStaticMemberType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceStaticMemberType) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType) LLVMSourceMemberType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceMemberType)

Example 5 with LLVMSourcePointerType

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

the class DebugExprPointerCastNode method getMember.

private Object getMember(Object executedPointerNode, VirtualFrame frame) {
    if (executedPointerNode == null) {
        throw DebugExprException.create(this, "debugObject to dereference is null");
    }
    if (!typeNode.getLLVMSourceType(frame).isPointer()) {
        throw DebugExprException.create(this, "%s is no pointer", executedPointerNode);
    }
    try {
        LLVMSourcePointerType llvmSourcePointerType = (LLVMSourcePointerType) typeNode.getLLVMSourceType(frame);
        LLVMDebugObject llvmPointerObject = (LLVMDebugObject) executedPointerNode;
        Object llvmPointerValue = llvmPointerObject.getValue();
        Builder builder = CommonNodeFactory.createDebugValueBuilder();
        LLVMDebugValue pointerValue = builder.build(llvmPointerValue);
        return LLVMDebugObject.create(llvmSourcePointerType, 0L, pointerValue, null);
    } catch (ClassCastException e) {
        throw DebugExprException.create(this, "%s cannot be casted to pointer ", executedPointerNode);
    }
}
Also used : LLVMDebugObject(com.oracle.truffle.llvm.runtime.debug.value.LLVMDebugObject) Builder(com.oracle.truffle.llvm.runtime.debug.value.LLVMDebugValue.Builder) LLVMSourcePointerType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourcePointerType) LLVMDebugObject(com.oracle.truffle.llvm.runtime.debug.value.LLVMDebugObject) LLVMDebugValue(com.oracle.truffle.llvm.runtime.debug.value.LLVMDebugValue)

Aggregations

LLVMSourcePointerType (com.oracle.truffle.llvm.runtime.debug.type.LLVMSourcePointerType)5 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)3 LLVMSourceType (com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType)3 LLVMSourceArrayLikeType (com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceArrayLikeType)2 LLVMSourceBasicType (com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceBasicType)2 LLVMSourceDecoratorType (com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceDecoratorType)2 LLVMSourceStructLikeType (com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceStructLikeType)2 Flags (com.oracle.truffle.llvm.parser.metadata.Flags)1 MDBaseNode (com.oracle.truffle.llvm.parser.metadata.MDBaseNode)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 MDGlobalVariable (com.oracle.truffle.llvm.parser.metadata.MDGlobalVariable)1 MDGlobalVariableExpression (com.oracle.truffle.llvm.parser.metadata.MDGlobalVariableExpression)1 MDLocalVariable (com.oracle.truffle.llvm.parser.metadata.MDLocalVariable)1 MDNode (com.oracle.truffle.llvm.parser.metadata.MDNode)1 MDString (com.oracle.truffle.llvm.parser.metadata.MDString)1 MDSubprogram (com.oracle.truffle.llvm.parser.metadata.MDSubprogram)1 MDSubrange (com.oracle.truffle.llvm.parser.metadata.MDSubrange)1