LLVM,Clang

在使用xcode时常常会遇到这2个概念,今天总结一下。

wiki中关于llvm的描述:

LLVM提供了完整編譯系統的中間層,它會將中間語言(IF, Intermediate form)從編譯器取出與最佳化,最佳化後的IF接著被轉換及鏈結到目標平台的汇编语言。LLVM可以接受來自GCC工具鏈所編譯的IF,包含它底下現存的編譯器。

请参考以下链接,http://www.weiphone.com/apple/blog/2009-09-27/The_heart_of_Snow_Leopard_LLVM_and_Clang_206356.shtml

Clang 和 LLVM 的更多资料,请参看官方文档,http://llvm.org    http://clang.llvm.org

以下是clang tools的简要介绍

 

DESCRIPTION
clang is a C, C++, and Objective-C compiler which encompasses preprocessing, parsing, optimization, code
generation, assembly, and linking. Depending on which high-level mode setting is passed, Clang will stop
before doing a full link. While Clang is highly integrated, it is important to understand the stages of
compilation, to understand how to invoke it. These stages are:

 

Driver
The clang executable is actually a small driver which controls the overall execution of other tools
such as the compiler, assembler and linker. Typically you do not need to interact with the driver, but
you transparently use it to run the other tools.

 

Preprocessing
This stage handles tokenization of the input source file, macro expansion, #include expansion and
handling of other preprocessor directives. The output of this stage is typically called a ".i" (for
C), ".ii" (for C++), ".mi" (for Objective-C) , or ".mii" (for Objective-C++) file.

 

Parsing and Semantic Analysis
This stage parses the input file, translating preprocessor tokens into a parse tree. Once in the form
of a parser tree, it applies semantic analysis to compute types for expressions as well and determine
whether the code is well formed. This stage is responsible for generating most of the compiler warnings
as well as parse errors. The output of this stage is an "Abstract Syntax Tree" (AST).

 

Code Generation and Optimization
This stage translates an AST into low-level intermediate code (known as "LLVM IR") and ultimately to
machine code. This phase is responsible for optimizing the generated code and handling target-specific
code generation. The output of this stage is typically called a ".s" file or "assembly" file.

 

Clang also supports the use of an integrated assembler, in which the code generator produces object
files directly. This avoids the overhead of generating the ".s" file and of calling the target
assembler.

Assembler
This stage runs the target assembler to translate the output of the compiler into a target object file.
The output of this stage is typically called a ".o" file or "object" file.

Linker
This stage runs the target linker to merge multiple object files into an executable or dynamic library.
The output of this stage is typically called an "a.out", ".dylib" or ".so" file.

The Clang compiler supports a large number of options to control each of these stages. In addition to
compilation of code, Clang also supports other tools:

Clang Static Analyzer

The Clang Static Analyzer is a tool that scans source code to try to find bugs through code analysis. This
tool uses many parts of Clang and is built into the same driver.

 

原文地址:https://www.cnblogs.com/breezemist/p/3491965.html