These functions provide the mechanism to call an LLVM
Function
, passing it R objects as arguments.
This is analogous to the .C
interface,
but for routines generated via LLVM, either read from
existing files or generated in the R session.
.llvm(.x, ..., .args = list(...),
.ee = ExecutionEngine(as(.x, "Module")),
.all = FALSE, .duplicate = .duplicateArgs(.x),
.ffi = TRUE)
the reference to the LLVM Function
object
arguments for the Function
an alternative way mechanism to pass the arguments for
the Function
as a single R list.
the LLVM ExecutionEngine
providing the context for
the Function
. This can be created for each call or an
instance can be reused across calls.
a logical value that controls whether all of the arguments
are also returned, or just the return value from the Function
is returned. When the Function
can modify any of the arguments
.all = TRUE
is typically important.
a logical vector indicating which arguments need to
be copied before being passed to the Function
.
This allows us to avoid copying inputs which are not mutated/modified
by the Function
.
a logical value or a CIF
object. If this is
TRUE
, we use the Rffi
package and the .llvmFFI
in this package to invoke the routine. If .ffi
is
FALSE
, we use the ExecutionEngine's runFunction
routine. For the MCJIT engine, this is currently (LLVM 3.8) very limited and only allows
us to call routines from a small number of possible signatures.
Therefore, we use .ffi = TRUE
by default.
This currently does not comprehensively coerce arguments to the
appropriate type. However, this may change soon.
Also, we will support more types in the future. For now, however,
it covers the common types, and is much more flexible than
MCJIT::runFunction().
(MCJIT::runFunction() basically only supports the common signatures
for main()/exec() routines, i.e. void|int fun(int , char *[])
and int fun(int)
, or routines with no parameters.
If .all
is FALSE
, the return value from Function
is returned as an R object.
# NOT RUN {
module = parseIR(system.file("IR", "fib.ll", package = "Rllvm"))
.llvm(module$fib, 11)
# }
Run the code above in your browser using DataLab