blob: a5987f230d30de71efff968a8dfdc1f558efd4d1 [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]) {
Ian Rogersb3ab25b2012-03-19 01:12:01 -070075 case 'c':
76 DCHECK_LT(static_cast<size_t>(operand), sizeof(x86CondName));
77 buf += x86CondName[operand];
78 break;
Ian Rogersb5d09b22012-03-06 22:14:17 -080079 case 'd':
80 buf += StringPrintf("%d", operand);
81 break;
82 case 'r':
83 if (FPREG(operand) || DOUBLEREG(operand)) {
84 int fp_reg = operand & FP_REG_MASK;
85 buf += StringPrintf("xmm%d", fp_reg);
buzbeee88dfbf2012-03-05 11:19:57 -080086 } else {
Ian Rogersb5d09b22012-03-06 22:14:17 -080087 DCHECK_LT(static_cast<size_t>(operand), sizeof(x86RegName));
88 buf += x86RegName[operand];
buzbeee88dfbf2012-03-05 11:19:57 -080089 }
Ian Rogersb5d09b22012-03-06 22:14:17 -080090 break;
Ian Rogersb3ab25b2012-03-19 01:12:01 -070091 case 't':
92 buf += StringPrintf("0x%08x (L%p)",
93 (intptr_t)baseAddr + lir->offset + operand,
94 lir->target);
Ian Rogersb5d09b22012-03-06 22:14:17 -080095 break;
96 default:
97 buf += StringPrintf("DecodeError '%c'", fmt[i]);
98 break;
buzbeee88dfbf2012-03-05 11:19:57 -080099 }
Ian Rogersb5d09b22012-03-06 22:14:17 -0800100 i++;
101 }
buzbeee88dfbf2012-03-05 11:19:57 -0800102 }
Ian Rogersb5d09b22012-03-06 22:14:17 -0800103 }
104 return buf;
buzbeee88dfbf2012-03-05 11:19:57 -0800105}
106
107void oatDumpResourceMask(LIR *lir, u8 mask, const char *prefix)
108{
buzbeee88dfbf2012-03-05 11:19:57 -0800109 char buf[256];
110 buf[0] = 0;
buzbeea7678db2012-03-05 15:35:46 -0800111 LIR *x86LIR = (LIR *) lir;
buzbeee88dfbf2012-03-05 11:19:57 -0800112
113 if (mask == ENCODE_ALL) {
114 strcpy(buf, "all");
115 } else {
116 char num[8];
117 int i;
118
119 for (i = 0; i < kRegEnd; i++) {
120 if (mask & (1ULL << i)) {
121 sprintf(num, "%d ", i);
122 strcat(buf, num);
123 }
124 }
125
126 if (mask & ENCODE_CCODE) {
127 strcat(buf, "cc ");
128 }
buzbeee88dfbf2012-03-05 11:19:57 -0800129 /* Memory bits */
buzbeea7678db2012-03-05 15:35:46 -0800130 if (x86LIR && (mask & ENCODE_DALVIK_REG)) {
131 sprintf(buf + strlen(buf), "dr%d%s", x86LIR->aliasInfo & 0xffff,
132 (x86LIR->aliasInfo & 0x80000000) ? "(+1)" : "");
buzbeee88dfbf2012-03-05 11:19:57 -0800133 }
134 if (mask & ENCODE_LITERAL) {
135 strcat(buf, "lit ");
136 }
137
138 if (mask & ENCODE_HEAP_REF) {
139 strcat(buf, "heap ");
140 }
141 if (mask & ENCODE_MUST_NOT_ALIAS) {
142 strcat(buf, "noalias ");
143 }
144 }
145 if (buf[0]) {
146 LOG(INFO) << prefix << ": " << buf;
147 }
buzbeee88dfbf2012-03-05 11:19:57 -0800148}
149
150} // namespace art