From 18f09925a2133150070a8d46199433e175a57473 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Thu, 25 Oct 2007 06:49:29 +0000 Subject: More tutorial cleanups. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43332 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/tutorial/JITTutorial1.html | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'docs/tutorial/JITTutorial1.html') diff --git a/docs/tutorial/JITTutorial1.html b/docs/tutorial/JITTutorial1.html index 5a2dcd0cbe..9819c77e0b 100644 --- a/docs/tutorial/JITTutorial1.html +++ b/docs/tutorial/JITTutorial1.html @@ -50,7 +50,18 @@ entry:

If you're unsure what the above code says, skim through the LLVM Language Reference Manual and convince yourself that the above LLVM IR is actually equivalent to the original function. Once you’re satisfied with that, let’s move on to actually generating it programmatically!

-

... STUFF ABOUT HEADERS ...

+

Of course, before we can start, we need to #include the appropriate LLVM header files:

+ +
+
+#include <llvm/Module.h>
+#include <llvm/Function.h>
+#include <llvm/PassManager.h>
+#include <llvm/Analysis/Verifier.h>
+#include <llvm/Assembly/PrintModulePass.h>
+#include <llvm/Support/LLVMBuilder.h>
+
+

Now, let’s get started on our real program. Here’s what our basic main() will look like:

@@ -153,9 +164,16 @@ Module* makeLLVMModule() {

The final step in creating our function is to create the instructions that make it up. Our mul_add function is composed of just three instructions: a multiply, an add, and a return. LLVMBuilder gives us a simple interface for constructing these instructions and appending them to the “entry” block. Each of the calls to LLVMBuilder returns a Value* that represents the value yielded by the instruction. You’ll also notice that, above, x, y, and z are also Value*’s, so it’s clear that instructions operate on Value*’s.

-

And that’s it! Now you can compile and run your code, and get a wonder textual print out of the LLVM IR we saw at the beginning.

+

And that’s it! Now you can compile and run your code, and get a wonderful textual print out of the LLVM IR we saw at the beginning. To compile, use the following commandline as a guide:

+ +
+
+# c++ -g tut2.cpp `llvm-config --cppflags --ldflags --libs core` -o tut2
+# ./tut2
+
+
-

... SECTION ABOUT USING llvm-config TO GET THE NECESSARY COMPILER FLAGS TO COMPILE YOUR CODE ...

+

The llvm-config utility is used to obtain the necessary GCC-compatible compiler flags for linking with LLVM. For this example, we only need the 'core' library. We'll use others once we start adding optimizers and the JIT engine.

-- cgit v1.2.3-70-g09d2