Clang

Clang
Clang
Low Level Virtual Machine Logo
Original author(s) Chris Lattner and others
Developer(s) Apple Inc. and others
Stable release 2.9
Preview release 3.0 rc3
Development status Active
Written in C++
Operating system Unix-like
Platform Cross-platform
Type Compiler
License University of Illinois/NCSA Open Source License[1]
Website clang.llvm.org

Clang (pronounced /ˈklæŋ/ like the English word clang)[2] is a compiler front end for the C, C++, Objective-C, and Objective-C++ programming languages. It uses the Low Level Virtual Machine (LLVM) as its back end, and Clang has been part of LLVM releases since LLVM 2.6.

Its goal is to offer a replacement to the GNU Compiler Collection (GCC). Development is sponsored by Apple. Clang is available under a free software license.

The Clang project includes the Clang front end and the Clang static analyzer among others.[3]

Contents

Background

Starting in 2005, Apple has made extensive use of LLVM in a number of commercial systems,[4] 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 using Intel Graphics Media Accelerator (GMA) chipsets, increasing performance on those machines.[5] 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"[6] 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."[7]

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.[8] Finally, GCC is GPL 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 [9] 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++.[8] This "clang" project was open-sourced in July 2007.[10]

Overview

Clang is a new C-targeted compiler intended specifically to work on top of LLVM.[9] 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.

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 compiler can be checked by diffing the intermediate form (IF).

Although development on GCC may be difficult, the reasons for this have been well explored by its developers. This allowed the Clang team to avoid these problems and make a more flexible system. Clang is highly modularized, based almost entirely on replaceable link-time libraries — as opposed to source-code modules that are combined at compile time — and well-documented. This makes it much easier for new developers to get up to speed in Clang and add to the project. 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.

Performance and GCC compatibility

Clang's developers claim that it provides reduced memory footprint and increased 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.[11]

Although Clang's overall compatibility with GCC is very good, and its compilation speed typically better than GCC's, as of early 2011 the runtime performance of clang/LLVM output is sometimes worse than GCC's.[12][13]

Status history

This table present only releases significant steps in Clang history.

Date Highlights
25 February 2009 Clang/LLVM able to compile a working FreeBSD kernel.[14][15] Currently all of the FreeBSD source code - both kernel and userland - can be compiled with Clang.
16 March 2009 Clang/LLVM able to compile a working DragonFly BSD kernel.[16][17]
23 October 2009 Clang 1.0 released along with LLVM 2.6 for the first time.
December 2009 Code generation for C and Objective-C reach production quality (support for C++ and Objective-C++ still incomplete). Clang C++ able to parse GCC 4.2 libstdc++ and generate working code for non-trivial programs[9] and was able to compile itself[18]
2 February 2010 Clang self-hosting.[19]
20 February 2010 The source code of HelenOS was modified to successfully compile with Clang, and passed all kernel and user space regression tests on IA-32.[20]
20 May 2010 The latest version of Clang successfully built the Boost C++ libraries, and passed nearly all tests.[21]
10 June 2010 Clang/LLVM became an integral part of FreeBSD (The default compiler is still GCC)[22]
25 October 2010 Clang/LLVM able to compile a working Linux Kernel.[23]
January 2011 Preliminary work completed to support the draft C++0x standard, with a few of the draft's new features supported in the development version of clang.[24][25]
10 February 2011 Clang able to compile a working HotSpot Java Virtual Machine[12]

See also

