summaryrefslogtreecommitdiff
path: root/sources/scalac/CompilerPhases.java
blob: 93007eda28ba61df729d7f8e0ef50cfd0bfbc77b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*     ____ ____  ____ ____  ______                                     *\
**    / __// __ \/ __// __ \/ ____/    SOcos COmpiles Scala             **
**  __\_ \/ /_/ / /__/ /_/ /\_ \       (c) 2002, LAMP/EPFL              **
** /_____/\____/\___/\____/____/                                        **
\*                                                                      */

// $Id$

package scalac;

import java.util.ArrayList;
import java.util.List;

/**
 * This class defines all compiler phases and maintains a list of
 * active phases.
 */
public class CompilerPhases {

    //########################################################################
    // Public Fields

    /** The compiler phases. */
    public final PhaseDescriptor INITIAL;
    public final PhaseDescriptor PARSER;
    public final PhaseDescriptor ANALYZER;
    public final PhaseDescriptor REFCHECK;
    public final PhaseDescriptor UNCURRY;
    // public final PhaseDescriptor OPTIMIZE;
    public final PhaseDescriptor TRANSMATCH;
    public final PhaseDescriptor LAMBDALIFT;
    public final PhaseDescriptor EXPLICITOUTER;
    public final PhaseDescriptor ADDACCESSORS;
    public final PhaseDescriptor TAILCALL;
    public final PhaseDescriptor ADDINTERFACES;
    public final PhaseDescriptor EXPANDMIXIN;
    public final PhaseDescriptor ADDCONSTRUCTORS;
    public final PhaseDescriptor ERASURE;
    public final PhaseDescriptor GENMSIL;
    public final PhaseDescriptor GENJVM;
    public final PhaseDescriptor TERMINAL;

    //########################################################################
    // Private Fields

    /** The list containing the active phases */
    private final List phases;

    //########################################################################
    // Public Constructors

    /** Initializes this instance. */
    public CompilerPhases() {
        this.phases = new ArrayList();
        PhaseDescriptor[] array = {
            this.INITIAL = new PhaseDescriptor(
                "initial",
                "initializing compiler",
                "initializing compiler",
                scalac.util.EmptyPhase.class),
            this.PARSER = new PhaseDescriptor(
                "parse",
                "parse source files",
                "parsed",
                scalac.ast.parser.ParserPhase.class),
            this.ANALYZER = new PhaseDescriptor(
                "analyze",
                "name and type analysis",
                "type checking",
                scalac.typechecker.AnalyzerPhase.class),
            this.REFCHECK = new PhaseDescriptor(
                "refcheck",
                "reference checking",
                "reference checking",
                scalac.typechecker.RefCheckPhase.class),
            this.UNCURRY = new PhaseDescriptor(
                "uncurry",
                "uncurry function types and applications",
                "uncurried",
                scalac.transformer.UnCurryPhase.class),
//             this.OPTIMIZE = new PhaseDescriptor(
//                 "optimize",
//                 "tree-optimizer",
//                 "tree optimization",
//                 scalac.optimizer.OptimizePhase.class),
            this.TRANSMATCH = new PhaseDescriptor(
                "transmatch",
                "translate match expressions",
                "translated pattern matching",
                scalac.transformer.TransMatchPhase.class),
            this.LAMBDALIFT = new PhaseDescriptor(
                "lambdalift",
                "lambda lifter",
                "lambda lifting",
                scalac.transformer.LambdaLiftPhase.class),
            this.EXPLICITOUTER = new PhaseDescriptor(
                "explicitouterclasses",
                "make links from inner classes to enclosing one explicit",
                "made outer links explicit",
                scalac.transformer.ExplicitOuterClassesPhase.class),
            this.ADDACCESSORS = new PhaseDescriptor(
                "addaccessors",
                "add accessors for constructor arguments",
                "added accessors",
                scalac.transformer.AddAccessorsPhase.class),
            this.TAILCALL = new PhaseDescriptor(
                "tailcall",
                "add tail-calls",
                "added tail-calls",
                scalac.transformer.TailCallPhase.class),
            this.ADDINTERFACES = new PhaseDescriptor(
                "addinterfaces",
                "add one interface per class",
                "added interfaces",
                scalac.transformer.AddInterfacesPhase.class),
            this.EXPANDMIXIN = new PhaseDescriptor(
                "expandmixins",
                "expand mixins by code copying",
                "expanded mixins",
                scalac.transformer.ExpandMixinsPhase.class),
            this.ADDCONSTRUCTORS = new PhaseDescriptor(
                "addconstructors",
                "add explicit constructor for each class",
                "added constructors",
                scalac.transformer.AddConstructorsPhase.class),
            this.ERASURE = new PhaseDescriptor(
                "erasure",
                "type eraser",
                "erased types",
                scalac.transformer.ErasurePhase.class),
            this.GENMSIL = new PhaseDescriptor(
                "genmsil",
                "generate MSIL code",
                "generated MSIL code",
                scalac.backend.msil.GenMSILPhase.class),
            this.GENJVM = new PhaseDescriptor(
                "genjvm",
                "generate JVM bytecodes",
                "generated JVM code",
                scalac.backend.jvm.GenJVMPhase.class),
            this.TERMINAL = new PhaseDescriptor(
                "terminal",
                "compilation terminated",
                "compilation terminated",
                scalac.util.EmptyPhase.class),
        };
        for (int i = 0; i < array.length; i++) phases.add(array[i]);
    }

    //########################################################################
    // Public Methods

    /** Returns an array containing all active phases. */
    public PhaseDescriptor[] phases() {
        PhaseDescriptor[] array = new PhaseDescriptor[phases.size()];
        phases.toArray(array);
        return array;
    }

    /** Freezes all active phases. */
    public void freeze() {
        PhaseDescriptor[] phases = phases();
        PhaseDescriptor.freeze(phases);
    }

    /** Activates phase "phase" by placing it before phase "where". */
    public int insertBefore(PhaseDescriptor phase, PhaseDescriptor where) {
        int index = phases.indexOf(where);
        assert index >= 0 : "could not find phase " + where;
        phases.add(index, phase);
        return index;
    }

    /** Activates phase "phase" by placing it after phase "where". */
    public int insertAfter(PhaseDescriptor phase, PhaseDescriptor where) {
        int index = phases.indexOf(where);
        assert index >= 0 : "could not find phase " + where;
        phases.add(index + 1, phase);
        return index + 1;
    }

    //########################################################################
}