@@ -3,11 +3,11 @@ layout: doc-page
33title : " 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
1818BCodeSkelBuilder ----------------> 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- |
2927BCodeIdiomatic ----------------> 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:
110113final 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 ####
116119In the spirit of ` BCodeIdiomatic ` , utilities are added in ` BCodeHelpers ` for
0 commit comments