Mercurial > hg > truffle
comparison graal/com.oracle.max.graal.compiler/src/com/sun/c1x/ir/TableSwitch.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/ir/TableSwitch.java@14708c03abba |
children |
comparison
equal
deleted
inserted
replaced
2871:d704eb526603 | 2872:0341b6424579 |
---|---|
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.sun.c1x.ir; | |
24 | |
25 import static com.sun.c1x.debug.InstructionPrinter.InstructionLineColumn.*; | |
26 | |
27 import java.util.*; | |
28 | |
29 import com.oracle.graal.graph.*; | |
30 import com.sun.c1x.debug.*; | |
31 | |
32 /** | |
33 * The {@code TableSwitch} instruction represents a table switch. | |
34 */ | |
35 public final class TableSwitch extends Switch { | |
36 | |
37 private static final int INPUT_COUNT = 0; | |
38 private static final int SUCCESSOR_COUNT = 0; | |
39 | |
40 final int lowKey; | |
41 | |
42 /** | |
43 * Constructs a new TableSwitch instruction. | |
44 * @param value the instruction producing the value being switched on | |
45 * @param successors the list of successors | |
46 * @param lowKey the lowest integer key in the table | |
47 * @param stateAfter the state after the switch | |
48 * @param graph | |
49 */ | |
50 public TableSwitch(Value value, List<? extends Instruction> successors, int lowKey, Graph graph) { | |
51 super(value, successors, INPUT_COUNT, SUCCESSOR_COUNT, graph); | |
52 this.lowKey = lowKey; | |
53 } | |
54 | |
55 /** | |
56 * Gets the lowest key in the table switch (inclusive). | |
57 * @return the low key | |
58 */ | |
59 public int lowKey() { | |
60 return lowKey; | |
61 } | |
62 | |
63 /** | |
64 * Gets the highest key in the table switch (exclusive). | |
65 * @return the high key | |
66 */ | |
67 public int highKey() { | |
68 return lowKey + numberOfCases(); | |
69 } | |
70 | |
71 @Override | |
72 public void accept(ValueVisitor v) { | |
73 v.visitTableSwitch(this); | |
74 } | |
75 | |
76 @Override | |
77 public void print(LogStream out) { | |
78 out.print("tableswitch "); | |
79 out.println(value()); | |
80 int l = numberOfCases(); | |
81 for (int i = 0; i < l; i++) { | |
82 INSTRUCTION.advance(out); | |
83 out.printf("case %5d: B%d%n", lowKey() + i, blockSuccessors().get(i)); | |
84 } | |
85 INSTRUCTION.advance(out); | |
86 out.print("default : ").print(defaultSuccessor()); | |
87 } | |
88 | |
89 @Override | |
90 public Node copy(Graph into) { | |
91 TableSwitch x = new TableSwitch(null, Arrays.asList(new Instruction[numberOfCases() + 1]), lowKey, into); | |
92 return x; | |
93 } | |
94 } |