Mercurial > hg > graal-compiler
comparison graal/GraalCompiler/src/com/sun/c1x/lir/LIRTableSwitch.java @ 2509:16b9a8b5ad39
Renamings Runtime=>GraalRuntime and Compiler=>GraalCompiler
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 27 Apr 2011 11:50:44 +0200 |
parents | graal/Compiler/src/com/sun/c1x/lir/LIRTableSwitch.java@9ec15d6914ca |
children | c1ce2a53d6c3 |
comparison
equal
deleted
inserted
replaced
2508:fea94949e0a2 | 2509:16b9a8b5ad39 |
---|---|
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.lir; | |
24 | |
25 import com.sun.c1x.ir.*; | |
26 import com.sun.cri.ci.*; | |
27 | |
28 /** | |
29 * @author Doug Simon | |
30 */ | |
31 public class LIRTableSwitch extends LIRInstruction { | |
32 | |
33 public BlockBegin defaultTarget; | |
34 | |
35 public final BlockBegin[] targets; | |
36 | |
37 public final int lowKey; | |
38 | |
39 public LIRTableSwitch(CiValue value, int lowKey, BlockBegin defaultTarget, BlockBegin[] targets) { | |
40 super(LIROpcode.TableSwitch, CiValue.IllegalValue, null, false, 1, 0, value); | |
41 this.lowKey = lowKey; | |
42 this.targets = targets; | |
43 this.defaultTarget = defaultTarget; | |
44 } | |
45 | |
46 @Override | |
47 public void emitCode(LIRAssembler masm) { | |
48 masm.emitTableSwitch(this); | |
49 } | |
50 | |
51 /** | |
52 * @return the input value to this switch | |
53 */ | |
54 public CiValue value() { | |
55 return operand(0); | |
56 } | |
57 | |
58 @Override | |
59 public String operationString(OperandFormatter operandFmt) { | |
60 StringBuilder buf = new StringBuilder(super.operationString(operandFmt)); | |
61 buf.append("\ndefault: [B").append(defaultTarget.blockID).append(']'); | |
62 int key = lowKey; | |
63 for (BlockBegin b : targets) { | |
64 buf.append("\ncase ").append(key).append(": [B").append(b.blockID).append(']'); | |
65 key++; | |
66 } | |
67 return buf.toString(); | |
68 } | |
69 | |
70 private BlockBegin substitute(BlockBegin block, BlockBegin oldBlock, BlockBegin newBlock) { | |
71 if (block == oldBlock) { | |
72 LIRInstruction instr = newBlock.lir().instructionsList().get(0); | |
73 assert instr instanceof LIRLabel : "first instruction of block must be label"; | |
74 return newBlock; | |
75 } | |
76 return oldBlock; | |
77 } | |
78 | |
79 public void substitute(BlockBegin oldBlock, BlockBegin newBlock) { | |
80 if (substitute(defaultTarget, oldBlock, newBlock) == newBlock) { | |
81 defaultTarget = newBlock; | |
82 } | |
83 for (int i = 0; i < targets.length; i++) { | |
84 if (substitute(targets[i], oldBlock, newBlock) == newBlock) { | |
85 targets[i] = newBlock; | |
86 } | |
87 } | |
88 } | |
89 } |