References

  1. ^ "LLVM Release License "
  2. ^ Christopher, Eric (3 July 2008). "simply wonder pronunciation of Clang". LLVMdev mailing list. http://lists.cs.uiuc.edu/pipermail/llvmdev/2008-July/015624.html. Retrieved 9 July 2008. 
  3. ^ "Clang Static Analyzer". LLVM. http://clang-analyzer.llvm.org/. Retrieved 3 September 2009. 
  4. ^ Treat, Adam (19 February 2005). "mkspecs and patches for LLVM compile of Qt4". Qt4-preview-feedback mailing list. http://lists.trolltech.com/qt4-preview-feedback/2005-02/msg00691.html. 
  5. ^ Lattner, Chris (25 May 2007). "LLVM for OpenGL and other stuff" (Slides). LLVM Developers' Meeting. http://llvm.org/devmtg/2007-05/10-Lattner-OpenGL.pdf. 
  6. ^ Zadeck, Kenneth (19 November 2005). "Re: LLVM/GCC Integration Proposal". GCC development mailing list. http://gcc.gnu.org/ml/gcc/2005-11/msg00918.html. 
  7. ^ Apostolou, Dimitrios (5 July 2011). "GSOC - Student Roundup". GCC development mailing list. http://gcc.gnu.org/ml/gcc/2011-07/msg00041.html. 
  8. ^ a b Naroff, Steve (25 May 2007). "New LLVM C Front-end" (Slides). LLVM Developers' Meeting. http://llvm.org/devmtg/2007-05/09-Naroff-CFE.pdf. 
  9. ^ a b c Clang team, clang: a C language family frontend for LLVM
  10. ^ Lattner, Chris (11 July 2007). "New LLVM C front-end: "clang"". cfe-dev mailing list. http://lists.cs.uiuc.edu/pipermail/cfe-dev/2007-July/000000.html. 
  11. ^ "Clang - Features and Goals: Fast compiles and Low Memory Use". October 2007. http://clang.llvm.org/features.html. 
  12. ^ a b Simonis, Volker (10 February 2011). "Compiling the HotSpot VM with Clang". http://weblogs.java.net/blog/simonis/archive/2011/02/10/compiling-hotspot-vm-clang. Retrieved 13 February 2011. "While the overall GCC compatibility is excellent and the compile times are impressive, the performance of the generated code is still lacking behind a recent GCC version. " 
  13. ^ "Benchmarking LLVM & Clang Against GCC 4.5". Phoronix. 21 April 2010. http://www.phoronix.com/scan.php?page=article&item=gcc_llvm_clang&num=6. Retrieved 13 February 2011. "Binaries from LLVM-GCC and Clang both struggled to compete with GCC 4.5.0 in the timed HMMer benchmark of a Pfam database search. LLVM-GCC and Clang were about 23% slower(...)Though LLVM / Clang isn't the performance champion at this point, both components continue to be under very active development and there will hopefully be more news to report in the coming months" 
  14. ^ Divacky, Roman. "[ANNOUNCE] clang/llvm can compile booting FreeBSD kernel on i386/amd64". http://lists.freebsd.org/pipermail/freebsd-current/2009-February/003743.html. 
  15. ^ http://wiki.freebsd.org/BuildingFreeBSDWithClang
  16. ^ Hornung, Alex. "llvm/clang once more". http://leaf.dragonflybsd.org/mailarchive/kernel/2009-03/msg00067.html. 
  17. ^ http://www.dragonflybsd.org/docs/developer/clang/
  18. ^ "Clang can compile LLVM and Clang". LLVM Project Blog. http://blog.llvm.org/2009/12/clang-builds-llvm.html. 
  19. ^ "Clang Successfully Self-Hosts". LLVM Project Blog. http://blog.llvm.org/2010/02/clang-successfully-self-hosts.html. 
  20. ^ "HelenOS mainline changeset head,294". http://trac.helenos.org/trac.fcgi/changeset/mainline%2C294. 
  21. ^ Gregor, Doug. "Clang++ Builds Boost!". LLVM Project Blog. http://blog.llvm.org/2010/05/clang-builds-boost.html. 
  22. ^ Davis, Brad. "FreeBSD Status Reports April - June, 2010". http://www.freebsd.org/news/status/report-2010-04-2010-06.html#Clang-Replacing-GCC-in-the-Base-System. 
  23. ^ [ANNOUNCE] Clang builds a working Linux Kernel (Boots to RL5 with SMP, networking and X, self hosts)
  24. ^ Gregor, Douglas (26 January 2011). "New C++0x feature support in Clang". http://lists.cs.uiuc.edu/pipermail/cfe-dev/2011-January/013013.html. Retrieved 29 January 2011. 
  25. ^ "C++ and C++'0x Support in Clang". LLVM. http://clang.llvm.org/cxx_status.html. 

External links


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать курсовую
Synonyms:

Look at other dictionaries:

  • Clang — Тип Компилятор Разработчик Apple Написана на …   Википедия

  • clang — clang; clang·or·ous; clang·er; clang·or; clang·or·ous·ly; …   English syllables

  • Clang — Développeur Université de l Illinois, Apple Éc …   Wikipédia en Français

  • Clang — Clang, v. i. To give out a clang; to resound. Clanging hoofs. Tennyson. [1913 Webster] …   The Collaborative International Dictionary of English

  • Clang — Clang, n. 1. A loud, ringing sound, like that made by metallic substances when clanged or struck together. [1913 Webster] The broadsword s deadly clang, As if a thousand anvils rang. Sir W. Scott. [1913 Webster] 2. (Mus.) Quality of tone. [1913… …   The Collaborative International Dictionary of English

  • clang — [klæŋ] v [I and T] [Date: 1500 1600; : Latin; Origin: clangere] if a metal object clangs, or if you clang it, it makes a loud ringing sound ▪ The gates clanged shut behind her. >clang n [singular] …   Dictionary of contemporary English

  • clang — [ klæŋ ] verb intransitive or transitive if something made of metal clangs, or if you clang it, it makes a loud sound ╾ clang noun count …   Usage of the words and phrases in modern English

  • Clang — (kl[a^]ng), v. t. [imp. & p. p. {Clanged} (kl[a^]ngd); p. pr. & vb. n. {Clanging}.] [L. clangere; akin to Gr. kla zein to clash, scream; or perh. to E. clank.] To strike together so as to produce a ringing metallic sound. [1913 Webster] The… …   The Collaborative International Dictionary of English

  • clang — ► NOUN ▪ a loud metallic sound. ► VERB ▪ make a clang. ORIGIN imitative, influenced by Latin clangere resound …   English terms dictionary

  • clang — fonosimb. CO voce che imita il suono di un oggetto metallico percosso, ad es. il suono del gong o del campanaccio delle mucche; anche s.m.inv. Sinonimi: clanghete. {{line}} {{/line}} DATA: sec. XX. ETIMO: voce onom …   Dizionario italiano

  • clang — (v.) 1570s, echoic (originally of trumpets and birds), akin to or from L. clangere resound, ring, and Gk. klange sharp sound, from PIE *klang , nasalized form of root *kleg to cry, sound. Related: Clanged; clanging. The noun is attested from… …   Etymology dictionary

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”