Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +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> |
Benjamin Kramer | 665a8dc | 2012-01-15 15:26:07 +0000 | [diff] [blame] | 5 | <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 6 | <title>Clang - Getting Started</title> |
Benjamin Kramer | 665a8dc | 2012-01-15 15:26:07 +0000 | [diff] [blame] | 7 | <link type="text/css" rel="stylesheet" href="menu.css"> |
| 8 | <link type="text/css" rel="stylesheet" href="content.css"> |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 9 | </head> |
| 10 | <body> |
| 11 | |
| 12 | <!--#include virtual="menu.html.incl"--> |
| 13 | |
| 14 | <div id="content"> |
| 15 | |
| 16 | <h1>Getting Started: Building and Running Clang</h1> |
| 17 | |
Ted Kremenek | 9b16da3 | 2009-03-27 16:32:57 +0000 | [diff] [blame] | 18 | <p>This page gives you the shortest path to checking out Clang and demos a few |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 19 | options. This should get you up and running with the minimum of muss and fuss. |
| 20 | If you like what you see, please consider <a href="get_involved.html">getting |
Chris Lattner | d2c1c60 | 2009-11-09 03:18:18 +0000 | [diff] [blame] | 21 | involved</a> with the Clang community. If you run into problems, please file |
Douglas Gregor | 9ff3e66 | 2010-10-07 20:20:57 +0000 | [diff] [blame] | 22 | bugs in <a href="http://llvm.org/bugs/">LLVM Bugzilla</a>.</p> |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 23 | |
Daniel Dunbar | fa8e11b | 2010-11-02 22:34:04 +0000 | [diff] [blame] | 24 | <h2 id="download">Release Clang Versions</h2> |
| 25 | |
| 26 | <p>Clang has been released as part of regular LLVM releases since LLVM 2.6. You |
| 27 | can download the release versions |
| 28 | from <a href="http://llvm.org/releases/">http://llvm.org/releases/</a>.</p> |
| 29 | |
Ted Kremenek | 9b16da3 | 2009-03-27 16:32:57 +0000 | [diff] [blame] | 30 | <h2 id="build">Building Clang and Working with the Code</h2> |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 31 | |
Eli Friedman | d1e1ef3 | 2009-08-03 19:42:28 +0000 | [diff] [blame] | 32 | <h3 id="buildNix">On Unix-like Systems</h3> |
| 33 | |
Ted Kremenek | 9b16da3 | 2009-03-27 16:32:57 +0000 | [diff] [blame] | 34 | <p>If you would like to check out and build Clang, the current procedure is as |
| 35 | follows:</p> |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 36 | |
| 37 | <ol> |
Anton Korobeynikov | 1816e48 | 2009-08-06 13:00:08 +0000 | [diff] [blame] | 38 | <li>Get the required tools. |
| 39 | <ul> |
| 40 | <li>See |
| 41 | <a href="http://llvm.org/docs/GettingStarted.html#requirements"> |
| 42 | Getting Started with the LLVM System - Requirements</a>.</li> |
| 43 | <li>Note also that Python is needed for running the test suite. |
| 44 | Get it at: <a href="http://www.python.org/download"> |
| 45 | http://www.python.org/download</a></li> |
| 46 | </ul> |
| 47 | |
Benjamin Kramer | 665a8dc | 2012-01-15 15:26:07 +0000 | [diff] [blame] | 48 | <li>Checkout LLVM: |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 49 | <ul> |
Chris Lattner | 357f7ce | 2009-08-20 06:17:11 +0000 | [diff] [blame] | 50 | <li>Change directory to where you want the llvm directory placed.</li> |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 51 | <li><tt>svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm</tt></li> |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 52 | </ul> |
Benjamin Kramer | 665a8dc | 2012-01-15 15:26:07 +0000 | [diff] [blame] | 53 | </li> |
| 54 | <li>Checkout Clang: |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 55 | <ul> |
Chris Lattner | 357f7ce | 2009-08-20 06:17:11 +0000 | [diff] [blame] | 56 | <li><tt>cd llvm/tools</tt> |
| 57 | <li><tt>svn co http://llvm.org/svn/llvm-project/cfe/trunk clang</tt></li> |
| 58 | </ul> |
Benjamin Kramer | 665a8dc | 2012-01-15 15:26:07 +0000 | [diff] [blame] | 59 | </li> |
| 60 | <li>Checkout Compiler-RT: |
Daniel Dunbar | 078f859 | 2011-12-07 03:04:42 +0000 | [diff] [blame] | 61 | <ul> |
Benjamin Kramer | bf020bb | 2012-02-09 16:04:50 +0000 | [diff] [blame] | 62 | <li><tt>cd ../..</tt> (back to where you started)</li> |
Daniel Dunbar | 078f859 | 2011-12-07 03:04:42 +0000 | [diff] [blame] | 63 | <li><tt>cd llvm/projects</tt> |
| 64 | <li><tt>svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk |
| 65 | compiler-rt</tt></li> |
| 66 | </ul> |
Benjamin Kramer | 665a8dc | 2012-01-15 15:26:07 +0000 | [diff] [blame] | 67 | </li> |
| 68 | <li>Build LLVM and Clang: |
Chris Lattner | 357f7ce | 2009-08-20 06:17:11 +0000 | [diff] [blame] | 69 | <ul> |
Rafael Espindola | fa5fa97 | 2010-10-29 22:05:17 +0000 | [diff] [blame] | 70 | <li><tt>cd ../..</tt> (back to where you started)</li> |
| 71 | <li><tt>mkdir build</tt> (for building without polluting the source dir) |
| 72 | </li> |
| 73 | <li><tt>cd build</tt></li> |
| 74 | <li><tt>../llvm/configure</tt></li> |
Chris Lattner | 357f7ce | 2009-08-20 06:17:11 +0000 | [diff] [blame] | 75 | <li><tt>make</tt></li> |
| 76 | <li>This builds both LLVM and Clang for debug mode.</li> |
| 77 | <li>Note: For subsequent Clang development, you can just do make at the |
| 78 | clang directory level.</li> |
Benjamin Kramer | 665a8dc | 2012-01-15 15:26:07 +0000 | [diff] [blame] | 79 | <li>It is also possible to use CMake instead of the makefiles. With CMake |
| 80 | it is also possible to generate project files for several IDEs: Eclipse |
| 81 | CDT4, CodeBlocks, Qt-Creator (use the CodeBlocks generator), KDevelop3.</li> |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 82 | </ul> |
Benjamin Kramer | 665a8dc | 2012-01-15 15:26:07 +0000 | [diff] [blame] | 83 | </li> |
Chris Lattner | 7878178 | 2010-05-06 21:57:57 +0000 | [diff] [blame] | 84 | |
Ted Kremenek | 9b16da3 | 2009-03-27 16:32:57 +0000 | [diff] [blame] | 85 | <li>If you intend to work on Clang C++ support, you may need to tell it how |
| 86 | to find your C++ standard library headers. If Clang cannot find your |
Benjamin Kramer | 665a8dc | 2012-01-15 15:26:07 +0000 | [diff] [blame] | 87 | system libstdc++ headers, please follow these instructions: |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 88 | <ul> |
Gabor Greif | 7435082 | 2010-03-29 21:36:06 +0000 | [diff] [blame] | 89 | <li>'<tt>gcc -v -x c++ /dev/null -fsyntax-only</tt>' to get the |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 90 | path.</li> |
| 91 | <li>Look for the comment "FIXME: temporary hack: |
Chris Lattner | ca8c49f | 2009-03-10 16:01:44 +0000 | [diff] [blame] | 92 | hard-coded paths" in <tt>clang/lib/Frontend/InitHeaderSearch.cpp</tt> and |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 93 | change the lines below to include that path.</li> |
| 94 | </ul> |
Benjamin Kramer | 665a8dc | 2012-01-15 15:26:07 +0000 | [diff] [blame] | 95 | </li> |
| 96 | <li>Try it out (assuming you add llvm/Debug+Asserts/bin to your path): |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 97 | <ul> |
Daniel Dunbar | dd63b28 | 2009-12-11 23:04:35 +0000 | [diff] [blame] | 98 | <li><tt>clang --help</tt></li> |
| 99 | <li><tt>clang file.c -fsyntax-only</tt> (check for correctness)</li> |
| 100 | <li><tt>clang file.c -S -emit-llvm -o -</tt> (print out unoptimized llvm code)</li> |
| 101 | <li><tt>clang file.c -S -emit-llvm -o - -O3</tt></li> |
| 102 | <li><tt>clang file.c -S -O3 -o -</tt> (output native machine code)</li> |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 103 | </ul> |
Benjamin Kramer | 665a8dc | 2012-01-15 15:26:07 +0000 | [diff] [blame] | 104 | </li> |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 105 | </ol> |
| 106 | |
Ted Kremenek | 9b16da3 | 2009-03-27 16:32:57 +0000 | [diff] [blame] | 107 | <p>Note that the C front-end uses LLVM, but does not depend on llvm-gcc. If you |
| 108 | encounter problems with building Clang, make sure you have the latest SVN |
| 109 | version of LLVM. LLVM contains support libraries for Clang that will be updated |
| 110 | as well as development on Clang progresses.</p> |
Ted Kremenek | 675a9ba | 2008-02-08 07:32:26 +0000 | [diff] [blame] | 111 | |
Ted Kremenek | 9b16da3 | 2009-03-27 16:32:57 +0000 | [diff] [blame] | 112 | <h3>Simultaneously Building Clang and LLVM:</h3> |
Eric Christopher | 562b4f3 | 2008-02-08 07:10:48 +0000 | [diff] [blame] | 113 | |
Ted Kremenek | 9b16da3 | 2009-03-27 16:32:57 +0000 | [diff] [blame] | 114 | <p>Once you have checked out Clang into the llvm source tree it will build along |
| 115 | with the rest of <tt>llvm</tt>. To build all of LLVM and Clang together all at |
| 116 | once simply run <tt>make</tt> from the root LLVM directory.</p> |
| 117 | |
| 118 | <p><em>Note:</em> Observe that Clang is technically part of a separate |
| 119 | Subversion repository. As mentioned above, the latest Clang sources are tied to |
| 120 | the latest sources in the LLVM tree. You can update your toplevel LLVM project |
| 121 | and all (possibly unrelated) projects inside it with <tt><b>make |
| 122 | update</b></tt>. This will run <tt>svn update</tt> on all subdirectories related |
| 123 | to subversion. </p> |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 124 | |
Eli Friedman | d1e1ef3 | 2009-08-03 19:42:28 +0000 | [diff] [blame] | 125 | <h3 id="buildWindows">Using Visual Studio</h3> |
| 126 | |
| 127 | <p>The following details setting up for and building Clang on Windows using |
| 128 | Visual Studio:</p> |
| 129 | |
| 130 | <ol> |
Benjamin Kramer | 665a8dc | 2012-01-15 15:26:07 +0000 | [diff] [blame] | 131 | <li>Get the required tools: |
Eli Friedman | d1e1ef3 | 2009-08-03 19:42:28 +0000 | [diff] [blame] | 132 | <ul> |
| 133 | <li><b>Subversion</b>. Source code control program. Get it from: |
| 134 | <a href="http://subversion.tigris.org/getting.html"> |
| 135 | http://subversion.tigris.org/getting.html</a></li> |
| 136 | <li><b>cmake</b>. This is used for generating Visual Studio solution and |
| 137 | project files. Get it from: |
| 138 | <a href="http://www.cmake.org/cmake/resources/software.html"> |
| 139 | http://www.cmake.org/cmake/resources/software.html</a></li> |
Chandler Carruth | 245a538 | 2011-11-16 19:29:07 +0000 | [diff] [blame] | 140 | <li><b>Visual Studio 2008 or 2010</b></li> |
Chris Lattner | 357f7ce | 2009-08-20 06:17:11 +0000 | [diff] [blame] | 141 | <li><b>Python</b>. This is needed only if you will be running the tests |
Eli Friedman | d1e1ef3 | 2009-08-03 19:42:28 +0000 | [diff] [blame] | 142 | (which is essential, if you will be developing for clang). |
| 143 | Get it from: |
NAKAMURA Takumi | cc8770a | 2011-03-27 02:04:21 +0000 | [diff] [blame] | 144 | <a href="http://www.python.org/download/"> |
| 145 | http://www.python.org/download/</a></li> |
Chris Lattner | 357f7ce | 2009-08-20 06:17:11 +0000 | [diff] [blame] | 146 | <li><b>GnuWin32 tools</b> |
| 147 | These are also necessary for running the tests. |
| 148 | (Note that the grep from MSYS or Cygwin doesn't work with the tests |
| 149 | because of embedded double-quotes in the search strings. The GNU |
| 150 | grep does work in this case.) |
NAKAMURA Takumi | cc8770a | 2011-03-27 02:04:21 +0000 | [diff] [blame] | 151 | Get them from <a href="http://getgnuwin32.sourceforge.net/"> |
| 152 | http://getgnuwin32.sourceforge.net/</a>.</li> |
Eli Friedman | d1e1ef3 | 2009-08-03 19:42:28 +0000 | [diff] [blame] | 153 | </ul> |
Benjamin Kramer | 665a8dc | 2012-01-15 15:26:07 +0000 | [diff] [blame] | 154 | </li> |
Eli Friedman | d1e1ef3 | 2009-08-03 19:42:28 +0000 | [diff] [blame] | 155 | |
Benjamin Kramer | 665a8dc | 2012-01-15 15:26:07 +0000 | [diff] [blame] | 156 | <li>Checkout LLVM: |
Eli Friedman | d1e1ef3 | 2009-08-03 19:42:28 +0000 | [diff] [blame] | 157 | <ul> |
| 158 | <li><tt>svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm</tt></li> |
| 159 | </ul> |
Benjamin Kramer | 665a8dc | 2012-01-15 15:26:07 +0000 | [diff] [blame] | 160 | </li> |
| 161 | <li>Checkout Clang: |
Eli Friedman | d1e1ef3 | 2009-08-03 19:42:28 +0000 | [diff] [blame] | 162 | <ul> |
| 163 | <li><tt>cd llvm\tools</tt> |
| 164 | <li><tt>svn co http://llvm.org/svn/llvm-project/cfe/trunk clang</tt></li> |
| 165 | </ul> |
Benjamin Kramer | 665a8dc | 2012-01-15 15:26:07 +0000 | [diff] [blame] | 166 | </li> |
| 167 | <li>Run cmake to generate the Visual Studio solution and project files: |
Eli Friedman | d1e1ef3 | 2009-08-03 19:42:28 +0000 | [diff] [blame] | 168 | <ul> |
Michael J. Spencer | 0de5786 | 2010-12-16 22:01:14 +0000 | [diff] [blame] | 169 | <li><tt>cd ..\..</tt> (back to where you started)</li> |
| 170 | <li><tt>mkdir build</tt> (for building without polluting the source dir)</li> |
| 171 | <li><tt>cd build</tt></li> |
Chandler Carruth | 245a538 | 2011-11-16 19:29:07 +0000 | [diff] [blame] | 172 | <li>If you are using Visual Studio 2008: <tt>cmake -G "Visual Studio 9 2008" ..\llvm</tt></li> |
Michael J. Spencer | 0de5786 | 2010-12-16 22:01:14 +0000 | [diff] [blame] | 173 | <li>Or if you are using Visual Studio 2010: <tt>cmake -G "Visual Studio 10" ..\llvm</tt></li> |
John Thompson | 13eb565 | 2011-04-06 18:22:12 +0000 | [diff] [blame] | 174 | <li>By default, cmake will target LLVM to X86. If you want all targets |
| 175 | (needed if you want to run the LLVM tests), add the <tt>-DLLVM_TARGETS_TO_BUILD=all</tt> option to the |
| 176 | cmake command line. Or specify a target from the LLVM_TARGETS_TO_BUILD |
| 177 | definition in CMakeLists.txt.</li> |
| 178 | <li>See the <a href="http://www.llvm.org/docs/CMake.html">LLVM CMake guide</a> for |
| 179 | more information on other configuration options for cmake.</li> |
Eli Friedman | d1e1ef3 | 2009-08-03 19:42:28 +0000 | [diff] [blame] | 180 | <li>The above, if successful, will have created an LLVM.sln file in the |
NAKAMURA Takumi | 542c762 | 2011-07-25 12:40:26 +0000 | [diff] [blame] | 181 | <tt>build</tt> directory. |
Eli Friedman | d1e1ef3 | 2009-08-03 19:42:28 +0000 | [diff] [blame] | 182 | </ul> |
Benjamin Kramer | 665a8dc | 2012-01-15 15:26:07 +0000 | [diff] [blame] | 183 | </li> |
| 184 | <li>Build Clang: |
Eli Friedman | d1e1ef3 | 2009-08-03 19:42:28 +0000 | [diff] [blame] | 185 | <ul> |
| 186 | <li>Open LLVM.sln in Visual Studio.</li> |
Daniel Dunbar | dd63b28 | 2009-12-11 23:04:35 +0000 | [diff] [blame] | 187 | <li>Build the "clang" project for just the compiler driver and front end, or |
| 188 | the "ALL_BUILD" project to build everything, including tools.</li> |
Eli Friedman | d1e1ef3 | 2009-08-03 19:42:28 +0000 | [diff] [blame] | 189 | </ul> |
Benjamin Kramer | 665a8dc | 2012-01-15 15:26:07 +0000 | [diff] [blame] | 190 | </li> |
Eli Friedman | d1e1ef3 | 2009-08-03 19:42:28 +0000 | [diff] [blame] | 191 | <li>Try it out (assuming you added llvm/debug/bin to your path). (See the |
| 192 | running examples from above.)</li> |
| 193 | <li>See <a href="hacking.html#testingWindows"> |
| 194 | Hacking on clang - Testing using Visual Studio on Windows</a> for information |
| 195 | on running regression tests on Windows.</li> |
| 196 | </ol> |
| 197 | |
| 198 | <p>Note that once you have checked out both llvm and clang, to synchronize |
| 199 | to the latest code base, use the <tt>svn update</tt> command in both the |
| 200 | llvm and llvm\tools\clang directories, as they are separate repositories.</p> |
| 201 | |
Benjamin Kramer | 665a8dc | 2012-01-15 15:26:07 +0000 | [diff] [blame] | 202 | <h2 id="driver">Clang Compiler Driver (Drop-in Substitute for GCC)</h2> |
Ted Kremenek | 9b16da3 | 2009-03-27 16:32:57 +0000 | [diff] [blame] | 203 | |
Daniel Dunbar | dd63b28 | 2009-12-11 23:04:35 +0000 | [diff] [blame] | 204 | <p>The <tt>clang</tt> tool is the compiler driver and front-end, which is |
| 205 | designed to be a drop-in replacement for the <tt>gcc</tt> command. Here are |
| 206 | some examples of how to use the high-level driver: |
Ted Kremenek | 9b16da3 | 2009-03-27 16:32:57 +0000 | [diff] [blame] | 207 | </p> |
| 208 | |
| 209 | <pre class="code"> |
| 210 | $ <b>cat t.c</b> |
| 211 | #include <stdio.h> |
| 212 | int main(int argc, char **argv) { printf("hello world\n"); } |
| 213 | $ <b>clang t.c</b> |
| 214 | $ <b>./a.out</b> |
| 215 | hello world |
| 216 | </pre> |
| 217 | |
Chris Lattner | 63d423d | 2009-11-09 03:21:02 +0000 | [diff] [blame] | 218 | <p>The 'clang' driver is designed to work as closely to GCC as possible to |
| 219 | maximize portability. The only major difference between the two is that |
| 220 | Clang defaults to gnu99 mode while GCC defaults to gnu89 mode. If you see |
Chris Lattner | d73fef6 | 2009-11-09 04:04:07 +0000 | [diff] [blame] | 221 | weird link-time errors relating to inline functions, try passing -std=gnu89 |
Chris Lattner | 63d423d | 2009-11-09 03:21:02 +0000 | [diff] [blame] | 222 | to clang.</p> |
| 223 | |
Ted Kremenek | 9b16da3 | 2009-03-27 16:32:57 +0000 | [diff] [blame] | 224 | <h2>Examples of using Clang</h2> |
| 225 | |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 226 | <!-- Thanks to |
| 227 | http://shiflett.org/blog/2006/oct/formatting-and-highlighting-php-code-listings |
| 228 | Site suggested using pre in CSS, but doesn't work in IE, so went for the <pre> |
| 229 | tag. --> |
| 230 | |
| 231 | <pre class="code"> |
| 232 | $ <b>cat ~/t.c</b> |
| 233 | typedef float V __attribute__((vector_size(16))); |
| 234 | V foo(V a, V b) { return a+b*a; } |
| 235 | </pre> |
| 236 | |
| 237 | |
Ted Kremenek | 35f29c5 | 2008-06-17 13:48:36 +0000 | [diff] [blame] | 238 | <h3>Preprocessing:</h3> |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 239 | |
| 240 | <pre class="code"> |
| 241 | $ <b>clang ~/t.c -E</b> |
| 242 | # 1 "/Users/sabre/t.c" 1 |
| 243 | |
| 244 | typedef float V __attribute__((vector_size(16))); |
| 245 | |
| 246 | V foo(V a, V b) { return a+b*a; } |
| 247 | </pre> |
| 248 | |
| 249 | |
Ted Kremenek | 35f29c5 | 2008-06-17 13:48:36 +0000 | [diff] [blame] | 250 | <h3>Type checking:</h3> |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 251 | |
| 252 | <pre class="code"> |
| 253 | $ <b>clang -fsyntax-only ~/t.c</b> |
| 254 | </pre> |
| 255 | |
| 256 | |
Ted Kremenek | 35f29c5 | 2008-06-17 13:48:36 +0000 | [diff] [blame] | 257 | <h3>GCC options:</h3> |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 258 | |
| 259 | <pre class="code"> |
| 260 | $ <b>clang -fsyntax-only ~/t.c -pedantic</b> |
Benjamin Kramer | 665a8dc | 2012-01-15 15:26:07 +0000 | [diff] [blame] | 261 | /Users/sabre/t.c:2:17: <span style="color:magenta">warning:</span> extension used |
| 262 | <span style="color:darkgreen">typedef float V __attribute__((vector_size(16)));</span> |
| 263 | <span style="color:blue"> ^</span> |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 264 | 1 diagnostic generated. |
| 265 | </pre> |
| 266 | |
| 267 | |
Ted Kremenek | 35f29c5 | 2008-06-17 13:48:36 +0000 | [diff] [blame] | 268 | <h3>Pretty printing from the AST:</h3> |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 269 | |
Daniel Dunbar | dd63b28 | 2009-12-11 23:04:35 +0000 | [diff] [blame] | 270 | <p>Note, the <tt>-cc1</tt> argument indicates the the compiler front-end, and |
| 271 | not the driver, should be run. The compiler front-end has several additional |
| 272 | Clang specific features which are not exposed through the GCC compatible driver |
| 273 | interface.</p> |
| 274 | |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 275 | <pre class="code"> |
Daniel Dunbar | dd63b28 | 2009-12-11 23:04:35 +0000 | [diff] [blame] | 276 | $ <b>clang -cc1 ~/t.c -ast-print</b> |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 277 | typedef float V __attribute__(( vector_size(16) )); |
| 278 | V foo(V a, V b) { |
| 279 | return a + b * a; |
| 280 | } |
| 281 | </pre> |
| 282 | |
| 283 | |
Ted Kremenek | 35f29c5 | 2008-06-17 13:48:36 +0000 | [diff] [blame] | 284 | <h3>Code generation with LLVM:</h3> |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 285 | |
| 286 | <pre class="code"> |
Daniel Dunbar | dd63b28 | 2009-12-11 23:04:35 +0000 | [diff] [blame] | 287 | $ <b>clang ~/t.c -S -emit-llvm -o -</b> |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 288 | define <4 x float> @foo(<4 x float> %a, <4 x float> %b) { |
| 289 | entry: |
| 290 | %mul = mul <4 x float> %b, %a |
| 291 | %add = add <4 x float> %mul, %a |
| 292 | ret <4 x float> %add |
| 293 | } |
Daniel Dunbar | dd63b28 | 2009-12-11 23:04:35 +0000 | [diff] [blame] | 294 | $ <b>clang -fomit-frame-pointer -O3 -S -o - t.c</b> <i># On x86_64</i> |
| 295 | ... |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 296 | _foo: |
Daniel Dunbar | dd63b28 | 2009-12-11 23:04:35 +0000 | [diff] [blame] | 297 | Leh_func_begin1: |
| 298 | mulps %xmm0, %xmm1 |
| 299 | addps %xmm1, %xmm0 |
| 300 | ret |
| 301 | Leh_func_end1: |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 302 | </pre> |
| 303 | |
Eric Christopher | 7dc0e57 | 2008-02-08 06:45:49 +0000 | [diff] [blame] | 304 | </div> |
| 305 | </body> |
| 306 | </html> |