Skip to content

Commit 0e9f89c

Browse files
committed
address review comments
1 parent 9b12be5 commit 0e9f89c

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

src/part-3-intro.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# Part 3: Source Code Representations
22

3-
This part of the guide looks at the various ways the compiler transforms and
4-
represents source code. This part describes the process of taking raw source
5-
code from the user and transforming it into various forms that the compiler can
6-
work with easily. These are called intermediate representations.
3+
This part describes the process of taking raw source code from the user and
4+
transforming it into various forms that the compiler can work with easily.
5+
These are called intermediate representations.
76

87
This process starts with compiler understanding what the user has asked for:
98
parsing the command line arguments given and determining what it is to compile.

src/part-5-intro.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ All of the preceding chapters of this guide have one thing in common: we never
44
generated any executable machine code at all! With this chapter, all of that
55
changes.
66

7-
It's often useful to think of compilers as being composed of a _frontend_ and a
8-
_backend_ (though in rustc, there's not a sharp line between frontend and
9-
backend). The _frontend_ is responsible for taking raw source code, checking it
10-
for correctness, and getting it into a format from which we can generate code.
11-
For rustc, we typically consider MIR to be this format (though arguably, one
12-
could consider LLVM IR to be this format). The _backend_ refers to the parts
13-
of the compiler that produce actual executable code (e.g. an ELF or EXE binary)
14-
that can run on a processor. All of the previous chapters deal with rustc's
15-
"frontend".
16-
17-
rustc's "backend" does the following:
7+
So far, we've shown how the compiler can take raw source code in text format
8+
and transform it into MIR. We have also shown how the compiler does various
9+
analyses on the code to detect things like type or lifetime errors. Now, we
10+
will finally take the MIR and produce some executable machine code.
11+
12+
> NOTE: This part of a compiler is often called the _backend_ the term is a bit
13+
> overloaded because in the compiler source, it usually refers to the "codegen
14+
> backend" (i.e. LLVM or Cranelift). Usually, when you see the word "backend"
15+
> in this part, we are refering to the "codegen backend".
16+
17+
So what do we need to do?
1818

1919
0. First, we need to collect the set of things to generate code for. In
2020
particular, we need to find out which concrete types to substitute for
@@ -24,15 +24,15 @@ rustc's "backend" does the following:
2424
collecting all the concrete types is called _monomorphization collection_.
2525
1. Next, we need to actually lower the MIR to a codegen IR
2626
(usually LLVM IR) for each concrete type we collected.
27-
2. Finally, we need to invoke the codegen backend (e.g. LLVM or Cranelift),
28-
which runs a bunch of optimization passes, generates executable code, and
29-
links together an executable binary.
27+
2. Finally, we need to invoke LLVM or Cranelift, which runs a bunch of
28+
optimization passes, generates executable code, and links together an
29+
executable binary.
3030

3131
[codegen1]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/base/fn.codegen_crate.html
3232

3333
The code for codegen is actually a bit complex due to a few factors:
3434

35-
- Support for multiple backends (LLVM and Cranelift). We try to share as much
35+
- Support for multiple codegen backends (LLVM and Cranelift). We try to share as much
3636
backend code between them as possible, so a lot of it is generic over the
3737
codegen implementation. This means that there are often a lot of layers of
3838
abstraction.

0 commit comments

Comments
 (0)