Search in sources :

Example 6 with LLVMSymbol

use of com.oracle.truffle.llvm.runtime.LLVMSymbol in project graal by oracle.

the class InitializeSymbolsNode method allocFunctions.

private void allocFunctions(LLVMContext context) {
    for (int i = 0; i < allocFuncs.length; i++) {
        AllocSymbolNode allocSymbol = allocFuncs[i];
        LLVMPointer pointer = allocSymbol.allocate(context);
        context.initializeSymbol(functions[i], pointer);
        List<LLVMSymbol> list = new ArrayList<>(1);
        list.add(allocSymbol.symbol);
        context.registerSymbolReverseMap(list, pointer);
    }
}
Also used : LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) ArrayList(java.util.ArrayList) LLVMSymbol(com.oracle.truffle.llvm.runtime.LLVMSymbol)

Example 7 with LLVMSymbol

use of com.oracle.truffle.llvm.runtime.LLVMSymbol in project graal by oracle.

the class LoadModulesNode method findMainFunction.

/**
 * Retrieves the function for the main method.
 */
private LLVMFunction findMainFunction() {
    // check if the freshly parsed code exports a main method
    LLVMScope fileScope = parserRuntime.getFileScope();
    LLVMSymbol mainSymbol = fileScope.get(MAIN_METHOD_NAME);
    if (mainSymbol != null && mainSymbol.isFunction()) {
        /*
             * The `isLLVMIRFunction` check makes sure the `main` function is really defined in
             * bitcode. This prevents us from finding a native `main` function (e.g. the `main` of
             * the VM we're running in).
             */
        LLVMFunction mainFunction = mainSymbol.asFunction();
        if (mainFunction.getFunction() instanceof LLVMFunctionCode.LLVMIRFunction || mainFunction.getFunction() instanceof LLVMFunctionCode.LazyLLVMIRFunction) {
            return mainFunction;
        }
    }
    return null;
}
Also used : LLVMFunction(com.oracle.truffle.llvm.runtime.LLVMFunction) LLVMFunctionCode(com.oracle.truffle.llvm.runtime.LLVMFunctionCode) LLVMScope(com.oracle.truffle.llvm.runtime.LLVMScope) LLVMSymbol(com.oracle.truffle.llvm.runtime.LLVMSymbol)

Example 8 with LLVMSymbol

use of com.oracle.truffle.llvm.runtime.LLVMSymbol in project graal by oracle.

the class LLVMParser method defineAlias.

private void defineAlias(GlobalAlias alias, DataLayout targetDataLayout) {
    LLVMSymbol alreadyRegisteredSymbol = runtime.getFileScope().get(alias.getName());
    if (alreadyRegisteredSymbol != null) {
        // this alias was already registered by a recursive call
        assert alreadyRegisteredSymbol instanceof LLVMAlias;
        return;
    }
    defineAlias(alias.getName(), alias.isExported(), alias.getValue(), targetDataLayout);
}
Also used : LLVMAlias(com.oracle.truffle.llvm.runtime.LLVMAlias) LLVMSymbol(com.oracle.truffle.llvm.runtime.LLVMSymbol)

Example 9 with LLVMSymbol

use of com.oracle.truffle.llvm.runtime.LLVMSymbol in project graal by oracle.

the class LLVMParser method defineExpressionSymbol.

private void defineExpressionSymbol(String aliasName, boolean isAliasExported, GetElementPointerConstant elementPointerConstant, DataLayout targetDataLayout) {
    LLVMSymbol baseSymbol = runtime.getFileScope().get(elementPointerConstant.getBasePointer().toString());
    Supplier<LLVMExpressionNode> createElemPtrNode = () -> elementPointerConstant.createNode(runtime, targetDataLayout, GetStackSpaceFactory.createAllocaFactory());
    LLVMElemPtrSymbol expressionSymbol = new LLVMElemPtrSymbol(aliasName, runtime.getBitcodeID(), -1, isAliasExported, elementPointerConstant.getType(), baseSymbol, createElemPtrNode);
    runtime.getFileScope().register(expressionSymbol);
}
Also used : LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) LLVMElemPtrSymbol(com.oracle.truffle.llvm.runtime.LLVMElemPtrSymbol) LLVMSymbol(com.oracle.truffle.llvm.runtime.LLVMSymbol)

Example 10 with LLVMSymbol

use of com.oracle.truffle.llvm.runtime.LLVMSymbol in project graal by oracle.

the class LLVMTruffleWriteManagedToSymbol method write.

@TruffleBoundary
@Specialization
protected Object write(LLVMPointer address, Object value) {
    /*
         * The list of symbols should be all global symbols or all function symbols more over, the
         * list of symbols should all be pointing to the same value or function code, and they
         * should all have the same name.
         */
    List<LLVMSymbol> symbols = getContext().removeSymbolReverseMap(address);
    if (symbols == null) {
        throw new LLVMPolyglotException(this, "First argument to truffle_assign_managed must be a pointer to a symbol.");
    }
    Object newValue = value;
    boolean allGlobals = symbols.get(0).isGlobalVariable();
    LLVMContext ctx = LLVMContext.get(this);
    /*
         * The interop type of the global symbol has to be attached to the new object that's
         * replacing the global. This is done by creating a LLVMTypedForeignObject wrapping it
         * around the new object with the global's interop type.
         */
    if (allGlobals) {
        newValue = attachType.execute(value, symbols.get(0).asGlobalVariable().getInteropType(ctx));
    }
    /*
         * Every symbol in the symbol list should point to the same value even if they are stored in
         * different locations in the symbol table.
         */
    for (LLVMSymbol symbol : symbols) {
        assert allGlobals ? symbol.isGlobalVariable() : symbol.isFunction();
        ctx.setSymbol(symbol, LLVMPointer.cast(newValue));
    }
    ctx.registerSymbolReverseMap(symbols, LLVMPointer.cast(value));
    return newValue;
}
Also used : LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) LLVMPolyglotException(com.oracle.truffle.llvm.runtime.except.LLVMPolyglotException) LLVMSymbol(com.oracle.truffle.llvm.runtime.LLVMSymbol) Specialization(com.oracle.truffle.api.dsl.Specialization) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

LLVMSymbol (com.oracle.truffle.llvm.runtime.LLVMSymbol)11 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)3 LLVMGlobal (com.oracle.truffle.llvm.runtime.global.LLVMGlobal)3 LLVMPointer (com.oracle.truffle.llvm.runtime.pointer.LLVMPointer)3 Specialization (com.oracle.truffle.api.dsl.Specialization)2 LLVMAlias (com.oracle.truffle.llvm.runtime.LLVMAlias)2 LLVMContext (com.oracle.truffle.llvm.runtime.LLVMContext)2 ArrayList (java.util.ArrayList)2 LLVMElemPtrSymbol (com.oracle.truffle.llvm.runtime.LLVMElemPtrSymbol)1 LLVMFunction (com.oracle.truffle.llvm.runtime.LLVMFunction)1 LLVMFunctionCode (com.oracle.truffle.llvm.runtime.LLVMFunctionCode)1 LLVMScope (com.oracle.truffle.llvm.runtime.LLVMScope)1 LLVMScopeChain (com.oracle.truffle.llvm.runtime.LLVMScopeChain)1 LLVMLinkerException (com.oracle.truffle.llvm.runtime.except.LLVMLinkerException)1 LLVMPolyglotException (com.oracle.truffle.llvm.runtime.except.LLVMPolyglotException)1 LLVMGlobalContainer (com.oracle.truffle.llvm.runtime.global.LLVMGlobalContainer)1 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)1