comparison graal/Compiler/src/com/sun/c1x/ir/NewMultiArray.java @ 2507:9ec15d6914ca

Pull over of compiler from maxine repository.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 27 Apr 2011 11:43:22 +0200
parents
children
comparison
equal deleted inserted replaced
2506:4a3bf8a5bf41 2507:9ec15d6914ca
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 com.sun.c1x.debug.*;
26 import com.sun.c1x.value.*;
27 import com.sun.cri.ci.*;
28 import com.sun.cri.ri.*;
29
30 /**
31 * The {@code NewMultiArray} instruction represents an allocation of a multi-dimensional object
32 * array.
33 *
34 * @author Ben L. Titzer
35 */
36 public final class NewMultiArray extends NewArray {
37 public final RiType elementKind;
38 final Value[] dimensions;
39 public final int cpi;
40 public final RiConstantPool constantPool;
41
42 /**
43 * Constructs a new NewMultiArray instruction.
44 * @param elementKind the element type of the array
45 * @param dimensions the instructions which produce the dimensions for this array
46 * @param stateBefore the state before this instruction
47 * @param cpi the constant pool index for resolution
48 * @param riConstantPool the constant pool for resolution
49 */
50 public NewMultiArray(RiType elementKind, Value[] dimensions, FrameState stateBefore, int cpi, RiConstantPool riConstantPool) {
51 super(null, stateBefore);
52 this.constantPool = riConstantPool;
53 this.elementKind = elementKind;
54 this.dimensions = dimensions;
55 this.cpi = cpi;
56 }
57
58 /**
59 * Gets the list of instructions which produce input for this instruction.
60 * @return the list of instructions which produce input
61 */
62 public Value[] dimensions() {
63 return dimensions;
64 }
65
66 /**
67 * Gets the rank of the array allocated by this instruction, i.e. how many array dimensions.
68 * @return the rank of the array allocated
69 */
70 public int rank() {
71 return dimensions.length;
72 }
73
74 @Override
75 public void inputValuesDo(ValueClosure closure) {
76 for (int i = 0; i < dimensions.length; i++) {
77 dimensions[i] = closure.apply(dimensions[i]);
78 }
79 }
80
81 @Override
82 public void accept(ValueVisitor v) {
83 v.visitNewMultiArray(this);
84 }
85
86 /**
87 * Gets the element type of the array.
88 * @return the element type of the array
89 */
90 public RiType elementType() {
91 return elementKind;
92 }
93
94 @Override
95 public void print(LogStream out) {
96 out.print("new multi array [");
97 final Value[] dimensions = dimensions();
98 for (int i = 0; i < dimensions.length; i++) {
99 if (i > 0) {
100 out.print(", ");
101 }
102 out.print(dimensions[i]);
103 }
104 out.print("] ").print(CiUtil.toJavaName(elementKind));
105 }
106 }