Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.max.graal.compiler/src/com/sun/c1x/ir/LookupSwitch.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/LookupSwitch.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 LookupSwitch} instruction represents a lookup switch bytecode, which has a sorted | |
34 * array of key values. | |
35 */ | |
36 public final class LookupSwitch extends Switch { | |
37 | |
38 private static final int INPUT_COUNT = 0; | |
39 private static final int SUCCESSOR_COUNT = 0; | |
40 | |
41 final int[] keys; | |
42 | |
43 /** | |
44 * Constructs a new LookupSwitch instruction. | |
45 * @param value the instruction producing the value being switched on | |
46 * @param successors the list of successors | |
47 * @param keys the list of keys, sorted | |
48 * @param stateAfter the state after the switch | |
49 * @param graph | |
50 */ | |
51 public LookupSwitch(Value value, List<? extends Instruction> successors, int[] keys, Graph graph) { | |
52 super(value, successors, INPUT_COUNT, SUCCESSOR_COUNT, graph); | |
53 this.keys = keys; | |
54 } | |
55 | |
56 /** | |
57 * Gets the key at the specified index. | |
58 * @param i the index | |
59 * @return the key at that index | |
60 */ | |
61 public int keyAt(int i) { | |
62 return keys[i]; | |
63 } | |
64 | |
65 public int keysLength() { | |
66 return keys.length; | |
67 } | |
68 | |
69 @Override | |
70 public void accept(ValueVisitor v) { | |
71 v.visitLookupSwitch(this); | |
72 } | |
73 | |
74 @Override | |
75 public void print(LogStream out) { | |
76 out.print("lookupswitch "); | |
77 out.println(value()); | |
78 int l = numberOfCases(); | |
79 for (int i = 0; i < l; i++) { | |
80 INSTRUCTION.advance(out); | |
81 out.printf("case %5d: B%d%n", keyAt(i), blockSuccessors().get(i)); | |
82 } | |
83 INSTRUCTION.advance(out); | |
84 out.print("default : ").print(defaultSuccessor()); | |
85 } | |
86 | |
87 @Override | |
88 public Node copy(Graph into) { | |
89 LookupSwitch x = new LookupSwitch(null, Arrays.asList(new Instruction[numberOfCases() + 1]), keys.clone(), into); | |
90 return x; | |
91 } | |
92 } |