diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2007-02-12 15:29:23 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2007-02-12 15:29:23 +0000 |
commit | ed30031b5cbae38799cad01dad8590e72897876a (patch) | |
tree | 17f3d89154df0fce6c595f29e5ad162dd1d379e2 /src | |
parent | b3a20024cb65086759f895af21a6e634fc3a3929 (diff) | |
download | scala-ed30031b5cbae38799cad01dad8590e72897876a.tar.gz scala-ed30031b5cbae38799cad01dad8590e72897876a.tar.bz2 scala-ed30031b5cbae38799cad01dad8590e72897876a.zip |
Added support for compileLate in icode phases.
Diffstat (limited to 'src')
7 files changed, 39 insertions, 28 deletions
diff --git a/src/compiler/scala/tools/nsc/CompilationUnits.scala b/src/compiler/scala/tools/nsc/CompilationUnits.scala index 4f2752b738..ad49327574 100644 --- a/src/compiler/scala/tools/nsc/CompilationUnits.scala +++ b/src/compiler/scala/tools/nsc/CompilationUnits.scala @@ -27,6 +27,11 @@ trait CompilationUnits requires Global { def position(pos: int) = new Position(source, pos) + /** The icode representation of classes in this compilation unit. + * It is empty up to phase 'icode'. + */ + val icode: HashSet[icodes.IClass] = new HashSet + val errorPositions = new HashSet[int] def error(pos: int, msg: String) = diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index 2d64666980..58f088002b 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -372,9 +372,9 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable mixer, cleanup, genicode, -// inliner, -// closureElimination, -// deadCode, + inliner, + closureElimination, + deadCode, if (forMSIL) genMSIL else genJVM, sampleTransform) diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala index eb4da57556..2622be079a 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala @@ -54,6 +54,7 @@ abstract class GenICode extends SubComponent { override def apply(unit: CompilationUnit): Unit = { this.unit = unit + unit.icode.clear log("Generating icode for " + unit) gen(unit.body) this.unit = null @@ -82,6 +83,7 @@ abstract class GenICode extends SubComponent { ctx setClass (new IClass(tree.symbol) setCompilationUnit unit) addClassFields(ctx, tree.symbol); classes += tree.symbol -> ctx.clazz + unit.icode += ctx.clazz gen(impl, ctx) ctx setClass null diff --git a/src/compiler/scala/tools/nsc/backend/icode/ICodes.scala b/src/compiler/scala/tools/nsc/backend/icode/ICodes.scala index 4806c575b3..a780a233d5 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/ICodes.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/ICodes.scala @@ -82,5 +82,16 @@ abstract class ICodes extends AnyRef } def init = { } + + /** A phase which works on icode. */ + abstract class ICodePhase(prev: Phase) extends global.GlobalPhase(prev) { + override def erasedTypes = true; + + override def apply(unit: global.CompilationUnit): Unit = { + unit.icode foreach { c => apply(c) } + } + + def apply(cls: global.icodes.IClass): Unit + } } diff --git a/src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala b/src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala index b19785a8e2..d4df49d05f 100644 --- a/src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala +++ b/src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala @@ -25,17 +25,13 @@ abstract class ClosureElimination extends SubComponent { /** The Inlining phase. */ - class ClosureEliminationPhase(prev: Phase) extends StdPhase(prev) { + class ClosureEliminationPhase(prev: Phase) extends ICodePhase(prev) { - override def erasedTypes = true; + def name = phaseName val closser = new ClosureElim; - override def run: Unit = { - if (settings.debug.value) inform("[running phase " + name + " on icode]"); - classes.values foreach closser.analyzeClass; - } - override def apply(unit: CompilationUnit): Unit = - abort("Inlining works on icode classes, not on compilation units!"); + override def apply(c: IClass): Unit = + closser.analyzeClass(c) } /** diff --git a/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala b/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala index 7220e230b6..8b987cdf79 100644 --- a/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala +++ b/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala @@ -25,18 +25,14 @@ abstract class DeadCodeElimination extends SubComponent { /** Dead code elimination phase. */ - class DeadCodeEliminationPhase(prev: Phase) extends StdPhase(prev) { + class DeadCodeEliminationPhase(prev: Phase) extends ICodePhase(prev) { - override def erasedTypes = true; + def name = phaseName val dce = new DeadCode(); - override def run: Unit = { - if (settings.debug.value) inform("[running phase " + name + " on icode]"); + override def apply(c: IClass): Unit = if (settings.Xdce.value) - classes.values foreach dce.analyzeClass; - } - override def apply(unit: CompilationUnit): Unit = - abort("Dead code elimination works on icode classes, not on compilation units!"); + dce.analyzeClass(c) } /** Remove dead code. diff --git a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala index d32ab4a87c..3afbbb56f0 100644 --- a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala +++ b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala @@ -25,17 +25,14 @@ abstract class Inliners extends SubComponent { /** The Inlining phase. */ - class InliningPhase(prev: Phase) extends StdPhase(prev) { + class InliningPhase(prev: Phase) extends ICodePhase(prev) { - override def erasedTypes = true; + def name = phaseName val inliner = new Inliner; - override def run: Unit = { - if (settings.debug.value) inform("[running phase " + name + " on icode]"); - classes.values foreach inliner.analyzeClass; - } - override def apply(unit: CompilationUnit): Unit = - abort("Inlining works on icode classes, not on compilation units!"); + override def apply(c: IClass): Unit = + inliner.analyzeClass(c) + } /** @@ -221,7 +218,11 @@ abstract class Inliners extends SubComponent { caller.exh = (callee.exh map translateExh) ::: caller.exh; } - val InlineAttr = if (settings.inline.value) global.definitions.getClass("scala.inline").tpe else null; + val InlineAttr = if (settings.inline.value) try { + global.definitions.getClass("scala.inline").tpe + } catch { + case e: FatalError => null + } else null; def analyzeClass(cls: IClass): Unit = if (settings.inline.value) { if (settings.debug.value) |