summaryrefslogtreecommitdiff
path: root/sources/scala/tools/scalac/icode/ICodePrinter.scala
blob: 7af0d6fa5efcfa8a3abce8b37f02b1a938de0d44 (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
/*     ____ ____  ____ ____  ______                                     *\
**    / __// __ \/ __// __ \/ ____/    SOcos COmpiles Scala             **
**  __\_ \/ /_/ / /__/ /_/ /\_ \       (c) 2002, LAMP/EPFL              **
** /_____/\____/\___/\____/____/                                        **
\*                                                                      */


// $Id$

import ch.epfl.lamp.util.CodePrinter;

import scalac.CompilationUnit;
import scalac.{Global => scalac_Global}
import scalac.atree._;

import scalac.{symtab => scalac_symtab}

package scala.tools.scalac.icode {

import scalac_symtab.Symbol;

/* This class implements a Printer for the ICode */
class ICodePrinter (printer: CodePrinter) extends ATreePrinter (printer: CodePrinter) {

  // ##################################################
  // Public methods

  /* This method print all ICode produced after the ICode phase */
  override def printGlobal(global: scalac_Global) : ATreePrinter = { // !!! Extends ATree !!!
    val phase = global.currentPhase;

    printer.println("[[ICode at "+phase+" (after "+phase.prev+")]]");
    val units_it = Iterator.fromArray(global.units);
    units_it.foreach(printAnUnit);

    this;
  }

  /* This method print a single unit. */
  def printAnUnit(unit: CompilationUnit) = { // ??? Private
    printer.println ("// Scala source: "+unit.source);
    val classes_it = Iterator.fromArray(unit.repository.classes());
    classes_it.foreach((c: AClass) => {
      printer.println ("");
      printer.println ("// ICode for class <"+c.symbol().name+">");
      val methods_it = Iterator.fromArray(c.methods());
      methods_it.foreach((m: AMethod) => {
	val icode : ICode = m.icode.asInstanceOf[ICode];
	printer.println ("// ::"+m.symbol().name);
	icode.icTraverse((bb: IBasicBlock) => {
	  printer.println("Block #"+bb.label);
	  printer.println("Initial stack -> "+bb.initialStack);
	  printer.println("Substituable variables : ");
	  if (bb.substituteVars != null)
	    bb.substituteVars.foreach((s: Symbol) => printer.print(s.name.toString()));
	  else
	    printer.println(" {Empty} ");
	  printer.println("Instructions:");
	  printer.indent();
	  bb.bbTraverse((ici: ICInstruction) =>
	    printer.println(ici.toString()));
	  printer.undent();
	  printer.println("End stack -> "+bb.endStack);
	  printer.print  ("Successors: ");
	  bb.successors.foreach((bb: IBasicBlock) => printer.print(bb.label+", "));
	  printer.println (""); // ?? Del
	  printer.println ();
	});
      });
    });


  }
}
}