annotate doc/compiler.rst @ 293:6aa721e7b10b

Try to improve build sequence
author Windel Bouwman
date Thu, 28 Nov 2013 20:39:37 +0100
parents ea93e0a7a31e
children a6f61e9a9d5c
rev   line source
273
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
1
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
2
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
3 Compiler
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
4 ========
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
5
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
6 This chapter describes the design of the compiler.
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
7
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
8
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
9 Overview
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
10 --------
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
11
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
12 The compiler consists a frontend, mid-end and back-end. The frontend deals with
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
13 source file parsing and semantics checking. The mid-end performs optimizations.
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
14 This is optional. The back-end generates machine code. The front-end produces
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
15 intermediate code. This is a simple representation of the source. The back-end
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
16 can accept this kind of representation. This way the compiler is portable and
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
17 a front end can be constructed without having to do the rest.
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
18
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
19 .. graphviz::
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
20
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
21 digraph x {
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
22 rankdir="LR"
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
23 1 [label="c3 source file"]
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
24 10 [label="c3 front end" ]
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
25 11 [label="language X front end" ]
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
26 20 [label="mid end" ]
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
27 30 [label="back end for X86" ]
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
28 31 [label="back end for ARM" ]
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
29 40 [label="object file"]
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
30 1 -> 10
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
31 10 -> 20 [label="IR-code"]
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
32 11 -> 20 [label="IR-code"]
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
33 20 -> 30 [label="IR-code"]
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
34 20 -> 31 [label="IR-code"]
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
35 30 -> 40
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
36 }
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
37
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
38 IR-code
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
39 -------
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
40 The IR-code is implemented in the ir package.
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
41
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
42 .. autoclass:: ir.Module
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
43
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
44 .. autoclass:: ir.Function
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
45
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
46 .. autoclass:: ir.Block
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
47
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
48 .. autoclass:: ir.Statement
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
49
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
50 .. autoclass:: ir.Expression
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
51
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
52 .. # .. inheritance-diagram:: ir.Statement
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
53
274
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
54 C3 Front-end
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
55 ------------
273
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
56
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
57 For the front-end a recursive descent parser is created for the c3 language.
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
58 This is a subset of the C language with some additional features.
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
59
274
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
60 .. graphviz::
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
61
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
62 digraph c3 {
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
63 rankdir="LR"
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
64 1 [label="source text"]
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
65 10 [label="lexer" ]
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
66 20 [label="parser" ]
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
67 30 [label="semantic checks" ]
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
68 40 [label="code generation"]
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
69 99 [label="IR-code object"]
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
70 1 -> 20
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
71 20 -> 30
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
72 30 -> 40
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
73 40 -> 99
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
74 subgraph rel1 {
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
75 edge [dir=none]
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
76 10 -> 20
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
77 }
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
78 }
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
79
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
80 .. autoclass:: c3.Builder
273
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
81
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
82 .. autoclass:: c3.Parser
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
83
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
84 .. autoclass:: c3.CodeGenerator
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
85
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
86 Back-end
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
87 --------
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
88
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
89 The back-end is more complicated. There are several steps to be taken here.
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
90
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
91 1. Instruction selection
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
92 2. register allocation
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
93 3. Peep hole optimization?
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
94 4. real code generation
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
95
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
96 .. automodule:: codegenarm
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
97 :members:
6b3a874edd6e Added some docs
Windel Bouwman
parents:
diff changeset
98
274
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
99 Instruction selection
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
100 ~~~~~~~~~~~~~~~~~~~~~
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
101
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
102 The instruction selection phase takes care of scheduling and instruction
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
103 selection. The output of this phase is a one frame per function with a flat
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
104 list of abstract machine instructions.
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
105
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
106 .. autoclass:: irmach.Frame
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
107
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
108 .. autoclass:: irmach.AbstractInstruction
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
109
ea93e0a7a31e Move docs
Windel Bouwman
parents: 273
diff changeset
110