Search in sources :

Example 6 with LLVMSourceLocation

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

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(VoidCallInstruction call) {
    // stackpointer
    final int argumentCount = call.getArgumentCount() + 1;
    final LLVMExpressionNode[] args = new LLVMExpressionNode[argumentCount];
    final Type[] argsType = new Type[argumentCount];
    int argIndex = 0;
    args[argIndex] = nodeFactory.createFrameRead(runtime, PointerType.VOID, getStackSlot());
    argsType[argIndex] = new PointerType(null);
    argIndex++;
    for (int i = 0; i < call.getArgumentCount(); i++) {
        args[argIndex] = symbols.resolve(call.getArgument(i));
        argsType[argIndex] = call.getArgument(i).getType();
        final AttributesGroup paramAttr = call.getParameterAttributesGroup(i);
        if (isByValue(paramAttr)) {
            args[argIndex] = capsuleAddressByValue(args[argIndex], argsType[argIndex], paramAttr);
        }
        argIndex++;
    }
    final LLVMSourceLocation source = sourceFunction.getSourceLocation(call);
    final SymbolImpl target = call.getCallTarget();
    LLVMExpressionNode node = nodeFactory.createLLVMBuiltin(runtime, target, args, argCount, source);
    if (node == null) {
        if (target instanceof InlineAsmConstant) {
            final InlineAsmConstant inlineAsmConstant = (InlineAsmConstant) target;
            node = createInlineAssemblerNode(inlineAsmConstant, args, argsType, call.getType(), source);
        } else {
            final LLVMExpressionNode function = symbols.resolve(target);
            final FunctionType functionType = new FunctionType(call.getType(), argsType, false);
            node = nodeFactory.createFunctionCall(runtime, function, args, functionType, source);
        }
    }
    addInstruction(node);
}
Also used : SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) LLVMConversionType(com.oracle.truffle.llvm.parser.instructions.LLVMConversionType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) LLVMArithmeticInstructionType(com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType) Type(com.oracle.truffle.llvm.runtime.types.Type) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) AttributesGroup(com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation) InlineAsmConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.InlineAsmConstant)

Example 7 with LLVMSourceLocation

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

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(StoreInstruction store) {
    final LLVMExpressionNode pointerNode = symbols.resolve(store.getDestination());
    final LLVMExpressionNode valueNode = symbols.resolve(store.getSource());
    Type type = store.getSource().getType();
    LLVMSourceLocation source = null;
    if (!(store.getSource() instanceof CallInstruction)) {
        // otherwise the debugger would stop on both the call and the store of the return value
        source = sourceFunction.getSourceLocation(store);
    }
    final LLVMExpressionNode node = nodeFactory.createStore(runtime, pointerNode, valueNode, type, source);
    addInstruction(node);
}
Also used : CallInstruction(com.oracle.truffle.llvm.parser.model.symbols.instructions.CallInstruction) VoidCallInstruction(com.oracle.truffle.llvm.parser.model.symbols.instructions.VoidCallInstruction) LLVMConversionType(com.oracle.truffle.llvm.parser.instructions.LLVMConversionType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) LLVMArithmeticInstructionType(com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType) Type(com.oracle.truffle.llvm.runtime.types.Type) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation)

Example 8 with LLVMSourceLocation

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

the class LazyToTruffleConverterImpl method convert.

@Override
public RootCallTarget convert() {
    CompilerAsserts.neverPartOfCompilation();
    // parse the function block
    parser.parse(diProcessor, source);
    // prepare the phis
    final Map<InstructionBlock, List<Phi>> phis = LLVMPhiManager.getPhis(method);
    // setup the frameDescriptor
    final FrameDescriptor frame = StackManager.createFrame(method);
    LLVMLivenessAnalysisResult liveness = LLVMLivenessAnalysis.computeLiveness(frame, context, phis, method);
    LLVMSymbolReadResolver symbols = new LLVMSymbolReadResolver(runtime, frame);
    List<FrameSlot> notNullable = new ArrayList<>();
    LLVMRuntimeDebugInformation dbgInfoHandler = new LLVMRuntimeDebugInformation(frame, nodeFactory, context, notNullable, symbols, runtime);
    dbgInfoHandler.registerStaticDebugSymbols(method);
    LLVMBitcodeFunctionVisitor visitor = new LLVMBitcodeFunctionVisitor(runtime, frame, phis, nodeFactory, method.getParameters().size(), symbols, method, liveness, notNullable, dbgInfoHandler);
    method.accept(visitor);
    FrameSlot[][] nullableBeforeBlock = getNullableFrameSlots(frame, liveness.getNullableBeforeBlock(), notNullable);
    FrameSlot[][] nullableAfterBlock = getNullableFrameSlots(frame, liveness.getNullableAfterBlock(), notNullable);
    LLVMSourceLocation location = method.getLexicalScope();
    List<LLVMExpressionNode> copyArgumentsToFrame = copyArgumentsToFrame(frame);
    LLVMExpressionNode[] copyArgumentsToFrameArray = copyArgumentsToFrame.toArray(new LLVMExpressionNode[copyArgumentsToFrame.size()]);
    LLVMExpressionNode body = nodeFactory.createFunctionBlockNode(runtime, frame.findFrameSlot(LLVMException.FRAME_SLOT_ID), visitor.getBlocks(), nullableBeforeBlock, nullableAfterBlock, location, copyArgumentsToFrameArray);
    RootNode rootNode = nodeFactory.createFunctionStartNode(runtime, body, method.getSourceSection(), frame, method, source, location);
    return Truffle.getRuntime().createCallTarget(rootNode);
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) RootNode(com.oracle.truffle.api.nodes.RootNode) LLVMLivenessAnalysisResult(com.oracle.truffle.llvm.parser.LLVMLivenessAnalysis.LLVMLivenessAnalysisResult) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) LLVMSymbolReadResolver(com.oracle.truffle.llvm.parser.nodes.LLVMSymbolReadResolver) ArrayList(java.util.ArrayList) LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) ArrayList(java.util.ArrayList) List(java.util.List) InstructionBlock(com.oracle.truffle.llvm.parser.model.blocks.InstructionBlock)

Example 9 with LLVMSourceLocation

use of com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation 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 10 with LLVMSourceLocation

use of com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation 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)

Aggregations

LLVMSourceLocation (com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation)15 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)7 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)5 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)5 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)5 LLVMSourceType (com.oracle.truffle.llvm.runtime.debug.LLVMSourceType)5 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)5 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)5 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)5 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)5 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)5 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)5 Type (com.oracle.truffle.llvm.runtime.types.Type)5 ArrayList (java.util.ArrayList)5 AttributesGroup (com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup)4 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)3 MDString (com.oracle.truffle.llvm.parser.metadata.MDString)3 List (java.util.List)3 SourceSection (com.oracle.truffle.api.source.SourceSection)2 LLVMFunctionStartNode (com.oracle.truffle.llvm.nodes.func.LLVMFunctionStartNode)2