-<!-- ======================================================================= -->
-<div class="doc_subsection"><a name="tutorial3">Example with llvm-gcc3</a></div>
-
-<div class="doc_text">
-
-<ol>
- <li>First, create a simple C file, name it 'hello.c':
- <pre>
- #include <stdio.h>
- int main() {
- printf("hello world\n");
- return 0;
- }
- </pre></li>
-
- <li><p>Next, compile the C file into a LLVM bytecode file:</p>
- <p><tt>% llvm-gcc hello.c -o hello</tt></p>
-
- <p>Note that you should have already built the tools and they have to be
- in your path, at least <tt>gccas</tt> and <tt>gccld</tt>.</p>
-
- <p>This will create two result files: <tt>hello</tt> and
- <tt>hello.bc</tt>. The <tt>hello.bc</tt> is the LLVM bytecode that
- corresponds the the compiled program and the library facilities that it
- required. <tt>hello</tt> is a simple shell script that runs the bytecode
- file with <tt>lli</tt>, making the result directly executable. Note that
- all LLVM optimizations are enabled by default, so there is no need for a
- "-O3" switch.</p></li>
-
- <li><p>Run the program. To make sure the program ran, execute one of the
- following commands:</p>
-
- <p><tt>% ./hello</tt></p>
-
- <p>or</p>
-
- <p><tt>% lli hello.bc</tt></p></li>
-
- <li><p>Use the <tt>llvm-dis</tt> utility to take a look at the LLVM assembly
- code:</p>
-
- <p><tt>% llvm-dis < hello.bc | less</tt><br><br></li>
-
- <li><p>Compile the program to native assembly using the LLC code
- generator:</p>
-
- <p><tt>% llc hello.bc -o hello.s</tt></p>
-
- <li><p>Assemble the native assembly language file into a program:</p>
-
- <p><b>Solaris:</b><tt>% /opt/SUNWspro/bin/cc -xarch=v9 hello.s -o hello.native</tt></p>
- <p><b>Others:</b><tt>% gcc hello.s -o hello.native</tt></p>
-
- <li><p>Execute the native code program:</p>
-
- <p><tt>% ./hello.native</tt></p></li>
-
-</ol>
-
-</div>