@@ -3,11 +3,11 @@ layout: doc-page
3
3
title : " Backend Internals"
4
4
---
5
5
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 .
8
8
9
9
```
10
- object GenBCode --- [defines] --> PlainClassBuilder GenBCode also defines class BCodePhase, the compiler phase
10
+ class GenBCodePipeline - [defines]--> PlainClassBuilder
11
11
| |
12
12
[extends] [extends]
13
13
| |
@@ -18,34 +18,37 @@ BCodeBodyBuilder ----------------> PlainBodyBuilder
18
18
BCodeSkelBuilder ----------------> PlainSkelBuilder
19
19
| / | \
20
20
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
+ | |
25
25
| BytecodeWriters ---------> methods and classes to write byte code files
26
26
|
27
- BCodeTypes ----------------> maps and fields for common BTypes, class Tracked, methods to collect information on classes, tests for BTypes (conforms), ...
28
- |
29
27
BCodeIdiomatic ----------------> utilities for code generation, e.g. genPrimitiveArithmetic
30
- |
31
- BCodeGlue ----------------> BType class, predefined BTypes
28
+ \--------------> `bTypes`: maps and fields for common BTypes
32
29
```
33
30
31
+ The ` BTypes.scala ` class contains the ` BType ` class and predefined BTypes
32
+
34
33
### 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:
36
36
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
40
38
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)
43
46
* ` 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
46
49
` 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
49
52
50
53
51
54
### Architecture ###
@@ -110,7 +113,7 @@ To understand how it's built, see:
110
113
final def exemplar (csym0 : Symbol ): Tracked = { ... }
111
114
```
112
115
113
- Details in ` BCodeTypes .scala`
116
+ Details in ` BTypes .scala`
114
117
115
118
#### (e) More "high-level" utilities for bytecode emission ####
116
119
In the spirit of ` BCodeIdiomatic ` , utilities are added in ` BCodeHelpers ` for
0 commit comments