blob: 9863b5441739ad8192310fdbd150206e0777781b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/* NSC -- new scala compiler
* Copyright 2005 LAMP/EPFL
* @author Martin Odersky
*/
// $Id$
package scala.tools.nsc.backend.icode;
import java.io.PrintWriter;
import scala.tools.nsc.symtab._;
import scala.collection.mutable.HashMap;
/** Glue together ICode parts.
*/
abstract class ICodes extends AnyRef
with Members
with BasicBlocks
with Opcodes
with TypeStacks
with TypeKinds
with ExceptionHandlers
with Primitives
with Linearizers
{
val global: Global;
/** The ICode representation of classes */
var classes: HashMap[global.Symbol, IClass] = new HashMap();
/** The ICode linearizer. */
val linearizer: Linearizer =
if (global.settings.Xlinearizer.value == "rpo")
new ReversePostOrderLinearizer();
else if (global.settings.Xlinearizer.value == "dfs")
new DepthFirstLinerizer();
else if (global.settings.Xlinearizer.value == "normal")
new NormalLinearizer();
else
global.abort("Unknown linearizer: " + global.settings.Xlinearizer.value);
/** Print all classes and basic blocks. Used for debugging. */
def dump: Unit = {
val printer = new global.icodePrinter.TextPrinter(new PrintWriter(System.out, true),
new global.icodes.DumpLinearizer());
global.icodes.classes.values foreach { c => printer.printClass(c); }
}
def dump(m: global.icodes.IMethod) = {
val printer = new global.icodePrinter.TextPrinter(new PrintWriter(System.out, true),
new global.icodes.DumpLinearizer());
printer.printMethod(m);
}
/** Merge together blocks that have a single successor which has a
* single predecessor. Exception handlers are taken into account (they
* might force to break a block of straight line code like that).
*
* This method should be most effective after heavy inlining.
*/
def normalize(m: IMethod): Unit = if (m.code ne null) {
Console.println("Method " + m);
val mergeablePairs =
for (val b <- m.code.blocks.toList;
b.successors.length == 1;
val succ = b.successors.head;
succ.predecessors.length == 1;
succ.predecessors.head == b
/* !(m.exh.contains { (e: ExceptionHandler) => e.covers(b) && !e.covers(succ) }) */) {
Console.println("Block " + b + ".lastInstruction" + b.lastInstruction);
Console.println(" has successors: " + b.successors + " and succ has pred: " + succ.predecessors);
//yield Pair(b, succ)
}
// Console.println("Mergeable: " + mergeablePairs.mkString("", "\n", ""));
()
}
def init = { }
}
|