Mercurial > hg > truffle
comparison graal/com.oracle.max.asmdis/src/com/sun/max/asm/gen/risc/field/AlignedImmediateOperandField.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.asm.*; | |
28 import com.sun.max.asm.gen.*; | |
29 import com.sun.max.asm.gen.risc.bitRange.*; | |
30 | |
31 /** | |
32 * An instruction field whose encoded value does not include bits for | |
33 * the low-order 0 bits of the aligned values that the field represents. | |
34 * This class can convert between the field's <i>argument</i> (i.e. | |
35 * the represented value) and it's <i>operand</i> (i.e. the encoded value). | |
36 */ | |
37 public class AlignedImmediateOperandField extends ImmediateOperandField { | |
38 | |
39 protected int zeroes; | |
40 | |
41 public AlignedImmediateOperandField(BitRange bitRange, int zeroes) { | |
42 super(bitRange); | |
43 this.zeroes = zeroes; | |
44 } | |
45 | |
46 @Override | |
47 public String asJavaExpression() { | |
48 final String value = valueString(); | |
49 return "(" + super.asJavaExpression() + ") && ((" + value + " % " + grain() + ") == 0)"; | |
50 } | |
51 | |
52 @Override | |
53 public boolean check(Template template, List<Argument> arguments) { | |
54 if (!super.check(template, arguments)) { | |
55 return false; | |
56 } | |
57 final long value = template.bindingFor(this, arguments).asLong(); | |
58 return (value % grain()) == 0; | |
59 } | |
60 | |
61 @Override | |
62 public int maxArgumentValue() { | |
63 return super.maxArgumentValue() << zeroes(); | |
64 } | |
65 | |
66 @Override | |
67 public int minArgumentValue() { | |
68 return super.minArgumentValue() << zeroes(); | |
69 } | |
70 | |
71 @Override | |
72 public int zeroes() { | |
73 return zeroes; | |
74 } | |
75 | |
76 /** | |
77 * Converts an argument value to the operand value that does not include bits for the | |
78 * implied low-order 0 bits that the aligned argument value is guaranteed to contain. | |
79 * For example, if this field represents a 4-byte aligned value, then {@code argumentToOperand(536) == 134}. | |
80 */ | |
81 private int argumentToOperand(int value) throws AssemblyException { | |
82 final int p = grain(); | |
83 if (value % p != 0) { | |
84 throw new AssemblyException("unaligned immediate operand: " + value); | |
85 } | |
86 return value / p; | |
87 } | |
88 | |
89 /** | |
90 * Converts an operand value to the argument value that includes | |
91 * low-order 0 bits for the alignment of this field. | |
92 * For example, if this field represents a 4-byte aligned value, | |
93 * then {@code operandToArgument(134) == 536}. | |
94 */ | |
95 private int operandToArgument(int operand) { | |
96 return operand << zeroes(); | |
97 } | |
98 | |
99 @Override | |
100 public int assemble(int value) throws IndexOutOfBoundsException, AssemblyException { | |
101 return super.assemble(argumentToOperand(value)); | |
102 } | |
103 | |
104 @Override | |
105 public Immediate32Argument disassemble(int instruction) { | |
106 return new Immediate32Argument(operandToArgument(extract(instruction))); | |
107 } | |
108 } |