Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.graal.printer/src/com/oracle/graal/printer/HexCodeFile.java @ 16324:cb196ea71d77
[SPARC] Fixing last issues on jtt.bytecode, reverting changes to HexCodeFile, fixed parsing method in Disassembler and submitted the patch
author | Stefan Anzinger <stefan.anzinger@gmail.com> |
---|---|
date | Fri, 06 Jun 2014 00:18:30 +0200 |
parents | f22e4fd06a7e |
children | 7cc21427d54b |
rev | line source |
---|---|
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
1 /* |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
4 * |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
8 * |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
14 * |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
18 * |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
21 * questions. |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
22 */ |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.printer; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
24 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
25 import java.io.*; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
26 import java.util.*; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
27 import java.util.regex.*; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
28 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
29 import com.oracle.graal.api.code.*; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.graal.api.code.CompilationResult.CodeAnnotation; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
31 import com.oracle.graal.api.code.CompilationResult.CodeComment; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
32 import com.oracle.graal.api.code.CompilationResult.JumpTable; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
33 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
34 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6693
diff
changeset
|
35 * A HexCodeFile is a textual format for representing a chunk of machine code along with extra |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6693
diff
changeset
|
36 * information that can be used to enhance a disassembly of the code. |
14906 | 37 * |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
38 * A pseudo grammar for a HexCodeFile is given below. |
14906 | 39 * |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
40 * <pre> |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
41 * HexCodeFile ::= Platform Delim HexCode Delim (OptionalSection Delim)* |
14977
cd9404a8216b
fix NPE in HexCodeFile
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14906
diff
changeset
|
42 * |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
43 * OptionalSection ::= Comment | OperandComment | JumpTable | LookupTable |
14977
cd9404a8216b
fix NPE in HexCodeFile
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14906
diff
changeset
|
44 * |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
45 * Platform ::= "Platform" ISA WordWidth |
14977
cd9404a8216b
fix NPE in HexCodeFile
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14906
diff
changeset
|
46 * |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
47 * HexCode ::= "HexCode" StartAddress HexDigits |
14977
cd9404a8216b
fix NPE in HexCodeFile
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14906
diff
changeset
|
48 * |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
49 * Comment ::= "Comment" Position String |
14977
cd9404a8216b
fix NPE in HexCodeFile
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14906
diff
changeset
|
50 * |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
51 * OperandComment ::= "OperandComment" Position String |
14977
cd9404a8216b
fix NPE in HexCodeFile
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14906
diff
changeset
|
52 * |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
53 * JumpTable ::= "JumpTable" Position EntrySize Low High |
14977
cd9404a8216b
fix NPE in HexCodeFile
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14906
diff
changeset
|
54 * |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
55 * LookupTable ::= "LookupTable" Position NPairs KeySize OffsetSize |
14977
cd9404a8216b
fix NPE in HexCodeFile
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14906
diff
changeset
|
56 * |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
57 * Position, EntrySize, Low, High, NPairs KeySize OffsetSize ::= int |
14977
cd9404a8216b
fix NPE in HexCodeFile
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14906
diff
changeset
|
58 * |
14906 | 59 * Delim := "<||@" |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
60 * </pre> |
14906 | 61 * |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6693
diff
changeset
|
62 * There must be exactly one HexCode and Platform part in a HexCodeFile. The length of HexDigits |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6693
diff
changeset
|
63 * must be even as each pair of digits represents a single byte. |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
64 * <p> |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
65 * Below is an example of a valid Code input: |
14906 | 66 * |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
67 * <pre> |
14906 | 68 * |
69 * Platform AMD64 64 <||@ | |
70 * HexCode 0 e8000000009090904883ec084889842410d0ffff48893c24e800000000488b3c24488bf0e8000000004883c408c3 <||@ | |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
71 * Comment 24 frame-ref-map: +0 {0} |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
72 * at java.lang.String.toLowerCase(String.java:2496) [bci: 1] |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
73 * |0 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
74 * locals: |stack:0:a |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
75 * stack: |stack:0:a |
14906 | 76 * <||@ |
77 * OperandComment 24 {java.util.Locale.getDefault()} <||@ | |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
78 * Comment 36 frame-ref-map: +0 {0} |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
79 * at java.lang.String.toLowerCase(String.java:2496) [bci: 4] |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
80 * |0 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
81 * locals: |stack:0:a |
14906 | 82 * <||@ |
83 * OperandComment 36 {java.lang.String.toLowerCase(Locale)} lt;||@ | |
84 * | |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
85 * </pre> |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
86 */ |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
87 public class HexCodeFile { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
88 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
89 public static final String NEW_LINE = CodeUtil.NEW_LINE; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
90 public static final String SECTION_DELIM = " <||@"; |
13543
9cd47b39b0ef
improve quoting in c1 visualizer output
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
8959
diff
changeset
|
91 public static final String COLUMN_END = " <|@"; |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
92 public static final Pattern SECTION = Pattern.compile("(\\S+)\\s+(.*)", Pattern.DOTALL); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
93 public static final Pattern COMMENT = Pattern.compile("(\\d+)\\s+(.*)", Pattern.DOTALL); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
94 public static final Pattern OPERAND_COMMENT = COMMENT; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
95 public static final Pattern JUMP_TABLE = Pattern.compile("(\\d+)\\s+(\\d+)\\s+(-{0,1}\\d+)\\s+(-{0,1}\\d+)\\s*"); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
96 public static final Pattern LOOKUP_TABLE = Pattern.compile("(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s*"); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
97 public static final Pattern HEX_CODE = Pattern.compile("(\\p{XDigit}+)(?:\\s+(\\p{XDigit}*))?"); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
98 public static final Pattern PLATFORM = Pattern.compile("(\\S+)\\s+(\\S+)", Pattern.DOTALL); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
99 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
100 /** |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
101 * Delimiter placed before a HexCodeFile when embedded in a string/stream. |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
102 */ |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
103 public static final String EMBEDDED_HCF_OPEN = "<<<HexCodeFile"; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
104 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
105 /** |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
106 * Delimiter placed after a HexCodeFile when embedded in a string/stream. |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
107 */ |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
108 public static final String EMBEDDED_HCF_CLOSE = "HexCodeFile>>>"; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
109 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
110 /** |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
111 * Map from a machine code position to a list of comments for the position. |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
112 */ |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
113 public final Map<Integer, List<String>> comments = new TreeMap<>(); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
114 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
115 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6693
diff
changeset
|
116 * Map from a machine code position to a comment for the operands of the instruction at the |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6693
diff
changeset
|
117 * position. |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
118 */ |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
119 public final Map<Integer, String> operandComments = new TreeMap<>(); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
120 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
121 public final byte[] code; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
122 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
123 public final ArrayList<JumpTable> jumpTables = new ArrayList<>(); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
124 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
125 public final String isa; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
126 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
127 public final int wordWidth; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
128 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
129 public final long startAddress; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
130 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
131 public HexCodeFile(byte[] code, long startAddress, String isa, int wordWidth) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
132 this.code = code; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
133 this.startAddress = startAddress; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
134 this.isa = isa; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
135 this.wordWidth = wordWidth; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
136 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
137 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
138 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6693
diff
changeset
|
139 * Parses a string in the format produced by {@link #toString()} to produce a |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6693
diff
changeset
|
140 * {@link HexCodeFile} object. |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
141 */ |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
142 public static HexCodeFile parse(String input, int sourceOffset, String source, String sourceName) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
143 return new Parser(input, sourceOffset, source, sourceName).hcf; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
144 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
145 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
146 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6693
diff
changeset
|
147 * Formats this HexCodeFile as a string that can be parsed with |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6693
diff
changeset
|
148 * {@link #parse(String, int, String, String)}. |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
149 */ |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
150 @Override |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
151 public String toString() { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
152 ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
153 writeTo(baos); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
154 return baos.toString(); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
155 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
156 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
157 public String toEmbeddedString() { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
158 return EMBEDDED_HCF_OPEN + NEW_LINE + toString() + EMBEDDED_HCF_CLOSE; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
159 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
160 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
161 public void writeTo(OutputStream out) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
162 PrintStream ps = out instanceof PrintStream ? (PrintStream) out : new PrintStream(out); |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6693
diff
changeset
|
163 ps.printf("Platform %s %d %s%n", isa, wordWidth, SECTION_DELIM); |
16324
cb196ea71d77
[SPARC] Fixing last issues on jtt.bytecode, reverting changes to HexCodeFile, fixed parsing method in Disassembler and submitted the patch
Stefan Anzinger <stefan.anzinger@gmail.com>
parents:
16323
diff
changeset
|
164 ps.printf("HexCode %x %s %s%n", startAddress, HexCodeFile.hexCodeString(code), SECTION_DELIM); |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
165 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
166 for (JumpTable table : jumpTables) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
167 ps.printf("JumpTable %d %d %d %d %s%n", table.position, table.entrySize, table.low, table.high, SECTION_DELIM); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
168 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
169 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
170 for (Map.Entry<Integer, List<String>> e : comments.entrySet()) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
171 int pos = e.getKey(); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
172 for (String comment : e.getValue()) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
173 ps.printf("Comment %d %s %s%n", pos, comment, SECTION_DELIM); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
174 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
175 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
176 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
177 for (Map.Entry<Integer, String> e : operandComments.entrySet()) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
178 ps.printf("OperandComment %d %s %s%n", e.getKey(), e.getValue(), SECTION_DELIM); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
179 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
180 ps.flush(); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
181 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
182 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
183 /** |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
184 * Formats a byte array as a string of hex digits. |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
185 */ |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
186 public static String hexCodeString(byte[] code) { |
14977
cd9404a8216b
fix NPE in HexCodeFile
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14906
diff
changeset
|
187 if (code == null) { |
cd9404a8216b
fix NPE in HexCodeFile
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14906
diff
changeset
|
188 return ""; |
cd9404a8216b
fix NPE in HexCodeFile
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14906
diff
changeset
|
189 } else { |
cd9404a8216b
fix NPE in HexCodeFile
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14906
diff
changeset
|
190 StringBuilder sb = new StringBuilder(code.length * 2); |
cd9404a8216b
fix NPE in HexCodeFile
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14906
diff
changeset
|
191 for (int b : code) { |
cd9404a8216b
fix NPE in HexCodeFile
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14906
diff
changeset
|
192 String hex = Integer.toHexString(b & 0xff); |
cd9404a8216b
fix NPE in HexCodeFile
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14906
diff
changeset
|
193 if (hex.length() == 1) { |
cd9404a8216b
fix NPE in HexCodeFile
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14906
diff
changeset
|
194 sb.append('0'); |
cd9404a8216b
fix NPE in HexCodeFile
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14906
diff
changeset
|
195 } |
cd9404a8216b
fix NPE in HexCodeFile
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14906
diff
changeset
|
196 sb.append(hex); |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
197 } |
14977
cd9404a8216b
fix NPE in HexCodeFile
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14906
diff
changeset
|
198 return sb.toString(); |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
199 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
200 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
201 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
202 /** |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
203 * Adds a comment to the list of comments for a given position. |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
204 */ |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
205 public void addComment(int pos, String comment) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
206 List<String> list = comments.get(pos); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
207 if (list == null) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
208 list = new ArrayList<>(); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
209 comments.put(pos, list); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
210 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
211 list.add(encodeString(comment)); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
212 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
213 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
214 /** |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
215 * Sets an operand comment for a given position. |
14906 | 216 * |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
217 * @return the previous operand comment for {@code pos} |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
218 */ |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
219 public String addOperandComment(int pos, String comment) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
220 return operandComments.put(pos, encodeString(comment)); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
221 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
222 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
223 /** |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
224 * Adds any jump tables, lookup tables or code comments from a list of code annotations. |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
225 */ |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
226 public static void addAnnotations(HexCodeFile hcf, List<CodeAnnotation> annotations) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
227 if (annotations == null || annotations.isEmpty()) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
228 return; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
229 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
230 for (CodeAnnotation a : annotations) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
231 if (a instanceof JumpTable) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
232 JumpTable table = (JumpTable) a; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
233 hcf.jumpTables.add(table); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
234 } else if (a instanceof CodeComment) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
235 CodeComment comment = (CodeComment) a; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
236 hcf.addComment(comment.position, comment.value); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
237 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
238 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
239 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
240 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
241 /** |
13543
9cd47b39b0ef
improve quoting in c1 visualizer output
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
8959
diff
changeset
|
242 * Modifies a string to mangle any substrings matching {@link #SECTION_DELIM} and |
9cd47b39b0ef
improve quoting in c1 visualizer output
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
8959
diff
changeset
|
243 * {@link #COLUMN_END}. |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
244 */ |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
245 public static String encodeString(String input) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
246 int index; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
247 String s = input; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
248 while ((index = s.indexOf(SECTION_DELIM)) != -1) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
249 s = s.substring(0, index) + " < |@" + s.substring(index + SECTION_DELIM.length()); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
250 } |
13543
9cd47b39b0ef
improve quoting in c1 visualizer output
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
8959
diff
changeset
|
251 while ((index = s.indexOf(COLUMN_END)) != -1) { |
9cd47b39b0ef
improve quoting in c1 visualizer output
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
8959
diff
changeset
|
252 s = s.substring(0, index) + " < @" + s.substring(index + COLUMN_END.length()); |
9cd47b39b0ef
improve quoting in c1 visualizer output
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
8959
diff
changeset
|
253 } |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
254 return s; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
255 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
256 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
257 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6693
diff
changeset
|
258 * Helper class to parse a string in the format produced by {@link HexCodeFile#toString()} and |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6693
diff
changeset
|
259 * produce a {@link HexCodeFile} object. |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
260 */ |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
261 static class Parser { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
262 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
263 final String input; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
264 final String inputSource; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
265 String isa; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
266 int wordWidth; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
267 byte[] code; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
268 long startAddress; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
269 HexCodeFile hcf; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
270 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
271 Parser(String input, int sourceOffset, String source, String sourceName) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
272 this.input = input; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
273 this.inputSource = sourceName; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
274 parseSections(sourceOffset, source); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
275 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
276 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
277 void makeHCF() { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
278 if (hcf == null) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
279 if (isa != null && wordWidth != 0 && code != null) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
280 hcf = new HexCodeFile(code, startAddress, isa, wordWidth); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
281 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
282 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
283 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
284 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
285 void checkHCF(String section, int offset) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
286 check(hcf != null, offset, section + " section must be after Platform and HexCode section"); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
287 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
288 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
289 void check(boolean condition, int offset, String message) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
290 if (!condition) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
291 error(offset, message); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
292 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
293 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
294 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
295 Error error(int offset, String message) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
296 throw new Error(errorMessage(offset, message)); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
297 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
298 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
299 void warning(int offset, String message) { |
14621
a6fda38d8484
refactored System.out|err into local variables to avoid need for Checkstyle disabling filters (which the Eclipse CS plugin doesn't always see)
Doug Simon <doug.simon@oracle.com>
parents:
13543
diff
changeset
|
300 PrintStream err = System.err; |
a6fda38d8484
refactored System.out|err into local variables to avoid need for Checkstyle disabling filters (which the Eclipse CS plugin doesn't always see)
Doug Simon <doug.simon@oracle.com>
parents:
13543
diff
changeset
|
301 err.println("Warning: " + errorMessage(offset, message)); |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
302 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
303 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
304 String errorMessage(int offset, String message) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
305 assert offset < input.length(); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
306 InputPos inputPos = filePos(offset); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
307 int lineEnd = input.indexOf(HexCodeFile.NEW_LINE, offset); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
308 int lineStart = offset - inputPos.col; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
309 String line = lineEnd == -1 ? input.substring(lineStart) : input.substring(lineStart, lineEnd); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
310 return String.format("%s:%d: %s%n%s%n%" + (inputPos.col + 1) + "s", inputSource, inputPos.line, message, line, "^"); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
311 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
312 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
313 static class InputPos { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6693
diff
changeset
|
314 |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
315 final int line; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
316 final int col; |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6693
diff
changeset
|
317 |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
318 public InputPos(int line, int col) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
319 this.line = line; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
320 this.col = col; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
321 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
322 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
323 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
324 InputPos filePos(int index) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
325 assert input != null; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
326 int lineStart = input.lastIndexOf(HexCodeFile.NEW_LINE, index) + 1; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
327 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
328 String l = input.substring(lineStart, lineStart + 10); |
14621
a6fda38d8484
refactored System.out|err into local variables to avoid need for Checkstyle disabling filters (which the Eclipse CS plugin doesn't always see)
Doug Simon <doug.simon@oracle.com>
parents:
13543
diff
changeset
|
329 PrintStream out = System.out; |
a6fda38d8484
refactored System.out|err into local variables to avoid need for Checkstyle disabling filters (which the Eclipse CS plugin doesn't always see)
Doug Simon <doug.simon@oracle.com>
parents:
13543
diff
changeset
|
330 out.println("YYY" + input.substring(index, index + 10) + "..."); |
a6fda38d8484
refactored System.out|err into local variables to avoid need for Checkstyle disabling filters (which the Eclipse CS plugin doesn't always see)
Doug Simon <doug.simon@oracle.com>
parents:
13543
diff
changeset
|
331 out.println("XXX" + l + "..."); |
6693
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
332 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
333 int pos = input.indexOf(HexCodeFile.NEW_LINE, 0); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
334 int line = 1; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
335 while (pos > 0 && pos < index) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
336 line++; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
337 pos = input.indexOf(HexCodeFile.NEW_LINE, pos + 1); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
338 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
339 return new InputPos(line, index - lineStart); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
340 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
341 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
342 void parseSections(int offset, String source) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
343 assert input.startsWith(source, offset); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
344 int index = 0; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
345 int endIndex = source.indexOf(SECTION_DELIM); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
346 while (endIndex != -1) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
347 while (source.charAt(index) <= ' ') { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
348 index++; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
349 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
350 String section = source.substring(index, endIndex).trim(); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
351 parseSection(offset + index, section); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
352 index = endIndex + SECTION_DELIM.length(); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
353 endIndex = source.indexOf(SECTION_DELIM, index); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
354 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
355 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
356 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
357 int parseInt(int offset, String value) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
358 try { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
359 return Integer.parseInt(value); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
360 } catch (NumberFormatException e) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
361 throw error(offset, "Not a valid integer: " + value); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
362 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
363 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
364 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
365 void parseSection(int offset, String section) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
366 if (section.isEmpty()) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
367 return; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
368 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
369 assert input.startsWith(section, offset); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
370 Matcher m = HexCodeFile.SECTION.matcher(section); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
371 check(m.matches(), offset, "Section does not match pattern " + HexCodeFile.SECTION); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
372 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
373 String header = m.group(1); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
374 String body = m.group(2); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
375 int headerOffset = offset + m.start(1); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
376 int bodyOffset = offset + m.start(2); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
377 |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
378 if (header.equals("Platform")) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
379 check(isa == null, bodyOffset, "Duplicate Platform section found"); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
380 m = HexCodeFile.PLATFORM.matcher(body); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
381 check(m.matches(), bodyOffset, "Platform does not match pattern " + HexCodeFile.PLATFORM); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
382 isa = m.group(1); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
383 wordWidth = parseInt(bodyOffset + m.start(2), m.group(2)); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
384 makeHCF(); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
385 } else if (header.equals("HexCode")) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
386 check(code == null, bodyOffset, "Duplicate Code section found"); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
387 m = HexCodeFile.HEX_CODE.matcher(body); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
388 check(m.matches(), bodyOffset, "Code does not match pattern " + HexCodeFile.HEX_CODE); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
389 String hexAddress = m.group(1); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
390 startAddress = Long.valueOf(hexAddress, 16); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
391 String hexCode = m.group(2); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
392 if (hexCode == null) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
393 code = new byte[0]; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
394 } else { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
395 check((hexCode.length() % 2) == 0, bodyOffset, "Hex code length must be even"); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
396 code = new byte[hexCode.length() / 2]; |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
397 for (int i = 0; i < code.length; i++) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
398 String hexByte = hexCode.substring(i * 2, (i + 1) * 2); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
399 code[i] = (byte) Integer.parseInt(hexByte, 16); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
400 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
401 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
402 makeHCF(); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
403 } else if (header.equals("Comment")) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
404 checkHCF("Comment", headerOffset); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
405 m = HexCodeFile.COMMENT.matcher(body); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
406 check(m.matches(), bodyOffset, "Comment does not match pattern " + HexCodeFile.COMMENT); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
407 int pos = parseInt(bodyOffset + m.start(1), m.group(1)); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
408 String comment = m.group(2); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
409 hcf.addComment(pos, comment); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
410 } else if (header.equals("OperandComment")) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
411 checkHCF("OperandComment", headerOffset); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
412 m = HexCodeFile.OPERAND_COMMENT.matcher(body); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
413 check(m.matches(), bodyOffset, "OperandComment does not match pattern " + HexCodeFile.OPERAND_COMMENT); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
414 int pos = parseInt(bodyOffset + m.start(1), m.group(1)); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
415 String comment = m.group(2); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
416 hcf.addOperandComment(pos, comment); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
417 } else if (header.equals("JumpTable")) { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
418 checkHCF("JumpTable", headerOffset); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
419 m = HexCodeFile.JUMP_TABLE.matcher(body); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
420 check(m.matches(), bodyOffset, "JumpTable does not match pattern " + HexCodeFile.JUMP_TABLE); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
421 int pos = parseInt(bodyOffset + m.start(1), m.group(1)); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
422 int entrySize = parseInt(bodyOffset + m.start(2), m.group(2)); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
423 int low = parseInt(bodyOffset + m.start(3), m.group(3)); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
424 int high = parseInt(bodyOffset + m.start(4), m.group(4)); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
425 hcf.jumpTables.add(new JumpTable(pos, low, high, entrySize)); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
426 } else { |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
427 error(offset, "Unknown section header: " + header); |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
428 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
429 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
430 } |
75785a8ba5a3
HexCodeFile is not HotSpot-specific, so move it to printer project
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
431 } |