Search in sources :

Example 16 with SymbolImpl

use of com.oracle.truffle.llvm.parser.model.SymbolImpl in project sulong by graalvm.

the class LLVMParserRuntime method getGlobalVariable.

private LLVMExpressionNode getGlobalVariable(LLVMSymbolReadResolver symbolResolver, GlobalValueSymbol global) {
    LLVMSourceSymbol sourceSymbol = null;
    SymbolImpl g = global;
    while (g instanceof GlobalAlias) {
        if (sourceSymbol == null) {
            sourceSymbol = ((GlobalAlias) g).getSourceSymbol();
        }
        g = aliases.get(g);
    }
    if (sourceSymbol == null && g instanceof GlobalValueSymbol) {
        sourceSymbol = ((GlobalValueSymbol) g).getSourceSymbol();
    }
    if (g instanceof GlobalValueSymbol) {
        final GlobalValueSymbol variable = (GlobalValueSymbol) g;
        final LLVMSourceSymbol finalSourceSymbol = sourceSymbol;
        Object globalVariableDescriptor = scope.lookupOrCreateGlobal(variable.getName(), !Linkage.isFileLocal(variable.getLinkage()), () -> {
            final Object globalValue;
            if (global instanceof GlobalVariable) {
                globalValue = nodeFactory.allocateGlobalVariable(this, (GlobalVariable) global, finalSourceSymbol);
            } else if (global instanceof GlobalConstant) {
                globalValue = nodeFactory.allocateGlobalConstant(this, (GlobalConstant) global, finalSourceSymbol);
            } else {
                throw new AssertionError("Cannot allocate global: " + global);
            }
            return globalValue;
        });
        return nodeFactory.createLiteral(this, globalVariableDescriptor, new PointerType(variable.getType()));
    } else {
        return symbolResolver.resolve(g);
    }
}
Also used : SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) GlobalVariable(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalVariable) GlobalConstant(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalConstant) LLVMSourceSymbol(com.oracle.truffle.llvm.runtime.debug.LLVMSourceSymbol) GlobalAlias(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalAlias) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) GlobalValueSymbol(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol)

Example 17 with SymbolImpl

use of com.oracle.truffle.llvm.parser.model.SymbolImpl in project sulong by graalvm.

the class LLVMRuntimeDebugInformation method registerStaticDebugSymbols.

void registerStaticDebugSymbols(FunctionDefinition fn) {
    if (!isEnabled) {
        return;
    }
    for (SourceVariable local : fn.getSourceFunction().getVariables()) {
        if (local.isSingleDeclaration()) {
            final DbgDeclareInstruction dbg = local.getSingleDeclaration();
            FrameSlot frameSlot = null;
            if (dbg.getValue() instanceof AllocateInstruction) {
                frameSlot = frame.findFrameSlot(((AllocateInstruction) dbg.getValue()).getName());
            }
            if (frameSlot == null) {
                continue;
            }
            final LLVMSourceSymbol symbol = local.getSymbol();
            final LLVMFrameValueAccess alloc = factory.createDebugFrameValue(frameSlot, true);
            notNullableSlots.add(frameSlot);
            context.getSourceContext().registerFrameValue(symbol, alloc);
            local.addStaticValue();
        } else if (local.isSingleValue()) {
            final DbgValueInstruction dbg = local.getSingleValue();
            final MDExpression expr = dbg.getExpression();
            final SymbolImpl value = dbg.getValue();
            if (expr.getElementCount() != 0) {
                continue;
            }
            final boolean mustDereference = mustDereferenceValue(expr, local.getSourceType(), value);
            staticValueAccessVisitor.registerStaticAccess(local, value, mustDereference);
        }
    }
}
Also used : SourceVariable(com.oracle.truffle.llvm.parser.metadata.debuginfo.SourceVariable) DbgDeclareInstruction(com.oracle.truffle.llvm.parser.model.symbols.instructions.DbgDeclareInstruction) LLVMFrameValueAccess(com.oracle.truffle.llvm.runtime.debug.scope.LLVMFrameValueAccess) SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) AllocateInstruction(com.oracle.truffle.llvm.parser.model.symbols.instructions.AllocateInstruction) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) DbgValueInstruction(com.oracle.truffle.llvm.parser.model.symbols.instructions.DbgValueInstruction) MDExpression(com.oracle.truffle.llvm.parser.metadata.MDExpression) LLVMSourceSymbol(com.oracle.truffle.llvm.runtime.debug.LLVMSourceSymbol)

Aggregations

SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)17 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)8 Type (com.oracle.truffle.llvm.runtime.types.Type)8 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)7 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)7 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)7 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)6 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)6 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)6 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)6 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)6 AttributesGroup (com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup)4 LLVMSourceLocation (com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation)4 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)3 NullConstant (com.oracle.truffle.llvm.parser.model.symbols.constants.NullConstant)3 IntegerConstant (com.oracle.truffle.llvm.parser.model.symbols.constants.integer.IntegerConstant)3 LLVMSourceSymbol (com.oracle.truffle.llvm.runtime.debug.LLVMSourceSymbol)3 MetaType (com.oracle.truffle.llvm.runtime.types.MetaType)3 VoidType (com.oracle.truffle.llvm.runtime.types.VoidType)3 ArrayList (java.util.ArrayList)3