Search in sources :

Example 1 with GlobalAlias

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

the class LLVMParserRuntime method registerFunctions.

private void registerFunctions(ModelModule model) {
    for (FunctionDefinition function : model.getDefinedFunctions()) {
        registerFunction(function, model);
    }
    for (Map.Entry<GlobalAlias, SymbolImpl> entry : aliases.entrySet()) {
        GlobalAlias alias = entry.getKey();
        SymbolImpl value = entry.getValue();
        if (value instanceof FunctionDefinition) {
            registerFunctionAlias(alias, (FunctionDefinition) value);
        }
    }
}
Also used : SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) FunctionDefinition(com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition) GlobalAlias(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalAlias) Map(java.util.Map)

Example 2 with GlobalAlias

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

the class Module method createGlobalAliasNew.

private void createGlobalAliasNew(long[] args) {
    final int recordOffset = useStrTab() ? STRTAB_RECORD_OFFSET : 0;
    final Type type = new PointerType(types.get(args[GLOBALALIAS_TYPE + recordOffset]));
    // idx = 1 is address space information
    final int value = (int) args[GLOBALALIAS_NEW_VALUE + recordOffset];
    final long linkage = args[GLOBALALIAS_NEW_LINKAGE + recordOffset];
    final GlobalAlias global = GlobalAlias.create(type, linkage, Visibility.DEFAULT.ordinal(), scope.getSymbols(), value);
    if (useStrTab()) {
        readNameFromStrTab(args, global);
    }
    module.addGlobalSymbol(global);
    scope.addSymbol(global, global.getType());
}
Also used : PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) Type(com.oracle.truffle.llvm.runtime.types.Type) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) GlobalAlias(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalAlias)

Example 3 with GlobalAlias

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

the class Module method createGlobalAliasOld.

private void createGlobalAliasOld(long[] args) {
    final int recordOffset = useStrTab() ? STRTAB_RECORD_OFFSET : 0;
    final Type type = types.get(args[GLOBALALIAS_TYPE + recordOffset]);
    int value = (int) args[GLOBALALIAS_OLD_VALUE + recordOffset];
    long linkage = args[GLOBALALIAS_OLD_LINKAGE + recordOffset];
    final GlobalAlias global = GlobalAlias.create(type, linkage, Visibility.DEFAULT.ordinal(), scope.getSymbols(), value);
    if (useStrTab()) {
        readNameFromStrTab(args, global);
    }
    module.addGlobalSymbol(global);
    scope.addSymbol(global, global.getType());
}
Also used : PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) Type(com.oracle.truffle.llvm.runtime.types.Type) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) GlobalAlias(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalAlias)

Example 4 with GlobalAlias

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

GlobalAlias (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalAlias)4 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)3 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)2 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)2 Type (com.oracle.truffle.llvm.runtime.types.Type)2 FunctionDefinition (com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition)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 Map (java.util.Map)1