Search in sources :

Example 1 with GlobalConstant

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

Aggregations

SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)1 GlobalAlias (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalAlias)1 GlobalConstant (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalConstant)1 GlobalValueSymbol (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol)1 GlobalVariable (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalVariable)1 LLVMSourceSymbol (com.oracle.truffle.llvm.runtime.debug.LLVMSourceSymbol)1 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)1