• C/C++ Build Tools: Preprocessor, Compiler, Assembler, Linker
  • General Compiler Structure: Front-end, Back-end, Optimizations
  • Front-end: Lexical Analysis, Syntax Analysis, Semantic Analysis
  • Back-end: Instruction Selection, Instruction Scheduling, Register Allocation


Recommended reading:

  • Physical Structure and C++ - Parts 1 and 2

AST Examples:

To get a better understanding of what an AST looks like, we can dump the ASTs produced by Clang for some simple files. To do this, run:

clang -Xclang -ast-dump -fsyntax-only <your-file>

You should try this for a few examples to get a feel of it. You can start with the ones below. You can try to modify them and check out other language constructs to see how they are expressed in the AST.

The -fsyntax-only option tells Clang to stop the compilation process after building the AST. The -Xclang flag specifies that the option following it should be passed to the front-end (which is confusingly dubbed Clang, just like the command line driver). Without this flag, -ast-dump is not recognized.

int inc(int a) {
  return a + 1;
int sum_sq(int a, int b) {
  return a * a + b * b;
int max(int a, int b, int c) {
  if (a > b) {
    if (c > a) {
      return c;
    } else {
      return a;
  if (b > c) {
    return b;
  return c;
int sum(int *a, int n) {
  int s = 0;
  for (int i = 0; i < n; i++) {
    s += a[i];
  return s;
struct point {
  int x, y;
int max(int a, int b) {
  return a < b ? b : a;
// Chebyshev
int distance(struct point A, struct point B) {
  return max(A.x - B.x, A.y - B.y);
sesiuni/llvm/intro.txt · Last modified: 2015/09/08 10:52 by freescale