blob: 61ad5705329375f9314bd5b5c5aabbf8082441c9 [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
Hal Finkel7c5cb062015-04-23 18:30:38 +000036#define PRINT_ALIAS_INSTR
Chris Lattnera76eab42010-11-14 19:40:38 +000037#include "PPCGenAsmWriter.inc"
38
Rafael Espindolad6860522011-06-02 02:34:55 +000039void PPCInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
Hal Finkelc93a9a22015-02-25 01:06:45 +000040 const char *RegName = getRegisterName(RegNo);
41 if (RegName[0] == 'q' /* QPX */) {
42 // The system toolchain on the BG/Q does not understand QPX register names
43 // in .cfi_* directives, so print the name of the floating-point
44 // subregister instead.
45 std::string RN(RegName);
46
47 RN[0] = 'f';
48 OS << RN;
49
50 return;
51 }
52
53 OS << RegName;
Rafael Espindola08600bc2011-05-30 20:20:15 +000054}
Chris Lattnera76eab42010-11-14 19:40:38 +000055
Owen Andersona0c3b972011-09-15 23:38:46 +000056void PPCInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
Akira Hatanakab46d0232015-03-27 20:36:02 +000057 StringRef Annot, const MCSubtargetInfo &STI) {
Chris Lattner219cc3d2010-11-14 21:39:51 +000058 // Check for slwi/srwi mnemonics.
59 if (MI->getOpcode() == PPC::RLWINM) {
60 unsigned char SH = MI->getOperand(2).getImm();
61 unsigned char MB = MI->getOperand(3).getImm();
62 unsigned char ME = MI->getOperand(4).getImm();
63 bool useSubstituteMnemonic = false;
64 if (SH <= 31 && MB == 0 && ME == (31-SH)) {
65 O << "\tslwi "; useSubstituteMnemonic = true;
66 }
67 if (SH <= 31 && MB == (32-SH) && ME == 31) {
68 O << "\tsrwi "; useSubstituteMnemonic = true;
69 SH = 32-SH;
70 }
71 if (useSubstituteMnemonic) {
72 printOperand(MI, 0, O);
73 O << ", ";
74 printOperand(MI, 1, O);
75 O << ", " << (unsigned int)SH;
Owen Andersona0c3b972011-09-15 23:38:46 +000076
Owen Andersonbcc3fad2011-09-21 17:58:45 +000077 printAnnotation(O, Annot);
Chris Lattner219cc3d2010-11-14 21:39:51 +000078 return;
79 }
80 }
81
82 if ((MI->getOpcode() == PPC::OR || MI->getOpcode() == PPC::OR8) &&
83 MI->getOperand(1).getReg() == MI->getOperand(2).getReg()) {
84 O << "\tmr ";
85 printOperand(MI, 0, O);
86 O << ", ";
87 printOperand(MI, 1, O);
Owen Andersonbcc3fad2011-09-21 17:58:45 +000088 printAnnotation(O, Annot);
Chris Lattner219cc3d2010-11-14 21:39:51 +000089 return;
90 }
91
92 if (MI->getOpcode() == PPC::RLDICR) {
93 unsigned char SH = MI->getOperand(2).getImm();
94 unsigned char ME = MI->getOperand(3).getImm();
95 // rldicr RA, RS, SH, 63-SH == sldi RA, RS, SH
96 if (63-SH == ME) {
97 O << "\tsldi ";
98 printOperand(MI, 0, O);
99 O << ", ";
100 printOperand(MI, 1, O);
101 O << ", " << (unsigned int)SH;
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000102 printAnnotation(O, Annot);
Chris Lattner219cc3d2010-11-14 21:39:51 +0000103 return;
104 }
105 }
Hal Finkelfefcfff2015-04-23 22:47:57 +0000106
107 // dcbt[st] is printed manually here because:
108 // 1. The assembly syntax is different between embedded and server targets
109 // 2. We must print the short mnemonics for TH == 0 because the
110 // embedded/server syntax default will not be stable across assemblers
111 // The syntax for dcbt is:
112 // dcbt ra, rb, th [server]
113 // dcbt th, ra, rb [embedded]
114 // where th can be omitted when it is 0. dcbtst is the same.
115 if (MI->getOpcode() == PPC::DCBT || MI->getOpcode() == PPC::DCBTST) {
116 unsigned char TH = MI->getOperand(0).getImm();
117 O << "\tdcbt";
118 if (MI->getOpcode() == PPC::DCBTST)
119 O << "st";
120 if (TH == 16)
121 O << "t";
122 O << " ";
123
Michael Kupersteindb0712f2015-05-26 10:47:10 +0000124 bool IsBookE = STI.getFeatureBits()[PPC::FeatureBookE];
Hal Finkelfefcfff2015-04-23 22:47:57 +0000125 if (IsBookE && TH != 0 && TH != 16)
126 O << (unsigned int) TH << ", ";
127
128 printOperand(MI, 1, O);
129 O << ", ";
130 printOperand(MI, 2, O);
131
132 if (!IsBookE && TH != 0 && TH != 16)
133 O << ", " << (unsigned int) TH;
134
135 printAnnotation(O, Annot);
136 return;
137 }
Hal Finkel277736e2016-09-02 23:41:54 +0000138
139 if (MI->getOpcode() == PPC::DCBF) {
140 unsigned char L = MI->getOperand(0).getImm();
141 if (!L || L == 1 || L == 3) {
142 O << "\tdcbf";
143 if (L == 1 || L == 3)
144 O << "l";
145 if (L == 3)
146 O << "p";
147 O << " ";
148
149 printOperand(MI, 1, O);
150 O << ", ";
151 printOperand(MI, 2, O);
152
153 printAnnotation(O, Annot);
154 return;
155 }
156 }
Chris Lattner219cc3d2010-11-14 21:39:51 +0000157
Hal Finkel7c5cb062015-04-23 18:30:38 +0000158 if (!printAliasInstr(MI, O))
159 printInstruction(MI, O);
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000160 printAnnotation(O, Annot);
Chris Lattnera76eab42010-11-14 19:40:38 +0000161}
162
Chris Lattnerf2cb69c2010-11-14 21:51:37 +0000163
164void PPCInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNo,
165 raw_ostream &O,
166 const char *Modifier) {
Chris Lattnerf2cb69c2010-11-14 21:51:37 +0000167 unsigned Code = MI->getOperand(OpNo).getImm();
Hal Finkel460e94d2012-06-22 23:10:08 +0000168
Chris Lattnerf2cb69c2010-11-14 21:51:37 +0000169 if (StringRef(Modifier) == "cc") {
170 switch ((PPC::Predicate)Code) {
Ulrich Weigand86247b62013-06-24 16:52:04 +0000171 case PPC::PRED_LT_MINUS:
172 case PPC::PRED_LT_PLUS:
173 case PPC::PRED_LT:
174 O << "lt";
175 return;
176 case PPC::PRED_LE_MINUS:
177 case PPC::PRED_LE_PLUS:
178 case PPC::PRED_LE:
179 O << "le";
180 return;
181 case PPC::PRED_EQ_MINUS:
182 case PPC::PRED_EQ_PLUS:
183 case PPC::PRED_EQ:
184 O << "eq";
185 return;
186 case PPC::PRED_GE_MINUS:
187 case PPC::PRED_GE_PLUS:
188 case PPC::PRED_GE:
189 O << "ge";
190 return;
191 case PPC::PRED_GT_MINUS:
192 case PPC::PRED_GT_PLUS:
193 case PPC::PRED_GT:
194 O << "gt";
195 return;
196 case PPC::PRED_NE_MINUS:
197 case PPC::PRED_NE_PLUS:
198 case PPC::PRED_NE:
199 O << "ne";
200 return;
201 case PPC::PRED_UN_MINUS:
202 case PPC::PRED_UN_PLUS:
203 case PPC::PRED_UN:
204 O << "un";
205 return;
206 case PPC::PRED_NU_MINUS:
207 case PPC::PRED_NU_PLUS:
208 case PPC::PRED_NU:
209 O << "nu";
210 return;
Hal Finkel940ab932014-02-28 00:27:01 +0000211 case PPC::PRED_BIT_SET:
212 case PPC::PRED_BIT_UNSET:
213 llvm_unreachable("Invalid use of bit predicate code");
Ulrich Weigand86247b62013-06-24 16:52:04 +0000214 }
Benjamin Kramer3912d782013-06-24 17:03:25 +0000215 llvm_unreachable("Invalid predicate code");
Ulrich Weigand86247b62013-06-24 16:52:04 +0000216 }
217
218 if (StringRef(Modifier) == "pm") {
219 switch ((PPC::Predicate)Code) {
220 case PPC::PRED_LT:
221 case PPC::PRED_LE:
222 case PPC::PRED_EQ:
223 case PPC::PRED_GE:
224 case PPC::PRED_GT:
225 case PPC::PRED_NE:
226 case PPC::PRED_UN:
227 case PPC::PRED_NU:
228 return;
229 case PPC::PRED_LT_MINUS:
230 case PPC::PRED_LE_MINUS:
231 case PPC::PRED_EQ_MINUS:
232 case PPC::PRED_GE_MINUS:
233 case PPC::PRED_GT_MINUS:
234 case PPC::PRED_NE_MINUS:
235 case PPC::PRED_UN_MINUS:
236 case PPC::PRED_NU_MINUS:
237 O << "-";
238 return;
239 case PPC::PRED_LT_PLUS:
240 case PPC::PRED_LE_PLUS:
241 case PPC::PRED_EQ_PLUS:
242 case PPC::PRED_GE_PLUS:
243 case PPC::PRED_GT_PLUS:
244 case PPC::PRED_NE_PLUS:
245 case PPC::PRED_UN_PLUS:
246 case PPC::PRED_NU_PLUS:
247 O << "+";
248 return;
Hal Finkel940ab932014-02-28 00:27:01 +0000249 case PPC::PRED_BIT_SET:
250 case PPC::PRED_BIT_UNSET:
251 llvm_unreachable("Invalid use of bit predicate code");
Chris Lattnerf2cb69c2010-11-14 21:51:37 +0000252 }
Benjamin Kramer3912d782013-06-24 17:03:25 +0000253 llvm_unreachable("Invalid predicate code");
Chris Lattnerf2cb69c2010-11-14 21:51:37 +0000254 }
255
256 assert(StringRef(Modifier) == "reg" &&
Ulrich Weigand86247b62013-06-24 16:52:04 +0000257 "Need to specify 'cc', 'pm' or 'reg' as predicate op modifier!");
Chris Lattnerf2cb69c2010-11-14 21:51:37 +0000258 printOperand(MI, OpNo+1, O);
259}
260
Hal Finkel522e4d92016-09-03 02:31:44 +0000261void PPCInstPrinter::printATBitsAsHint(const MCInst *MI, unsigned OpNo,
262 raw_ostream &O) {
263 unsigned Code = MI->getOperand(OpNo).getImm();
264 if (Code == 2)
265 O << "-";
266 else if (Code == 3)
267 O << "+";
268}
269
Nemanja Ivanovice8effe12015-03-04 20:44:33 +0000270void PPCInstPrinter::printU1ImmOperand(const MCInst *MI, unsigned OpNo,
271 raw_ostream &O) {
272 unsigned int Value = MI->getOperand(OpNo).getImm();
273 assert(Value <= 1 && "Invalid u1imm argument!");
274 O << (unsigned int)Value;
275}
276
Hal Finkel27774d92014-03-13 07:58:58 +0000277void PPCInstPrinter::printU2ImmOperand(const MCInst *MI, unsigned OpNo,
278 raw_ostream &O) {
279 unsigned int Value = MI->getOperand(OpNo).getImm();
280 assert(Value <= 3 && "Invalid u2imm argument!");
281 O << (unsigned int)Value;
282}
283
Kit Barton535e69d2015-03-25 19:36:23 +0000284void PPCInstPrinter::printU3ImmOperand(const MCInst *MI, unsigned OpNo,
285 raw_ostream &O) {
286 unsigned int Value = MI->getOperand(OpNo).getImm();
287 assert(Value <= 8 && "Invalid u3imm argument!");
288 O << (unsigned int)Value;
289}
290
Joerg Sonnenberger9e9623c2014-07-29 22:21:57 +0000291void PPCInstPrinter::printU4ImmOperand(const MCInst *MI, unsigned OpNo,
292 raw_ostream &O) {
293 unsigned int Value = MI->getOperand(OpNo).getImm();
294 assert(Value <= 15 && "Invalid u4imm argument!");
295 O << (unsigned int)Value;
296}
297
Chris Lattner94881432010-11-14 20:11:21 +0000298void PPCInstPrinter::printS5ImmOperand(const MCInst *MI, unsigned OpNo,
299 raw_ostream &O) {
Adhemerval Zanellafe3f7932012-10-08 18:59:53 +0000300 int Value = MI->getOperand(OpNo).getImm();
Richard Smith228e6d42012-08-24 23:29:28 +0000301 Value = SignExtend32<5>(Value);
Chris Lattner94881432010-11-14 20:11:21 +0000302 O << (int)Value;
303}
304
305void PPCInstPrinter::printU5ImmOperand(const MCInst *MI, unsigned OpNo,
306 raw_ostream &O) {
Adhemerval Zanellafe3f7932012-10-08 18:59:53 +0000307 unsigned int Value = MI->getOperand(OpNo).getImm();
Chris Lattner94881432010-11-14 20:11:21 +0000308 assert(Value <= 31 && "Invalid u5imm argument!");
309 O << (unsigned int)Value;
310}
311
312void PPCInstPrinter::printU6ImmOperand(const MCInst *MI, unsigned OpNo,
313 raw_ostream &O) {
Adhemerval Zanellafe3f7932012-10-08 18:59:53 +0000314 unsigned int Value = MI->getOperand(OpNo).getImm();
Chris Lattner94881432010-11-14 20:11:21 +0000315 assert(Value <= 63 && "Invalid u6imm argument!");
316 O << (unsigned int)Value;
317}
318
Chuang-Yu Cheng80722712016-03-28 08:34:28 +0000319void PPCInstPrinter::printU7ImmOperand(const MCInst *MI, unsigned OpNo,
320 raw_ostream &O) {
321 unsigned int Value = MI->getOperand(OpNo).getImm();
322 assert(Value <= 127 && "Invalid u7imm argument!");
323 O << (unsigned int)Value;
324}
325
326void PPCInstPrinter::printU8ImmOperand(const MCInst *MI, unsigned OpNo,
327 raw_ostream &O) {
328 unsigned int Value = MI->getOperand(OpNo).getImm();
329 assert(Value <= 255 && "Invalid u8imm argument!");
330 O << (unsigned int)Value;
331}
332
Bill Schmidte26236e2015-05-22 16:44:10 +0000333void PPCInstPrinter::printU10ImmOperand(const MCInst *MI, unsigned OpNo,
334 raw_ostream &O) {
335 unsigned short Value = MI->getOperand(OpNo).getImm();
336 assert(Value <= 1023 && "Invalid u10imm argument!");
337 O << (unsigned short)Value;
338}
339
Hal Finkelc93a9a22015-02-25 01:06:45 +0000340void PPCInstPrinter::printU12ImmOperand(const MCInst *MI, unsigned OpNo,
341 raw_ostream &O) {
342 unsigned short Value = MI->getOperand(OpNo).getImm();
343 assert(Value <= 4095 && "Invalid u12imm argument!");
344 O << (unsigned short)Value;
345}
346
Chris Lattner94881432010-11-14 20:11:21 +0000347void PPCInstPrinter::printS16ImmOperand(const MCInst *MI, unsigned OpNo,
348 raw_ostream &O) {
Ulrich Weigand41789de2013-05-23 22:26:41 +0000349 if (MI->getOperand(OpNo).isImm())
350 O << (short)MI->getOperand(OpNo).getImm();
351 else
352 printOperand(MI, OpNo, O);
Chris Lattner94881432010-11-14 20:11:21 +0000353}
354
355void PPCInstPrinter::printU16ImmOperand(const MCInst *MI, unsigned OpNo,
356 raw_ostream &O) {
Ulrich Weigandfd3ad692013-06-26 13:49:15 +0000357 if (MI->getOperand(OpNo).isImm())
358 O << (unsigned short)MI->getOperand(OpNo).getImm();
359 else
360 printOperand(MI, OpNo, O);
Chris Lattner94881432010-11-14 20:11:21 +0000361}
362
Chris Lattner3dc9bb22010-11-14 21:20:46 +0000363void PPCInstPrinter::printBranchOperand(const MCInst *MI, unsigned OpNo,
364 raw_ostream &O) {
365 if (!MI->getOperand(OpNo).isImm())
366 return printOperand(MI, OpNo, O);
367
368 // Branches can take an immediate operand. This is used by the branch
Ulrich Weigandb9d5d072013-05-03 19:53:04 +0000369 // selection pass to print .+8, an eight byte displacement from the PC.
370 O << ".+";
Ulrich Weigandb6a30d12013-06-24 11:03:33 +0000371 printAbsBranchOperand(MI, OpNo, O);
Chris Lattner3dc9bb22010-11-14 21:20:46 +0000372}
373
Ulrich Weigandb6a30d12013-06-24 11:03:33 +0000374void PPCInstPrinter::printAbsBranchOperand(const MCInst *MI, unsigned OpNo,
375 raw_ostream &O) {
376 if (!MI->getOperand(OpNo).isImm())
377 return printOperand(MI, OpNo, O);
378
Alexey Samsonov9ca48702014-09-02 17:38:34 +0000379 O << SignExtend32<32>((unsigned)MI->getOperand(OpNo).getImm() << 2);
Chris Lattnerf2cb69c2010-11-14 21:51:37 +0000380}
Chris Lattner3dc9bb22010-11-14 21:20:46 +0000381
382
Chris Lattner0dcd8002010-11-14 20:22:56 +0000383void PPCInstPrinter::printcrbitm(const MCInst *MI, unsigned OpNo,
384 raw_ostream &O) {
385 unsigned CCReg = MI->getOperand(OpNo).getReg();
386 unsigned RegNo;
387 switch (CCReg) {
Craig Toppere55c5562012-02-07 02:50:20 +0000388 default: llvm_unreachable("Unknown CR register");
Chris Lattner0dcd8002010-11-14 20:22:56 +0000389 case PPC::CR0: RegNo = 0; break;
390 case PPC::CR1: RegNo = 1; break;
391 case PPC::CR2: RegNo = 2; break;
392 case PPC::CR3: RegNo = 3; break;
393 case PPC::CR4: RegNo = 4; break;
394 case PPC::CR5: RegNo = 5; break;
395 case PPC::CR6: RegNo = 6; break;
396 case PPC::CR7: RegNo = 7; break;
397 }
398 O << (0x80 >> RegNo);
399}
400
401void PPCInstPrinter::printMemRegImm(const MCInst *MI, unsigned OpNo,
402 raw_ostream &O) {
Ulrich Weigand41789de2013-05-23 22:26:41 +0000403 printS16ImmOperand(MI, OpNo, O);
Chris Lattner0dcd8002010-11-14 20:22:56 +0000404 O << '(';
Chris Lattnerfd56ee22010-11-15 03:51:13 +0000405 if (MI->getOperand(OpNo+1).getReg() == PPC::R0)
Chris Lattner0dcd8002010-11-14 20:22:56 +0000406 O << "0";
407 else
408 printOperand(MI, OpNo+1, O);
409 O << ')';
410}
411
Chris Lattner0dcd8002010-11-14 20:22:56 +0000412void PPCInstPrinter::printMemRegReg(const MCInst *MI, unsigned OpNo,
413 raw_ostream &O) {
414 // When used as the base register, r0 reads constant zero rather than
415 // the value contained in the register. For this reason, the darwin
416 // assembler requires that we print r0 as 0 (no r) when used as the base.
417 if (MI->getOperand(OpNo).getReg() == PPC::R0)
418 O << "0";
419 else
420 printOperand(MI, OpNo, O);
421 O << ", ";
422 printOperand(MI, OpNo+1, O);
423}
424
Ulrich Weigand5143bab2013-07-02 21:31:04 +0000425void PPCInstPrinter::printTLSCall(const MCInst *MI, unsigned OpNo,
426 raw_ostream &O) {
Hal Finkel7c8ae532014-07-25 17:47:22 +0000427 // On PPC64, VariantKind is VK_None, but on PPC32, it's VK_PLT, and it must
428 // come at the _end_ of the expression.
429 const MCOperand &Op = MI->getOperand(OpNo);
430 const MCSymbolRefExpr &refExp = cast<MCSymbolRefExpr>(*Op.getExpr());
431 O << refExp.getSymbol().getName();
Ulrich Weigand5143bab2013-07-02 21:31:04 +0000432 O << '(';
433 printOperand(MI, OpNo+1, O);
434 O << ')';
Hal Finkel7c8ae532014-07-25 17:47:22 +0000435 if (refExp.getKind() != MCSymbolRefExpr::VK_None)
436 O << '@' << MCSymbolRefExpr::getVariantKindName(refExp.getKind());
Ulrich Weigand5143bab2013-07-02 21:31:04 +0000437}
Chris Lattner0dcd8002010-11-14 20:22:56 +0000438
Chris Lattner94881432010-11-14 20:11:21 +0000439
Chris Lattner7a5c57e2010-11-14 20:02:39 +0000440/// stripRegisterPrefix - This method strips the character prefix from a
441/// register name so that only the number is left. Used by for linux asm.
Benjamin Krameraef5bd02010-11-25 16:42:51 +0000442static const char *stripRegisterPrefix(const char *RegName) {
Hal Finkelc6a24392013-11-11 14:58:40 +0000443 if (FullRegNames)
444 return RegName;
445
Chris Lattner7a5c57e2010-11-14 20:02:39 +0000446 switch (RegName[0]) {
447 case 'r':
448 case 'f':
Hal Finkelc93a9a22015-02-25 01:06:45 +0000449 case 'q': // for QPX
Hal Finkel27774d92014-03-13 07:58:58 +0000450 case 'v':
451 if (RegName[1] == 's')
452 return RegName + 2;
453 return RegName + 1;
Chris Lattner7a5c57e2010-11-14 20:02:39 +0000454 case 'c': if (RegName[1] == 'r') return RegName + 2;
455 }
456
457 return RegName;
458}
459
460void PPCInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
461 raw_ostream &O) {
462 const MCOperand &Op = MI->getOperand(OpNo);
463 if (Op.isReg()) {
464 const char *RegName = getRegisterName(Op.getReg());
465 // The linux and AIX assembler does not take register prefixes.
466 if (!isDarwinSyntax())
467 RegName = stripRegisterPrefix(RegName);
468
469 O << RegName;
470 return;
471 }
472
473 if (Op.isImm()) {
474 O << Op.getImm();
475 return;
476 }
477
478 assert(Op.isExpr() && "unknown operand kind in printOperand");
Matt Arsenault8b643552015-06-09 00:31:39 +0000479 Op.getExpr()->print(O, &MAI);
Chris Lattner7a5c57e2010-11-14 20:02:39 +0000480}
Chris Lattnercfb62872010-11-14 21:54:34 +0000481