blob: a09559ed8e6263f5f267744b138b38bac627624c [file] [log] [blame]
Jeff Cohen7a4f03d2005-01-31 05:42:10 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3<html>
4<head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6 <title>Getting Started with LLVM System for Microsoft Visual Studio</title>
7 <link rel="stylesheet" href="llvm.css" type="text/css">
8</head>
9<body>
10
11<div class="doc_title">
12 Getting Started with the LLVM System using Microsoft Visual Studio
13</div>
14
15<ul>
16 <li><a href="#overview">Overview</a>
17 <li><a href="#quickstart">Getting Started Quickly (A Summary)</a>
18 <li><a href="#requirements">Requirements</a>
19 <ol>
20 <li><a href="#hardware">Hardware</a>
21 <li><a href="#software">Software</a>
22 </ol></li>
23
24 <li><a href="#starting">Getting Started with LLVM</a>
25 <ol>
26 <li><a href="#terminology">Terminology and Notation</a>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000027 <li><a href="#objfiles">The Location of LLVM Object Files</a>
28 </ol></li>
29
30 <li><a href="#tutorial">An Example Using the LLVM Tool Chain</a>
31 <li><a href="#problems">Common Problems</a>
32 <li><a href="#links">Links</a>
33</ul>
34
35<div class="doc_author">
36 <p>Written by:
Jeff Cohenb9a47d12005-02-01 15:59:28 +000037 <a href="mailto:jeffc@jolt-lang.org">Jeff Cohen</a>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000038 </p>
39</div>
40
41
42<!-- *********************************************************************** -->
43<div class="doc_section">
44 <a name="overview"><b>Overview</b></a>
45</div>
46<!-- *********************************************************************** -->
47
48<div class="doc_text">
49
50 <p>The Visual Studio port at this time is experimental. It is suitable for
51 use only if you are writing your own compiler front end or otherwise have a
52 need to dynamically generate machine code. The JIT and interpreter are
Jeff Cohenca0a9092005-03-08 03:56:50 +000053 functional, but it is currently not possible to generate assembly code which
54 is then assembled into an executable. You can indirectly create executables
55 by using the C back end.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000056
Jeff Cohenb9a47d12005-02-01 15:59:28 +000057 <p>To emphasize, there is no C/C++ front end currently available.
58 <tt>llvm-gcc</tt> is based on GCC, which cannot be bootstrapped using VC++.
59 Eventually there should be a <tt>llvm-gcc</tt> based on Cygwin or MinGW that
Gabor Greif04367bf2007-07-06 22:07:22 +000060 is usable. There is also the option of generating bitcode files on Unix and
Jeff Cohenb9a47d12005-02-01 15:59:28 +000061 copying them over to Windows. But be aware the odds of linking C++ code
62 compiled with <tt>llvm-gcc</tt> with code compiled with VC++ is essentially
63 zero.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000064
65 <p>The LLVM test suite cannot be run on the Visual Studio port at this
66 time.</p>
67
68 <p>Most of the tools build and work. <tt>llvm-db</tt> does not build at this
69 time. <tt>bugpoint</tt> does build, but does not work.
70
71 <p>Additional information about the LLVM directory structure and tool chain
72 can be found on the main <a href="GettingStarted.html">Getting Started</a>
73 page.</P>
74
75</div>
76
77<!-- *********************************************************************** -->
78<div class="doc_section">
79 <a name="quickstart"><b>Getting Started Quickly (A Summary)</b></a>
80</div>
81<!-- *********************************************************************** -->
82
83<div class="doc_text">
84
85<p>Here's the short story for getting up and running quickly with LLVM:</p>
86
87<ol>
88 <li>Read the documentation.</li>
Bill Wendling03c993a2007-09-22 09:39:19 +000089 <li>Seriously, read the documentation.</li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000090 <li>Remember that you were warned twice about reading the documentation.</li>
91
92 <li>Get the Source Code
93 <ul>
94 <li>With the distributed files:
95 <ol>
96 <li><tt>cd <i>where-you-want-llvm-to-live</i></tt>
97 <li><tt>gunzip --stdout llvm-<i>version</i>.tar.gz | tar -xvf -</tt>
Jeff Cohenb9a47d12005-02-01 15:59:28 +000098 <i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;or use WinZip</i>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +000099 <li><tt>cd llvm</tt></li>
100 </ol></li>
101
Reid Spencer669ed452007-07-09 08:04:31 +0000102 <li>With anonymous Subversion access:
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000103 <ol>
104 <li><tt>cd <i>where-you-want-llvm-to-live</i></tt></li>
Reid Spencer669ed452007-07-09 08:04:31 +0000105 <li><tt>svn co http://llvm.org/svn/llvm-project/llvm-top/trunk llvm-top
106 </tt></li>
107 <li><tt>make checkout MODULE=llvm</tt>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000108 <li><tt>cd llvm</tt></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000109 </ol></li>
110 </ul></li>
111
112 <li>Start Visual Studio
113 <ol>
114 <li>Simply double click on the solution file <tt>llvm/win32/llvm.sln</tt>.
115 </li>
116 </ol></li>
117
118 <li>Build the LLVM Suite:
119 <ol>
120 <li>Simply build the solution.</li>
121 <li>The Fibonacci project is a sample program that uses the JIT. Modify
122 the project's debugging properties to provide a numeric command line
123 argument. The program will print the corresponding fibonacci value.</li>
124 </ol></li>
125
126</ol>
127
Reid Spencer669ed452007-07-09 08:04:31 +0000128<p>It is strongly encouraged that you get the latest version from Subversion as
129changes are continually making the VS support better.</p>
Jeff Cohenb9a47d12005-02-01 15:59:28 +0000130
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000131</div>
132
133<!-- *********************************************************************** -->
134<div class="doc_section">
135 <a name="requirements"><b>Requirements</b></a>
136</div>
137<!-- *********************************************************************** -->
138
139<div class="doc_text">
140
141 <p>Before you begin to use the LLVM system, review the requirements given
142 below. This may save you some trouble by knowing ahead of time what hardware
143 and software you will need.</p>
144
145</div>
146
147<!-- ======================================================================= -->
148<div class="doc_subsection">
149 <a name="hardware"><b>Hardware</b></a>
150</div>
151
152<div class="doc_text">
153
154 <p>Any system that can adequately run Visual Studio .NET 2003 is fine. The
155 LLVM source tree and object files, libraries and executables will consume
156 approximately 3GB.</p>
157
158</div>
159
160<!-- ======================================================================= -->
161<div class="doc_subsection"><a name="software"><b>Software</b></a></div>
162<div class="doc_text">
163
164 <p>You will need Visual Studio .NET 2003. Earlier versions cannot open the
165 solution/project files. The VS 2005 beta can, but will migrate these files
166 to its own format in the process. While it should work with the VS 2005
Jeff Cohenca0a9092005-03-08 03:56:50 +0000167 beta, there are no guarantees and there is no support for it at this time.
168 It has been reported that VC++ Express also works.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000169
Jeff Cohena0887342005-10-30 21:00:24 +0000170 <p>If you plan to modify any .y or .l files, you will need to have bison
171 and/or flex installed where Visual Studio can find them. Otherwise, you do
172 not need them and the pre-generated files that come with the source tree
173 will be used.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000174
Chris Lattnerc2bb1232007-11-14 07:04:44 +0000175 <p>
176 Do not install the LLVM directory tree into a path containing spaces (e.g.
177 C:\Documents and Settings\...) as the configure step will fail.</p>
178
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000179</div>
180
181<!-- *********************************************************************** -->
182<div class="doc_section">
183 <a name="starting"><b>Getting Started with LLVM</b></a>
184</div>
185<!-- *********************************************************************** -->
186
187<div class="doc_text">
188
189<p>The remainder of this guide is meant to get you up and running with
190LLVM using Visual Studio and to give you some basic information about the LLVM
191environment.</p>
192
193</div>
194
195<!-- ======================================================================= -->
196<div class="doc_subsection">
197 <a name="terminology">Terminology and Notation</a>
198</div>
199
200<div class="doc_text">
201
202<p>Throughout this manual, the following names are used to denote paths
203specific to the local system and working environment. <i>These are not
204environment variables you need to set but just strings used in the rest
205of this document below</i>. In any of the examples below, simply replace
206each of these names with the appropriate pathname on your local system.
207All these paths are absolute:</p>
208
209<dl>
Bill Wendling03c993a2007-09-22 09:39:19 +0000210 <dt>SRC_ROOT</dt>
211 <dd><p>This is the top level directory of the LLVM source tree.</p></dd>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000212
Bill Wendling03c993a2007-09-22 09:39:19 +0000213 <dt>OBJ_ROOT</dt>
214 <dd><p>This is the top level directory of the LLVM object tree (i.e. the
215 tree where object files and compiled programs will be placed. It is
216 fixed at SRC_ROOT/win32).</p></dd>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000217</dl>
218
219</div>
220
221<!-- ======================================================================= -->
222<div class="doc_subsection">
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000223 <a name="objfiles">The Location of LLVM Object Files</a>
224</div>
225
226<div class="doc_text">
227
228 <p>The object files are placed under <tt>OBJ_ROOT/Debug</tt> for debug builds
229 and <tt>OBJ_ROOT/Release</tt> for release (optimized) builds. These include
Bill Wendling03c993a2007-09-22 09:39:19 +0000230 both executables and libararies that your application can link against.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000231
232 <p>The files that <tt>configure</tt> would create when building on Unix are
233 created by the <tt>Configure</tt> project and placed in
234 <tt>OBJ_ROOT/llvm</tt>. You application must have OBJ_ROOT in its include
Bill Wendling03c993a2007-09-22 09:39:19 +0000235 search path just before <tt>SRC_ROOT/include</tt>.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000236
237</div>
238
239<!-- *********************************************************************** -->
240<div class="doc_section">
241 <a name="tutorial">An Example Using the LLVM Tool Chain</a>
242</div>
243<!-- *********************************************************************** -->
244
245<div class="doc_text">
246
247<ol>
Bill Wendling03c993a2007-09-22 09:39:19 +0000248 <li><p>First, create a simple C file, name it 'hello.c':</p>
249
250<div class="doc_code">
251<pre>
252#include &lt;stdio.h&gt;
253int main() {
254 printf("hello world\n");
255 return 0;
256}
257</pre></div></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000258
Gabor Greif04367bf2007-07-06 22:07:22 +0000259 <li><p>Next, compile the C file into a LLVM bitcode file:</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000260
Bill Wendling03c993a2007-09-22 09:39:19 +0000261<div class="doc_code">
262<pre>
263% llvm-gcc -c hello.c -emit-llvm -o hello.bc
264</pre>
265</div>
266
267 <p>This will create the result file <tt>hello.bc</tt> which is the LLVM
268 bitcode that corresponds the the compiled program and the library
269 facilities that it required. You can execute this file directly using
270 <tt>lli</tt> tool, compile it to native assembly with the <tt>llc</tt>,
271 optimize or analyze it further with the <tt>opt</tt> tool, etc.</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000272
273 <p><b>Note: while you cannot do this step on Windows, you can do it on a
Bill Wendling03c993a2007-09-22 09:39:19 +0000274 Unix system and transfer <tt>hello.bc</tt> to Windows. Important:
275 transfer as a binary file!</b></p></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000276
Jeff Cohena0887342005-10-30 21:00:24 +0000277 <li><p>Run the program using the just-in-time compiler:</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000278
Bill Wendling03c993a2007-09-22 09:39:19 +0000279<div class="doc_code">
280<pre>
281% lli hello.bc
282</pre>
283</div>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000284
Jeff Cohen3c8dfcd2007-03-28 20:27:51 +0000285 <p>Note: this will only work for trivial C programs. Non-trivial programs
Bill Wendling03c993a2007-09-22 09:39:19 +0000286 (and any C++ program) will have dependencies on the GCC runtime that
287 won't be satisfied by the Microsoft runtime libraries.</p></li>
Jeff Cohen3c8dfcd2007-03-28 20:27:51 +0000288
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000289 <li><p>Use the <tt>llvm-dis</tt> utility to take a look at the LLVM assembly
290 code:</p>
291
Bill Wendling03c993a2007-09-22 09:39:19 +0000292<div class="doc_code">
293<pre>
294% llvm-dis &lt; hello.bc | more
295</pre>
296</div></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000297
Jeff Cohena0887342005-10-30 21:00:24 +0000298 <li><p>Compile the program to C using the LLC code generator:</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000299
Bill Wendling03c993a2007-09-22 09:39:19 +0000300<div class="doc_code">
301<pre>
302% llc -march=c hello.bc
303</pre>
304</div></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000305
Jeff Cohena0887342005-10-30 21:00:24 +0000306 <li><p>Compile to binary using Microsoft C:</p>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000307
Bill Wendling03c993a2007-09-22 09:39:19 +0000308<div class="doc_code">
309<pre>
310% cl hello.cbe.c
311</pre>
312</div>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000313
Jeff Cohen3c8dfcd2007-03-28 20:27:51 +0000314 <p>Note: this will only work for trivial C programs. Non-trivial programs
315 (and any C++ program) will have dependencies on the GCC runtime that
Bill Wendling03c993a2007-09-22 09:39:19 +0000316 won't be satisfied by the Microsoft runtime libraries.</p></li>
Jeff Cohen3c8dfcd2007-03-28 20:27:51 +0000317
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000318 <li><p>Execute the native code program:</p>
319
Bill Wendling03c993a2007-09-22 09:39:19 +0000320<div class="doc_code">
321<pre>
322% hello.cbe.exe
323</pre>
324</div></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000325</ol>
326
327</div>
328
329<!-- *********************************************************************** -->
330<div class="doc_section">
331 <a name="problems">Common Problems</a>
332</div>
333<!-- *********************************************************************** -->
334
335<div class="doc_text">
336
337<p>If you are having problems building or using LLVM, or if you have any other
338general questions about LLVM, please consult the <a href="FAQ.html">Frequently
339Asked Questions</a> page.</p>
340
341</div>
342
343<!-- *********************************************************************** -->
344<div class="doc_section">
345 <a name="links">Links</a>
346</div>
347<!-- *********************************************************************** -->
348
349<div class="doc_text">
350
351<p>This document is just an <b>introduction</b> to how to use LLVM to do
352some simple things... there are many more interesting and complicated things
353that you can do that aren't documented here (but we'll gladly accept a patch
354if you want to write something up!). For more information about LLVM, check
355out:</p>
356
357<ul>
Reid Spencer05fe4b02006-03-14 05:39:39 +0000358 <li><a href="http://llvm.org/">LLVM homepage</a></li>
359 <li><a href="http://llvm.org/doxygen/">LLVM doxygen tree</a></li>
360 <li><a href="http://llvm.org/docs/Projects.html">Starting a Project
Bill Wendling03c993a2007-09-22 09:39:19 +0000361 that Uses LLVM</a></li>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000362</ul>
363
364</div>
365
366<!-- *********************************************************************** -->
367
368<hr>
369<address>
370 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
371 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
372 <a href="http://validator.w3.org/check/referer"><img
373 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
374
Jeff Cohenb9a47d12005-02-01 15:59:28 +0000375 <a href="mailto:jeffc@jolt-lang.org">Jeff Cohen</a><br>
Reid Spencer05fe4b02006-03-14 05:39:39 +0000376 <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
Jeff Cohen7a4f03d2005-01-31 05:42:10 +0000377 Last modified: $Date$
378</address>
379</body>
380</html>