Search in sources :

Example 1 with MetadataSymbol

use of com.oracle.truffle.llvm.parser.metadata.MetadataSymbol in project graal by oracle.

the class DebugInfoFunctionProcessor method handleDebugIntrinsic.

private Instruction handleDebugIntrinsic(FunctionDefinition function, VoidCallInstruction call, boolean isDeclaration) {
    SymbolImpl value = getArg(call, LLVM_DBG_INTRINSICS_VALUE_ARGINDEX);
    if (value instanceof MetadataSymbol) {
        value = MDSymbolExtractor.getSymbol(((MetadataSymbol) value).getNode());
    }
    if (value == null) {
        // this may happen if llvm optimizations removed a variable
        value = new NullConstant(MetaType.DEBUG);
    }
    int mdLocalArgIndex;
    int mdExprArgIndex;
    if (isDeclaration) {
        mdLocalArgIndex = LLVM_DBG_DECLARE_LOCALREF_ARGINDEX;
        mdExprArgIndex = LLVM_DBG_DECLARE_EXPR_ARGINDEX;
    } else if (call.getArgumentCount() == LLVM_DBG_VALUE_LOCALREF_ARGSIZE_NEW) {
        mdLocalArgIndex = LLVM_DBG_VALUE_LOCALREF_ARGINDEX_NEW;
        mdExprArgIndex = LLVM_DBG_VALUE_EXPR_ARGINDEX_NEW;
    } else if (call.getArgumentCount() == LLVM_DBG_VALUE_LOCALREF_ARGSIZE_OLD) {
        mdLocalArgIndex = LLVM_DBG_VALUE_LOCALREF_ARGINDEX_OLD;
        mdExprArgIndex = LLVM_DBG_VALUE_EXPR_ARGINDEX_OLD;
    } else {
        return call;
    }
    final SourceVariable variable = getVariable(function, call, mdLocalArgIndex, mdExprArgIndex);
    if (variable == null) {
        // remove upper indices so we do not need to update the later ones
        return null;
    }
    final MDExpression expression = getExpression(call, mdExprArgIndex);
    if (ValueFragment.describesFragment(expression)) {
        variable.addFragment(ValueFragment.parse(expression));
    } else {
        variable.addFullDefinition();
    }
    if (isDeclaration) {
        return new DbgDeclareInstruction(value, variable, expression);
    } else {
        long index = 0;
        if (call.getArgumentCount() == LLVM_DBG_VALUE_LOCALREF_ARGSIZE_OLD) {
            final SymbolImpl indexSymbol = call.getArgument(LLVM_DBG_VALUE_INDEX_ARGINDEX_OLD);
            final Long l = LLVMSymbolReadResolver.evaluateLongIntegerConstant(indexSymbol);
            if (l != null) {
                index = l;
            }
        }
        return new DbgValueInstruction(value, variable, index, expression);
    }
}
Also used : SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) DbgDeclareInstruction(com.oracle.truffle.llvm.parser.model.symbols.instructions.DbgDeclareInstruction) MDExpression(com.oracle.truffle.llvm.parser.metadata.MDExpression) DbgValueInstruction(com.oracle.truffle.llvm.parser.model.symbols.instructions.DbgValueInstruction) MetadataSymbol(com.oracle.truffle.llvm.parser.metadata.MetadataSymbol) NullConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.NullConstant)

Example 2 with MetadataSymbol

use of com.oracle.truffle.llvm.parser.metadata.MetadataSymbol in project graal by oracle.

the class DebugInfoFunctionProcessor method getVariable.

private SourceVariable getVariable(FunctionDefinition function, VoidCallInstruction call, int mdLocalArgIndex, int mdExprArgIndex) {
    final SymbolImpl varSymbol = getArg(call, mdLocalArgIndex);
    if (varSymbol instanceof MetadataSymbol) {
        MDBaseNode mdLocal = ((MetadataSymbol) varSymbol).getNode();
        LLVMSourceSymbol symbol = cache.getSourceSymbol(mdLocal, false);
        attachSourceArgumentInformation(function, call, mdLocalArgIndex, mdExprArgIndex);
        return function.getSourceFunction().getLocal(symbol);
    }
    return null;
}
Also used : SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) MetadataSymbol(com.oracle.truffle.llvm.parser.metadata.MetadataSymbol) MDBaseNode(com.oracle.truffle.llvm.parser.metadata.MDBaseNode) LLVMSourceSymbol(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceSymbol)

Example 3 with MetadataSymbol

use of com.oracle.truffle.llvm.parser.metadata.MetadataSymbol in project graal by oracle.

