Skip to content

Commit f29eea7

Browse files
authored
Merge pull request #15062 from raboof/update-backend-docs
Update backend.md
2 parents 9d6e87a + 3124fc0 commit f29eea7

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

compiler/src/dotty/tools/backend/jvm/GenBCode.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class GenBCode extends Phase {
6161

6262
private var myPrimitives: DottyPrimitives = null
6363

64-
def run(using Context): Unit =
64+
override def run(using Context): Unit =
6565
if myPrimitives == null then myPrimitives = new DottyPrimitives(ctx)
6666
new GenBCodePipeline(
6767
DottyBackendInterface(outputDir, superCallsMap),

docs/_docs/internals/backend.md

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ layout: doc-page
33
title: "Backend Internals"
44
---
55

6-
The code for the backend is split up by functionality and assembled in the
7-
object `GenBCode`.
6+
The code for the JVM backend is split up by functionality and assembled in
7+
`GenBCode.scala`. This file defines class `GenBCode`, the compiler phase.
88

99
```
10-
object GenBCode --- [defines] --> PlainClassBuilder GenBCode also defines class BCodePhase, the compiler phase
10+
class GenBCodePipeline -[defines]--> PlainClassBuilder
1111
| |
1212
[extends] [extends]
1313
| |
@@ -18,34 +18,37 @@ BCodeBodyBuilder ----------------> PlainBodyBuilder
1818
BCodeSkelBuilder ----------------> PlainSkelBuilder
1919
| / | \
2020
BCodeHelpers ----------------> BCClassGen BCAnnotGen ... (more components)
21-
| \ \
22-
| \ \-------------> helper methods
23-
| \ \------------> JMirrorBuilder, JBeanInfoBuilder (uses some components, e.g. BCInnerClassGen)
24-
| \
21+
| | \
22+
| | \-------------> helper methods
23+
| | \------------> JMirrorBuilder, JBeanInfoBuilder (uses some components, e.g. BCInnerClassGen)
24+
| |
2525
| BytecodeWriters ---------> methods and classes to write byte code files
2626
|
27-
BCodeTypes ----------------> maps and fields for common BTypes, class Tracked, methods to collect information on classes, tests for BTypes (conforms), ...
28-
|
2927
BCodeIdiomatic ----------------> utilities for code generation, e.g. genPrimitiveArithmetic
30-
|
31-
BCodeGlue ----------------> BType class, predefined BTypes
28+
\--------------> `bTypes`: maps and fields for common BTypes
3229
```
3330

31+
The `BTypes.scala` class contains the `BType` class and predefined BTypes
32+
3433
### Data Flow ###
35-
Compiler creates a `BCodePhase`, calls `runOn(compilationUnits)`.
34+
Compiler creates a `GenBCode` `Phase`, calls `runOn(compilationUnits)`,
35+
which calls `run(context)`. This:
3636

37-
* initializes fields of `GenBCode` defined in `BCodeTypes` (BType maps,
38-
common BTypes like `StringReference`)
39-
* initialize `primitives` map defined in `scalaPrimitives` (maps primitive
37+
* initializes `myPrimitives` defined in `DottyPrimitives` (maps primitive
4038
members, like `int.+`, to bytecode instructions)
41-
* creates `BytecodeWriter`, `JMirrorBuilder` and `JBeanInfoBuilder` instances
42-
(on each compiler run)
39+
* creates a `GenBCodePipeline` and calls `run(tree)`
40+
41+
`GenBCodePipeline` now:
42+
43+
* initializes the `bTypes` field of `GenBCodePipeline` defined in `BCodeIdiomatic`
44+
(BType maps, common BTypes like `StringRef`)
45+
* creates `BytecodeWriter` and `JMirrorBuilder` instances (on each compiler run)
4346
* `buildAndSendToDisk(units)`: uses work queues, see below.
44-
- `BCodePhase.addToQ1` adds class trees to `q1`
45-
- `Worker1.visit` creates ASM `ClassNodes`, adds to `q2`. It creates one
47+
- `GenBCodePipeline.feedPipeline1` adds ClassDefs to `q1`
48+
- `Worker1.run` creates ASM `ClassNodes`, adds to `q2`. It creates one
4649
`PlainClassBuilder` for each compilation unit.
47-
- `Worker2.addToQ3` adds byte arrays (one for each class) to `q3`
48-
- `BCodePhase.drainQ3` writes byte arrays to disk
50+
- `Worker2.run` adds byte arrays (one for each class) to `q3`
51+
- `GenBCodePipeline.drainQ3` writes byte arrays to disk
4952

5053

5154
### Architecture ###
@@ -110,7 +113,7 @@ To understand how it's built, see:
110113
final def exemplar(csym0: Symbol): Tracked = { ... }
111114
```
112115

113-
Details in `BCodeTypes.scala`
116+
Details in `BTypes.scala`
114117

115118
#### (e) More "high-level" utilities for bytecode emission ####
116119
In the spirit of `BCodeIdiomatic`, utilities are added in `BCodeHelpers` for

0 commit comments

Comments
 (0)