summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/list/scalac.lst3
-rw-r--r--sources/scala/tools/scalac/CompilerPhases.scala2
-rw-r--r--sources/scala/tools/scalac/Global.scala16
-rw-r--r--sources/scala/tools/scalac/Main.scala3
-rw-r--r--sources/scala/tools/scalac/backend/GenJVMFromICode.scala8
-rw-r--r--sources/scala/tools/scalac/backend/GenJVMFromICodePhase.scala34
-rw-r--r--sources/scalac/CompilerPhases.java21
-rw-r--r--sources/scalac/Global.java12
-rw-r--r--sources/scalac/backend/jvm/GenJVM.java8
-rw-r--r--sources/scalac/backend/jvm/GenJVMPhase.java49
-rw-r--r--sources/scalac/backend/msil/GenMSIL.java21
-rw-r--r--sources/scalac/backend/msil/GenMSILPhase.java62
-rw-r--r--sources/scalac/backend/msil/TypeCreator.java12
13 files changed, 57 insertions, 194 deletions
diff --git a/config/list/scalac.lst b/config/list/scalac.lst
index 8bb2e4c81f..1bbf495f71 100644
--- a/config/list/scalac.lst
+++ b/config/list/scalac.lst
@@ -50,10 +50,8 @@
../../../scalac/backend/Primitive.java
../../../scalac/backend/Primitives.java
-../../../scalac/backend/jvm/GenJVMPhase.java
../../../scalac/backend/jvm/GenJVM.java
../../../scalac/backend/msil/GenMSIL.java
-../../../scalac/backend/msil/GenMSILPhase.java
../../../scalac/backend/msil/TypeCreator.java
../../../scalac/checkers/CheckTreeNodes.java
@@ -212,7 +210,6 @@ icode/ICodePrinter.scala
icode/ICTypeStack.scala
backend/GenJVMFromICode.scala
-backend/GenJVMFromICodePhase.scala
wholeprog/ApplicationBuilder.scala
wholeprog/PrintDotFile.scala
diff --git a/sources/scala/tools/scalac/CompilerPhases.scala b/sources/scala/tools/scalac/CompilerPhases.scala
index 3990e425ac..3f242be80c 100644
--- a/sources/scala/tools/scalac/CompilerPhases.scala
+++ b/sources/scala/tools/scalac/CompilerPhases.scala
@@ -30,8 +30,6 @@ class CompilerPhases extends scalac_CompilerPhases {
Class.forName("scala.tools.scalac.wholeprog.WholeProgPhase$class");
protected override def ICODE_PHASE(): Class =
Class.forName("scala.tools.scalac.icode.ICodePhase$class");
- protected override def GENJVMFROMICODE_PHASE(): Class =
- Class.forName("scala.tools.scalac.backend.GenJVMFromICodePhase$class");
}
}
diff --git a/sources/scala/tools/scalac/Global.scala b/sources/scala/tools/scalac/Global.scala
index 81ce563e70..4ed46cfb22 100644
--- a/sources/scala/tools/scalac/Global.scala
+++ b/sources/scala/tools/scalac/Global.scala
@@ -6,8 +6,11 @@
** $Id: Global.scala
\* */
-import scalac.{CompilerCommand, Global => scalac_Global};
+import scalac.{CompilationUnit, CompilerCommand, Global => scalac_Global};
import scalac.ast.printer.TreePrinter;
+import scalac.backend.jvm.GenJVM;
+import scalac.backend.msil.GenMSIL;
+import scala.tools.scalac.backend.GenJVMFromICode;
package scala.tools.scalac {
@@ -31,5 +34,16 @@ class Global(args: CompilerCommand, interpret: boolean) extends scalac_Global(ar
override def newSwingTreePrinter(writer: PrintWriter): TreePrinter =
new SwingTreePrinter(this);
+ override def dump(units: Array[CompilationUnit]): Unit = {
+ if (target == scalac_Global.TARGET_JVM) {
+ GenJVM.translate(this, units);
+ } else if (target == scalac_Global.TARGET_MSIL) {
+ GenMSIL.translate(this, units);
+ } else if (target == scalac_Global.TARGET_JVMFROMICODE) {
+ GenJVMFromICode.translate(this, units);
+ }
+ symdata.clear();
+ }
+
}
}
diff --git a/sources/scala/tools/scalac/Main.scala b/sources/scala/tools/scalac/Main.scala
index 25f033cba9..2f020983e5 100644
--- a/sources/scala/tools/scalac/Main.scala
+++ b/sources/scala/tools/scalac/Main.scala
@@ -42,7 +42,8 @@ object Main {
}
if (ok) {
val global = new Global(command);
- global.compile(command.files.toArray(), false);
+ val units = global.compile(command.files.toArray(), false);
+ if (reporter.errors() == 0) global.dump(units);
global.stop("total");
global.reporter.printSummary();
}
diff --git a/sources/scala/tools/scalac/backend/GenJVMFromICode.scala b/sources/scala/tools/scalac/backend/GenJVMFromICode.scala
index 41e6a424c6..3ad109b379 100644
--- a/sources/scala/tools/scalac/backend/GenJVMFromICode.scala
+++ b/sources/scala/tools/scalac/backend/GenJVMFromICode.scala
@@ -20,6 +20,14 @@ import java.io.File;
package scala.tools.scalac.backend {
+object GenJVMFromICode {
+ def translate(global: scalac_Global, units: Array[CompilationUnit]): Unit = {
+ val translator = new GenJVMFromICode(global);
+ var i = 0;
+ while (i < units.length) { translator.translate(units(i)); i = i + 1; }
+ }
+}
+
/* This class implements the backend which create
* Java Virtual Machine's bytecode with
* The Intermediate Code of the compiler */
diff --git a/sources/scala/tools/scalac/backend/GenJVMFromICodePhase.scala b/sources/scala/tools/scalac/backend/GenJVMFromICodePhase.scala
deleted file mode 100644
index 195d38fdd4..0000000000
--- a/sources/scala/tools/scalac/backend/GenJVMFromICodePhase.scala
+++ /dev/null
@@ -1,34 +0,0 @@
-/* ____ ____ ____ ____ ______ *\
-** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
-** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
-** /_____/\____/\___/\____/____/ **
-\* */
-
-// $Id$
-
-import scalac.{Global => scalac_Global}
-import scalac.CompilationUnit;
-import scalac.PhaseDescriptor;
-import scalac.Phase;
-
-package scala.tools.scalac.backend {
-
-/* This class represents the JVMFromICode backend production
- * Phase. It uses the ICode to create class files using
- * the JVM's bytecode */
-class GenJVMFromICodePhase(global0: scalac_Global, descriptor0: PhaseDescriptor) extends Phase(global0, descriptor0) {
-
- //##########################################################################
- // Private Fields
-
- private val generator = new GenJVMFromICode(global);
-
- //##########################################################################
- // Public Methods
-
- /** Applies this phase to the given compilation unit. */
- override def apply(unit: CompilationUnit): Unit = generator.translate(unit);
-
- //##########################################################################
-}
-}
diff --git a/sources/scalac/CompilerPhases.java b/sources/scalac/CompilerPhases.java
index 4eab9b131f..4bf445cf26 100644
--- a/sources/scalac/CompilerPhases.java
+++ b/sources/scalac/CompilerPhases.java
@@ -40,9 +40,6 @@ public abstract class CompilerPhases {
public final PhaseDescriptor MAKEBOXINGEXPLICIT;
public final PhaseDescriptor ERASURE;
public final PhaseDescriptor ICODE;
- public final PhaseDescriptor GENMSIL;
- public final PhaseDescriptor GENJVM;
- public final PhaseDescriptor GENJVMFROMICODE;
public final PhaseDescriptor TERMINAL;
//########################################################################
@@ -69,9 +66,6 @@ public abstract class CompilerPhases {
protected Class EXPANDMIXIN_PHASE() { return scalac.transformer.ExpandMixinsPhase.class; }
protected Class ERASURE_PHASE() { return scalac.transformer.ErasurePhase.class; }
protected Class ICODE_PHASE() { return scalac.util.EmptyPhase.class; } // No java version
- protected Class GENMSIL_PHASE() { return scalac.backend.msil.GenMSILPhase.class; }
- protected Class GENJVM_PHASE() { return scalac.backend.jvm.GenJVMPhase.class; }
- protected Class GENJVMFROMICODE_PHASE() { return scalac.util.EmptyPhase.class; } // No java version
//########################################################################
// Public Constructors
@@ -175,21 +169,6 @@ public abstract class CompilerPhases {
"generate icode",
"generated icode",
ICODE_PHASE()),
- this.GENMSIL = new PhaseDescriptor(
- "genmsil",
- "generate MSIL code",
- "generated MSIL code",
- GENMSIL_PHASE()),
- this.GENJVM = new PhaseDescriptor(
- "genjvm",
- "generate JVM bytecodes",
- "generated JVM code",
- GENJVM_PHASE()),
- this.GENJVMFROMICODE = new PhaseDescriptor(
- "genjvmfromicode",
- "generate JVM bytecodes using ICode",
- "generated JVM code using ICode",
- GENJVMFROMICODE_PHASE()),
this.TERMINAL = new PhaseDescriptor(
"terminal",
"compilation terminated",
diff --git a/sources/scalac/Global.java b/sources/scalac/Global.java
index ec8f20ab81..141d6ec140 100644
--- a/sources/scalac/Global.java
+++ b/sources/scalac/Global.java
@@ -273,14 +273,7 @@ public abstract class Global {
// if (!optimize) PHASE.remove(args.phases.OPTIMIZE);
// TODO: Enable TailCall for other backends when they handle LabelDefs
if (!runTimeTypes) args.phases.TYPESASVALUES.addSkipFlag();
- if (target != TARGET_MSIL) args.phases.GENMSIL.addSkipFlag();
- if (target != TARGET_JVM) args.phases.GENJVM.addSkipFlag();
- if (target != TARGET_JVMFROMICODE) {
- args.phases.ICODE.addSkipFlag();
- args.phases.GENJVMFROMICODE.addSkipFlag();
- } else {
- ;//args.phases.ERASURE.addSkipFlag();
- }
+ if (target != TARGET_JVMFROMICODE) args.phases.ICODE.addSkipFlag();
PHASE.freeze();
PhaseDescriptor[] descriptors = PHASE.phases();
for (int i = 0; i <= PHASE.ANALYZER.id(); i++)
@@ -407,7 +400,6 @@ public abstract class Global {
clasz.reset(new SourceCompleter(this, file));
}
}
- symdata.clear();
compiledNow.clear();
treePrinter.end();
return units;
@@ -429,6 +421,8 @@ public abstract class Global {
}
}
+ public abstract void dump(CompilationUnit[] units);
+
private void print(CompilationUnit[] units) {
if (currentPhase.id == PHASE.MAKEBOXINGEXPLICIT.id()) {
boolean html = args.printer.value.equals(PRINTER_HTML);
diff --git a/sources/scalac/backend/jvm/GenJVM.java b/sources/scalac/backend/jvm/GenJVM.java
index ac8728e2d0..2a32495f8f 100644
--- a/sources/scalac/backend/jvm/GenJVM.java
+++ b/sources/scalac/backend/jvm/GenJVM.java
@@ -56,7 +56,7 @@ import scalac.util.*;
* @author Michel Schinz
*/
-class GenJVM {
+public class GenJVM {
protected final static String JAVA_LANG_OBJECT = "java.lang.Object";
protected final static String JAVA_LANG_STRING = "java.lang.String";
protected final static String JAVA_LANG_STRINGBUFFER =
@@ -118,6 +118,12 @@ class GenJVM {
/// Code generation
//////////////////////////////////////////////////////////////////////
+ /** Generate code for the given units. */
+ public static void translate(Global global, CompilationUnit[] units) {
+ GenJVM translator = new GenJVM(global);
+ for (int i = 0; i < units.length; i++) translator.translate(units[i]);
+ }
+
/**
* Generate code for the given unit.
*/
diff --git a/sources/scalac/backend/jvm/GenJVMPhase.java b/sources/scalac/backend/jvm/GenJVMPhase.java
deleted file mode 100644
index 06d39839c8..0000000000
--- a/sources/scalac/backend/jvm/GenJVMPhase.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/* ____ ____ ____ ____ ______ *\
-** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
-** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
-** /_____/\____/\___/\____/____/ **
-\* */
-
-// $Id$
-
-package scalac.backend.jvm;
-
-import scalac.Global;
-import scalac.Phase;
-import scalac.PhaseDescriptor;
-import scalac.CompilationUnit;
-
-/**
- * Phase to generate Java bytecodes using the FJBG library.
- *
- * @author Michel Schinz
- * @version 1.0
- */
-
-public class GenJVMPhase extends Phase {
-
- //########################################################################
- // Private Fields
-
- /** The tree to code translator */
- private final GenJVM translator;
-
- //########################################################################
- // Public Constructors
-
- /** Initializes this instance. */
- public GenJVMPhase(Global global, PhaseDescriptor descriptor) {
- super(global, descriptor);
- this.translator = new GenJVM(global);
- }
-
- //########################################################################
- // Public Methods
-
- /** Applies this phase to the given compilation unit. */
- public void apply(CompilationUnit unit) {
- translator.translate(unit);
- }
-
- //########################################################################
-}
diff --git a/sources/scalac/backend/msil/GenMSIL.java b/sources/scalac/backend/msil/GenMSIL.java
index 53c7da5021..0d6250e4c5 100644
--- a/sources/scalac/backend/msil/GenMSIL.java
+++ b/sources/scalac/backend/msil/GenMSIL.java
@@ -74,14 +74,25 @@ public final class GenMSIL {
private static final Item TRUE_ITEM = Item.CondItem(Test.True, null, null);
private static final Item FALSE_ITEM = Item.CondItem(Test.False, null, null);
+ /** The public entry point into the code generator. */
+ public static void translate(Global global, CompilationUnit[] units) {
+ TypeCreator tc = new TypeCreator(global);
+ GenMSIL translator = new GenMSIL(global, tc);
+ tc.init();
+ tc.collectSymbols(units);
+ tc.initAssembly();
+ for (int i = 0; i < units.length; i++) translator.apply(units[i]);
+ tc.saveAssembly();
+ }
+
/**
- * The public constructor of the code generator.
+ * The private constructor of the code generator.
*/
- public GenMSIL(Global global, GenMSILPhase phase) {
+ private GenMSIL(Global global, TypeCreator tc) {
this.global = global;
this.defs = global.definitions;
this.primitives = global.primitives;
- this.tc = phase.tc; //new TypeCreator(global, this, phase);
+ this.tc = tc; //new TypeCreator(global, this, phase);
this.items = new ItemFactory(this);
}
@@ -95,10 +106,10 @@ public final class GenMSIL {
private CompilationUnit currUnit;
/**
- * The main entry point into the code generator. Called from GenMSILPhase
+ * The main entry point into the code generator. Called from translate
* for every compilation unit.
*/
- public void apply(CompilationUnit unit) {
+ private void apply(CompilationUnit unit) {
currUnit = unit;
for (int i = 0; i < unit.body.length; i++) {
Tree tree = unit.body[i];
diff --git a/sources/scalac/backend/msil/GenMSILPhase.java b/sources/scalac/backend/msil/GenMSILPhase.java
deleted file mode 100644
index 0df65a1eb8..0000000000
--- a/sources/scalac/backend/msil/GenMSILPhase.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/* ____ ____ ____ ____ ______ *\
-** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
-** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
-** /_____/\____/\___/\____/____/ **
-\* */
-
-// $Id$
-
-package scalac.backend.msil;
-
-import scalac.Global;
-import scalac.Phase;
-import scalac.PhaseDescriptor;
-import scalac.CompilationUnit;
-
-import java.util.HashMap;
-
-public class GenMSILPhase extends Phase {
-
- //########################################################################
- // Private Fields
-
- /** The tree to code translator */
- private final GenMSIL translator;
-
- final HashMap types2symbols = new HashMap();
- final HashMap symbols2types = new HashMap();
- final HashMap symbols2fields = new HashMap();
- final HashMap symbols2methods = new HashMap();
- final HashMap symbols2moduleFields = new HashMap();
-
- final TypeCreator tc;
-
- //########################################################################
- // Public Constructors
-
- /** Initializes this instance. */
- public GenMSILPhase(Global global, PhaseDescriptor descriptor) {
- super(global, descriptor);
- this.tc = new TypeCreator(global, this);
- this.translator = new GenMSIL(global, this);
- }
-
- //########################################################################
- // Public Methods
-
- /** Applies this phase to the given compilation units. */
- public void apply(CompilationUnit[] units) {
- tc.init();
- tc.collectSymbols(units);
- tc.initAssembly();
- super.apply(units);
- tc.saveAssembly();
- }
-
- /** Applies this phase to the given compilation unit. */
- public void apply(CompilationUnit unit) {
- translator.apply(unit);
- }
-
- //########################################################################
-}
diff --git a/sources/scalac/backend/msil/TypeCreator.java b/sources/scalac/backend/msil/TypeCreator.java
index 85f793d87a..1b8fae8277 100644
--- a/sources/scalac/backend/msil/TypeCreator.java
+++ b/sources/scalac/backend/msil/TypeCreator.java
@@ -125,18 +125,18 @@ final class TypeCreator {
//##########################################################################
- TypeCreator(Global global, GenMSILPhase phase) {
+ TypeCreator(Global global) {
this.global = global;
this.defs = global.definitions;
this.backPhase = global.PHASE.ADDINTERFACES.phase();
ti = CLRTypes.instance();
- types2symbols = phase.types2symbols;
- symbols2types = phase.symbols2types;
- symbols2fields = phase.symbols2fields;
- symbols2methods = phase.symbols2methods;
- symbols2moduleFields = phase.symbols2moduleFields;
+ types2symbols = new HashMap();
+ symbols2types = new HashMap();
+ symbols2fields = new HashMap();
+ symbols2methods = new HashMap();
+ symbols2moduleFields = new HashMap();
BYTE = ti.BYTE;
CHAR = ti.CHAR;