parseIR: Read LLVM Code in the Intermediate Representation (IR)...

Description Usage Arguments Value Author(s) References See Also Examples

Description

This function is used for de-serializing LLVM code in intermediate representation form into in-memory description of the code. This can then be converted to machine code and run, including passed through optimization passes. This allows us to create the code description directly using the IR language rather than via the functions to create the function, blocks, instructions incrementally with R code.

Usage

1
2
3
4
parseIR(content, context = NULL,
         asText = is(content, "AsIs") || !file.exists(content))
parseAssembly(code, module = NULL, context = NULL,
                asText = !file.exists(code)) 

Arguments

content,code

the name of a file containing the IR content, or the actual IR content as a character vector. Content can be identified via the I() function to mark it "AsIs".

context

the LLVM context in which to parse the code and create the Module. By default, we use the global context

module

the module into which to create the code objects. This will be created if not specified.

asText

a logical value that indicates whether content is the name of a file (FALSE) or the actual content of the IR code (TRUE)

Value

An object of class Module, or NULL if the code cannot be parsed.

Author(s)

Duncan Temple Lang

References

LLVM API

See Also

Module

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
InitializeNativeTarget()

## Not run:   
ff = system.file("IR", "add.ll", package = "Rllvm")

 # Read directly from a file
m = parseIR(ff)

print(showModule(m))

ee = ExecutionEngine(m)
Optimize(m, ee)

foo = getModuleFunctions(m)$foo

run(foo, x = 1L, y = 12L, .ee = ee)
run(foo, x = 30000L, y = 12L, .ee = ee)

  # Now read the content of the file into a string and
  # work with the code in memory.
ll = readLines(ff)

m = parseIR(ll, asText = TRUE)


  # Now actually create the code as a string
ll = 'define i32 @bar() nounwind readnone ssp {
entry:
  ret i32 2
}'

 m = parseIR(ll, asText = TRUE)
 Optimize(m,)
 run(getModuleFunctions(m)$bar)

## End(Not run)

doktorschiwago/Rllvm2 documentation built on May 15, 2019, 9:42 a.m.