Chapter 6: Extending the Preprocessor
In the previous chapter, we went through the structure of Clang—the official frontend of Low-Level Virtual Machine (LLVM) for C-family languages—and some of its most important components. We also introduced a variety of Clang's tooling and extension options. In this chapter, we're diving into the first phase in Clang's frontend pipeline: the preprocessor.
For C-family programming languages, preprocessing is an early compilation phase that replaces any directive starting with a hash (#
) character—#include
and #define
, to name but a few—with some other textual contents (or non-textual tokens, in some rare cases). For example, the preprocessor will basically copy and paste contents of header files designated by the #include
directive into the current compilation unit before parsing it. This technique has the advantage of extracting common code and reusing it.
In this chapter, we will briefly explain...