the class DebugInfoFunctionProcessor method attachSourceArgumentInformation.

/**
 * Attaches debug information about a particular function argument to the corresponding
 * function's type. As an example: which struct member this argument actually is in the source
 * code.
 *
 * @param function The corresponding function.
 * @param call The LLVM metadata.debug "call" (intrinsic).
 * @param mdLocalArgIndex The debug value reference index for the argument.
 * @param mdExprArgIndex The argument's index in the debug statement;
 */
private static void attachSourceArgumentInformation(FunctionDefinition function, VoidCallInstruction call, int mdLocalArgIndex, int mdExprArgIndex) {
    SymbolImpl callTarget = call.getCallTarget();
    /*
         * The call target is actually an LLVM bitcode debugging metadata call, so we should attach
         * argument information to the corresponding function.
         */
    if (LLVM_DBG_VALUE_NAME.equals(((FunctionDeclaration) callTarget).getName())) {
        SymbolImpl intrinsicValueArg = call.getArguments()[LLVM_DBG_INTRINSICS_VALUE_ARGINDEX];
        SymbolImpl localArg = call.getArguments()[mdLocalArgIndex];
        SymbolImpl exprArg = call.getArguments()[mdExprArgIndex];
        if (!(intrinsicValueArg instanceof MetadataSymbol && localArg instanceof MetadataSymbol && exprArg instanceof MetadataSymbol)) {
            return;
        }
        MDBaseNode intrinsicValueNode = ((MetadataSymbol) intrinsicValueArg).getNode();
        MDBaseNode localNode = ((MetadataSymbol) localArg).getNode();
        MDBaseNode exprNode = ((MetadataSymbol) exprArg).getNode();
        if (!(intrinsicValueNode instanceof MDValue && localNode instanceof MDLocalVariable && exprNode instanceof MDExpression)) {
            return;
        }
        SymbolImpl intrinsicValue = ((MDValue) intrinsicValueNode).getValue();
        MDLocalVariable local = (MDLocalVariable) localNode;
        MDExpression expr = (MDExpression) exprNode;
        if (!(intrinsicValue instanceof FunctionParameter)) {
            return;
        }
        FunctionParameter parameter = (FunctionParameter) intrinsicValue;
        ValueFragment fragment = ValueFragment.parse(expr);
        if (!fragment.isComplete()) {
            long sourceArgIndex = local.getArg();
            if (Long.compareUnsigned(sourceArgIndex, Integer.MAX_VALUE) > 0) {
                throw new IndexOutOfBoundsException(String.format("Source argument index (%s) is out of integer range", Long.toUnsignedString(sourceArgIndex)));
            }
            /*
                 * Attach the argument info to the source function type: sourceArgIndex needs to be
                 * decremented by 1 because the 0th index belongs to the return type.
                 */
            function.getSourceFunction().getSourceType().attachSourceArgumentInformation(parameter.getArgIndex(), (int) sourceArgIndex - 1, fragment.getOffset(), fragment.getLength());
        }
    }
}
Also used : SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) MDExpression(com.oracle.truffle.llvm.parser.metadata.MDExpression) MetadataSymbol(com.oracle.truffle.llvm.parser.metadata.MetadataSymbol) MDValue(com.oracle.truffle.llvm.parser.metadata.MDValue) MDLocalVariable(com.oracle.truffle.llvm.parser.metadata.MDLocalVariable) MDBaseNode(com.oracle.truffle.llvm.parser.metadata.MDBaseNode) FunctionParameter(com.oracle.truffle.llvm.parser.model.functions.FunctionParameter)

Aggregations

MetadataSymbol (com.oracle.truffle.llvm.parser.metadata.MetadataSymbol)3 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)3 MDBaseNode (com.oracle.truffle.llvm.parser.metadata.MDBaseNode)2 MDExpression (com.oracle.truffle.llvm.parser.metadata.MDExpression)2 MDLocalVariable (com.oracle.truffle.llvm.parser.metadata.MDLocalVariable)1 MDValue (com.oracle.truffle.llvm.parser.metadata.MDValue)1 FunctionParameter (com.oracle.truffle.llvm.parser.model.functions.FunctionParameter)1 NullConstant (com.oracle.truffle.llvm.parser.model.symbols.constants.NullConstant)1 DbgDeclareInstruction (com.oracle.truffle.llvm.parser.model.symbols.instructions.DbgDeclareInstruction)1 DbgValueInstruction (com.oracle.truffle.llvm.parser.model.symbols.instructions.DbgValueInstruction)1 LLVMSourceSymbol (com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceSymbol)1