Mercurial > hg > truffle
comparison graal/com.oracle.max.graal.compiler/src/com/sun/c1x/debug/BlockPrinter.java @ 2872:0341b6424579
Project renaming.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 08 Jun 2011 08:42:25 +0200 |
parents | graal/GraalCompiler/src/com/sun/c1x/debug/BlockPrinter.java@2af109bec0c0 |
children |
comparison
equal
deleted
inserted
replaced
2871:d704eb526603 | 2872:0341b6424579 |
---|---|
1 /* | |
2 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.sun.c1x.debug; | |
24 | |
25 import com.oracle.graal.graph.*; | |
26 import com.oracle.max.graal.schedule.*; | |
27 import com.sun.c1x.graph.*; | |
28 import com.sun.c1x.ir.*; | |
29 import com.sun.c1x.util.*; | |
30 import com.sun.c1x.value.*; | |
31 | |
32 /** | |
33 * Prints a listing for a {@linkplain Merge block}. | |
34 */ | |
35 public class BlockPrinter implements BlockClosure { | |
36 | |
37 private final InstructionPrinter ip; | |
38 private final boolean cfgOnly; | |
39 | |
40 public BlockPrinter(IR ir, InstructionPrinter ip, boolean cfgOnly) { | |
41 this.ip = ip; | |
42 this.cfgOnly = cfgOnly; | |
43 } | |
44 | |
45 public void apply(Block block) { | |
46 if (cfgOnly) { | |
47 if (block.getInstructions().size() > 0) { | |
48 ip.printInstruction((Instruction) block.getInstructions().get(0)); | |
49 } else { | |
50 ip.out().println("Empty block"); | |
51 } | |
52 ip.out().println(); | |
53 } else { | |
54 printBlock(block); | |
55 } | |
56 } | |
57 | |
58 public void printBlock(Block block) { | |
59 LogStream out = ip.out(); | |
60 out.println(); | |
61 | |
62 ip.printInstructionListingHeader(); | |
63 | |
64 for (Node i : block.getInstructions()) { | |
65 if (i instanceof Instruction) { | |
66 ip.printInstructionListing((Instruction) i); | |
67 } | |
68 } | |
69 out.println(); | |
70 | |
71 } | |
72 | |
73 private static void printFrameState(FrameState newFrameState, LogStream out) { | |
74 int startPosition = out.position(); | |
75 if (newFrameState.stackSize() == 0) { | |
76 out.print("empty stack"); | |
77 } else { | |
78 out.print("stack ["); | |
79 int i = 0; | |
80 while (i < newFrameState.stackSize()) { | |
81 if (i > 0) { | |
82 out.print(", "); | |
83 } | |
84 Value value = newFrameState.stackAt(i); | |
85 out.print(i + ":" + Util.valueString(value)); | |
86 if (value == null) { | |
87 i++; | |
88 } else { | |
89 i += value.kind.sizeInSlots(); | |
90 if (value instanceof Phi) { | |
91 Phi phi = (Phi) value; | |
92 if (phi.operand() != null) { | |
93 out.print(" "); | |
94 out.print(phi.operand().toString()); | |
95 } | |
96 } | |
97 } | |
98 } | |
99 out.print(']'); | |
100 } | |
101 if (newFrameState.locksSize() != 0) { | |
102 // print out the lines on the line below this | |
103 // one at the same indentation level. | |
104 out.println(); | |
105 out.fillTo(startPosition, ' '); | |
106 out.print("locks ["); | |
107 for (int i = 0; i < newFrameState.locksSize(); i++) { | |
108 Value value = newFrameState.lockAt(i); | |
109 if (i > 0) { | |
110 out.print(", "); | |
111 } | |
112 out.print(i + ":"); | |
113 if (value == null) { | |
114 // synchronized methods push null on the lock stack | |
115 out.print("this"); | |
116 } else { | |
117 out.print(Util.valueString(value)); | |
118 } | |
119 } | |
120 out.print("]"); | |
121 } | |
122 } | |
123 } |