comparison graal/com.oracle.jvmci.asm.sparc/src/com/oracle/jvmci/asm/sparc/SPARCAddress.java @ 21708:6df25b1418be

moved com.oracle.asm.** to jvmci-util.jar (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Wed, 03 Jun 2015 18:06:44 +0200
parents graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCAddress.java@5024c80224c7
children
comparison
equal deleted inserted replaced
21707:e0f311284930 21708:6df25b1418be
1 /*
2 * Copyright (c) 2013, 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.asm.sparc;
24
25 import static com.oracle.jvmci.sparc.SPARC.*;
26
27 import com.oracle.jvmci.code.*;
28 import com.oracle.jvmci.sparc.*;
29
30 public class SPARCAddress extends AbstractAddress {
31
32 private final Register base;
33 private final Register index;
34 private final int displacement;
35
36 /**
37 * Creates an {@link SPARCAddress} with given base register, no scaling and a given
38 * displacement.
39 *
40 * @param base the base register
41 * @param displacement the displacement
42 */
43 public SPARCAddress(Register base, int displacement) {
44 this.base = base;
45 this.index = Register.None;
46 this.displacement = displacement;
47 }
48
49 /**
50 * Creates an {@link SPARCAddress} with given base register, no scaling and a given index.
51 *
52 * @param base the base register
53 * @param index the index register
54 */
55 public SPARCAddress(Register base, Register index) {
56 this.base = base;
57 this.index = index;
58 this.displacement = 0;
59 }
60
61 @Override
62 public String toString() {
63 StringBuilder s = new StringBuilder();
64 s.append("[");
65 String sep = "";
66 if (!getBase().equals(Register.None)) {
67 s.append(getBase());
68 sep = " + ";
69 }
70 if (!getIndex().equals(Register.None)) {
71 s.append(sep).append(getIndex());
72 sep = " + ";
73 } else {
74 if (getDisplacement() < 0) {
75 s.append(" - ").append(-getDisplacement());
76 } else if (getDisplacement() > 0) {
77 s.append(sep).append(getDisplacement());
78 }
79 }
80 s.append("]");
81 return s.toString();
82 }
83
84 /**
85 * @return Base register that defines the start of the address computation. If not present, is
86 * denoted by {@link Register#None}.
87 */
88 public Register getBase() {
89 return base;
90 }
91
92 /**
93 * @return Index register, the value of which is added to {@link #getBase}. If not present, is
94 * denoted by {@link Register#None}.
95 */
96 public Register getIndex() {
97 return index;
98 }
99
100 /**
101 * @return true if this address has an index register
102 */
103 public boolean hasIndex() {
104 return !getIndex().equals(Register.None);
105 }
106
107 /**
108 * This method adds the stack-bias to the displacement if the base register is either
109 * {@link SPARC#sp} or {@link SPARC#fp}.
110 *
111 * @return Optional additive displacement.
112 */
113 public int getDisplacement() {
114 if (hasIndex()) {
115 throw new InternalError("address has index register");
116 }
117 // TODO Should we also hide the register save area size here?
118 if (getBase().equals(sp) || getBase().equals(fp)) {
119 return displacement + STACK_BIAS;
120 }
121 return displacement;
122 }
123 }