Mercurial > hg > truffle
comparison graal/com.oracle.max.asmdis/src/com/sun/max/asm/gen/cisc/ia32/IA32AssemblerGenerator.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.ia32; | |
24 | |
25 import java.util.*; | |
26 | |
27 import com.sun.max.asm.*; | |
28 import com.sun.max.asm.dis.*; | |
29 import com.sun.max.asm.dis.ia32.*; | |
30 import com.sun.max.asm.gen.cisc.x86.*; | |
31 import com.sun.max.asm.ia32.*; | |
32 import com.sun.max.asm.ia32.complete.*; | |
33 import com.sun.max.io.*; | |
34 import com.sun.max.lang.*; | |
35 | |
36 /** | |
37 * Run this program to generate the IA32RawAssembler and IA32LabelAssembler classes. | |
38 */ | |
39 public class IA32AssemblerGenerator extends X86AssemblerGenerator<IA32Template> { | |
40 | |
41 public IA32AssemblerGenerator() { | |
42 super(IA32Assembly.ASSEMBLY, WordWidth.BITS_32); | |
43 } | |
44 | |
45 public static void main(String[] programArguments) { | |
46 final IA32AssemblerGenerator generator = new IA32AssemblerGenerator(); | |
47 generator.options.parseArguments(programArguments); | |
48 generator.generate(); | |
49 } | |
50 | |
51 @Override | |
52 protected void printModVariants(IndentWriter stream, IA32Template template) { | |
53 if (template.modCase() != X86TemplateContext.ModCase.MOD_0 || template.parameters().size() == 0) { | |
54 return; | |
55 } | |
56 switch (template.rmCase()) { | |
57 case NORMAL: { | |
58 switch (template.addressSizeAttribute()) { | |
59 case BITS_16: | |
60 printModVariant(stream, template, IA32IndirectRegister16.BP_INDIRECT); | |
61 break; | |
62 default: | |
63 printModVariant(stream, template, IA32IndirectRegister32.EBP_INDIRECT); | |
64 break; | |
65 } | |
66 break; | |
67 } | |
68 case SIB: { | |
69 switch (template.sibBaseCase()) { | |
70 case GENERAL_REGISTER: | |
71 printModVariant(stream, template, IA32BaseRegister32.EBP_BASE); | |
72 break; | |
73 default: | |
74 break; | |
75 } | |
76 break; | |
77 } | |
78 default: { | |
79 break; | |
80 } | |
81 } | |
82 } | |
83 | |
84 @Override | |
85 protected void printSibVariants(IndentWriter stream, IA32Template template) { | |
86 if (template.modCase() != null && template.modCase() != X86TemplateContext.ModCase.MOD_3 && | |
87 template.rmCase() == X86TemplateContext.RMCase.NORMAL && | |
88 template.addressSizeAttribute() == WordWidth.BITS_32 && | |
89 template.parameters().size() > 0) { | |
90 printSibVariant(stream, template, IA32IndirectRegister32.ESP_INDIRECT); | |
91 } | |
92 } | |
93 | |
94 @Override | |
95 protected DisassembledInstruction generateExampleInstruction(IA32Template template, List<Argument> arguments) throws AssemblyException { | |
96 final IA32Assembler assembler = new IA32Assembler(0); | |
97 assembly().assemble(assembler, template, arguments); | |
98 final byte[] bytes = assembler.toByteArray(); | |
99 return new DisassembledInstruction(new IA32Disassembler(0, null), 0, bytes, template, arguments); | |
100 } | |
101 } |