Advanced

Passes as a pipeline

The compiler is a list of passes. The list is written once, and the list is the reason a compiler can grow without becoming one large function.

What you will see

5 gen. The printed number is the position, which is the claim.

About 1 min of reading

Try It

Write the pipeline and check the order

1

Write the list

printf 'parse\ncheck\nfold\nscope\ngen\n' > /tmp/p.txt; wc -l < /tmp/p.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
5. Five lines is the pipeline, and the pipeline is the list.
2

Write a need

printf 'gen needs check\n' > /tmp/n.txt; cat /tmp/n.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
One line. The need is written, which is what is checked at start.
3

Print the order

cat -n /tmp/p.txt | tail -1

Before you run it, say out loud what it will print. Then open the answer.

What it prints
5 gen. The printed number is the position, which is the claim.

Data Flow

A list of passes to a printed order
1 The passes are written in a list
↓
2 Each reads and writes the same shape
↓
3 The needs are checked at start
↓
4 The order is printed
Why this works
Why the pipeline is printed

The print is the list with the order. A printed list is a list that a bug report can point at.

The cost of adding a pass

One more walk of the tree. The walk is the cost, and the cost is why the list is short.

Examples

Each pass reads and writes a tree

The shape is the same in and out. The same shape is what lets the passes be reordered.

The order is a written decision

A pass that needs another's output must come after it. The need is written, and written needs are checked at start.

A pass is named by what it removes

The name says the claim. A name that says the claim is a name that a reader can argue with.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← Constant folding as a rewrite
Previous Lesson
Constant folding as a rewrite
Next Lesson
Names and scopes
Names and scopes →