summaryrefslogtreecommitdiff
path: root/sources/scalac
diff options
context:
space:
mode:
authorNAME <USER@epfl.ch>2004-01-30 13:07:45 +0000
committerNAME <USER@epfl.ch>2004-01-30 13:07:45 +0000
commitbec9884b00d60a79671e51a5a65b1717f753f981 (patch)
tree0a8d4bfa78fbe173ddaf6a8fa8f1e34902f8ee84 /sources/scalac
parent0bc48e99d91c250590e6ec1ed376aec348df5cb4 (diff)
downloadscala-bec9884b00d60a79671e51a5a65b1717f753f981.tar.gz
scala-bec9884b00d60a79671e51a5a65b1717f753f981.tar.bz2
scala-bec9884b00d60a79671e51a5a65b1717f753f981.zip
Added intermediate code and corresponding jvm b...
Added intermediate code and corresponding jvm backend
Diffstat (limited to 'sources/scalac')
-rw-r--r--sources/scalac/CompilerPhases.java16
-rw-r--r--sources/scalac/Global.java23
-rw-r--r--sources/scalac/atree/AMethod.java5
-rw-r--r--sources/scalac/atree/AShiftOp.java14
-rw-r--r--sources/scalac/atree/ATreeTyper.java32
-rw-r--r--sources/scalac/transformer/ICodePhase.java59
6 files changed, 137 insertions, 12 deletions
diff --git a/sources/scalac/CompilerPhases.java b/sources/scalac/CompilerPhases.java
index dae13e6c91..adac32a95e 100644
--- a/sources/scalac/CompilerPhases.java
+++ b/sources/scalac/CompilerPhases.java
@@ -37,8 +37,10 @@ public class CompilerPhases {
public final PhaseDescriptor EXPANDMIXIN;
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;
//########################################################################
@@ -62,8 +64,10 @@ public class CompilerPhases {
protected Class ADDINTERFACES_PHASE() { return scalac.transformer.AddInterfacesPhase.class; }
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
@@ -152,6 +156,11 @@ public class CompilerPhases {
"type eraser",
"erased types",
ERASURE_PHASE()),
+ this.ICODE = new PhaseDescriptor(
+ "icode",
+ "generate icode",
+ "generated icode",
+ ICODE_PHASE()),
this.GENMSIL = new PhaseDescriptor(
"genmsil",
"generate MSIL code",
@@ -162,7 +171,12 @@ public class CompilerPhases {
"generate JVM bytecodes",
"generated JVM code",
GENJVM_PHASE()),
- this.TERMINAL = new PhaseDescriptor(
+ this.GENJVMFROMICODE = new PhaseDescriptor(
+ "genjvmfromicode",
+ "generate JVM bytecodes using ICode",
+ "generated JVM code using ICode",
+ GENJVMFROMICODE_PHASE()),
+ this.TERMINAL = new PhaseDescriptor(
"terminal",
"compilation terminated",
"compilation terminated",
diff --git a/sources/scalac/Global.java b/sources/scalac/Global.java
index bd411f7439..37e2ed95d9 100644
--- a/sources/scalac/Global.java
+++ b/sources/scalac/Global.java
@@ -136,11 +136,13 @@ public class Global {
public static final String TARGET_INT;
public static final String TARGET_JVM;
public static final String TARGET_MSIL;
+ public static final String TARGET_JVMFROMICODE;
public static final String[] TARGETS = new String[] {
- TARGET_INT = "int",
- TARGET_JVM = "jvm",
- TARGET_MSIL = "msil",
+ TARGET_INT = "int",
+ TARGET_JVM = "jvm",
+ TARGET_MSIL = "msil",
+ TARGET_JVMFROMICODE = "jvmfromicode"
};
/** tree printers
@@ -225,6 +227,12 @@ public class Global {
// TODO: Enable TailCall for other backends when they handle LabelDefs
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();
+ }
PHASE.freeze();
PhaseDescriptor[] descriptors = PHASE.phases();
this.firstPhase = descriptors[0].create(this);
@@ -334,6 +342,15 @@ public class Global {
printer.printGlobal(this);
if (next) currentPhase = currentPhase.prev;
if (html) writer.println("</pre>");
+ } else if (currentPhase.id == PHASE.ICODE.id()) {
+ boolean html = args.printer.value.equals(PRINTER_HTML);
+ if (html) writer.println("<pre>");
+ ATreePrinter printer = ((scalac.transformer.ICodePhase)currentPhase).getPrinter(new CodePrinter(writer)); // Oh !!
+ boolean next = currentPhase.next != null;
+ if (next) currentPhase = currentPhase.next;
+ printer.printGlobal(this);
+ if (next) currentPhase = currentPhase.prev;
+ if (html) writer.println("</pre>");
} else {
// go to next phase to print symbols with their new type
boolean next = currentPhase.next != null;
diff --git a/sources/scalac/atree/AMethod.java b/sources/scalac/atree/AMethod.java
index 332f2284d4..f904fa6b92 100644
--- a/sources/scalac/atree/AMethod.java
+++ b/sources/scalac/atree/AMethod.java
@@ -13,6 +13,11 @@ import scalac.symtab.Type;
/** This class represents an attributed method. */
public class AMethod extends AMember {
+ //########################################################################
+ // Public Fields
+
+ /** Contains the Intermediate code of this Method */
+ public Object icode = null;
//########################################################################
// Public Constructors
diff --git a/sources/scalac/atree/AShiftOp.java b/sources/scalac/atree/AShiftOp.java
index 102f7963bd..fbed80fcde 100644
--- a/sources/scalac/atree/AShiftOp.java
+++ b/sources/scalac/atree/AShiftOp.java
@@ -16,24 +16,24 @@ public class AShiftOp {
//########################################################################
// Public Cases
- /** A logical shift to the left */
- public case LSL;
-
- /** A logical shift to the right */
- public case LSR;
+ /** An arithmetic shift to the left */
+ public case ASL;
/** An arithmetic shift to the right */
public case ASR;
+ /** A logical shift to the right */
+ public case LSR;
+
//########################################################################
// Public Methods
/** Returns a string representation of this operation. */
public String toString() {
switch (this) {
- case LSL: return "LSL";
- case LSR: return "LSR";
+ case ASL: return "ASL";
case ASR: return "ASR";
+ case LSR: return "LSR";
default: throw Debug.abort("unknown case", this);
}
}
diff --git a/sources/scalac/atree/ATreeTyper.java b/sources/scalac/atree/ATreeTyper.java
index 3a1a1df5c7..dead4e7c40 100644
--- a/sources/scalac/atree/ATreeTyper.java
+++ b/sources/scalac/atree/ATreeTyper.java
@@ -217,6 +217,36 @@ public class ATreeTyper {
}
//########################################################################
+ // Public Methods - aliases of type() for scala
+ public Type[] computeType(ACode[] codes) {
+ return type(codes);
+ }
+
+ public Type computeType(ACode code) {
+ return type(code);
+ }
+
+ public Type computeType(ALocation location) {
+ return type(location);
+ }
+
+ public Type computeType(AFunction function) {
+ return type(function);
+ }
+
+ public Type computeType(APrimitive primitive) {
+ return type(primitive);
+ }
+
+ public Type computeType(AConstant constant) {
+ return type(constant);
+ }
+
+ public Type computeType(ATypeKind kind) {
+ return type(kind);
+ }
+
+ //########################################################################
// Private Methods
/** Returns the application of given arguments to given type. */
@@ -231,7 +261,7 @@ public class ATreeTyper {
}
/** Returns the element type of the given array type. */
- private Type getArrayElementType(Type type) {
+ public Type getArrayElementType(Type type) { // !!! public / private
switch (type) {
case TypeRef(_, Symbol symbol, Type[] args):
assert symbol == definitions.ARRAY_CLASS && args.length == 1: type;
diff --git a/sources/scalac/transformer/ICodePhase.java b/sources/scalac/transformer/ICodePhase.java
new file mode 100644
index 0000000000..5ed3212da1
--- /dev/null
+++ b/sources/scalac/transformer/ICodePhase.java
@@ -0,0 +1,59 @@
+/* ____ ____ ____ ____ ______ *\
+** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
+** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
+** /_____/\____/\___/\____/____/ **
+\* */
+
+// $Id:
+
+package scalac.transformer;
+
+import scalac.Global;
+import scalac.Phase;
+import scalac.PhaseDescriptor;
+import scalac.Unit;
+import scalac.checkers.TreeChecker;
+import scalac.symtab.Definitions;
+
+import ch.epfl.lamp.util.CodePrinter;
+import scalac.atree.ATreePrinter;
+
+
+/**
+ * This class represents the ICode phase for the java version
+ * of the compiler. It doesn't do anything but permit to make
+ * a bridge between the java implementation of Socos et the
+ * scala one. See scala.tools.scalac.icode.ICodePhase for
+ * implementation
+ */
+public class ICodePhase extends Phase {
+
+ //########################################################################
+ // Private Fields
+
+ private final Definitions definitions;
+
+ //########################################################################
+ // Public Constructors
+
+ /** Initializes this instance. */
+ public ICodePhase(Global global, PhaseDescriptor descriptor) {
+ super(global, descriptor);
+ this.definitions = global.definitions;
+ }
+
+ //########################################################################
+ // Public Methods
+
+ /** Applies this phase to the given compilation units. */
+ public void apply(Unit[] units) {
+ // This java version doesn't make anything
+ }
+
+ public ATreePrinter getPrinter(CodePrinter cp) {
+ return new ATreePrinter(cp);
+ // !! Useless
+ }
+
+}
+