comparison graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/CallingConvention.java @ 21556:48c1ebd24120

renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Wed, 27 May 2015 00:36:16 +0200
parents graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CallingConvention.java@1cde96b96673
children f5b549811bac
comparison
equal deleted inserted replaced
21555:d12eaef9af72 21556:48c1ebd24120
1 /*
2 * Copyright (c) 2009, 2012, 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.jvmci.code;
24
25 import com.oracle.jvmci.meta.Value;
26 import com.oracle.jvmci.meta.AllocatableValue;
27 import static com.oracle.jvmci.code.ValueUtil.*;
28
29
30 /**
31 * A calling convention describes the locations in which the arguments for a call are placed and the
32 * location in which the return value is placed if the call is not void.
33 */
34 public class CallingConvention {
35
36 /**
37 * Constants denoting the type of a call for which a calling convention is requested.
38 */
39 public enum Type {
40 /**
41 * A request for the outgoing argument locations at a call site to Java code.
42 */
43 JavaCall(true),
44
45 /**
46 * A request for the incoming argument locations.
47 */
48 JavaCallee(false),
49
50 /**
51 * A request for the outgoing argument locations at a call site to external native code that
52 * complies with the platform ABI.
53 */
54 NativeCall(true);
55
56 /**
57 * Determines if this is a request for the outgoing argument locations at a call site.
58 */
59 public final boolean out;
60
61 public static final Type[] VALUES = values();
62
63 private Type(boolean out) {
64 this.out = out;
65 }
66 }
67
68 /**
69 * The amount of stack space (in bytes) required for the stack-based arguments of the call.
70 */
71 private final int stackSize;
72
73 private final AllocatableValue returnLocation;
74
75 /**
76 * The ordered locations in which the arguments are placed.
77 */
78 private final AllocatableValue[] argumentLocations;
79
80 /**
81 * Creates a description of the registers and stack locations used by a call.
82 *
83 * @param stackSize amount of stack space (in bytes) required for the stack-based arguments of
84 * the call
85 * @param returnLocation the location for the return value or {@link Value#ILLEGAL} if a void
86 * call
87 * @param argumentLocations the ordered locations in which the arguments are placed
88 */
89 public CallingConvention(int stackSize, AllocatableValue returnLocation, AllocatableValue... argumentLocations) {
90 assert argumentLocations != null;
91 assert returnLocation != null;
92 this.argumentLocations = argumentLocations;
93 this.stackSize = stackSize;
94 this.returnLocation = returnLocation;
95 assert verify();
96 }
97
98 /**
99 * Gets the location for the return value or {@link Value#ILLEGAL} if a void call.
100 */
101 public AllocatableValue getReturn() {
102 return returnLocation;
103 }
104
105 /**
106 * Gets the location for the {@code index}'th argument.
107 */
108 public AllocatableValue getArgument(int index) {
109 return argumentLocations[index];
110 }
111
112 /**
113 * Gets the amount of stack space (in bytes) required for the stack-based arguments of the call.
114 */
115 public int getStackSize() {
116 return stackSize;
117 }
118
119 /**
120 * Gets the number of locations required for the arguments.
121 */
122 public int getArgumentCount() {
123 return argumentLocations.length;
124 }
125
126 /**
127 * Gets the locations required for the arguments.
128 */
129 public AllocatableValue[] getArguments() {
130 if (argumentLocations.length == 0) {
131 return argumentLocations;
132 }
133 return argumentLocations.clone();
134 }
135
136 @Override
137 public String toString() {
138 StringBuilder sb = new StringBuilder();
139 sb.append("CallingConvention[");
140 String sep = "";
141 for (Value op : argumentLocations) {
142 sb.append(sep).append(op);
143 sep = ", ";
144 }
145 if (!returnLocation.equals(Value.ILLEGAL)) {
146 sb.append(" -> ").append(returnLocation);
147 }
148 sb.append("]");
149 return sb.toString();
150 }
151
152 private boolean verify() {
153 for (int i = 0; i < argumentLocations.length; i++) {
154 Value location = argumentLocations[i];
155 assert isStackSlot(location) || isAllocatableValue(location);
156 }
157 return true;
158 }
159 }