Added 'loop header' field to basic blocks to ease Andre's computation of the cut set.

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@7089 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
dragos 2006-04-10 09:47:38 +00:00
parent bdb68eb59c
commit a27966c7cd
5 changed files with 14 additions and 19 deletions

View File

@ -662,7 +662,7 @@ trait Parsers requires SyntaxAnalyzer {
Try(body, catches, finalizer)
}
case WHILE =>
val lname: Name = unit.fresh.newName("label$");
val lname: Name = unit.fresh.newName("while$");
val pos = in.skipToken();
accept(LPAREN);
val cond = expr();
@ -671,7 +671,7 @@ trait Parsers requires SyntaxAnalyzer {
val body = expr();
atPos(pos) { makeWhile(lname, cond, body) }
case DO =>
val lname: Name = unit.fresh.newName("label$");
val lname: Name = unit.fresh.newName("doWhile$");
val pos = in.skipToken();
val body = expr();
if (in.token == SEMI || in.token == NEWLINE) in.nextToken();

View File

@ -24,19 +24,16 @@ trait BasicBlocks requires ICodes {
extends AnyRef
with ProgramPoint[BasicBlock] {
/** The type stack at the begining of the block */
var initialStack : TypeStack = null;
/** The label of the block */
val label = theLabel;
/** The stack at the end of the block */
var endStack : TypeStack = null;
/** When set, the 'emit' methods will be ignored. */
var ignore: Boolean = false;
var preds: List[BasicBlock] = null;
/** Is this block the head of a while? */
var loopHeader = false;
/** ICode instructions, used as temporary storage while emitting code.
* Once closed is called, only the `instrs' array should be used.
@ -85,14 +82,6 @@ trait BasicBlocks requires ICodes {
else
instructionList.length;
/** Initialize the stack of the block, must be done before evaluation
* the type stack */
def initStack(stack : TypeStack) = {
if (initialStack == null) {
initialStack = stack;
endStack = null;
}
}
///////////////////// Substitutions ///////////////////////

View File

@ -336,6 +336,9 @@ abstract class GenICode extends SubComponent {
val resCtx: Context = tree match {
case LabelDef(name, params, rhs) =>
val ctx1 = ctx.newBlock;
if (isLoopHeaderLabel(name))
ctx1.bb.loopHeader = true;
ctx1.labels.get(tree.symbol) match {
case Some(label) =>
label.anchor(ctx1.bb);
@ -1381,6 +1384,9 @@ abstract class GenICode extends SubComponent {
List.forall2(tree.params, ctx.defdef.vparamss.head)
{ (x, y) => x.symbol == y.symbol }
);
def isLoopHeaderLabel(name: Name): Boolean =
name.startsWith("while$") || name.startsWith("doWhile$");
/////////////////////// Context ////////////////////////////////

View File

@ -35,8 +35,6 @@ trait Members requires ICodes {
// Constructor code
startBlock = newBlock;
startBlock.initStack(new TypeStack);
def removeBlock(b: BasicBlock) = {
if (settings.debug.value) {

View File

@ -113,7 +113,9 @@ abstract class Printers {
}
def printBlock(bb: BasicBlock): Unit = {
print(bb.label); print(": "); indent; println;
print(bb.label);
if (bb.loopHeader) print("[loop header]");
print(": "); indent; println;
bb.toList foreach printInstruction;
undent; println;
}