Search in sources :

Example 6 with LLVMFunction

use of com.oracle.truffle.llvm.runtime.LLVMFunction 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 7 with LLVMFunction

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

the class InitializeExternalNode method execute.

/*
     * (PLi): Need to be careful of native functions/globals that are not in the nfi context (i.e.
     * __xstat). Ideally they will be added to the symbol table as unresolved/undefined
     * functions/globals.
     */
public void execute(LLVMContext context, LLVMScopeChain localScope, LLVMDLOpen.RTLDFlags rtldFlags) {
    LLVMScopeChain globalScope = context.getGlobalScopeChain();
    LLVMIntrinsicProvider intrinsicProvider = getLanguage().getCapability(LLVMIntrinsicProvider.class);
    NativeContextExtension nativeContextExtension = getNativeContextExtension(context);
    for (int i = 0; i < globals.length; i++) {
        LLVMGlobal global = globals[i];
        LLVMPointer pointer = allocExternalSymbol.execute(localScope, globalScope, intrinsicProvider, nativeContextExtension, context, rtldFlags, global);
        if (pointer == null) {
            continue;
        }
        context.initializeSymbol(globals[i], pointer);
    }
    for (int i = 0; i < functions.length; i++) {
        LLVMFunction function = functions[i];
        LLVMPointer pointer = allocExternalSymbol.execute(localScope, globalScope, intrinsicProvider, nativeContextExtension, context, rtldFlags, function);
        if (pointer == null) {
            continue;
        }
        context.initializeSymbol(functions[i], pointer);
    }
}
Also used : LLVMFunction(com.oracle.truffle.llvm.runtime.LLVMFunction) LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) LLVMScopeChain(com.oracle.truffle.llvm.runtime.LLVMScopeChain) LLVMGlobal(com.oracle.truffle.llvm.runtime.global.LLVMGlobal) LLVMIntrinsicProvider(com.oracle.truffle.llvm.runtime.LLVMIntrinsicProvider) NativeContextExtension(com.oracle.truffle.llvm.runtime.NativeContextExtension)

Example 8 with LLVMFunction

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

the class InitializeOverwriteNode method execute.

public void execute(LLVMContext context, LLVMScopeChain localScope, RTLDFlags rtldFlags) {
    LLVMScopeChain globalScope = context.getGlobalScopeChain();
    for (LLVMFunction function : functions) {
        LLVMPointer pointer = allocExternalSymbol.execute(localScope, globalScope, null, null, context, rtldFlags, function);
        // skip allocating fallbacks
        if (pointer == null) {
            continue;
        }
        context.initializeSymbol(function, pointer);
    }
    for (LLVMGlobal global : globals) {
        LLVMPointer pointer = allocExternalSymbol.execute(localScope, globalScope, null, null, context, rtldFlags, global);
        // skip allocating fallbacks
        if (pointer == null) {
            continue;
        }
        context.initializeSymbol(global, pointer);
    }
}
Also used : LLVMFunction(com.oracle.truffle.llvm.runtime.LLVMFunction) LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) LLVMScopeChain(com.oracle.truffle.llvm.runtime.LLVMScopeChain) LLVMGlobal(com.oracle.truffle.llvm.runtime.global.LLVMGlobal)

Example 9 with LLVMFunction

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

the class LLVMParser method defineFunction.

private void defineFunction(FunctionSymbol functionSymbol, ModelModule model, DataLayout dataLayout) {
    assert !functionSymbol.isExternal();
    // handle the file scope
    FunctionDefinition functionDefinition = (FunctionDefinition) functionSymbol;
    LazyToTruffleConverterImpl lazyConverter = new LazyToTruffleConverterImpl(runtime, functionDefinition, source, model.getFunctionParser(functionDefinition), model.getFunctionProcessor(), dataLayout);
    Function function = new LazyLLVMIRFunction(lazyConverter);
    LLVMFunction llvmFunction = LLVMFunction.create(functionSymbol.getName(), function, functionSymbol.getType(), runtime.getBitcodeID(), functionSymbol.getIndex(), functionDefinition.isExported(), runtime.getFile().getPath(), functionDefinition.isExternalWeak());
    lazyConverter.setRootFunction(llvmFunction);
    runtime.getFileScope().register(llvmFunction);
    registerInPublicFileScope(llvmFunction);
    final boolean cxxInterop = LLVMLanguage.getContext().getEnv().getOptions().get(SulongEngineOption.CXX_INTEROP);
    if (cxxInterop) {
        model.getFunctionParser(functionDefinition).parseLinkageName(runtime);
    }
}
Also used : LazyLLVMIRFunction(com.oracle.truffle.llvm.runtime.LLVMFunctionCode.LazyLLVMIRFunction) LLVMFunction(com.oracle.truffle.llvm.runtime.LLVMFunction) Function(com.oracle.truffle.llvm.runtime.LLVMFunctionCode.Function) LLVMFunction(com.oracle.truffle.llvm.runtime.LLVMFunction) FunctionDefinition(com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition) LazyLLVMIRFunction(com.oracle.truffle.llvm.runtime.LLVMFunctionCode.LazyLLVMIRFunction)

Aggregations

LLVMFunction (com.oracle.truffle.llvm.runtime.LLVMFunction)9 LLVMFunctionCode (com.oracle.truffle.llvm.runtime.LLVMFunctionCode)3 LLVMScopeChain (com.oracle.truffle.llvm.runtime.LLVMScopeChain)3 LLVMIRFunction (com.oracle.truffle.llvm.runtime.LLVMFunctionCode.LLVMIRFunction)2 LLVMFunctionDescriptor (com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor)2 LLVMGlobal (com.oracle.truffle.llvm.runtime.global.LLVMGlobal)2 LLVMPointer (com.oracle.truffle.llvm.runtime.pointer.LLVMPointer)2 Specialization (com.oracle.truffle.api.dsl.Specialization)1 AsmFactory (com.oracle.truffle.llvm.asm.amd64.AsmFactory)1 AsmParseException (com.oracle.truffle.llvm.asm.amd64.AsmParseException)1 FunctionDefinition (com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition)1 LLVMContext (com.oracle.truffle.llvm.runtime.LLVMContext)1 Function (com.oracle.truffle.llvm.runtime.LLVMFunctionCode.Function)1 LazyLLVMIRFunction (com.oracle.truffle.llvm.runtime.LLVMFunctionCode.LazyLLVMIRFunction)1 LLVMIntrinsicProvider (com.oracle.truffle.llvm.runtime.LLVMIntrinsicProvider)1 LLVMScope (com.oracle.truffle.llvm.runtime.LLVMScope)1 LLVMSymbol (com.oracle.truffle.llvm.runtime.LLVMSymbol)1 NativeContextExtension (com.oracle.truffle.llvm.runtime.NativeContextExtension)1 SulongLibrary (com.oracle.truffle.llvm.runtime.SulongLibrary)1 CachedMainFunction (com.oracle.truffle.llvm.runtime.SulongLibrary.CachedMainFunction)1