blob: 18aa9f4f36b618018010a451f6b80dd3730e3b9e [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 */
26#define X86_REG_COUNT 16
27static const char *x86RegName[X86_REG_COUNT] = {
28 "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
29 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
30};
31
32/*
33 * Interpret a format string and build a string no longer than size
34 * See format key in Assemble.c.
35 */
36std::string buildInsnString(const char *fmt, LIR *lir, unsigned char* baseAddr)
37{
38 UNIMPLEMENTED(WARNING) << "buildInsnString";
39 return NULL;
40#if 0
41 std::string buf;
42 int i;
43 const char *fmtEnd = &fmt[strlen(fmt)];
44 char tbuf[256];
45 char nc;
46 while (fmt < fmtEnd) {
47 int operand;
48 if (*fmt == '!') {
49 fmt++;
50 DCHECK_LT(fmt, fmtEnd);
51 nc = *fmt++;
52 if (nc=='!') {
53 strcpy(tbuf, "!");
54 } else {
55 DCHECK_LT(fmt, fmtEnd);
56 DCHECK_LT((unsigned)(nc-'0'), 4u);
57 operand = lir->operands[nc-'0'];
58 switch(*fmt++) {
59 case 'b':
60 strcpy(tbuf,"0000");
61 for (i=3; i>= 0; i--) {
62 tbuf[i] += operand & 1;
63 operand >>= 1;
64 }
65 break;
66 case 's':
67 sprintf(tbuf,"$f%d",operand & FP_REG_MASK);
68 break;
69 case 'S':
70 DCHECK_EQ(((operand & FP_REG_MASK) & 1), 0);
71 sprintf(tbuf,"$f%d",operand & FP_REG_MASK);
72 break;
73 case 'h':
74 sprintf(tbuf,"%04x", operand);
75 break;
76 case 'M':
77 case 'd':
78 sprintf(tbuf,"%d", operand);
79 break;
80 case 'D':
81 sprintf(tbuf,"%d", operand+1);
82 break;
83 case 'E':
84 sprintf(tbuf,"%d", operand*4);
85 break;
86 case 'F':
87 sprintf(tbuf,"%d", operand*2);
88 break;
89 case 't':
90 sprintf(tbuf,"0x%08x (L%p)",
91 (int) baseAddr + lir->offset + 4 +
92 (operand << 2),
93 lir->target);
94 break;
95 case 'T':
96 sprintf(tbuf,"0x%08x",
97 (int) (operand << 2));
98 break;
99 case 'u': {
100 int offset_1 = lir->operands[0];
101 int offset_2 = NEXT_LIR(lir)->operands[0];
102 intptr_t target =
103 ((((intptr_t) baseAddr + lir->offset + 4) &
104 ~3) + (offset_1 << 21 >> 9) + (offset_2 << 1)) &
105 0xfffffffc;
106 sprintf(tbuf, "%p", (void *) target);
107 break;
108 }
109
110 /* Nothing to print for BLX_2 */
111 case 'v':
112 strcpy(tbuf, "see above");
113 break;
114 case 'r':
115 DCHECK(operand >= 0 && operand < MIPS_REG_COUNT);
116 strcpy(tbuf, mipsRegName[operand]);
117 break;
118 case 'N':
119 // Placeholder for delay slot handling
120 strcpy(tbuf, "; nop");
121 break;
122 default:
123 strcpy(tbuf,"DecodeError");
124 break;
125 }
126 buf += tbuf;
127 }
128 } else {
129 buf += *fmt++;
130 }
131 }
132 return buf;
133#endif
134}
135
136void oatDumpResourceMask(LIR *lir, u8 mask, const char *prefix)
137{
138 UNIMPLEMENTED(WARNING) << "oatDumpResourceMasks";
139#if 0
140 char buf[256];
141 buf[0] = 0;
142 LIR *mipsLIR = (LIR *) lir;
143
144 if (mask == ENCODE_ALL) {
145 strcpy(buf, "all");
146 } else {
147 char num[8];
148 int i;
149
150 for (i = 0; i < kRegEnd; i++) {
151 if (mask & (1ULL << i)) {
152 sprintf(num, "%d ", i);
153 strcat(buf, num);
154 }
155 }
156
157 if (mask & ENCODE_CCODE) {
158 strcat(buf, "cc ");
159 }
160 if (mask & ENCODE_FP_STATUS) {
161 strcat(buf, "fpcc ");
162 }
163 /* Memory bits */
164 if (mipsLIR && (mask & ENCODE_DALVIK_REG)) {
165 sprintf(buf + strlen(buf), "dr%d%s", mipsLIR->aliasInfo & 0xffff,
166 (mipsLIR->aliasInfo & 0x80000000) ? "(+1)" : "");
167 }
168 if (mask & ENCODE_LITERAL) {
169 strcat(buf, "lit ");
170 }
171
172 if (mask & ENCODE_HEAP_REF) {
173 strcat(buf, "heap ");
174 }
175 if (mask & ENCODE_MUST_NOT_ALIAS) {
176 strcat(buf, "noalias ");
177 }
178 }
179 if (buf[0]) {
180 LOG(INFO) << prefix << ": " << buf;
181 }
182#endif
183}
184
185} // namespace art