Mercurial > hg > truffle
comparison graal/com.oracle.max.asmdis/src/com/sun/max/asm/gen/cisc/x86/X86InstructionDescriptionVisitor.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 |
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.cisc.x86; | |
24 | |
25 import com.sun.max.asm.gen.*; | |
26 import com.sun.max.asm.gen.cisc.*; | |
27 import com.sun.max.asm.x86.*; | |
28 import com.sun.max.program.*; | |
29 | |
30 /** | |
31 * Almost like the visitor pattern. | |
32 * Specialized dispatch over InstructionDescription objects. | |
33 */ | |
34 public interface X86InstructionDescriptionVisitor { | |
35 | |
36 void visitOperandCode(OperandCode operandCode, X86Operand.Designation designation, ArgumentRange argumentRange, TestArgumentExclusion testArgumentExclusion) throws TemplateNotNeededException; | |
37 | |
38 void visitAddressingMethodCode(AddressingMethodCode addressingMethodCode, X86Operand.Designation designation) throws TemplateNotNeededException; | |
39 | |
40 void visitOperandTypeCode(OperandTypeCode operandTypeCode) throws TemplateNotNeededException; | |
41 | |
42 void visitRegisterOperandCode(RegisterOperandCode registerOperandCode, X86Operand.Designation designation, ImplicitOperand.ExternalPresence externalPresence); | |
43 | |
44 void visitGeneralRegister(GeneralRegister generalRegister, X86Operand.Designation designation, ImplicitOperand.ExternalPresence externalPresence); | |
45 | |
46 void visitSegmentRegister(SegmentRegister segmentRegister, X86Operand.Designation designation); | |
47 | |
48 void visitModRMGroup(ModRMGroup modRMGroup) throws TemplateNotNeededException; | |
49 | |
50 void visitModCase(X86TemplateContext.ModCase modCase) throws TemplateNotNeededException; | |
51 | |
52 void visitFloatingPointOperandCode(FloatingPointOperandCode floatingPointOperandCode, X86Operand.Designation designation, TestArgumentExclusion testArgumentExclusion) throws TemplateNotNeededException; | |
53 | |
54 void visitFPStackRegister(FPStackRegister fpStackRegister, X86Operand.Designation designation); | |
55 | |
56 void visitString(String string); | |
57 | |
58 void visitInteger(Integer integer, X86Operand.Designation designation); | |
59 | |
60 void visitHexByte(HexByte hexByte) throws TemplateNotNeededException; | |
61 | |
62 void visitInstructionConstraint(InstructionConstraint constraint); | |
63 | |
64 public static final class Static { | |
65 private Static() { | |
66 } | |
67 | |
68 /** | |
69 * @return whether the specification constitutes an operand | |
70 * @throws TemplateNotNeededException | |
71 */ | |
72 private static boolean visitSpecification(X86InstructionDescriptionVisitor visitor, Object specification, | |
73 final X86Operand.Designation designation, ArgumentRange argumentRange, | |
74 final TestArgumentExclusion testArgumentExclusion, ImplicitOperand.ExternalPresence externalPresence) throws TemplateNotNeededException { | |
75 if (specification instanceof OperandCode) { | |
76 visitor.visitOperandCode((OperandCode) specification, designation, argumentRange, testArgumentExclusion); | |
77 return true; | |
78 } else if (specification instanceof AddressingMethodCode) { | |
79 visitor.visitAddressingMethodCode((AddressingMethodCode) specification, designation); | |
80 return true; | |
81 } else if (specification instanceof OperandTypeCode) { | |
82 visitor.visitOperandTypeCode((OperandTypeCode) specification); | |
83 return false; | |
84 } else if (specification instanceof RegisterOperandCode) { | |
85 visitor.visitRegisterOperandCode((RegisterOperandCode) specification, designation, externalPresence); | |
86 return true; | |
87 } else if (specification instanceof GeneralRegister) { | |
88 visitor.visitGeneralRegister((GeneralRegister) specification, designation, externalPresence); | |
89 return true; | |
90 } else if (specification instanceof SegmentRegister) { | |
91 visitor.visitSegmentRegister((SegmentRegister) specification, designation); | |
92 return true; | |
93 } else if (specification instanceof ModRMGroup) { | |
94 visitor.visitModRMGroup((ModRMGroup) specification); | |
95 return false; | |
96 } else if (specification instanceof X86TemplateContext.ModCase) { | |
97 visitor.visitModCase((X86TemplateContext.ModCase) specification); | |
98 return false; | |
99 } else if (specification instanceof FloatingPointOperandCode) { | |
100 visitor.visitFloatingPointOperandCode((FloatingPointOperandCode) specification, designation, testArgumentExclusion); | |
101 return true; | |
102 } else if (specification instanceof FPStackRegister) { | |
103 visitor.visitFPStackRegister((FPStackRegister) specification, designation); | |
104 return true; | |
105 } else if (specification instanceof String) { | |
106 visitor.visitString((String) specification); | |
107 return false; | |
108 } else if (specification instanceof Integer) { | |
109 visitor.visitInteger((Integer) specification, designation); | |
110 return true; | |
111 } else if (specification instanceof ArgumentRange) { | |
112 final ArgumentRange newArgumentRange = (ArgumentRange) specification; | |
113 return visitSpecification(visitor, newArgumentRange.wrappedSpecification(), designation, newArgumentRange, testArgumentExclusion, externalPresence); | |
114 } else if (specification instanceof HexByte) { | |
115 visitor.visitHexByte((HexByte) specification); | |
116 return false; | |
117 } else if (specification instanceof TestArgumentExclusion) { | |
118 final TestArgumentExclusion exclusion = (TestArgumentExclusion) specification; | |
119 return visitSpecification(visitor, exclusion.wrappedSpecification(), designation, argumentRange, exclusion, externalPresence); | |
120 } else if (specification instanceof ExternalOmission) { | |
121 final ExternalOmission omission = (ExternalOmission) specification; | |
122 return visitSpecification(visitor, omission.wrappedSpecification(), designation, argumentRange, testArgumentExclusion, ImplicitOperand.ExternalPresence.OMITTED); | |
123 } else { | |
124 throw ProgramError.unexpected("unknown instruction description specification: " + specification); | |
125 } | |
126 } | |
127 | |
128 /** | |
129 * @return whether this instruction description is to be used to create a template in the given context | |
130 */ | |
131 public static boolean visitInstructionDescription(X86InstructionDescriptionVisitor visitor, InstructionDescription instructionDescription) { | |
132 try { | |
133 int designationIndex = 0; | |
134 for (Object specification : instructionDescription) { | |
135 final X86Operand.Designation designation = X86Operand.Designation.VALUES.get(designationIndex); | |
136 if (visitSpecification(visitor, specification, designation, ArgumentRange.UNSPECIFIED, TestArgumentExclusion.NONE, ImplicitOperand.ExternalPresence.EXPLICIT)) { | |
137 designationIndex++; | |
138 } | |
139 } | |
140 return true; | |
141 } catch (TemplateNotNeededException templateNotNeededException) { | |
142 return false; | |
143 } | |
144 } | |
145 } | |
146 } |