Clang (pron.: /ˈklæŋ/)[2] is a compiler front end for the C, C++,Objective-C and Objective-C++ programming languages. It uses LLVM as its back end and has been part of its releases since LLVM 2.6.
Its goal is to offer a replacement to the GNU Compiler Collection (GCC). Development is completely open-source,[3]with several major software development companies (e.g.Google, Apple) involved. Clang is available under theUniversity of Illinois/NCSA License.
The Clang project includes the Clang front end and the Clangstatic analyzer among others.[4]
Contents[hide] |
[edit]Background
Starting in 2005, Apple has made extensive use of LLVM in a number of commercial systems,[5] including the iPhone development kit and Xcode 3.1.
One of the first uses of LLVM was an OpenGL code compiler for Mac OS X that converts OpenGL calls into more fundamental calls for graphics processing units (GPU) that do not support certain features. This allowed Apple to support the entire OpenGL application programming interface (API) on computers usingIntel Graphics Media Accelerator (GMA) chipsets, increasing performance on those machines.[6] For sufficiently capable GPUs, the code is compiled to take full advantage of the underlying hardware, but on GMA machines, LLVM compiles the same OpenGL code into subroutines to ensure it continues to work properly.
LLVM was originally intended to use GCC's front end, but GCC turned out to cause some problems for both the LLVM developers and Apple. GCC is a large and somewhat cumbersome system to develop; as one long-time GCC developer put it, "Trying to make the hippo dance is not really a lot of fun"[7] and a Google Summer of Code intern commented, "Reading GCC codebase has been a hard exercise for me. In fact it's the only project I know of that becomes more and more difficult as time passes."[8]
Apple software makes heavy use of Objective-C, but the Objective-C front-end in GCC is a low priority for the current GCC developers. Also, GCC does not fit smoothly into Apple's IDE.[9] Finally, GCC is GPL version 3 licensed, which requires developers who distribute extensions for (or modified versions of) GCC to make their source code available, whereas LLVM has a BSD-like license [10] which permits including the source into proprietary software.
Apple chose to develop a new compiler front end from scratch, supporting only C99, Objective-C and C++.[9]This "clang" project was open-sourced in July 2007.[11]
[edit]Design
Clang is intended specifically to work on top of LLVM.[10] The combination of Clang and LLVM provides the majority of a toolchain, allowing the replacement of the whole GCC stack. Because it is built with a library-based design, like the rest of LLVM, Clang is easy to embed into other applications. This is one reason why a majority of the OpenCL implementations are built with Clang and LLVM.[citation needed]
One of Clang's primary goals is to better support incremental compilation to allow the compiler to be more tightly tied to the IDE GUI. GCC is designed to work in a "classic" compile-link-debug cycle, and although it provides useful ways to support incremental and interrupted compiling on-the-fly, integrating them with other tools is not always easy. For instance, GCC uses a step called "fold" that is key to the overall compile process, which has the side effect of translating the code tree into a form that does not look very much like the original source code. If an error is found during or after the fold step, it can be difficult to translate that back into a single location in the original source. Additionally, vendors using the GCC stack within IDEs used separate tools to index the code to provide features like syntax highlighting and autocomplete.
Clang is designed to retain more information during the compilation process than GCC, and preserve the overall form of the original code. The objective of this is to make it easier to map errors back into the original source. The error reports offered by Clang are also aimed to be more detailed and specific, as well as machine-readable, so IDEs can index the output of the compiler during compilation. Modular design of the compiler can offer source code indexing, syntax checking, and other features normally associated with rapid application development systems. The parse tree is also more suitable for supporting automated code refactoring, as it remains in a parsable text form at all times. Changes to the program can be checked bydiffing the intermediate form (IF).
Clang is modularized, based almost entirely on replaceable link-time libraries — as opposed to source-code modules that are combined at compile time — and well-documented. In some cases the libraries are provided in several versions that can be swapped out at runtime; for instance the parser comes with a version that offers performance measurement of the compile process.
Clang, as the name implies, is a compiler only for C and C-like languages. It does not offer compiler front-ends for languages other than C, C++, Objective-C, and Objective-C++. For other languages, including Java,Fortran, and Ada, LLVM remains dependent on GCC. In many cases, Clang can be used or swapped out for GCC as needed, with no other effects on the toolchain as a whole.[citation needed] It supports most of the commonly used GCC options.
[edit]Performance and GCC compatibility
Clang's developers claim that it provides reduced memory footprint and increased compilation speed compared to competing compilers, such as GCC. To support their claim, they present that, as of October 2007, Clang compiled the Carbon libraries well over twice as fast as GCC, while using about one-sixth GCC's memory and disk space.[12]
Clang's overall compatibility with GCC is very good, and its compilation speed typically better than GCC's.[13] The runtime performance of Clang/LLVM output used to be sometimes worse than GCC's,[13][14]but as of the middle of 2012, runtime performance has improved to the point where GCC wins some benchmarks and Clang others.[15]
From: http://en.wikipedia.org/wiki/Clang
-EOF
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
In compilers, the front end translates a computer programming source code into an intermediate representation, and the back end works with the intermediate representation to produce code in a computer output language. The back end usually optimizes to produce code that runs faster. The front-end–back-end distinction can separate the parser section that deals with source code and the back end that generates code and optimizes; some designs (such as GCC) offer choices between multiple front ends (parsing different source languages) or back ends (generating code for different target processors).
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////