1. Use Libclan g or clang plug-in including ( Libclang and Clangkit)
Note:
Clangkit, which is a library that is encapsulated with OBJECTIVE-C based on the functionality provided by Clang.
The API provided by Libclang is very simple and can be bridged with C and clang, and it can be used to analyze all the source code.
2. Custom analyzers
Note:
Follow Tutorial for building tools using libtooling to construct add-ons for LLVM, Clang, and Clan G
3. Clang Other Features
Note:
There are many other uses for clang. For example, you can write a compiler plug-in (for example, a checker example like above) and load it dynamically into the compiler. Although I did not personally experiment, but I think in Xcode should be feasible. For example, you can also customize code styles by writing Clang plug-ins (see the compilation process for details )
4. Extended Reading
Note:
- Clang Tutorial
- x86_64 Assembly Language Tutorial
- Custom clang Build with Xcode (I) and (II)
- Clang Tutorial (I), (II) and (III)
- Clang Plugin Tutorial
- LLVM Blog:what Every C programmer should Know (I), (II) and (III)
5. Compile the process:
Note:
Pretreatment
? Symbolize (tokenization)
? Expansion of macro definition
? The unfolding of the #include
Syntax and semantic analysis
? Converts the symbolized content into a parse tree
? Parsing Tree for semantic analysis
? Output an abstract syntax tree (abstract Syntax tree* (AST))
Generate code and optimizations
? Convert AST to lower intermediate code (LLVM IR)
? Optimization of the generated intermediate code
? Generate specific target code
? Output assembly code
Assembler Series
? Converts the assembly code to the target object file.
Linker
? Merging multiple target object files into one executable file (or a dynamic library)
Expect an update for the next issue.