Skip to content

Commit 41a7177

Browse files
committed
Update librustc's README.txt for some code changes and reformat it.
1 parent fda8673 commit 41a7177

File tree

1 file changed

+53
-49
lines changed

1 file changed

+53
-49
lines changed

src/librustc/README.txt

+53-49
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ Your concerns are probably the same as someone else's.
1616
The crates of rustc
1717
===================
1818

19-
Rustc consists of four crates altogether: `libsyntax`, `librustc`,
20-
`librustc_back`, and `librustc_trans` (the names and divisions are not
21-
set in stone and may change; in general, a finer-grained division of
22-
crates is preferable):
19+
Rustc consists of a number of crates, including `libsyntax`,
20+
`librustc`, `librustc_back`, `librustc_trans`, and `librustc_driver`
21+
(the names and divisions are not set in stone and may change;
22+
in general, a finer-grained division of crates is preferable):
2323

24-
- `libsyntax` contains those things concerned purely with syntax --
24+
- `libsyntax` contains those things concerned purely with syntax
2525
that is, the AST, parser, pretty-printer, lexer, macro expander, and
26-
utilities for traversing ASTs -- are in a separate crate called
27-
"syntax", whose files are in ./../libsyntax, where . is the current
28-
directory (that is, the parent directory of front/, middle/, back/,
29-
and so on).
26+
utilities for traversing ASTs are in a separate crate called
27+
"syntax", whose files are in `./../libsyntax`, where `.` is the
28+
current directory (that is, the parent directory of front/, middle/,
29+
back/, and so on).
3030

3131
- `librustc` (the current directory) contains the high-level analysis
3232
passes, such as the type checker, borrow checker, and so forth.
@@ -41,66 +41,70 @@ crates is preferable):
4141
of miscellany. In general it contains code that runs towards the
4242
end of the compilation process.
4343

44+
- `librustc_driver` invokes the compiler from `libsyntax`, then the
45+
analysis phases from `librustc`, and finally the lowering and
46+
codegen passes from `librustc_trans`.
47+
4448
Roughly speaking the "order" of the three crates is as follows:
4549

4650
libsyntax -> librustc -> librustc_trans
4751
| |
4852
+-----------------+-------------------+
4953
|
50-
librustc_trans/driver
54+
librustc_driver
5155

52-
Here the role of `librustc_trans/driver` is to invoke the compiler
53-
from libsyntax, then the analysis phases from librustc, and finally
54-
the lowering and codegen passes from librustc_trans.
5556

5657
Modules in the rustc crate
5758
==========================
5859

59-
The rustc crate itself consists of the following subdirectories
60+
The rustc crate itself consists of the following submodules
6061
(mostly, but not entirely, in their own directories):
6162

62-
session - options and data that pertain to the compilation session as a whole
63-
middle - middle-end: name resolution, typechecking, LLVM code
64-
generation
65-
metadata - encoder and decoder for data required by
66-
separate compilation
67-
util - ubiquitous types and helper functions
68-
lib - bindings to LLVM
63+
- session: options and data that pertain to the compilation session as
64+
a whole
65+
- middle: middle-end: name resolution, typechecking, LLVM code
66+
generation
67+
- metadata: encoder and decoder for data required by separate
68+
compilation
69+
- plugin: infrastructure for compiler plugins
70+
- lint: infrastructure for compiler warnings
71+
- util: ubiquitous types and helper functions
72+
- lib: bindings to LLVM
6973

7074
The entry-point for the compiler is main() in the librustc_trans
7175
crate.
7276

7377
The 3 central data structures:
7478
------------------------------
7579

76-
#1: ./../libsyntax/ast.rs defines the AST. The AST is treated as immutable
77-
after parsing, but it depends on mutable context data structures
78-
(mainly hash maps) to give it meaning.
80+
1. `./../libsyntax/ast.rs` defines the AST. The AST is treated as
81+
immutable after parsing, but it depends on mutable context data
82+
structures (mainly hash maps) to give it meaning.
7983

