Mercurial > hg > truffle
comparison graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/debug/InstructionPrinter.java @ 2874:d90bf514d647
Renamed packages.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 08 Jun 2011 08:59:54 +0200 |
parents | graal/com.oracle.max.graal.compiler/src/com/sun/c1x/debug/InstructionPrinter.java@0341b6424579 |
children | f35a9ae24f11 |
comparison
equal
deleted
inserted
replaced
2873:810e2d253e00 | 2874:d90bf514d647 |
---|---|
1 /* | |
2 * Copyright (c) 2009, 2011, 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.oracle.max.graal.compiler.debug; | |
24 | |
25 import static com.oracle.max.graal.compiler.debug.InstructionPrinter.InstructionLineColumn.*; | |
26 | |
27 import com.oracle.max.graal.compiler.ir.*; | |
28 | |
29 /** | |
30 * A {@link ValueVisitor} for {@linkplain #printInstruction(Value) printing} | |
31 * an {@link Instruction} as an expression or statement. | |
32 * | |
33 * @author Doug Simon | |
34 */ | |
35 public class InstructionPrinter { | |
36 | |
37 | |
38 /** | |
39 * The columns printed in a tabulated instruction | |
40 * {@linkplain InstructionPrinter#printInstructionListing(Value) listing}. | |
41 */ | |
42 public enum InstructionLineColumn { | |
43 /** | |
44 * The instruction's bytecode index. | |
45 */ | |
46 BCI(2, "bci"), | |
47 | |
48 /** | |
49 * The instruction's use count. | |
50 */ | |
51 USE(7, "use"), | |
52 | |
53 /** | |
54 * The instruction as a {@linkplain com.oracle.max.graal.compiler.util.Util#valueString(com.oracle.max.graal.compiler.ir.Value) value}. | |
55 */ | |
56 VALUE(12, "tid"), | |
57 | |
58 /** | |
59 * The instruction formatted as an expression or statement. | |
60 */ | |
61 INSTRUCTION(19, "instr"), | |
62 | |
63 END(60, ""); | |
64 | |
65 final int position; | |
66 final String label; | |
67 | |
68 private InstructionLineColumn(int position, String label) { | |
69 this.position = position; | |
70 this.label = label; | |
71 } | |
72 | |
73 /** | |
74 * Prints this column's label to a given stream after padding the stream with '_' characters | |
75 * until its {@linkplain LogStream#position() position} is equal to this column's position. | |
76 * @param out the print stream | |
77 */ | |
78 public void printLabel(LogStream out) { | |
79 out.fillTo(position + out.indentationLevel(), '_'); | |
80 out.print(label); | |
81 } | |
82 | |
83 /** | |
84 * Prints space characters to a given stream until its {@linkplain LogStream#position() position} | |
85 * is equal to this column's position. | |
86 * @param out the print stream | |
87 */ | |
88 public void advance(LogStream out) { | |
89 out.fillTo(position + out.indentationLevel(), ' '); | |
90 } | |
91 } | |
92 | |
93 private final LogStream out; | |
94 | |
95 public InstructionPrinter(LogStream out) { | |
96 this.out = out; | |
97 } | |
98 | |
99 public LogStream out() { | |
100 return out; | |
101 } | |
102 | |
103 /** | |
104 * Prints a given instruction as an expression or statement. | |
105 * | |
106 * @param instruction the instruction to print | |
107 */ | |
108 public void printInstruction(Value instruction) { | |
109 instruction.print(out); | |
110 } | |
111 | |
112 | |
113 /** | |
114 * Prints a header for the tabulated data printed by {@link #printInstructionListing(Value)}. | |
115 */ | |
116 public void printInstructionListingHeader() { | |
117 BCI.printLabel(out); | |
118 USE.printLabel(out); | |
119 VALUE.printLabel(out); | |
120 INSTRUCTION.printLabel(out); | |
121 END.printLabel(out); | |
122 out.println(); | |
123 } | |
124 | |
125 /** | |
126 * Prints an instruction listing on one line. The instruction listing is composed of the | |
127 * columns specified by {@link InstructionLineColumn}. | |
128 * | |
129 * @param instruction the instruction to print | |
130 */ | |
131 public void printInstructionListing(Value instruction) { | |
132 int indentation = out.indentationLevel(); | |
133 out.fillTo(BCI.position + indentation, ' '). | |
134 print(0). | |
135 fillTo(USE.position + indentation, ' '). | |
136 print("0"). | |
137 fillTo(VALUE.position + indentation, ' '). | |
138 print(instruction). | |
139 fillTo(INSTRUCTION.position + indentation, ' '); | |
140 printInstruction(instruction); | |
141 String flags = instruction.flagsToString(); | |
142 if (!flags.isEmpty()) { | |
143 out.print(" [flags: " + flags + "]"); | |
144 } | |
145 if (instruction instanceof StateSplit) { | |
146 out.print(" [state: " + ((StateSplit) instruction).stateAfter() + "]"); | |
147 } | |
148 out.println(); | |
149 } | |
150 } |