Search in sources :

Example 6 with GlobalValueSymbol

use of com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol 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 7 with GlobalValueSymbol

use of com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol in project sulong by graalvm.

the class LLVMParserRuntime method getStructor.

private RootCallTarget getStructor(String name, List<GlobalValueSymbol> globals, Comparator<Pair<Integer, ?>> priorityComparator) {
    for (GlobalValueSymbol globalValueSymbol : globals) {
        if (globalValueSymbol.getName().equals(name)) {
            final LLVMExpressionNode[] targets = resolveStructor(globalValueSymbol, priorityComparator);
            final RootCallTarget constructorFunctionsRootCallTarget = Truffle.getRuntime().createCallTarget(nodeFactory.createStaticInitsRootNode(this, targets));
            return constructorFunctionsRootCallTarget;
        }
    }
    return null;
}
Also used : LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) GlobalValueSymbol(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol) RootCallTarget(com.oracle.truffle.api.RootCallTarget)

Example 8 with GlobalValueSymbol

use of com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol in project sulong by graalvm.

the class LLVMRuntimeDebugInformation method handleDebugIntrinsic.

LLVMExpressionNode handleDebugIntrinsic(SymbolImpl value, SourceVariable variable, MDExpression expression, long index, boolean isDeclaration) {
    if (!isEnabled || variable.hasStaticAllocation()) {
        return null;
    }
    LLVMExpressionNode valueRead = null;
    if (isDeclaration) {
        if (value instanceof UndefinedConstant) {
            if (variable.hasValue()) {
                // know this from the presence of the value
                return null;
            }
            valueRead = symbols.resolve(new NullConstant(MetaType.DEBUG));
        } else if (value instanceof NullConstant) {
            valueRead = symbols.resolve(new NullConstant(MetaType.DEBUG));
        } else if (value instanceof GlobalValueSymbol || value.getType() instanceof PointerType) {
            valueRead = symbols.resolve(value);
        }
    } else {
        valueRead = symbols.resolve(value);
        if (index != 0) {
            // this is unsupported, it doesn't appear in LLVM 3.8+
            return null;
        }
    }
    if (valueRead == null) {
        return null;
    }
    int partIndex = -1;
    int[] clearParts = null;
    if (ValueFragment.describesFragment(expression)) {
        final ValueFragment fragment = ValueFragment.parse(expression);
        final List<ValueFragment> siblings = variable.getFragments();
        final List<Integer> clearSiblings = new ArrayList<>(siblings.size());
        partIndex = ValueFragment.getPartIndex(fragment, siblings, clearSiblings);
        if (clearSiblings.isEmpty()) {
            // this will be the case most of the time
            clearParts = CLEAR_NONE;
        } else {
            clearParts = clearSiblings.stream().mapToInt(Integer::intValue).toArray();
        }
    }
    if (partIndex < 0 && variable.hasFragments()) {
        partIndex = variable.getFragmentIndex(0, (int) variable.getSymbol().getType().getSize());
        if (partIndex < 0) {
            throw new IllegalStateException("Cannot find index of value fragment!");
        }
        clearParts = new int[variable.getFragments().size() - 1];
        for (int i = 0; i < partIndex; i++) {
            clearParts[i] = i;
        }
        for (int i = partIndex; i < clearParts.length; i++) {
            clearParts[i] = i + 1;
        }
    }
    final boolean mustDereference = isDeclaration || mustDereferenceValue(expression, variable.getSourceType(), value);
    final FrameSlot targetSlot = frame.findOrAddFrameSlot(variable.getSymbol(), MetaType.DEBUG, FrameSlotKind.Object);
    final LLVMExpressionNode containerRead = factory.createFrameRead(runtime, MetaType.DEBUG, targetSlot);
    return factory.createDebugWrite(mustDereference, valueRead, targetSlot, containerRead, partIndex, clearParts);
}
Also used : UndefinedConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.UndefinedConstant) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) ArrayList(java.util.ArrayList) NullConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.NullConstant) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) GlobalValueSymbol(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) ValueFragment(com.oracle.truffle.llvm.parser.metadata.debuginfo.ValueFragment)

Aggregations

GlobalValueSymbol (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol)8 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)3 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)2 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)2 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)2 RootCallTarget (com.oracle.truffle.api.RootCallTarget)1 ValueFragment (com.oracle.truffle.llvm.parser.metadata.debuginfo.ValueFragment)1 ValueSymbol (com.oracle.truffle.llvm.parser.model.ValueSymbol)1 FunctionDeclaration (com.oracle.truffle.llvm.parser.model.functions.FunctionDeclaration)1 FunctionDefinition (com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition)1 NullConstant (com.oracle.truffle.llvm.parser.model.symbols.constants.NullConstant)1 UndefinedConstant (com.oracle.truffle.llvm.parser.model.symbols.constants.UndefinedConstant)1 GlobalAlias (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalAlias)1 GlobalConstant (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalConstant)1 GlobalVariable (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalVariable)1 LLVMSourceSymbol (com.oracle.truffle.llvm.runtime.debug.LLVMSourceSymbol)1 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)1 Type (com.oracle.truffle.llvm.runtime.types.Type)1 ArrayList (java.util.ArrayList)1