2.4 Clang frontend overview
It’s evident that the Clang compiler toolchain conforms to the pattern widely described in various compiler books [1, 18]. However, Clang’s frontend part diverges significantly from a typical compiler frontend. The primary reason for this distinction is the complexity of the C++ language. Some features, such as macros, can modify the source code itself, while others, such as typedef, can influence the kind of token. Clang can also generate output in a variety of formats. For instance, the following command generates an aesthetically pleasing HTML view of the program shown in Figure 2.5:
$ <...>/llvm-project/install/bin/clang -cc1 -emit-html max.cpp
Take note that we pass the argument to emit the HTML form of the source program to the Clang frontend, specified with the -cc1
option. Alternatively, you can pass an option to the frontend via the -Xclang
option, which requires an additional argument representing...