blob: 9513fd3cdaf94e74c708fb3b77e21b8a4a59cd00 [file] [log] [blame]
Chris Lattnera76eab42010-11-14 19:40:38 +00001//===-- PPCInstPrinter.cpp - Convert PPC MCInst to assembly syntax --------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This class prints an PPC MCInst to a .s file.
11//
12//===----------------------------------------------------------------------===//
13
Chris Lattnera76eab42010-11-14 19:40:38 +000014#include "PPCInstPrinter.h"
Hal Finkelfeea6532013-03-26 20:08:20 +000015#include "MCTargetDesc/PPCMCTargetDesc.h"
Evan Cheng11424442011-07-26 00:24:13 +000016#include "MCTargetDesc/PPCPredicates.h"
Chris Lattner7a5c57e2010-11-14 20:02:39 +000017#include "llvm/MC/MCExpr.h"
Chris Lattnera76eab42010-11-14 19:40:38 +000018#include "llvm/MC/MCInst.h"
Craig Topperdab9e352012-04-02 07:01:04 +000019#include "llvm/MC/MCInstrInfo.h"
Pete Cooper3de83e42015-05-15 21:58:42 +000020#include "llvm/MC/MCRegisterInfo.h"
21#include "llvm/MC/MCSubtargetInfo.h"
Hal Finkel7c8ae532014-07-25 17:47:22 +000022#include "llvm/MC/MCSymbol.h"
Hal Finkelc6a24392013-11-11 14:58:40 +000023#include "llvm/Support/CommandLine.h"
Chris Lattnera76eab42010-11-14 19:40:38 +000024#include "llvm/Support/raw_ostream.h"
Bill Schmidt8d86fe72013-08-30 15:18:11 +000025#include "llvm/Target/TargetOpcodes.h"
Chris Lattnera76eab42010-11-14 19:40:38 +000026using namespace llvm;
27
Chandler Carruth84e68b22014-04-22 02:41:26 +000028#define DEBUG_TYPE "asm-printer"
29
Hal Finkelc6a24392013-11-11 14:58:40 +000030// FIXME: Once the integrated assembler supports full register names, tie this
31// to the verbose-asm setting.
32static cl::opt<bool>
33FullRegNames("ppc-asm-full-reg-names", cl::Hidden, cl::init(false),
34 cl::desc("Use full register names when printing assembly"));
35
Nemanja Ivanovic6e7879c2016-09-22 09:52:19 +000036// Useful for testing purposes. Prints vs{31-63} as v{0-31} respectively.
37static cl::opt<bool>
38ShowVSRNumsAsVR("ppc-vsr-nums-as-vr", cl::Hidden, cl::init(false),
39 cl::desc("Prints full register names with vs{31-63} as v{0-31}"));
40
Hal Finkel7c5cb062015-04-23 18:30:38 +000041#define PRINT_ALIAS_INSTR
Chris Lattnera76eab42010-11-14 19:40:38 +000042#include "PPCGenAsmWriter.inc"
43
Rafael Espindolad6860522011-06-02 02:34:55 +000044void PPCInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
Hal Finkelc93a9a22015-02-25 01:06:45 +000045 const char *RegName = getRegisterName(RegNo);
46 if (RegName[0] == 'q' /* QPX */) {
47 // The system toolchain on the BG/Q does not understand QPX register names
48 // in .cfi_* directives, so print the name of the floating-point
49 // subregister instead.
50 std::string RN(RegName);
51
52 RN[0] = 'f';
53 OS << RN;
54
55 return;
56 }
57
58 OS << RegName;
Rafael Espindola08600bc2011-05-30 20:20:15 +000059}
Chris Lattnera76eab42010-11-14 19:40:38 +000060
Owen Andersona0c3b972011-09-15 23:38:46 +000061void PPCInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
Akira Hatanakab46d0232015-03-27 20:36:02 +000062 StringRef Annot, const MCSubtargetInfo &STI) {
Chris Lattner219cc3d2010-11-14 21:39:51 +000063 // Check for slwi/srwi mnemonics.
64 if (MI->getOpcode() == PPC::RLWINM) {
65 unsigned char SH = MI->getOperand(2).getImm();
66 unsigned char MB = MI->getOperand(3).getImm();
67 unsigned char ME = MI->getOperand(4).getImm();
68 bool useSubstituteMnemonic = false;
69 if (SH <= 31 && MB == 0 && ME == (31-SH)) {
70 O << "\tslwi "; useSubstituteMnemonic = true;
71 }
72 if (SH <= 31 && MB == (32-SH) && ME == 31) {
73 O << "\tsrwi "; useSubstituteMnemonic = true;
74 SH = 32-SH;
75 }
76 if (useSubstituteMnemonic) {
77 printOperand(MI, 0, O);
78 O << ", ";
79 printOperand(MI, 1, O);
80 O << ", " << (unsigned int)SH;
Owen Andersona0c3b972011-09-15 23:38:46 +000081
Owen Andersonbcc3fad2011-09-21 17:58:45 +000082 printAnnotation(O, Annot);
Chris Lattner219cc3d2010-11-14 21:39:51 +000083 return;
84 }
85 }
86
87 if ((MI->getOpcode() == PPC::OR || MI->getOpcode() == PPC::OR8) &&
88 MI->getOperand(1).getReg() == MI->getOperand(2).getReg()) {
89 O << "\tmr ";
90 printOperand(MI, 0, O);
91 O << ", ";
92 printOperand(MI, 1, O);
Owen Andersonbcc3fad2011-09-21 17:58:45 +000093 printAnnotation(O, Annot);
Chris Lattner219cc3d2010-11-14 21:39:51 +000094 return;
95 }
96
97 if (MI->getOpcode() == PPC::RLDICR) {
98 unsigned char SH = MI->getOperand(2).getImm();
99 unsigned char ME = MI->getOperand(3).getImm();
100 // rldicr RA, RS, SH, 63-SH == sldi RA, RS, SH
101 if (63-SH == ME) {
102 O << "\tsldi ";
103 printOperand(MI, 0, O);
104 O << ", ";
105 printOperand(MI, 1, O);
106 O << ", " << (unsigned int)SH;
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000107 printAnnotation(O, Annot);
Chris Lattner219cc3d2010-11-14 21:39:51 +0000108 return;
109 }
110 }
Hal Finkelfefcfff2015-04-23 22:47:57 +0000111
112 // dcbt[st] is printed manually here because:
113 // 1. The assembly syntax is different between embedded and server targets
114 // 2. We must print the short mnemonics for TH == 0 because the
115 // embedded/server syntax default will not be stable across assemblers
116 // The syntax for dcbt is:
117 // dcbt ra, rb, th [server]
118 // dcbt th, ra, rb [embedded]
119 // where th can be omitted when it is 0. dcbtst is the same.
120 if (MI->getOpcode() == PPC::DCBT || MI->getOpcode() == PPC::DCBTST) {
121 unsigned char TH = MI->getOperand(0).getImm();
122 O << "\tdcbt";
123 if (MI->getOpcode() == PPC::DCBTST)
124 O << "st";
125 if (TH == 16)
126 O << "t";
127 O << " ";
128
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000129 bool IsBookE = STI.getFeatureBits()[PPC::FeatureBookE];
Hal Finkelfefcfff2015-04-23 22:47:57 +0000130 if (IsBookE && TH != 0 && TH != 16)
131 O << (unsigned int) TH << ", ";
132
133 printOperand(MI, 1, O);
134 O << ", ";
135 printOperand(MI, 2, O);
136
137 if (!IsBookE && TH != 0 && TH != 16)
138 O << ", " << (unsigned int) TH;
139
140 printAnnotation(O, Annot);
141 return;
142 }
Hal Finkel277736e2016-09-02 23:41:54 +0000143
144 if (MI->getOpcode() == PPC::DCBF) {
145 unsigned char L = MI->getOperand(0).getImm();
146 if (!L || L == 1 || L == 3) {
147 O << "\tdcbf";
148 if (L == 1 || L == 3)
149 O << "l";
150 if (L == 3)
151 O << "p";
152 O << " ";
153
154 printOperand(MI, 1, O);
155 O << ", ";
156 printOperand(MI, 2, O);
157
158 printAnnotation(O, Annot);
159 return;
160 }
161 }
Chris Lattner219cc3d2010-11-14 21:39:51 +0000162
Hal Finkel7c5cb062015-04-23 18:30:38 +0000163 if (!printAliasInstr(MI, O))
164 printInstruction(MI, O);
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000165 printAnnotation(O, Annot);
Chris Lattnera76eab42010-11-14 19:40:38 +0000166}
167
Chris Lattnerf2cb69c2010-11-14 21:51:37 +0000168
169void PPCInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNo,
170 raw_ostream &O,
171 const char *Modifier) {
Chris Lattnerf2cb69c2010-11-14 21:51:37 +0000172 unsigned Code = MI->getOperand(OpNo).getImm();
Hal Finkel460e94d2012-06-22 23:10:08 +0000173
Chris Lattnerf2cb69c2010-11-14 21:51:37 +0000174 if (StringRef(Modifier) == "cc") {
175 switch ((PPC::Predicate)Code) {
Ulrich Weigand86247b62013-06-24 16:52:04 +0000176 case PPC::PRED_LT_MINUS:
177 case PPC::PRED_LT_PLUS:
178 case PPC::PRED_LT:
179 O << "lt";
180 return;
181 case PPC::PRED_LE_MINUS:
182 case PPC::PRED_LE_PLUS:
183 case PPC::PRED_LE:
184 O << "le";
185 return;
186 case PPC::PRED_EQ_MINUS:
187 case PPC::PRED_EQ_PLUS:
188 case PPC::PRED_EQ:
189 O << "eq";
190 return;
191 case PPC::PRED_GE_MINUS:
192 case PPC::PRED_GE_PLUS:
193 case PPC::PRED_GE:
194 O << "ge";
195 return;
196 case PPC::PRED_GT_MINUS:
197 case PPC::PRED_GT_PLUS:
198 case PPC::PRED_GT:
199 O << "gt";
200 return;
201 case PPC::PRED_NE_MINUS:
202 case PPC::PRED_NE_PLUS:
203 case PPC::PRED_NE:
204 O << "ne";
205 return;
206 case PPC::PRED_UN_MINUS:
207 case PPC::PRED_UN_PLUS:
208 case PPC::PRED_UN:
209 O << "un";
210 return;
211 case PPC::PRED_NU_MINUS:
212 case PPC::PRED_NU_PLUS:
213 case PPC::PRED_NU:
214 O << "nu";
215 return;
Hal Finkel940ab932014-02-28 00:27:01 +0000216 case PPC::PRED_BIT_SET:
217 case PPC::PRED_BIT_UNSET:
218 llvm_unreachable("Invalid use of bit predicate code");
Ulrich Weigand86247b62013-06-24 16:52:04 +0000219 }
Benjamin Kramer3912d782013-06-24 17:03:25 +0000220 llvm_unreachable("Invalid predicate code");
Ulrich Weigand86247b62013-06-24 16:52:04 +0000221 }
222
223 if (StringRef(Modifier) == "pm") {
224 switch ((PPC::Predicate)Code) {
225 case PPC::PRED_LT:
226 case PPC::PRED_LE:
227 case PPC::PRED_EQ:
228 case PPC::PRED_GE:
229 case PPC::PRED_GT:
230 case PPC::PRED_NE:
231 case PPC::PRED_UN:
232 case PPC::PRED_NU:
233 return;
234 case PPC::PRED_LT_MINUS:
235 case PPC::PRED_LE_MINUS:
236 case PPC::PRED_EQ_MINUS:
237 case PPC::PRED_GE_MINUS:
238 case PPC::PRED_GT_MINUS:
239 case PPC::PRED_NE_MINUS:
240 case PPC::PRED_UN_MINUS:
241 case PPC::PRED_NU_MINUS:
242 O << "-";
243 return;
244 case PPC::PRED_LT_PLUS:
245 case PPC::PRED_LE_PLUS:
246 case PPC::PRED_EQ_PLUS:
247 case PPC::PRED_GE_PLUS:
248 case PPC::PRED_GT_PLUS:
249 case PPC::PRED_NE_PLUS:
250 case PPC::PRED_UN_PLUS:
251 case PPC::PRED_NU_PLUS:
252 O << "+";
253 return;
Hal Finkel940ab932014-02-28 00:27:01 +0000254 case PPC::PRED_BIT_SET:
255 case PPC::PRED_BIT_UNSET:
256 llvm_unreachable("Invalid use of bit predicate code");
Chris Lattnerf2cb69c2010-11-14 21:51:37 +0000257 }
Benjamin Kramer3912d782013-06-24 17:03:25 +0000258 llvm_unreachable("Invalid predicate code");
Chris Lattnerf2cb69c2010-11-14 21:51:37 +0000259 }
260
261 assert(StringRef(Modifier) == "reg" &&
Ulrich Weigand86247b62013-06-24 16:52:04 +0000262 "Need to specify 'cc', 'pm' or 'reg' as predicate op modifier!");
Chris Lattnerf2cb69c2010-11-14 21:51:37 +0000263 printOperand(MI, OpNo+1, O);
264}
265
Hal Finkel522e4d92016-09-03 02:31:44 +0000266void PPCInstPrinter::printATBitsAsHint(const MCInst *MI, unsigned OpNo,
267 raw_ostream &O) {
268 unsigned Code = MI->getOperand(OpNo).getImm();
269 if (Code == 2)
270 O << "-";
271 else if (Code == 3)
272 O << "+";
273}
274
Nemanja Ivanovice8effe12015-03-04 20:44:33 +0000275void PPCInstPrinter::printU1ImmOperand(const MCInst *MI, unsigned OpNo,
276 raw_ostream &O) {
277 unsigned int Value = MI->getOperand(OpNo).getImm();
278 assert(Value <= 1 && "Invalid u1imm argument!");
279 O << (unsigned int)Value;
280}
281
Hal Finkel27774d92014-03-13 07:58:58 +0000282void PPCInstPrinter::printU2ImmOperand(const MCInst *MI, unsigned OpNo,
283 raw_ostream &O) {
284 unsigned int Value = MI->getOperand(OpNo).getImm();
285 assert(Value <= 3 && "Invalid u2imm argument!");
286 O << (unsigned int)Value;
287}
288
Kit Barton535e69d2015-03-25 19:36:23 +0000289void PPCInstPrinter::printU3ImmOperand(const MCInst *MI, unsigned OpNo,
290 raw_ostream &O) {
291 unsigned int Value = MI->getOperand(OpNo).getImm();
292 assert(Value <= 8 && "Invalid u3imm argument!");
293 O << (unsigned int)Value;
294}
295
Joerg Sonnenberger9e9623c2014-07-29 22:21:57 +0000296void PPCInstPrinter::printU4ImmOperand(const MCInst *MI, unsigned OpNo,
297 raw_ostream &O) {
298 unsigned int Value = MI->getOperand(OpNo).getImm();
299 assert(Value <= 15 && "Invalid u4imm argument!");
300 O << (unsigned int)Value;
301}
302
Chris Lattner94881432010-11-14 20:11:21 +0000303void PPCInstPrinter::printS5ImmOperand(const MCInst *MI, unsigned OpNo,
304 raw_ostream &O) {
Adhemerval Zanellafe3f7932012-10-08 18:59:53 +0000305 int Value = MI->getOperand(OpNo).getImm();
Richard Smith228e6d42012-08-24 23:29:28 +0000306 Value = SignExtend32<5>(Value);
Chris Lattner94881432010-11-14 20:11:21 +0000307 O << (int)Value;
308}
309
310void PPCInstPrinter::printU5ImmOperand(const MCInst *MI, unsigned OpNo,
311 raw_ostream &O) {
Adhemerval Zanellafe3f7932012-10-08 18:59:53 +0000312 unsigned int Value = MI->getOperand(OpNo).getImm();
Chris Lattner94881432010-11-14 20:11:21 +0000313 assert(Value <= 31 && "Invalid u5imm argument!");
314 O << (unsigned int)Value;
315}
316
317void PPCInstPrinter::printU6ImmOperand(const MCInst *MI, unsigned OpNo,
318 raw_ostream &O) {
Adhemerval Zanellafe3f7932012-10-08 18:59:53 +0000319 unsigned int Value = MI->getOperand(OpNo).getImm();
Chris Lattner94881432010-11-14 20:11:21 +0000320 assert(Value <= 63 && "Invalid u6imm argument!");
321 O << (unsigned int)Value;
322}
323
Chuang-Yu Cheng80722712016-03-28 08:34:28 +0000324void PPCInstPrinter::printU7ImmOperand(const MCInst *MI, unsigned OpNo,
325 raw_ostream &O) {
326 unsigned int Value = MI->getOperand(OpNo).getImm();
327 assert(Value <= 127 && "Invalid u7imm argument!");
328 O << (unsigned int)Value;
329}
330
Nemanja Ivanovicd2c3c512016-09-23 13:25:31 +0000331// Operands of BUILD_VECTOR are signed and we use this to print operands
332// of XXSPLTIB which are unsigned. So we simply truncate to 8 bits and
333// print as unsigned.
Chuang-Yu Cheng80722712016-03-28 08:34:28 +0000334void PPCInstPrinter::printU8ImmOperand(const MCInst *MI, unsigned OpNo,
335 raw_ostream &O) {
Nemanja Ivanovicd2c3c512016-09-23 13:25:31 +0000336 unsigned char Value = MI->getOperand(OpNo).getImm();
Chuang-Yu Cheng80722712016-03-28 08:34:28 +0000337 O << (unsigned int)Value;
338}
339
Bill Schmidte26236e2015-05-22 16:44:10 +0000340void PPCInstPrinter::printU10ImmOperand(const MCInst *MI, unsigned OpNo,
341 raw_ostream &O) {
342 unsigned short Value = MI->getOperand(OpNo).getImm();
343 assert(Value <= 1023 && "Invalid u10imm argument!");
344 O << (unsigned short)Value;
345}
346
Hal Finkelc93a9a22015-02-25 01:06:45 +0000347void PPCInstPrinter::printU12ImmOperand(const MCInst *MI, unsigned OpNo,
348 raw_ostream &O) {
349 unsigned short Value = MI->getOperand(OpNo).getImm();
350 assert(Value <= 4095 && "Invalid u12imm argument!");
351 O << (unsigned short)Value;
352}
353
Chris Lattner94881432010-11-14 20:11:21 +0000354void PPCInstPrinter::printS16ImmOperand(const MCInst *MI, unsigned OpNo,
355 raw_ostream &O) {
Ulrich Weigand41789de2013-05-23 22:26:41 +0000356 if (MI->getOperand(OpNo).isImm())
357 O << (short)MI->getOperand(OpNo).getImm();
358 else
359 printOperand(MI, OpNo, O);
Chris Lattner94881432010-11-14 20:11:21 +0000360}
361
362void PPCInstPrinter::printU16ImmOperand(const MCInst *MI, unsigned OpNo,
363 raw_ostream &O) {
Ulrich Weigandfd3ad692013-06-26 13:49:15 +0000364 if (MI->getOperand(OpNo).isImm())
365 O << (unsigned short)MI->getOperand(OpNo).getImm();
366 else
367 printOperand(MI, OpNo, O);
Chris Lattner94881432010-11-14 20:11:21 +0000368}
369
Chris Lattner3dc9bb22010-11-14 21:20:46 +0000370void PPCInstPrinter::printBranchOperand(const MCInst *MI, unsigned OpNo,
371 raw_ostream &O) {
372 if (!MI->getOperand(OpNo).isImm())
373 return printOperand(MI, OpNo, O);
374
375 // Branches can take an immediate operand. This is used by the branch
Ulrich Weigandb9d5d072013-05-03 19:53:04 +0000376 // selection pass to print .+8, an eight byte displacement from the PC.
377 O << ".+";
Ulrich Weigandb6a30d12013-06-24 11:03:33 +0000378 printAbsBranchOperand(MI, OpNo, O);
Chris Lattner3dc9bb22010-11-14 21:20:46 +0000379}
380
Ulrich Weigandb6a30d12013-06-24 11:03:33 +0000381void PPCInstPrinter::printAbsBranchOperand(const MCInst *MI, unsigned OpNo,
382 raw_ostream &O) {
383 if (!MI->getOperand(OpNo).isImm())
384 return printOperand(MI, OpNo, O);
385
Alexey Samsonov9ca48702014-09-02 17:38:34 +0000386 O << SignExtend32<32>((unsigned)MI->getOperand(OpNo).getImm() << 2);
Chris Lattnerf2cb69c2010-11-14 21:51:37 +0000387}
Chris Lattner3dc9bb22010-11-14 21:20:46 +0000388
389
Chris Lattner0dcd8002010-11-14 20:22:56 +0000390void PPCInstPrinter::printcrbitm(const MCInst *MI, unsigned OpNo,
391 raw_ostream &O) {
392 unsigned CCReg = MI->getOperand(OpNo).getReg();
393 unsigned RegNo;
394 switch (CCReg) {
Craig Toppere55c5562012-02-07 02:50:20 +0000395 default: llvm_unreachable("Unknown CR register");
Chris Lattner0dcd8002010-11-14 20:22:56 +0000396 case PPC::CR0: RegNo = 0; break;
397 case PPC::CR1: RegNo = 1; break;
398 case PPC::CR2: RegNo = 2; break;
399 case PPC::CR3: RegNo = 3; break;
400 case PPC::CR4: RegNo = 4; break;
401 case PPC::CR5: RegNo = 5; break;
402 case PPC::CR6: RegNo = 6; break;
403 case PPC::CR7: RegNo = 7; break;
404 }
405 O << (0x80 >> RegNo);
406}
407
408void PPCInstPrinter::printMemRegImm(const MCInst *MI, unsigned OpNo,
409 raw_ostream &O) {
Ulrich Weigand41789de2013-05-23 22:26:41 +0000410 printS16ImmOperand(MI, OpNo, O);
Chris Lattner0dcd8002010-11-14 20:22:56 +0000411 O << '(';
Chris Lattnerfd56ee22010-11-15 03:51:13 +0000412 if (MI->getOperand(OpNo+1).getReg() == PPC::R0)
Chris Lattner0dcd8002010-11-14 20:22:56 +0000413 O << "0";
414 else
415 printOperand(MI, OpNo+1, O);
416 O << ')';
417}
418
Chris Lattner0dcd8002010-11-14 20:22:56 +0000419void PPCInstPrinter::printMemRegReg(const MCInst *MI, unsigned OpNo,
420 raw_ostream &O) {
421 // When used as the base register, r0 reads constant zero rather than
422 // the value contained in the register. For this reason, the darwin
423 // assembler requires that we print r0 as 0 (no r) when used as the base.
424 if (MI->getOperand(OpNo).getReg() == PPC::R0)
425 O << "0";
426 else
427 printOperand(MI, OpNo, O);
428 O << ", ";
429 printOperand(MI, OpNo+1, O);
430}
431
Ulrich Weigand5143bab2013-07-02 21:31:04 +0000432void PPCInstPrinter::printTLSCall(const MCInst *MI, unsigned OpNo,
433 raw_ostream &O) {
Hal Finkel7c8ae532014-07-25 17:47:22 +0000434 // On PPC64, VariantKind is VK_None, but on PPC32, it's VK_PLT, and it must
435 // come at the _end_ of the expression.
436 const MCOperand &Op = MI->getOperand(OpNo);
437 const MCSymbolRefExpr &refExp = cast<MCSymbolRefExpr>(*Op.getExpr());
438 O << refExp.getSymbol().getName();
Ulrich Weigand5143bab2013-07-02 21:31:04 +0000439 O << '(';
440 printOperand(MI, OpNo+1, O);
441 O << ')';
Hal Finkel7c8ae532014-07-25 17:47:22 +0000442 if (refExp.getKind() != MCSymbolRefExpr::VK_None)
443 O << '@' << MCSymbolRefExpr::getVariantKindName(refExp.getKind());
Ulrich Weigand5143bab2013-07-02 21:31:04 +0000444}
Chris Lattner0dcd8002010-11-14 20:22:56 +0000445
Chris Lattner94881432010-11-14 20:11:21 +0000446
Chris Lattner7a5c57e2010-11-14 20:02:39 +0000447/// stripRegisterPrefix - This method strips the character prefix from a
448/// register name so that only the number is left. Used by for linux asm.
Benjamin Krameraef5bd02010-11-25 16:42:51 +0000449static const char *stripRegisterPrefix(const char *RegName) {
Hal Finkelc6a24392013-11-11 14:58:40 +0000450 if (FullRegNames)
451 return RegName;
452
Chris Lattner7a5c57e2010-11-14 20:02:39 +0000453 switch (RegName[0]) {
454 case 'r':
455 case 'f':
Hal Finkelc93a9a22015-02-25 01:06:45 +0000456 case 'q': // for QPX
Hal Finkel27774d92014-03-13 07:58:58 +0000457 case 'v':
458 if (RegName[1] == 's')
459 return RegName + 2;
460 return RegName + 1;
Chris Lattner7a5c57e2010-11-14 20:02:39 +0000461 case 'c': if (RegName[1] == 'r') return RegName + 2;
462 }
463
464 return RegName;
465}
466
467void PPCInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
468 raw_ostream &O) {
469 const MCOperand &Op = MI->getOperand(OpNo);
470 if (Op.isReg()) {
471 const char *RegName = getRegisterName(Op.getReg());
Nemanja Ivanovic6e7879c2016-09-22 09:52:19 +0000472 if (ShowVSRNumsAsVR) {
473 unsigned RegNum = Op.getReg();
474 if (RegNum >= PPC::VSH0 && RegNum <= PPC::VSH31)
475 O << 'v' << RegNum - PPC::VSH0;
476 else
477 O << RegName;
478 return;
479 }
Chris Lattner7a5c57e2010-11-14 20:02:39 +0000480 // The linux and AIX assembler does not take register prefixes.
481 if (!isDarwinSyntax())
482 RegName = stripRegisterPrefix(RegName);
483
484 O << RegName;
485 return;
486 }
487
488 if (Op.isImm()) {
489 O << Op.getImm();
490 return;
491 }
492
493 assert(Op.isExpr() && "unknown operand kind in printOperand");
Matt Arsenault8b643552015-06-09 00:31:39 +0000494 Op.getExpr()->print(O, &MAI);
Chris Lattner7a5c57e2010-11-14 20:02:39 +0000495}
Chris Lattnercfb62872010-11-14 21:54:34 +0000496