blob: ec293cdcaf6d7cffefc3e224f39bba971ceae915 [file] [log] [blame]
Chris Lattner7a274392007-10-06 05:23:00 +00001<!-- Consulted: http://www.w3.org/TR/CSS1 & http://www.w3.org/TR/CSS21/ -->
2<!-- Material used from: HTML 4.01 specs: http://www.w3.org/TR/html401/ -->
3<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4<html>
5<head>
6 <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
7 <title>Clang - Features</title>
8 <link type="text/css" rel="stylesheet" href="menu.css" />
9 <link type="text/css" rel="stylesheet" href="content.css" />
10 <style type="text/css">
11</style>
12</head>
13<body>
14<!--#include virtual="menu.html.incl"-->
15<div id="content">
16 <h1>Features of Clang</h1>
17<p>
18This page outlines the main goals of Clang, as well as some compelling reasons why you should consider using Clang. In the <a href="#goals">Goals</a> section below, you will find a brief, bulleted overview of the goals and features that we are striving for in the development of Clang. However, in the <a href="#keyfeatures">Key Features</a> section you will find a more detailed presentation on what we believe are some key drawing points for the Clang front-end.</p>
19
Chris Lattner96e778b2007-10-06 05:30:19 +000020<p><em>If you are new to the Clang front-end and you want a reason for considering working on or using the new front-end, then make sure you check out the <a href="#keyfeatures">Key Features</a> section.</em></p>
Chris Lattner7a274392007-10-06 05:23:00 +000021
22<h1><a name="goals">Goals</a></h1>
23 <ul>
24 <li>Real-world, production quality compiler</li>
25 <li>Unified parser for C-based languages</li>
26 <div class="li_desc">We are only focusing on the C family of languages (C, C++, ObjC); however, if someone wants to work on another language, they are free to take charge of such a project.</div>
27 <li>Language conformance with C, ObjC, C++, including dialects (C99, C90, ObjC2, etc)</li>
28 <li>GCC compatibility (GCC extensions and 'quirks', where it makes sense)</li>
29 <li>Library based architecture with finely crafted C++ APIs</li>
30 <div class="li_desc">Makes Clang easier to work with and more flexible.</div>
31 <div class="li_weak_desc">(more details on this in the "Key Features" section)</div>
32 <li>Easy to extend</li>
33 <div class="li_weak_desc">(because of the library based architecture)</div>
34 <li>Multipurpose</li>
35 <div class="li_desc">Can be used for:
36 Indexing, static analysis, code generation,
37 source to source tools, refactoring</div>
38 <div class="li_weak_desc">(because of library based architecture)</div>
39 <li>High performance</li>
40 <div class="li_desc">Extremely fast (much faster than GCC), low memory footprint, use lazy evaluation and multithreading</div>
41 <div class="li_weak_desc">(more details in the "Key Features" section)</div>
42 <li>Better integration with IDEs</li>
43 <div class="li_weak_desc">(more details in the "Key Features" section)</div>
44 <li><a href="#expressivediags">Expressive diagnostics</a></li>
45 <div class="li_desc">Error reporting and diagnostic messages are more detailed an accurate than GCC.</div>
46 <div class="li_weak_desc">(more details in the "Key Features" section)</div>
47 <li>BSD License</li>
48 <div class="li_desc">Fewer restrictions on developers; allows for use in commercial products.</div>
49 </ul>
50<h1><a name="keyfeatures">Key Features</a></h1>
51
52There are several key features which we believe make Clang an exciting front-end. These features are designed to make things easier for both the compiler developer (people working on Clang and derivative products) and the application developer (those who use Clang/LLVM).
53
54<h2>Library based architecture</h2>
55A major design concept for the LLVM front-end involves using a library based architecture. In this library based architecture, various parts of the front-end can be cleanly divided into separate libraries which can then be mixed up for different needs and uses. In addition, the library based approach makes it much easier for new developers to get involved and extend LLVM to do new and unique things. In the words of Chris,
Chris Lattnerbafc68f2007-10-06 05:48:57 +000056<div class="quote">"The world needs better compiler tools, tools which are built as libraries. This design point allows reuse of the tools in new and novel ways. However, building the tools as libraries isn't enough: they must have clean APIs, be as decoupled from each other as possible, and be easy to modify/extend. This requires clean layering, decent design, and keeping the libraries independent of any specific client."</div>
Chris Lattner7a274392007-10-06 05:23:00 +000057Currently, the LLVM front-end is divided into the following libraries:
58<ul>
59 <li>libsupport - Basic support library, reused from LLVM.
60 <li>libsystem - System abstraction library, reused from LLVM.
61 <li>libbasic - Diagnostics, SourceLocations, SourceBuffer abstraction, file system caching for input source files. <span class="weak_txt">(depends on above libraries)</span>
62 <li>libast - Provides classes to represent the C AST, the C type system, builtin functions, and various helpers for analyzing and manipulating the AST (visitors, pretty printers, etc). <span class="weak_txt">(depends on above libraries)</span>
63 <li>liblex - C/C++/ObjC lexing and preprocessing, identifier hash table, pragma handling, tokens, and macros. <span class="weak_txt">(depends on above libraries)</span>
64 <li>libparse - Parsing and local semantic analysis. This library invokes coarse-grained 'Actions' provided by the client to do stuff (e.g. libsema builds ASTs). <span class="weak_txt">(depends on above libraries)</span>
65 <li>libsema - Provides a set of parser actions to build a standardized AST for programs. AST's are 'streamed' out a top-level declaration at a time, allowing clients to use decl-at-a-time processing, build up entire translation units, or even build 'whole program' ASTs depending on how they use the APIs. <span class="weak_txt">(depends on libast and libparse)</span>
66 <li>libcodegen - Lower the AST to LLVM IR for optimization &amp; codegen. <span class="weak_txt">(depends on libast)</span>
67 <li>librewrite - Editing of text buffers, depends on libast.</li>
68 <li>libanalysis - Static analysis support, depends on libast.</li>
69 <li><b>clang</b> - An example driver, client of the libraries at various levels. <span class="weak_txt">(depends on above libraries, and LLVM VMCore)</span>
70</ul>
71As an example of the power of this library based design.... If you wanted to build a preprocessor, you would take the Basic and Lexer libraries. If you want an indexer, you would take the previous two and add the Parser library and some actions for indexing. If you want a refactoring, static analysis, or source-to-source compiler tool, you would then add the AST building and semantic analyzer libraries.
72In the end, LLVM's library based design will provide developers with many more possibilities.
73
74<h2>Speed and Memory</h2>
Chris Lattner96e778b2007-10-06 05:30:19 +000075Another major focus of LLVM's frontend is speed (for all libraries). Even at this early stage, the clang front-end is quicker than gcc and uses less memory.<br>
Chris Lattner7a274392007-10-06 05:23:00 +000076<div class="img_container">
77 <div class="img_title">Memory:</div>
78 <img src="feature-memory1.png" />
79 <div class="img_desc">This test was run using Mac OS X's Carbon.h header, which is 12.3MB spread across 558 files!
Chris Lattner96e778b2007-10-06 05:30:19 +000080 Although large headers are one of the worst case scenarios for GCC, they are very common and it shows how clang's implemenation is significantly more memory efficient.
Chris Lattner7a274392007-10-06 05:23:00 +000081 </div>
82</div>
83<div class="img_container">
84 <div class="img_title">Performance:</div>
85 <img src="feature-compile1.png" />
Chris Lattner96e778b2007-10-06 05:30:19 +000086 <div class="img_desc">Even at this early stage, the C parser for Clang is able to achieve significantly better performance. Many optimizations are still possible of course.
Chris Lattner7a274392007-10-06 05:23:00 +000087 </div>
88</div>
89<div class="img_container">
90 <div class="img_title">Performance:</div>
91 <img src="feature-compile2.png" />
Chris Lattner96e778b2007-10-06 05:30:19 +000092 <div class="img_desc">By using very trivial file-system caching, clang can significantly speed up preprocessing-bound applications like distcc. <span class="img_notes">(<a href="clang_video-07-25-2007.html">more details</a>)</span>
93</div>
Chris Lattner7a274392007-10-06 05:23:00 +000094</div>
95
96<h2><a name="expressivediags">Expressive Diagnostics</a></h2>
Chris Lattner96e778b2007-10-06 05:30:19 +000097Clang is designed to efficiently capture range information for expressions and statements, which allows it to emit very detailed diagnostic information when a problem is detected.<br>
Chris Lattner7a274392007-10-06 05:23:00 +000098<div class="img_container">
99 <div class="img_title">Clang vs GCC:</div>
100 <img src="feature-diagnostics1.png" />
101 <div class="img_desc">There are several things to take note of in this example:
102 <ul>
103 <li>The error messages from Clang are more detailed.
104 <li>Clang shows you exactly where the error is, plus the range it has a problem with.
105 </ul>
106 </div>
107 <div class="img_notes"><span>Notes:</span>The first results are from clang; the second results are from gcc.</div>
108</div>
109<h2>Better Integration with IDEs</h2>
Chris Lattner96e778b2007-10-06 05:30:19 +0000110Another design goal of Clang is to integrate extremely well with IDEs. IDEs often have very different requirements than code generation, often requiring information that a codegen-only frontend can throw away. Clang is specifically designed and built to capture this information.
Chris Lattner7a274392007-10-06 05:23:00 +0000111</div>
112</body>
Chris Lattnerbafc68f2007-10-06 05:48:57 +0000113</html>