1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

More tutorial cleanups.

llvm-svn: 43332
This commit is contained in:
Owen Anderson 2007-10-25 06:49:29 +00:00
parent f0de089267
commit df57f1e429
2 changed files with 22 additions and 5 deletions

View File

@ -50,7 +50,18 @@ entry:
<p>If you're unsure what the above code says, skim through the <a href="../LangRef.html">LLVM Language Reference Manual</a> and convince yourself that the above LLVM IR is actually equivalent to the original function. Once youre satisfied with that, lets move on to actually generating it programmatically!</p>
<p>... STUFF ABOUT HEADERS ... </p>
<p>Of course, before we can start, we need to <code>#include</code> the appropriate LLVM header files:</p>
<div class="doc_code">
<pre>
#include &lt;llvm/Module.h&gt;
#include &lt;llvm/Function.h&gt;
#include &lt;llvm/PassManager.h&gt;
#include &lt;llvm/Analysis/Verifier.h&gt;
#include &lt;llvm/Assembly/PrintModulePass.h&gt;
#include &lt;llvm/Support/LLVMBuilder.h&gt;
</pre>
</div>
<p>Now, lets get started on our real program. Heres what our basic <code>main()</code> will look like:</p>
@ -153,9 +164,16 @@ Module* makeLLVMModule() {
<p>The final step in creating our function is to create the instructions that make it up. Our <code>mul_add</code> function is composed of just three instructions: a multiply, an add, and a return. <code>LLVMBuilder</code> gives us a simple interface for constructing these instructions and appending them to the “entry” block. Each of the calls to <code>LLVMBuilder</code> returns a <code>Value*</code> that represents the value yielded by the instruction. Youll also notice that, above, <code>x</code>, <code>y</code>, and <code>z</code> are also <code>Value*</code>s, so its clear that instructions operate on <code>Value*</code>s.</p>
<p>And thats 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.</p>
<p>And thats 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:</p>
<p> ... SECTION ABOUT USING llvm-config TO GET THE NECESSARY COMPILER FLAGS TO COMPILE YOUR CODE ... </p>
<div class="doc_code">
<pre>
# c++ -g tut2.cpp `llvm-config --cppflags --ldflags --libs core` -o tut2
# ./tut2
</pre>
</div>
<p>The <code>llvm-config</code> 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.</p>
</div>

View File

@ -166,8 +166,7 @@ Module* makeLLVMModule() {
<div class="doc_code">
<pre>
# c++ -g tut2.cpp `llvm-config --cppflags` `llvm-config --ldflags` \
`llvm-config --libs core` -o tut2
# c++ -g tut2.cpp `llvm-config --cppflags --ldflags --libs core` -o tut2
# ./tut2
</pre>
</div>