comparison graal/com.oracle.max.asmdis/src/com/sun/max/asm/gen/risc/RiscAssembly.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;
24
25 import java.io.*;
26 import java.util.*;
27
28 import com.sun.max.asm.dis.risc.*;
29 import com.sun.max.asm.gen.*;
30 import com.sun.max.collect.*;
31 import com.sun.max.lang.*;
32
33 /**
34 */
35 public abstract class RiscAssembly extends Assembly<RiscTemplate> {
36
37 protected RiscAssembly(ISA isa, Class<RiscTemplate> templateType) {
38 super(isa, templateType);
39 }
40
41 private List<SpecificityGroup> specificityGroups;
42
43 private void initialize() {
44 final IntHashMap<IntHashMap<OpcodeMaskGroup>> specificityTable = new IntHashMap<IntHashMap<OpcodeMaskGroup>>();
45 for (RiscTemplate template : templates()) {
46 if (!template.isRedundant()) {
47 IntHashMap<OpcodeMaskGroup> opcodeMaskGroups = specificityTable.get(template.specificity());
48 if (opcodeMaskGroups == null) {
49 opcodeMaskGroups = new IntHashMap<OpcodeMaskGroup>();
50 specificityTable.put(template.specificity(), opcodeMaskGroups);
51 }
52 final int opcodeMask = template.opcodeMask();
53 OpcodeMaskGroup opcodeMaskGroup = opcodeMaskGroups.get(opcodeMask);
54 if (opcodeMaskGroup == null) {
55 opcodeMaskGroup = new OpcodeMaskGroup(opcodeMask);
56 opcodeMaskGroups.put(opcodeMask, opcodeMaskGroup);
57 }
58 opcodeMaskGroup.add(template);
59 }
60 }
61 specificityGroups = new LinkedList<SpecificityGroup>();
62 for (int specificity = 33; specificity >= 0; specificity--) {
63 final IntHashMap<OpcodeMaskGroup> opcodeGroupTable = specificityTable.get(specificity);
64 if (opcodeGroupTable != null) {
65 final List<OpcodeMaskGroup> opcodeMaskGroups = opcodeGroupTable.toList();
66 final SpecificityGroup specificityGroup = new SpecificityGroup(specificity, opcodeMaskGroups);
67 specificityGroups.add(specificityGroup);
68 }
69 }
70 }
71
72 public void printSpecificityGroups(PrintStream out) {
73 for (SpecificityGroup specificityGroup : specificityGroups) {
74 out.println("Specificity group " + specificityGroup.specificity());
75 for (OpcodeMaskGroup opcodeMaskGroup : specificityGroup.opcodeMaskGroups()) {
76 out.println(" Opcode mask group " + Integer.toBinaryString(opcodeMaskGroup.mask()));
77 for (RiscTemplate template : opcodeMaskGroup.templates()) {
78 out.println(" " + template);
79 }
80 }
81 }
82 }
83
84 public List<SpecificityGroup> specificityGroups() {
85 if (specificityGroups == null) {
86 initialize();
87 }
88 return specificityGroups;
89 }
90
91 }