Jeff Cohen | 7a4f03d | 2005-01-31 05:42:10 +0000 | [diff] [blame] | 1 | <!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 Cohen | 7a4f03d | 2005-01-31 05:42:10 +0000 | [diff] [blame] | 27 | <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 Cohen | b9a47d1 | 2005-02-01 15:59:28 +0000 | [diff] [blame^] | 37 | <a href="mailto:jeffc@jolt-lang.org">Jeff Cohen</a> |
Jeff Cohen | 7a4f03d | 2005-01-31 05:42:10 +0000 | [diff] [blame] | 38 | </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 |
| 53 | functional, but it is currently not possible to directly generate an |
| 54 | executable file. You can do so indirectly by using the C back end.</p> |
| 55 | |
Jeff Cohen | b9a47d1 | 2005-02-01 15:59:28 +0000 | [diff] [blame^] | 56 | <p>To emphasize, there is no C/C++ front end currently available. |
| 57 | <tt>llvm-gcc</tt> is based on GCC, which cannot be bootstrapped using VC++. |
| 58 | Eventually there should be a <tt>llvm-gcc</tt> based on Cygwin or MinGW that |
| 59 | is usable. There is also the option of generating bytecode files on Unix and |
| 60 | copying them over to Windows. But be aware the odds of linking C++ code |
| 61 | compiled with <tt>llvm-gcc</tt> with code compiled with VC++ is essentially |
| 62 | zero.</p> |
Jeff Cohen | 7a4f03d | 2005-01-31 05:42:10 +0000 | [diff] [blame] | 63 | |
| 64 | <p>The LLVM test suite cannot be run on the Visual Studio port at this |
| 65 | time.</p> |
| 66 | |
| 67 | <p>Most of the tools build and work. <tt>llvm-db</tt> does not build at this |
| 68 | time. <tt>bugpoint</tt> does build, but does not work. |
| 69 | |
| 70 | <p>Additional information about the LLVM directory structure and tool chain |
| 71 | can be found on the main <a href="GettingStarted.html">Getting Started</a> |
| 72 | page.</P> |
| 73 | |
| 74 | </div> |
| 75 | |
| 76 | <!-- *********************************************************************** --> |
| 77 | <div class="doc_section"> |
| 78 | <a name="quickstart"><b>Getting Started Quickly (A Summary)</b></a> |
| 79 | </div> |
| 80 | <!-- *********************************************************************** --> |
| 81 | |
| 82 | <div class="doc_text"> |
| 83 | |
| 84 | <p>Here's the short story for getting up and running quickly with LLVM:</p> |
| 85 | |
| 86 | <ol> |
| 87 | <li>Read the documentation.</li> |
| 88 | <li>Read the documentation.</li> |
| 89 | <li>Remember that you were warned twice about reading the documentation.</li> |
| 90 | |
| 91 | <li>Get the Source Code |
| 92 | <ul> |
| 93 | <li>With the distributed files: |
| 94 | <ol> |
| 95 | <li><tt>cd <i>where-you-want-llvm-to-live</i></tt> |
| 96 | <li><tt>gunzip --stdout llvm-<i>version</i>.tar.gz | tar -xvf -</tt> |
Jeff Cohen | b9a47d1 | 2005-02-01 15:59:28 +0000 | [diff] [blame^] | 97 | <i> or use WinZip</i> |
Jeff Cohen | 7a4f03d | 2005-01-31 05:42:10 +0000 | [diff] [blame] | 98 | <li><tt>cd llvm</tt></li> |
| 99 | </ol></li> |
| 100 | |
| 101 | <li>With anonymous CVS access (or use a <a href="#mirror">mirror</a>): |
| 102 | <ol> |
| 103 | <li><tt>cd <i>where-you-want-llvm-to-live</i></tt></li> |
| 104 | <li><tt>cvs -d |
| 105 | :pserver:anon@llvm-cvs.cs.uiuc.edu:/var/cvs/llvm login</tt></li> |
| 106 | <li>Hit the return key when prompted for the password. |
| 107 | <li><tt>cvs -z3 -d :pserver:anon@llvm-cvs.cs.uiuc.edu:/var/cvs/llvm |
| 108 | co llvm</tt></li> |
| 109 | <li><tt>cd llvm</tt></li> |
| 110 | <li><tt>cvs up -P -d</tt></li> |
| 111 | </ol></li> |
| 112 | </ul></li> |
| 113 | |
| 114 | <li>Start Visual Studio |
| 115 | <ol> |
| 116 | <li>Simply double click on the solution file <tt>llvm/win32/llvm.sln</tt>. |
| 117 | </li> |
| 118 | </ol></li> |
| 119 | |
| 120 | <li>Build the LLVM Suite: |
| 121 | <ol> |
| 122 | <li>Simply build the solution.</li> |
| 123 | <li>The Fibonacci project is a sample program that uses the JIT. Modify |
| 124 | the project's debugging properties to provide a numeric command line |
| 125 | argument. The program will print the corresponding fibonacci value.</li> |
| 126 | </ol></li> |
| 127 | |
| 128 | </ol> |
| 129 | |
Jeff Cohen | b9a47d1 | 2005-02-01 15:59:28 +0000 | [diff] [blame^] | 130 | <p>It is strongly encouraged that you get the latest version from CVS. Much |
| 131 | progress has been made since the 1.4 release.</p> |
| 132 | |
Jeff Cohen | 7a4f03d | 2005-01-31 05:42:10 +0000 | [diff] [blame] | 133 | </div> |
| 134 | |
| 135 | <!-- *********************************************************************** --> |
| 136 | <div class="doc_section"> |
| 137 | <a name="requirements"><b>Requirements</b></a> |
| 138 | </div> |
| 139 | <!-- *********************************************************************** --> |
| 140 | |
| 141 | <div class="doc_text"> |
| 142 | |
| 143 | <p>Before you begin to use the LLVM system, review the requirements given |
| 144 | below. This may save you some trouble by knowing ahead of time what hardware |
| 145 | and software you will need.</p> |
| 146 | |
| 147 | </div> |
| 148 | |
| 149 | <!-- ======================================================================= --> |
| 150 | <div class="doc_subsection"> |
| 151 | <a name="hardware"><b>Hardware</b></a> |
| 152 | </div> |
| 153 | |
| 154 | <div class="doc_text"> |
| 155 | |
| 156 | <p>Any system that can adequately run Visual Studio .NET 2003 is fine. The |
| 157 | LLVM source tree and object files, libraries and executables will consume |
| 158 | approximately 3GB.</p> |
| 159 | |
| 160 | </div> |
| 161 | |
| 162 | <!-- ======================================================================= --> |
| 163 | <div class="doc_subsection"><a name="software"><b>Software</b></a></div> |
| 164 | <div class="doc_text"> |
| 165 | |
| 166 | <p>You will need Visual Studio .NET 2003. Earlier versions cannot open the |
| 167 | solution/project files. The VS 2005 beta can, but will migrate these files |
| 168 | to its own format in the process. While it should work with the VS 2005 |
| 169 | beta, there are no guarantees and there is no support for it at this time.</p> |
| 170 | |
| 171 | <p>You will also need several open source packages: bison, flex, and sed. |
| 172 | These must be installed in <tt>llvm/win32/tools</tt>. These can be found at |
| 173 | <a href="http://gnuwin32.sourceforge.net/">http://gnuwin32.sourceforge.net/ |
| 174 | </a>. Bison prefers that m4 be in the path. You must add it to the Visual |
| 175 | Studio configuration under the menu Options -> Projects -> VC++ |
| 176 | Directories. Alternatively, you can set the environment variable <tt>M4</tt> |
| 177 | to point to <tt>m4</tt> executable.</p> |
| 178 | |
| 179 | </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 |
| 190 | LLVM using Visual Studio and to give you some basic information about the LLVM |
| 191 | environment.</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 |
| 203 | specific to the local system and working environment. <i>These are not |
| 204 | environment variables you need to set but just strings used in the rest |
| 205 | of this document below</i>. In any of the examples below, simply replace |
| 206 | each of these names with the appropriate pathname on your local system. |
| 207 | All these paths are absolute:</p> |
| 208 | |
| 209 | <dl> |
| 210 | <dt>SRC_ROOT |
| 211 | <dd> |
| 212 | This is the top level directory of the LLVM source tree. |
| 213 | <p> |
| 214 | |
| 215 | <dt>OBJ_ROOT |
| 216 | <dd> |
| 217 | This is the top level directory of the LLVM object tree (i.e. the |
| 218 | tree where object files and compiled programs will be placed. It |
| 219 | is fixed at SRC_ROOT/win32). |
| 220 | <p> |
| 221 | </dl> |
| 222 | |
| 223 | </div> |
| 224 | |
| 225 | <!-- ======================================================================= --> |
| 226 | <div class="doc_subsection"> |
Jeff Cohen | 7a4f03d | 2005-01-31 05:42:10 +0000 | [diff] [blame] | 227 | <a name="objfiles">The Location of LLVM Object Files</a> |
| 228 | </div> |
| 229 | |
| 230 | <div class="doc_text"> |
| 231 | |
| 232 | <p>The object files are placed under <tt>OBJ_ROOT/Debug</tt> for debug builds |
| 233 | and <tt>OBJ_ROOT/Release</tt> for release (optimized) builds. These include |
| 234 | both executables and libararies that your application can link against. |
| 235 | |
| 236 | <p>The files that <tt>configure</tt> would create when building on Unix are |
| 237 | created by the <tt>Configure</tt> project and placed in |
| 238 | <tt>OBJ_ROOT/llvm</tt>. You application must have OBJ_ROOT in its include |
| 239 | search path just before <tt>SRC_ROOT/include</tt>. |
| 240 | |
| 241 | </div> |
| 242 | |
| 243 | <!-- *********************************************************************** --> |
| 244 | <div class="doc_section"> |
| 245 | <a name="tutorial">An Example Using the LLVM Tool Chain</a> |
| 246 | </div> |
| 247 | <!-- *********************************************************************** --> |
| 248 | |
| 249 | <div class="doc_text"> |
| 250 | |
| 251 | <ol> |
| 252 | <li>First, create a simple C file, name it 'hello.c': |
| 253 | <pre> |
| 254 | #include <stdio.h> |
| 255 | int main() { |
| 256 | printf("hello world\n"); |
| 257 | return 0; |
| 258 | } |
| 259 | </pre></li> |
| 260 | |
| 261 | <li><p>Next, compile the C file into a LLVM bytecode file:</p> |
| 262 | <p><tt>% llvm-gcc hello.c -o hello</tt></p> |
| 263 | |
| 264 | <p>Note that you should have already built the tools and they have to be |
| 265 | in your path, at least <tt>gccas</tt> and <tt>gccld</tt>.</p> |
| 266 | |
| 267 | <p>This will create two result files: <tt>hello</tt> and |
| 268 | <tt>hello.bc</tt>. The <tt>hello.bc</tt> is the LLVM bytecode that |
| 269 | corresponds the the compiled program and the library facilities that it |
| 270 | required. <tt>hello</tt> is a simple shell script that runs the bytecode |
| 271 | file with <tt>lli</tt>, making the result directly executable. Note that |
| 272 | all LLVM optimizations are enabled by default, so there is no need for a |
| 273 | "-O3" switch.</p> |
| 274 | |
| 275 | <p><b>Note: while you cannot do this step on Windows, you can do it on a |
| 276 | Unix system and transfer <tt>hello.bc</tt> to Windows.</b></p></li> |
| 277 | |
| 278 | <li><p>Run the program. To make sure the program ran, execute the |
| 279 | following command:</p> |
| 280 | |
| 281 | <p><tt>% lli hello.bc</tt></p></li> |
| 282 | |
| 283 | <li><p>Use the <tt>llvm-dis</tt> utility to take a look at the LLVM assembly |
| 284 | code:</p> |
| 285 | |
| 286 | <p><tt>% llvm-dis < hello.bc | less</tt><p></li> |
| 287 | |
| 288 | <li><p>Compile the program to native assembly using the LLC code |
| 289 | generator:</p> |
| 290 | |
| 291 | <p><tt>% llc hello.bc -o hello.s</tt></p> |
| 292 | |
| 293 | <li><p>Assemble the native assembly language file into a program:</p> |
| 294 | |
| 295 | <p><b>Not currently possible, but eventually will use <tt>NASMW</tt>.</b></p> |
| 296 | |
| 297 | <li><p>Execute the native code program:</p> |
| 298 | |
| 299 | <p><tt>% ./hello.native</tt></p></li> |
| 300 | |
| 301 | </ol> |
| 302 | |
| 303 | </div> |
| 304 | |
| 305 | <!-- *********************************************************************** --> |
| 306 | <div class="doc_section"> |
| 307 | <a name="problems">Common Problems</a> |
| 308 | </div> |
| 309 | <!-- *********************************************************************** --> |
| 310 | |
| 311 | <div class="doc_text"> |
| 312 | |
| 313 | <p>If you are having problems building or using LLVM, or if you have any other |
| 314 | general questions about LLVM, please consult the <a href="FAQ.html">Frequently |
| 315 | Asked Questions</a> page.</p> |
| 316 | |
| 317 | </div> |
| 318 | |
| 319 | <!-- *********************************************************************** --> |
| 320 | <div class="doc_section"> |
| 321 | <a name="links">Links</a> |
| 322 | </div> |
| 323 | <!-- *********************************************************************** --> |
| 324 | |
| 325 | <div class="doc_text"> |
| 326 | |
| 327 | <p>This document is just an <b>introduction</b> to how to use LLVM to do |
| 328 | some simple things... there are many more interesting and complicated things |
| 329 | that you can do that aren't documented here (but we'll gladly accept a patch |
| 330 | if you want to write something up!). For more information about LLVM, check |
| 331 | out:</p> |
| 332 | |
| 333 | <ul> |
| 334 | <li><a href="http://llvm.cs.uiuc.edu/">LLVM homepage</a></li> |
| 335 | <li><a href="http://llvm.cs.uiuc.edu/doxygen/">LLVM doxygen tree</a></li> |
| 336 | <li><a href="http://llvm.cs.uiuc.edu/docs/Projects.html">Starting a Project |
| 337 | that Uses LLVM</a></li> |
| 338 | </ul> |
| 339 | |
| 340 | </div> |
| 341 | |
| 342 | <!-- *********************************************************************** --> |
| 343 | |
| 344 | <hr> |
| 345 | <address> |
| 346 | <a href="http://jigsaw.w3.org/css-validator/check/referer"><img |
| 347 | src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a> |
| 348 | <a href="http://validator.w3.org/check/referer"><img |
| 349 | src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a> |
| 350 | |
Jeff Cohen | b9a47d1 | 2005-02-01 15:59:28 +0000 | [diff] [blame^] | 351 | <a href="mailto:jeffc@jolt-lang.org">Jeff Cohen</a><br> |
Jeff Cohen | 7a4f03d | 2005-01-31 05:42:10 +0000 | [diff] [blame] | 352 | <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br> |
| 353 | Last modified: $Date$ |
| 354 | </address> |
| 355 | </body> |
| 356 | </html> |