blob: 9830e135d651049d897d3f140553c93b434c3fb1 [file] [log] [blame]
buzbeee88dfbf2012-03-05 11:19:57 -08001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "../../CompilerInternals.h"
18#include "X86LIR.h"
19#include "../Ralloc.h"
20
21#include <string>
22
23namespace art {
24
25/* For dumping instructions */
Ian Rogersb5d09b22012-03-06 22:14:17 -080026static const char* x86RegName[] = {
buzbeee88dfbf2012-03-05 11:19:57 -080027 "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
28 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
29};
30
Ian Rogersb5d09b22012-03-06 22:14:17 -080031static const char* x86CondName[] = {
32 "O",
33 "NO",
34 "B/NAE/C",
35 "NB/AE/NC",
36 "Z/EQ",
37 "NZ/NE",
38 "BE/NA",
39 "NBE/A",
40 "S",
41 "NS",
42 "P/PE",
43 "NP/PO",
44 "L/NGE",
45 "NL/GE",
46 "LE/NG",
47 "NLE/G"
48};
49
buzbeee88dfbf2012-03-05 11:19:57 -080050/*
51 * Interpret a format string and build a string no longer than size
52 * See format key in Assemble.c.
53 */
Ian Rogersb5d09b22012-03-06 22:14:17 -080054std::string buildInsnString(const char *fmt, LIR *lir, unsigned char* baseAddr) {
55 std::string buf;
56 size_t i = 0;
57 size_t fmt_len = strlen(fmt);
58 while(i < fmt_len) {
59 if (fmt[i] != '!') {
60 buf += fmt[i];
61 i++;
62 } else {
63 i++;
64 DCHECK_LT(i, fmt_len);
65 char operand_number_ch = fmt[i];
66 i++;
67 if (operand_number_ch == '!') {
68 buf += "!";
69 } else {
70 int operand_number = operand_number_ch - '0';
71 DCHECK_LT(operand_number, 6); // Expect upto 6 LIR operands.
72 DCHECK_LT(i, fmt_len);
73 int operand = lir->operands[operand_number];
74 switch(fmt[i]) {
75 case 'd':
76 buf += StringPrintf("%d", operand);
77 break;
78 case 'r':
79 if (FPREG(operand) || DOUBLEREG(operand)) {
80 int fp_reg = operand & FP_REG_MASK;
81 buf += StringPrintf("xmm%d", fp_reg);
buzbeee88dfbf2012-03-05 11:19:57 -080082 } else {
Ian Rogersb5d09b22012-03-06 22:14:17 -080083 DCHECK_LT(static_cast<size_t>(operand), sizeof(x86RegName));
84 buf += x86RegName[operand];
buzbeee88dfbf2012-03-05 11:19:57 -080085 }
Ian Rogersb5d09b22012-03-06 22:14:17 -080086 break;
87 case 'c':
88 DCHECK_LT(static_cast<size_t>(operand), sizeof(x86CondName));
89 buf += x86CondName[operand];
90 break;
91 default:
92 buf += StringPrintf("DecodeError '%c'", fmt[i]);
93 break;
buzbeee88dfbf2012-03-05 11:19:57 -080094 }
Ian Rogersb5d09b22012-03-06 22:14:17 -080095 i++;
96 }
buzbeee88dfbf2012-03-05 11:19:57 -080097 }
Ian Rogersb5d09b22012-03-06 22:14:17 -080098 }
99 return buf;
buzbeee88dfbf2012-03-05 11:19:57 -0800100}
101
102void oatDumpResourceMask(LIR *lir, u8 mask, const char *prefix)
103{
buzbeee88dfbf2012-03-05 11:19:57 -0800104 char buf[256];
105 buf[0] = 0;
buzbeea7678db2012-03-05 15:35:46 -0800106 LIR *x86LIR = (LIR *) lir;
buzbeee88dfbf2012-03-05 11:19:57 -0800107
108 if (mask == ENCODE_ALL) {
109 strcpy(buf, "all");
110 } else {
111 char num[8];
112 int i;
113
114 for (i = 0; i < kRegEnd; i++) {
115 if (mask & (1ULL << i)) {
116 sprintf(num, "%d ", i);
117 strcat(buf, num);
118 }
119 }
120
121 if (mask & ENCODE_CCODE) {
122 strcat(buf, "cc ");
123 }
buzbeee88dfbf2012-03-05 11:19:57 -0800124 /* Memory bits */
buzbeea7678db2012-03-05 15:35:46 -0800125 if (x86LIR && (mask & ENCODE_DALVIK_REG)) {
126 sprintf(buf + strlen(buf), "dr%d%s", x86LIR->aliasInfo & 0xffff,
127 (x86LIR->aliasInfo & 0x80000000) ? "(+1)" : "");
buzbeee88dfbf2012-03-05 11:19:57 -0800128 }
129 if (mask & ENCODE_LITERAL) {
130 strcat(buf, "lit ");
131 }
132
133 if (mask & ENCODE_HEAP_REF) {
134 strcat(buf, "heap ");
135 }
136 if (mask & ENCODE_MUST_NOT_ALIAS) {
137 strcat(buf, "noalias ");
138 }
139 }
140 if (buf[0]) {
141 LOG(INFO) << prefix << ": " << buf;
142 }
buzbeee88dfbf2012-03-05 11:19:57 -0800143}
144
145} // namespace art