August 2014
Beginner to intermediate
314 pages
7h 57m
English
LLVM provides a few tools to work with JIT engines. The examples of such tools are lli and llvm-rtdyld.
The interpreter tool (lli) implements an LLVM bitcode interpreter and JIT compiler as well by using the LLVM execution engines studied in this chapter. Let's consider the source file, sum-main.c:
#include <stdio.h>
int sum(int a, int b) {
return a + b;
}
int main() {
printf("sum: %d\n", sum(2, 3) + sum(3, 4));
return 0;
}The lli tool is capable of running bitcode files when a main function is provided. Generate the sum-main.bc bitcode file by using clang:
$ clang -emit-llvm -c sum-main.c -o sum-main.bc
Now, run the bitcode through lli by using the old JIT compilation engine:
$ lli sum-main.bc ...Read now
Unlock full access