summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2006-06-20 14:32:50 +0000
committerIulian Dragos <jaguarul@gmail.com>2006-06-20 14:32:50 +0000
commit913b2c9b3a887fb9c1cecff1e2d699af29f312ab (patch)
tree691e9ca8a55f3f6cb60149eb84d99c51f89b1887 /src
parente10bdf2f822aa2c5a1faa9ccca5e7287809e3e33 (diff)
downloadscala-913b2c9b3a887fb9c1cecff1e2d699af29f312ab.tar.gz
scala-913b2c9b3a887fb9c1cecff1e2d699af29f312ab.tar.bz2
scala-913b2c9b3a887fb9c1cecff1e2d699af29f312ab.zip
Added a 'blocks' member to ExceptionHandlers wh...
Added a 'blocks' member to ExceptionHandlers which lists the basic blocks which form the given handler.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/Settings.scala2
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/ExceptionHandlers.scala15
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/GenICode.scala21
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/ICodes.scala2
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/Printers.scala1
5 files changed, 33 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala
index a75002249c..d6cd2536f6 100644
--- a/src/compiler/scala/tools/nsc/Settings.scala
+++ b/src/compiler/scala/tools/nsc/Settings.scala
@@ -117,7 +117,7 @@ class Settings(error: String => unit) {
val Xshowobj = StringSetting ("-Xshowobj", "object", "Show object info", "")
val Xshowicode = BooleanSetting("-Xshowicode", "Print the generated ICode")
val Xgadt = BooleanSetting("-Xgadt", "enable gadt for classes")
- val Xlinearizer = ChoiceSetting ("-Xlinearizer", "Linearizer to use", List("normal", "dfs", "rpo"), "rpo")
+ val Xlinearizer = ChoiceSetting ("-Xlinearizer", "Linearizer to use", List("normal", "dfs", "rpo", "dump"), "rpo")
val Xgenerics = BooleanSetting("-Xgenerics", "Use generic Java types");
/** A list of all settings */
diff --git a/src/compiler/scala/tools/nsc/backend/icode/ExceptionHandlers.scala b/src/compiler/scala/tools/nsc/backend/icode/ExceptionHandlers.scala
index 172c90cf7a..8f9d0a52e8 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/ExceptionHandlers.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/ExceptionHandlers.scala
@@ -27,17 +27,26 @@ trait ExceptionHandlers requires ICodes {
def setStartBlock(b: BasicBlock) = _startBlock = b;
def startBlock = _startBlock;
- def addBlock(b: BasicBlock): ExceptionHandler = {
+ /** The list of blocks that are covered by this exception handler */
+ var covered: List[BasicBlock] = Nil;
+
+ def addCoveredBlock(b: BasicBlock): ExceptionHandler = {
covered = b :: covered;
this
}
- var covered: List[BasicBlock] = Nil;
-
+ /** Is `b' covered by this exception handler? */
def covers(b: BasicBlock): Boolean = covered.contains(b);
+ /** The body of this exception handler. May contain 'dead' blocks (which will not
+ * make it into generated code because linearizers may not include them) */
+ var blocks: List[BasicBlock] = Nil;
+
+ def addBlock(b: BasicBlock): Unit = blocks = b :: blocks;
+
override def toString() = "exh_" + label + "(" + cls.simpleName + ")";
+ /** A standard copy constructor */
def this(other: ExceptionHandler) = {
this(other.method, other.label, other.cls);
covered = other.covered;
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
index 84ae7f7cde..931a041d3f 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
@@ -1378,6 +1378,7 @@ abstract class GenICode extends SubComponent {
method.code.removeBlock(block);
for (val e <- method.exh) {
e.covered = e.covered filter (.!=(block))
+ e.blocks = e.blocks filter (.!=(block))
if (e.startBlock eq block)
e setStartBlock cont;
}
@@ -1450,6 +1451,9 @@ abstract class GenICode extends SubComponent {
/** The current monitors, if inside synchronized blocks. */
var monitors: List[Local] = Nil;
+ /** The current exception handler, when we generate code for one. */
+ var currentExceptionHandler: Option[ExceptionHandler] = None;
+
var handlerCount = 0;
override def toString(): String = {
@@ -1476,6 +1480,7 @@ abstract class GenICode extends SubComponent {
this.handlers = other.handlers;
this.handlerCount = other.handlerCount;
this.monitors = other.monitors;
+ this.currentExceptionHandler = other.currentExceptionHandler;
}
def setPackage(p: Name): this.type = {
@@ -1523,12 +1528,18 @@ abstract class GenICode extends SubComponent {
/** Return a new context for a new basic block. */
def newBlock: Context = {
val block = method.code.newBlock;
- handlers foreach (h => h addBlock block);
+ handlers foreach (h => h addCoveredBlock block);
+ currentExceptionHandler match {
+ case Some(e) => e.addBlock(block)
+ case None => ()
+ }
new Context(this) setBasicBlock block;
}
/** Create a new exception handler and adds it in the list
- * of current exception handlers.
+ * of current exception handlers. All new blocks will be
+ * 'covered' by this exception handler (in addition to the
+ * previously active handlers).
*/
def newHandler(cls: Symbol): ExceptionHandler = {
handlerCount = handlerCount + 1;
@@ -1545,12 +1556,14 @@ abstract class GenICode extends SubComponent {
* exception handler.
*/
def enterHandler(exh: ExceptionHandler): Context = {
+ currentExceptionHandler = Some(exh);
val ctx = newBlock;
exh.setStartBlock(ctx.bb);
ctx
}
- def exitHandler(exh: ExceptionHandler): Unit = {
+ /** Remove the given handler from the list of active exception handlers. */
+ def removeHandler(exh: ExceptionHandler): Unit = {
assert(handlerCount > 0 && handlers.head == exh,
"Wrong nesting of exception handlers." + this + " for " + exh);
handlerCount = handlerCount - 1;
@@ -1599,7 +1612,7 @@ abstract class GenICode extends SubComponent {
outerCtx.bb.emit(JUMP(bodyCtx.bb));
outerCtx.bb.close;
- exhs.reverse foreach finalCtx.exitHandler;
+ exhs.reverse foreach finalCtx.removeHandler;
finalCtx.bb.emit(JUMP(afterCtx.bb));
finalCtx.bb.close;
diff --git a/src/compiler/scala/tools/nsc/backend/icode/ICodes.scala b/src/compiler/scala/tools/nsc/backend/icode/ICodes.scala
index b16e9a9893..6977f82e4e 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/ICodes.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/ICodes.scala
@@ -38,6 +38,8 @@ abstract class ICodes extends AnyRef
new DepthFirstLinerizer();
else if (global.settings.Xlinearizer.value == "normal")
new NormalLinearizer();
+ else if (global.settings.Xlinearizer.value == "dump")
+ new DumpLinearizer();
else
global.abort("Unknown linearizer: " + global.settings.Xlinearizer.value);
diff --git a/src/compiler/scala/tools/nsc/backend/icode/Printers.scala b/src/compiler/scala/tools/nsc/backend/icode/Printers.scala
index 629c4e0d5b..621936693d 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/Printers.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/Printers.scala
@@ -108,6 +108,7 @@ abstract class Printers {
def printExceptionHandler(e: ExceptionHandler) = {
indent;
println("catch (" + e.cls.simpleName + ") in " + e.covered + " starting at: " + e.startBlock);
+ println("consisting of blocks: " + e.blocks);
undent;
println("with finalizer: " + e.finalizer);
// linearizer.linearize(e.startBlock) foreach printBlock;