Mercurial > hg > truffle
comparison graal/com.oracle.max.asmdis/src/com/sun/max/asm/gen/InstructionDescription.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; | |
24 | |
25 import java.util.*; | |
26 | |
27 import com.sun.max.asm.gen.cisc.x86.*; | |
28 import com.sun.max.asm.gen.risc.*; | |
29 import com.sun.max.asm.gen.risc.field.*; | |
30 import com.sun.max.lang.*; | |
31 import com.sun.max.program.*; | |
32 | |
33 /** | |
34 * A sequence of objects that describe group of closely related instructions. An | |
35 * {@link #Template instruction template} is created for each instruction in the | |
36 * group. | |
37 * <p> | |
38 * The types of objects that an instruction description contains | |
39 * depend on the whether the underlying platform is CISC or RISC. | |
40 * The types for these two instruction categories are enumerated by | |
41 * the {@code visit...} methods in the {@link RiscInstructionDescriptionVisitor} | |
42 * and {@link X86InstructionDescriptionVisitor} classes. | |
43 */ | |
44 public abstract class InstructionDescription implements Iterable<Object>, Cloneable { | |
45 | |
46 private static int nextSerial; | |
47 | |
48 private int serial; | |
49 | |
50 /** | |
51 * The components of the description. | |
52 */ | |
53 private final List<Object> specifications; | |
54 | |
55 public InstructionDescription(List<Object> specifications) { | |
56 this.specifications = specifications; | |
57 this.serial = nextSerial++; | |
58 } | |
59 | |
60 public int serial() { | |
61 return serial; | |
62 } | |
63 | |
64 /** | |
65 * @return the objects from which this description is composed | |
66 */ | |
67 public List<Object> specifications() { | |
68 return specifications; | |
69 } | |
70 | |
71 private List<InstructionConstraint> constraints; | |
72 | |
73 /** | |
74 * @return the {@link InstructionConstraint} instances (if any) within this description | |
75 */ | |
76 public List<InstructionConstraint> constraints() { | |
77 if (constraints == null) { | |
78 constraints = new ArrayList<InstructionConstraint>(specifications.size()); | |
79 for (Object s : specifications) { | |
80 if (s instanceof InstructionConstraint) { | |
81 constraints.add((InstructionConstraint) s); | |
82 } | |
83 } | |
84 } | |
85 return constraints; | |
86 } | |
87 | |
88 private String architectureManualSection; | |
89 | |
90 public InstructionDescription setArchitectureManualSection(String section) { | |
91 architectureManualSection = section; | |
92 return this; | |
93 } | |
94 | |
95 public String architectureManualSection() { | |
96 return architectureManualSection; | |
97 } | |
98 | |
99 private String externalName; | |
100 | |
101 public String externalName() { | |
102 return externalName; | |
103 } | |
104 | |
105 public InstructionDescription setExternalName(String name) { | |
106 this.externalName = name; | |
107 return this; | |
108 } | |
109 | |
110 private boolean isDisassemblable = true; | |
111 | |
112 /** | |
113 * Determines if the templates created from the description can be recovered from an assembled instruction. | |
114 * This is almost always possible. One example where it isn't is an instruction description that | |
115 * has a parameter that is not correlated one-to-one with some bits in the encoded instruction. | |
116 * In RISC architectures, this will be any instruction that has at least one {@link InputOperandField} | |
117 * parameter. | |
118 */ | |
119 public boolean isDisassemblable() { | |
120 return isDisassemblable; | |
121 } | |
122 | |
123 public InstructionDescription beNotDisassemblable() { | |
124 isDisassemblable = false; | |
125 return this; | |
126 } | |
127 | |
128 public boolean isSynthetic() { | |
129 return false; | |
130 } | |
131 | |
132 private boolean isExternallyTestable = true; | |
133 | |
134 public boolean isExternallyTestable() { | |
135 return isExternallyTestable; | |
136 } | |
137 | |
138 public InstructionDescription beNotExternallyTestable() { | |
139 isExternallyTestable = false; | |
140 return this; | |
141 } | |
142 | |
143 private WordWidth requiredAddressSize; | |
144 | |
145 public WordWidth requiredAddressSize() { | |
146 return requiredAddressSize; | |
147 } | |
148 | |
149 public InstructionDescription requireAddressSize(WordWidth addressSize) { | |
150 this.requiredAddressSize = addressSize; | |
151 return this; | |
152 } | |
153 | |
154 private WordWidth requiredOperandSize; | |
155 | |
156 public WordWidth requiredOperandSize() { | |
157 return requiredOperandSize; | |
158 } | |
159 | |
160 public InstructionDescription requireOperandSize(WordWidth operandSize) { | |
161 this.requiredOperandSize = operandSize; | |
162 return this; | |
163 } | |
164 | |
165 public Iterator<Object> iterator() { | |
166 return specifications.iterator(); | |
167 } | |
168 | |
169 @Override | |
170 public InstructionDescription clone() { | |
171 try { | |
172 final InstructionDescription clone = (InstructionDescription) super.clone(); | |
173 clone.serial = ++nextSerial; | |
174 return clone; | |
175 } catch (CloneNotSupportedException cloneNotSupportedException) { | |
176 throw ProgramError.unexpected(cloneNotSupportedException); | |
177 } | |
178 } | |
179 | |
180 @Override | |
181 public final int hashCode() { | |
182 return serial; | |
183 } | |
184 | |
185 @Override | |
186 public final boolean equals(Object object) { | |
187 if (object instanceof InstructionDescription) { | |
188 return serial == ((InstructionDescription) object).serial; | |
189 } | |
190 return false; | |
191 } | |
192 | |
193 } |