comparison graal/com.oracle.max.asmdis/src/com/sun/max/asm/gen/risc/field/OperandField.java @ 3733:e233f5660da4

Added Java files from Maxine project.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sat, 17 Dec 2011 19:59:18 +0100
parents
children bc8527f3071c
comparison
equal deleted inserted replaced
3732:3e2e8b8abdaf 3733:e233f5660da4
1 /*
2 * Copyright (c) 2007, 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.max.asm.gen.risc.field;
24
25 import java.util.*;
26
27 import com.sun.max.*;
28 import com.sun.max.asm.*;
29 import com.sun.max.asm.gen.*;
30 import com.sun.max.asm.gen.risc.*;
31 import com.sun.max.asm.gen.risc.bitRange.*;
32
33 /**
34 * An operand field defines an instruction field whose value is given as a parameter in the generated
35 * assembler method. The field is also a parameter in the external assembler syntax unless
36 * it's {@link #type value type} implements {@link ExternalMnemonicSuffixArgument} in which
37 * case, the field's value is represented as a suffix of the mnemonic in the external assembler syntax.
38 */
39 public abstract class OperandField<Argument_Type extends Argument> extends RiscField implements Parameter, Expression {
40
41 private SignDependentOperations signDependentOperations;
42
43 protected OperandField(BitRange bitRange) {
44 super(bitRange);
45 signDependentOperations = SignDependentOperations.UNSIGNED;
46 }
47
48 public RiscConstant constant(int value) {
49 return new RiscConstant(new ConstantField(name(), bitRange()), value);
50 }
51
52 protected SignDependentOperations signDependentOperations() {
53 return signDependentOperations;
54 }
55
56 protected void setSignDependentOperations(SignDependentOperations signDependentOperations) {
57 this.signDependentOperations = signDependentOperations;
58 }
59
60 public int maxArgumentValue() {
61 return signDependentOperations.maxArgumentValue(bitRange());
62 }
63
64 public int minArgumentValue() {
65 return signDependentOperations.minArgumentValue(bitRange());
66 }
67
68 public int assemble(int value) throws AssemblyException {
69 return signDependentOperations.assemble(value, bitRange());
70 }
71
72 public int extract(int instruction) {
73 return signDependentOperations.extract(instruction, bitRange());
74 }
75
76 public abstract Argument_Type disassemble(int instruction);
77
78 /**
79 * @return the minimal difference between any two potential operands
80 */
81 public int grain() {
82 return 1 << zeroes();
83 }
84
85 /**
86 * @return implied zeroes to be "appended" to respective operands
87 */
88 public int zeroes() {
89 return 0;
90 }
91
92 @Override
93 public OperandField<Argument_Type> clone() {
94 final Class<OperandField<Argument_Type>> type = null;
95 return Utils.cast(type, super.clone());
96 }
97
98 public OperandField<Argument_Type> beSigned() {
99 final OperandField<Argument_Type> result = clone();
100 result.setSignDependentOperations(SignDependentOperations.SIGNED);
101 return result;
102 }
103
104 public OperandField<Argument_Type> beSignedOrUnsigned() {
105 final OperandField<Argument_Type> result = clone();
106 result.setSignDependentOperations(SignDependentOperations.SIGNED_OR_UNSIGNED);
107 return result;
108 }
109
110 public boolean isSigned() {
111 return signDependentOperations == SignDependentOperations.SIGNED;
112 }
113
114 public abstract Class type();
115
116 private String variableName;
117
118 public String variableName() {
119 if (variableName != null) {
120 return variableName;
121 }
122 return name();
123 }
124
125 public Argument getExampleArgument() {
126 final Iterator<? extends Argument> it = getLegalTestArguments().iterator();
127 if (it.hasNext()) {
128 return it.next();
129 }
130 return null;
131 }
132
133 public OperandField<Argument_Type> setVariableName(String name) {
134 variableName = name;
135 return this;
136 }
137
138 public String externalName() {
139 return variableName();
140 }
141
142 private Set<Argument> excludedDisassemblerTestArguments = Collections.emptySet();
143
144 public OperandField<Argument_Type> withExcludedDisassemblerTestArguments(Set<Argument> arguments) {
145 final OperandField<Argument_Type> result = clone();
146 result.excludedDisassemblerTestArguments = arguments;
147 return result;
148 }
149
150 public OperandField<Argument_Type> withExcludedDisassemblerTestArguments(Argument... arguments) {
151 return withExcludedDisassemblerTestArguments(new HashSet<Argument>(Arrays.asList(arguments)));
152 }
153
154 public Set<Argument> excludedDisassemblerTestArguments() {
155 return excludedDisassemblerTestArguments;
156 }
157
158 private Set<Argument> excludedExternalTestArguments = Collections.emptySet();
159
160 public OperandField<Argument_Type> withExcludedExternalTestArguments(Set<Argument> arguments) {
161 final OperandField<Argument_Type> result = clone();
162 result.excludedExternalTestArguments = arguments;
163 return result;
164 }
165
166 public OperandField<Argument_Type> withExcludedExternalTestArguments(Argument... arguments) {
167 return withExcludedExternalTestArguments(new HashSet<Argument>(Arrays.asList(arguments)));
168 }
169
170 public Set<Argument> excludedExternalTestArguments() {
171 return excludedExternalTestArguments;
172 }
173
174 public int compareTo(Parameter other) {
175 return type().getName().compareTo(other.type().getName());
176 }
177
178 public long evaluate(Template template, List<Argument> arguments) {
179 if (boundTo() != null) {
180 return boundTo().evaluate(template, arguments);
181 }
182 return template.bindingFor(this, arguments).asLong();
183 }
184
185 private Expression expression;
186
187 public OperandField<Argument_Type> bindTo(Expression expr) {
188 final OperandField<Argument_Type> result = clone();
189 result.expression = expr;
190 return result;
191 }
192
193 public Expression boundTo() {
194 return expression;
195 }
196 }