@@ -13,31 +13,62 @@ https://github.com/rust-lang/rust/issues
1313
1414Your concerns are probably the same as someone else's.
1515
16-
17- High-level concepts
16+ The crates of rustc
1817===================
1918
20- Rustc consists of the following subdirectories:
21-
22- front/ - front-end: attributes, conditional compilation
23- middle/ - middle-end: name resolution, typechecking, LLVM code
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):
23+
24+ - `libsyntax` contains those things concerned purely with syntax --
25+ 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).
30+
31+ - `librustc` (the current directory) contains the high-level analysis
32+ passes, such as the type checker, borrow checker, and so forth.
33+ It is the heart of the compiler.
34+
35+ - `librustc_back` contains some very low-level details that are
36+ specific to different LLVM targets and so forth.
37+
38+ - `librustc_trans` contains the code to convert from Rust IR into LLVM
39+ IR, and then from LLVM IR into machine code, as well as the main
40+ driver that orchestrates all the other passes and various other bits
41+ of miscellany. In general it contains code that runs towards the
42+ end of the compilation process.
43+
44+ Roughly speaking the "order" of the three crates is as follows:
45+
46+ libsyntax -> librustc -> librustc_trans
47+ | |
48+ +-----------------+-------------------+
49+ |
50+ librustc_trans/driver
51+
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.
55+
56+ Modules in the rustc crate
57+ ==========================
58+
59+ The rustc crate itself consists of the following subdirectories
60+ (mostly, but not entirely, in their own directories):
61+
62+ session - options and data that pertain to the compilation session as a whole
63+ middle - middle-end: name resolution, typechecking, LLVM code
2464 generation
25- back/ - back-end: linking and ABI
26- metadata/ - encoder and decoder for data required by
65+ metadata - encoder and decoder for data required by
2766 separate compilation
28- driver/ - command-line processing, main() entrypoint
29- util/ - ubiquitous types and helper functions
30- lib/ - bindings to LLVM
31-
32- The files concerned purely with syntax -- that is, the AST, parser,
33- pretty-printer, lexer, macro expander, and utilities for traversing
34- ASTs -- are in a separate crate called "syntax", whose files are in
35- ./../libsyntax, where . is the current directory (that is, the parent
36- directory of front/, middle/, back/, and so on).
37-
38- The entry-point for the compiler is main() in lib.rs, and
39- this file sequences the various parts together.
67+ util - ubiquitous types and helper functions
68+ lib - bindings to LLVM
4069
70+ The entry-point for the compiler is main() in the librustc_trans
71+ crate. But the
4172
4273The 3 central data structures:
4374------------------------------
@@ -66,10 +97,10 @@ The 3 central data structures:
6697 compilation. Most variants in the ast::ty tag have a
6798 corresponding variant in the ty::sty tag.
6899
69- #3: lib/llvm.rs defines the exported types ValueRef, TypeRef,
70- BasicBlockRef, and several others. Each of these is an opaque
71- pointer to an LLVM type, manipulated through the lib::llvm
72- interface.
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.
73104
74105
75106Control and information flow within the compiler:
@@ -87,7 +118,7 @@ Control and information flow within the compiler:
87118 structures. The driver passes environments to each compiler pass
88119 that needs to refer to them.
89120
90- - Finally middle/trans.rs translates the Rust AST to LLVM bitcode in a
91- type-directed way. When it's finished synthesizing LLVM values,
92- rustc asks LLVM to write them out in some form (.bc, .o) and
93- possibly run the system linker.
121+ - Finally, the `trans` module in `librustc_trans` translates the Rust
122+ AST to LLVM bitcode in a type-directed way. When it's finished
123+ synthesizing LLVM values, rustc asks LLVM to write them out in some
124+ form (.bc, .o) and possibly run the system linker.
0 commit comments