ModuleODSigs: Module with On-Demand External Signatures

View source: R/ModuleODSigs.R

ModuleODSigsR Documentation

Module with On-Demand External Signatures

Description

This is a function and also supporting class and methods that take an LLVM Module in which to create new Function objects, but which also will search additional Modules for the signatures of external routines that we want to call. By external, we mean not in the current module. If a Function is not found by name in the current module, this looks in the other Modules provided when we call ModuleODSigs. These can be provided as actual Module objects, or as a collection of file names which will be read sequentially when looking for a Function. These files are loaded only once and the resulting Module cached and reused across subsequent calls to find a Function.

We have a sequence of Modules and also file names which we will lazily load when looking for a Function by name. This is analogous to the R search path when looking for a symbol.

Usage

ModuleODSigs(mod, files = system.file("Rmain.bc", package = "RLLVMCompile"), ..., .modules = list(...))

Arguments

mod

the actual Module-class in which we are generating code. We will look for Functions by name here first.

files

a character vector of files whose contents can be read by parseIR to return a Module-class. These will only be read as needed, i.e., lazily.

...

zero or Module-class objects that have already been parsed or created and contain Functions we may want to reference.

.modules

an alternative form of specifying the list of Module-class we could pass via .... If these are already in a list, one can pass that directly.

Details

This uses the externalptr object in the target Module-class, i.e., mod to dynamically or "across-calls" update the list of Module-classs in which to search for the named Function. If we don't find the named Function, we sequentially read the remaining files. As we read each file, we remove it from the list and add the resulting Module-class to the available Module-classs list for subsequent calls so that we won't have to parse it again.

Value

An object of class ModuleODSigs-class which extends the Module-class class, i.e. this is a regular Module-class and is the mod value passed to the R function. It just has extra information and functionality.

Author(s)

DTL

See Also

Module-class, Function-class

Examples

    m = Module()
    Function("x", Int32Type, module = m)
    names(m)
    em = ModuleODSigs(m, c(system.file("IR/rapiEg.ir", package = "Rllvm"),
                           system.file("IR/fib.ll", package = "Rllvm")))
    em$Rf_allocVector
    names(m)
    names(em)
    em[["Rf_allocVector"]]
    em$fib
    em$x
    # returns NULL. 
    em[["Rf_allocVector3"]]


    # Show the parseIR() calls when they happen and that we load fib when looking for doesnt_exist
    # because it is not in the first Module() on the sub-Module list.

    other = Module()
    Function("foo", VoidType, module = other)
    
    m = Module()
    em = ModuleODSigs(m, c(system.file("IR/rapiEg.ir", package = "Rllvm"), 
                           system.file("IR/fib.ll", package = "Rllvm")), other)
    trace(parseIR, quote(print(content)))

    f0 = files(em)
    em$Rf_allocVector
    em$foo
    f1 = files(em)
    em$doesnt_exist
    f2 = files(em)
    em$fib
    em$bob

    f0
    f1
    f2

    untrace(parseIR)

duncantl/Rllvm documentation built on May 13, 2024, 7:45 p.m.