80-
- Many -- though not all -- nodes within this data structure are
81-
wrapped in the type `spanned<T>`, meaning that the front-end has
82-
marked the input coordinates of that node. The member .node is
83-
the data itself, the member .span is the input location (file,
84-
line, column; both low and high).
84+
- Many though not all nodes within this data structure are
85+
wrapped in the type `spanned<T>`, meaning that the front-end has
86+
marked the input coordinates of that node. The member `node` is
87+
the data itself, the member `span` is the input location (file,
88+
line, column; both low and high).
8589

86-
- Many other nodes within this data structure carry a
87-
def_id. These nodes represent the 'target' of some name
88-
reference elsewhere in the tree. When the AST is resolved, by
89-
middle/resolve.rs, all names wind up acquiring a def that they
90-
point to. So anything that can be pointed-to by a name winds
91-
up with a def_id.
90+
- Many other nodes within this data structure carry a
91+
`def_id`. These nodes represent the 'target' of some name
92+
reference elsewhere in the tree. When the AST is resolved, by
93+
`middle/resolve.rs`, all names wind up acquiring a def that they
94+
point to. So anything that can be pointed-to by a name winds
95+
up with a `def_id`.
9296

93-
#2: middle/ty.rs defines the datatype sty. This is the type that
94-
represents types after they have been resolved and normalized by
95-
the middle-end. The typeck phase converts every ast type to a
96-
ty::sty, and the latter is used to drive later phases of
97-
compilation. Most variants in the ast::ty tag have a
98-
corresponding variant in the ty::sty tag.
97+
2. `middle/ty.rs` defines the datatype `sty`. This is the type that
98+
represents types after they have been resolved and normalized by
99+
the middle-end. The typeck phase converts every ast type to a
100+
`ty::sty`, and the latter is used to drive later phases of
101+
compilation. Most variants in the `ast::ty` tag have a
102+
corresponding variant in the `ty::sty` tag.
99103

100-
#3: lib/llvm.rs (in librustc_trans) defines the exported types
101-
ValueRef, TypeRef, BasicBlockRef, and several others. Each of
102-
these is an opaque pointer to an LLVM type, manipulated through
103-
the lib::llvm interface.
104+
3. `./../librustc_llvm/lib.rs` defines the exported types
105+
`ValueRef`, `TypeRef`, `BasicBlockRef`, and several others.
106+
Each of these is an opaque pointer to an LLVM type,
107+
manipulated through the `lib::llvm` interface.
104108

105109

106110
Control and information flow within the compiler:
@@ -109,10 +113,10 @@ Control and information flow within the compiler:
109113
- main() in lib.rs assumes control on startup. Options are
110114
parsed, platform is detected, etc.
111115

112-
- ./../libsyntax/parse/parser.rs parses the input files and produces an AST
113-
that represents the input crate.
116+
- `./../libsyntax/parse/parser.rs` parses the input files and produces
117+
an AST that represents the input crate.
114118

115-
- Multiple middle-end passes (middle/resolve.rs, middle/typeck.rs)
119+
- Multiple middle-end passes (`middle/resolve.rs`, `middle/typeck.rs`)
116120
analyze the semantics of the resulting AST. Each pass generates new
117121
information about the AST and stores it in various environment data
118122
structures. The driver passes environments to each compiler pass
@@ -121,4 +125,4 @@ Control and information flow within the compiler:
121125
- Finally, the `trans` module in `librustc_trans` translates the Rust
122126
AST to LLVM bitcode in a type-directed way. When it's finished
123127
synthesizing LLVM values, rustc asks LLVM to write them out in some
124-
form (.bc, .o) and possibly run the system linker.
128+
form (`.bc`, `.o`) and possibly run the system linker.

0 commit comments

Comments
 (0)