Using JIT compilation for direct execution
Running LLVM IR directly is the first idea that comes to mind when thinking about a JIT compiler. This is what the lli
tool, the LLVM interpreter, and the dynamic compiler do. We will explore the lli
tool in the next section, and subsequently implement a similar tool on our own.
Exploring the lli tool
Let's try the lli
tool with a very simple example. Store the following source as a hello.ll
file. It is the equivalent of a C hello world application. It declares the prototype for the printf()
function from the C library. The hellostr
constant contains the message to be printed. Inside the main()
function, a pointer to the first character of the message is calculated via the getelementptr
instruction, and this value is passed to the printf()
function. The application always returns 0
. The complete source code is as follows:
declare i32 @printf(i8*, ...) @hellostr = private unnamed_addr constant [13 x i8] c"Hello   ...