1 //===-- AsmPrinterInlineAsm.cpp - AsmPrinter Inline Asm Handling ----------===//
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 file implements the inline assembler pieces of the AsmPrinter class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/CodeGen/AsmPrinter.h"
15 #include "llvm/ADT/SmallString.h"
16 #include "llvm/ADT/Twine.h"
17 #include "llvm/CodeGen/MachineBasicBlock.h"
18 #include "llvm/CodeGen/MachineFunction.h"
19 #include "llvm/CodeGen/MachineModuleInfo.h"
20 #include "llvm/IR/Constants.h"
21 #include "llvm/IR/DataLayout.h"
22 #include "llvm/IR/InlineAsm.h"
23 #include "llvm/IR/LLVMContext.h"
24 #include "llvm/IR/Module.h"
25 #include "llvm/MC/MCAsmInfo.h"
26 #include "llvm/MC/MCParser/MCTargetAsmParser.h"
27 #include "llvm/MC/MCStreamer.h"
28 #include "llvm/MC/MCSubtargetInfo.h"
29 #include "llvm/MC/MCSymbol.h"
30 #include "llvm/Support/ErrorHandling.h"
31 #include "llvm/Support/MemoryBuffer.h"
32 #include "llvm/Support/SourceMgr.h"
33 #include "llvm/Support/TargetRegistry.h"
34 #include "llvm/Support/raw_ostream.h"
35 #include "llvm/Target/TargetInstrInfo.h"
36 #include "llvm/Target/TargetMachine.h"
37 #include "llvm/Target/TargetRegisterInfo.h"
38 #include "llvm/Target/TargetSubtargetInfo.h"
39 using namespace llvm;
40 
41 #define DEBUG_TYPE "asm-printer"
42 
43 /// srcMgrDiagHandler - This callback is invoked when the SourceMgr for an
44 /// inline asm has an error in it.  diagInfo is a pointer to the SrcMgrDiagInfo
45 /// struct above.
46 static void srcMgrDiagHandler(const SMDiagnostic &Diag, void *diagInfo) {
47   AsmPrinter::SrcMgrDiagInfo *DiagInfo =
48       static_cast<AsmPrinter::SrcMgrDiagInfo *>(diagInfo);
49   assert(DiagInfo && "Diagnostic context not passed down?");
50 
51   // If the inline asm had metadata associated with it, pull out a location
52   // cookie corresponding to which line the error occurred on.
53   unsigned LocCookie = 0;
54   if (const MDNode *LocInfo = DiagInfo->LocInfo) {
55     unsigned ErrorLine = Diag.getLineNo()-1;
56     if (ErrorLine >= LocInfo->getNumOperands())
57       ErrorLine = 0;
58 
59     if (LocInfo->getNumOperands() != 0)
60       if (const ConstantInt *CI =
61               mdconst::dyn_extract<ConstantInt>(LocInfo->getOperand(ErrorLine)))
62         LocCookie = CI->getZExtValue();
63   }
64 
65   DiagInfo->DiagHandler(Diag, DiagInfo->DiagContext, LocCookie);
66 }
67 
68 /// EmitInlineAsm - Emit a blob of inline asm to the output streamer.
69 void AsmPrinter::EmitInlineAsm(StringRef Str, const MCSubtargetInfo &STI,
70                                const MCTargetOptions &MCOptions,
71                                const MDNode *LocMDNode,
72                                InlineAsm::AsmDialect Dialect) const {
73   assert(!Str.empty() && "Can't emit empty inline asm block");
74 
75   // Remember if the buffer is nul terminated or not so we can avoid a copy.
76   bool isNullTerminated = Str.back() == 0;
77   if (isNullTerminated)
78     Str = Str.substr(0, Str.size()-1);
79 
80   // If the output streamer does not have mature MC support or the integrated
81   // assembler has been disabled, just emit the blob textually.
82   // Otherwise parse the asm and emit it via MC support.
83   // This is useful in case the asm parser doesn't handle something but the
84   // system assembler does.
85   const MCAsmInfo *MCAI = TM.getMCAsmInfo();
86   assert(MCAI && "No MCAsmInfo");
87   if (!MCAI->useIntegratedAssembler() &&
88       !OutStreamer->isIntegratedAssemblerRequired()) {
89     emitInlineAsmStart();
90     OutStreamer->EmitRawText(Str);
91     emitInlineAsmEnd(STI, nullptr);
92     return;
93   }
94 
95   if (!DiagInfo) {
96     DiagInfo = make_unique<SrcMgrDiagInfo>();
97 
98     MCContext &Context = MMI->getContext();
99     Context.setInlineSourceManager(&DiagInfo->SrcMgr);
100 
101     LLVMContext &LLVMCtx = MMI->getModule()->getContext();
102     if (LLVMCtx.getInlineAsmDiagnosticHandler()) {
103       DiagInfo->DiagHandler = LLVMCtx.getInlineAsmDiagnosticHandler();
104       DiagInfo->DiagContext = LLVMCtx.getInlineAsmDiagnosticContext();
105       DiagInfo->SrcMgr.setDiagHandler(srcMgrDiagHandler, DiagInfo.get());
106     }
107   }
108 
109   SourceMgr &SrcMgr = DiagInfo->SrcMgr;
110   SrcMgr.setIncludeDirs(MCOptions.IASSearchPaths);
111   DiagInfo->LocInfo = LocMDNode;
112 
113   std::unique_ptr<MemoryBuffer> Buffer;
114   // The inline asm source manager will outlive Str, so make a copy of the
115   // string for SourceMgr to own.
116   Buffer = MemoryBuffer::getMemBufferCopy(Str, "<inline asm>");
117 
118   // Tell SrcMgr about this buffer, it takes ownership of the buffer.
119   unsigned BufNum = SrcMgr.AddNewSourceBuffer(std::move(Buffer), SMLoc());
120 
121   std::unique_ptr<MCAsmParser> Parser(
122       createMCAsmParser(SrcMgr, OutContext, *OutStreamer, *MAI, BufNum));
123 
124   // We create a new MCInstrInfo here since we might be at the module level
125   // and not have a MachineFunction to initialize the TargetInstrInfo from and
126   // we only need MCInstrInfo for asm parsing. We create one unconditionally
127   // because it's not subtarget dependent.
128   std::unique_ptr<MCInstrInfo> MII(TM.getTarget().createMCInstrInfo());
129   std::unique_ptr<MCTargetAsmParser> TAP(TM.getTarget().createMCAsmParser(
130       STI, *Parser, *MII, MCOptions));
131   if (!TAP)
132     report_fatal_error("Inline asm not supported by this streamer because"
133                        " we don't have an asm parser for this target\n");
134   Parser->setAssemblerDialect(Dialect);
135   Parser->setTargetParser(*TAP.get());
136   if (MF) {
137     const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
138     TAP->SetFrameRegister(TRI->getFrameRegister(*MF));
139   }
140 
141   emitInlineAsmStart();
142   // Don't implicitly switch to the text section before the asm.
143   int Res = Parser->Run(/*NoInitialTextSection*/ true,
144                         /*NoFinalize*/ true);
145   emitInlineAsmEnd(STI, &TAP->getSTI());
146 
147   // LocInfo cannot be used for error generation from the backend.
148   // FIXME: associate LocInfo with the SourceBuffer to improve backend
149   // messages.
150   DiagInfo->LocInfo = nullptr;
151 
152   if (Res && !DiagInfo->DiagHandler)
153     report_fatal_error("Error parsing inline asm\n");
154 }
155 
156 static void EmitMSInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
157                                MachineModuleInfo *MMI, int InlineAsmVariant,
158                                AsmPrinter *AP, unsigned LocCookie,
159                                raw_ostream &OS) {
160   // Switch to the inline assembly variant.
161   OS << "\t.intel_syntax\n\t";
162 
163   const char *LastEmitted = AsmStr; // One past the last character emitted.
164   unsigned NumOperands = MI->getNumOperands();
165 
166   while (*LastEmitted) {
167     switch (*LastEmitted) {
168     default: {
169       // Not a special case, emit the string section literally.
170       const char *LiteralEnd = LastEmitted+1;
171       while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
172              *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
173         ++LiteralEnd;
174 
175       OS.write(LastEmitted, LiteralEnd-LastEmitted);
176       LastEmitted = LiteralEnd;
177       break;
178     }
179     case '\n':
180       ++LastEmitted;   // Consume newline character.
181       OS << '\n';      // Indent code with newline.
182       break;
183     case '$': {
184       ++LastEmitted;   // Consume '$' character.
185       bool Done = true;
186 
187       // Handle escapes.
188       switch (*LastEmitted) {
189       default: Done = false; break;
190       case '$':
191         ++LastEmitted;  // Consume second '$' character.
192         break;
193       }
194       if (Done) break;
195 
196       // If we have ${:foo}, then this is not a real operand reference, it is a
197       // "magic" string reference, just like in .td files.  Arrange to call
198       // PrintSpecial.
199       if (LastEmitted[0] == '{' && LastEmitted[1] == ':') {
200         LastEmitted += 2;
201         const char *StrStart = LastEmitted;
202         const char *StrEnd = strchr(StrStart, '}');
203         if (!StrEnd)
204           report_fatal_error("Unterminated ${:foo} operand in inline asm"
205                              " string: '" + Twine(AsmStr) + "'");
206 
207         std::string Val(StrStart, StrEnd);
208         AP->PrintSpecial(MI, OS, Val.c_str());
209         LastEmitted = StrEnd+1;
210         break;
211       }
212 
213       const char *IDStart = LastEmitted;
214       const char *IDEnd = IDStart;
215       while (*IDEnd >= '0' && *IDEnd <= '9') ++IDEnd;
216 
217       unsigned Val;
218       if (StringRef(IDStart, IDEnd-IDStart).getAsInteger(10, Val))
219         report_fatal_error("Bad $ operand number in inline asm string: '" +
220                            Twine(AsmStr) + "'");
221       LastEmitted = IDEnd;
222 
223       if (Val >= NumOperands-1)
224         report_fatal_error("Invalid $ operand number in inline asm string: '" +
225                            Twine(AsmStr) + "'");
226 
227       // Okay, we finally have a value number.  Ask the target to print this
228       // operand!
229       unsigned OpNo = InlineAsm::MIOp_FirstOperand;
230 
231       bool Error = false;
232 
233       // Scan to find the machine operand number for the operand.
234       for (; Val; --Val) {
235         if (OpNo >= MI->getNumOperands()) break;
236         unsigned OpFlags = MI->getOperand(OpNo).getImm();
237         OpNo += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
238       }
239 
240       // We may have a location metadata attached to the end of the
241       // instruction, and at no point should see metadata at any
242       // other point while processing. It's an error if so.
243       if (OpNo >= MI->getNumOperands() ||
244           MI->getOperand(OpNo).isMetadata()) {
245         Error = true;
246       } else {
247         unsigned OpFlags = MI->getOperand(OpNo).getImm();
248         ++OpNo;  // Skip over the ID number.
249 
250         if (InlineAsm::isMemKind(OpFlags)) {
251           Error = AP->PrintAsmMemoryOperand(MI, OpNo, InlineAsmVariant,
252                                             /*Modifier*/ nullptr, OS);
253         } else {
254           Error = AP->PrintAsmOperand(MI, OpNo, InlineAsmVariant,
255                                       /*Modifier*/ nullptr, OS);
256         }
257       }
258       if (Error) {
259         std::string msg;
260         raw_string_ostream Msg(msg);
261         Msg << "invalid operand in inline asm: '" << AsmStr << "'";
262         MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
263       }
264       break;
265     }
266     }
267   }
268   OS << "\n\t.att_syntax\n" << (char)0;  // null terminate string.
269 }
270 
271 static void EmitGCCInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
272                                 MachineModuleInfo *MMI, int InlineAsmVariant,
273                                 int AsmPrinterVariant, AsmPrinter *AP,
274                                 unsigned LocCookie, raw_ostream &OS) {
275   int CurVariant = -1;            // The number of the {.|.|.} region we are in.
276   const char *LastEmitted = AsmStr; // One past the last character emitted.
277   unsigned NumOperands = MI->getNumOperands();
278 
279   OS << '\t';
280 
281   while (*LastEmitted) {
282     switch (*LastEmitted) {
283     default: {
284       // Not a special case, emit the string section literally.
285       const char *LiteralEnd = LastEmitted+1;
286       while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
287              *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
288         ++LiteralEnd;
289       if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
290         OS.write(LastEmitted, LiteralEnd-LastEmitted);
291       LastEmitted = LiteralEnd;
292       break;
293     }
294     case '\n':
295       ++LastEmitted;   // Consume newline character.
296       OS << '\n';      // Indent code with newline.
297       break;
298     case '$': {
299       ++LastEmitted;   // Consume '$' character.
300       bool Done = true;
301 
302       // Handle escapes.
303       switch (*LastEmitted) {
304       default: Done = false; break;
305       case '$':     // $$ -> $
306         if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
307           OS << '$';
308         ++LastEmitted;  // Consume second '$' character.
309         break;
310       case '(':             // $( -> same as GCC's { character.
311         ++LastEmitted;      // Consume '(' character.
312         if (CurVariant != -1)
313           report_fatal_error("Nested variants found in inline asm string: '" +
314                              Twine(AsmStr) + "'");
315         CurVariant = 0;     // We're in the first variant now.
316         break;
317       case '|':
318         ++LastEmitted;  // consume '|' character.
319         if (CurVariant == -1)
320           OS << '|';       // this is gcc's behavior for | outside a variant
321         else
322           ++CurVariant;   // We're in the next variant.
323         break;
324       case ')':         // $) -> same as GCC's } char.
325         ++LastEmitted;  // consume ')' character.
326         if (CurVariant == -1)
327           OS << '}';     // this is gcc's behavior for } outside a variant
328         else
329           CurVariant = -1;
330         break;
331       }
332       if (Done) break;
333 
334       bool HasCurlyBraces = false;
335       if (*LastEmitted == '{') {     // ${variable}
336         ++LastEmitted;               // Consume '{' character.
337         HasCurlyBraces = true;
338       }
339 
340       // If we have ${:foo}, then this is not a real operand reference, it is a
341       // "magic" string reference, just like in .td files.  Arrange to call
342       // PrintSpecial.
343       if (HasCurlyBraces && *LastEmitted == ':') {
344         ++LastEmitted;
345         const char *StrStart = LastEmitted;
346         const char *StrEnd = strchr(StrStart, '}');
347         if (!StrEnd)
348           report_fatal_error("Unterminated ${:foo} operand in inline asm"
349                              " string: '" + Twine(AsmStr) + "'");
350 
351         std::string Val(StrStart, StrEnd);
352         AP->PrintSpecial(MI, OS, Val.c_str());
353         LastEmitted = StrEnd+1;
354         break;
355       }
356 
357       const char *IDStart = LastEmitted;
358       const char *IDEnd = IDStart;
359       while (*IDEnd >= '0' && *IDEnd <= '9') ++IDEnd;
360 
361       unsigned Val;
362       if (StringRef(IDStart, IDEnd-IDStart).getAsInteger(10, Val))
363         report_fatal_error("Bad $ operand number in inline asm string: '" +
364                            Twine(AsmStr) + "'");
365       LastEmitted = IDEnd;
366 
367       char Modifier[2] = { 0, 0 };
368 
369       if (HasCurlyBraces) {
370         // If we have curly braces, check for a modifier character.  This
371         // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
372         if (*LastEmitted == ':') {
373           ++LastEmitted;    // Consume ':' character.
374           if (*LastEmitted == 0)
375             report_fatal_error("Bad ${:} expression in inline asm string: '" +
376                                Twine(AsmStr) + "'");
377 
378           Modifier[0] = *LastEmitted;
379           ++LastEmitted;    // Consume modifier character.
380         }
381 
382         if (*LastEmitted != '}')
383           report_fatal_error("Bad ${} expression in inline asm string: '" +
384                              Twine(AsmStr) + "'");
385         ++LastEmitted;    // Consume '}' character.
386       }
387 
388       if (Val >= NumOperands-1)
389         report_fatal_error("Invalid $ operand number in inline asm string: '" +
390                            Twine(AsmStr) + "'");
391 
392       // Okay, we finally have a value number.  Ask the target to print this
393       // operand!
394       if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
395         unsigned OpNo = InlineAsm::MIOp_FirstOperand;
396 
397         bool Error = false;
398 
399         // Scan to find the machine operand number for the operand.
400         for (; Val; --Val) {
401           if (OpNo >= MI->getNumOperands()) break;
402           unsigned OpFlags = MI->getOperand(OpNo).getImm();
403           OpNo += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
404         }
405 
406         // We may have a location metadata attached to the end of the
407         // instruction, and at no point should see metadata at any
408         // other point while processing. It's an error if so.
409         if (OpNo >= MI->getNumOperands() ||
410             MI->getOperand(OpNo).isMetadata()) {
411           Error = true;
412         } else {
413           unsigned OpFlags = MI->getOperand(OpNo).getImm();
414           ++OpNo;  // Skip over the ID number.
415 
416           if (Modifier[0] == 'l') { // Labels are target independent.
417             // FIXME: What if the operand isn't an MBB, report error?
418             const MCSymbol *Sym = MI->getOperand(OpNo).getMBB()->getSymbol();
419             Sym->print(OS, AP->MAI);
420           } else {
421             if (InlineAsm::isMemKind(OpFlags)) {
422               Error = AP->PrintAsmMemoryOperand(MI, OpNo, InlineAsmVariant,
423                                                 Modifier[0] ? Modifier : nullptr,
424                                                 OS);
425             } else {
426               Error = AP->PrintAsmOperand(MI, OpNo, InlineAsmVariant,
427                                           Modifier[0] ? Modifier : nullptr, OS);
428             }
429           }
430         }
431         if (Error) {
432           std::string msg;
433           raw_string_ostream Msg(msg);
434           Msg << "invalid operand in inline asm: '" << AsmStr << "'";
435           MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
436         }
437       }
438       break;
439     }
440     }
441   }
442   OS << '\n' << (char)0;  // null terminate string.
443 }
444 
445 /// EmitInlineAsm - This method formats and emits the specified machine
446 /// instruction that is an inline asm.
447 void AsmPrinter::EmitInlineAsm(const MachineInstr *MI) const {
448   assert(MI->isInlineAsm() && "printInlineAsm only works on inline asms");
449 
450   // Count the number of register definitions to find the asm string.
451   unsigned NumDefs = 0;
452   for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef();
453        ++NumDefs)
454     assert(NumDefs != MI->getNumOperands()-2 && "No asm string?");
455 
456   assert(MI->getOperand(NumDefs).isSymbol() && "No asm string?");
457 
458   // Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
459   const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
460 
461   // If this asmstr is empty, just print the #APP/#NOAPP markers.
462   // These are useful to see where empty asm's wound up.
463   if (AsmStr[0] == 0) {
464     OutStreamer->emitRawComment(MAI->getInlineAsmStart());
465     OutStreamer->emitRawComment(MAI->getInlineAsmEnd());
466     return;
467   }
468 
469   // Emit the #APP start marker.  This has to happen even if verbose-asm isn't
470   // enabled, so we use emitRawComment.
471   OutStreamer->emitRawComment(MAI->getInlineAsmStart());
472 
473   // Get the !srcloc metadata node if we have it, and decode the loc cookie from
474   // it.
475   unsigned LocCookie = 0;
476   const MDNode *LocMD = nullptr;
477   for (unsigned i = MI->getNumOperands(); i != 0; --i) {
478     if (MI->getOperand(i-1).isMetadata() &&
479         (LocMD = MI->getOperand(i-1).getMetadata()) &&
480         LocMD->getNumOperands() != 0) {
481       if (const ConstantInt *CI =
482               mdconst::dyn_extract<ConstantInt>(LocMD->getOperand(0))) {
483         LocCookie = CI->getZExtValue();
484         break;
485       }
486     }
487   }
488 
489   // Emit the inline asm to a temporary string so we can emit it through
490   // EmitInlineAsm.
491   SmallString<256> StringData;
492   raw_svector_ostream OS(StringData);
493 
494   // The variant of the current asmprinter.
495   int AsmPrinterVariant = MAI->getAssemblerDialect();
496   InlineAsm::AsmDialect InlineAsmVariant = MI->getInlineAsmDialect();
497   AsmPrinter *AP = const_cast<AsmPrinter*>(this);
498   if (InlineAsmVariant == InlineAsm::AD_ATT)
499     EmitGCCInlineAsmStr(AsmStr, MI, MMI, InlineAsmVariant, AsmPrinterVariant,
500                         AP, LocCookie, OS);
501   else
502     EmitMSInlineAsmStr(AsmStr, MI, MMI, InlineAsmVariant, AP, LocCookie, OS);
503 
504   // Reset SanitizeAddress based on the function's attribute.
505   MCTargetOptions MCOptions = TM.Options.MCOptions;
506   MCOptions.SanitizeAddress =
507       MF->getFunction()->hasFnAttribute(Attribute::SanitizeAddress);
508 
509   EmitInlineAsm(OS.str(), getSubtargetInfo(), MCOptions, LocMD,
510                 MI->getInlineAsmDialect());
511 
512   // Emit the #NOAPP end marker.  This has to happen even if verbose-asm isn't
513   // enabled, so we use emitRawComment.
514   OutStreamer->emitRawComment(MAI->getInlineAsmEnd());
515 }
516 
517 
518 /// PrintSpecial - Print information related to the specified machine instr
519 /// that is independent of the operand, and may be independent of the instr
520 /// itself.  This can be useful for portably encoding the comment character
521 /// or other bits of target-specific knowledge into the asmstrings.  The
522 /// syntax used is ${:comment}.  Targets can override this to add support
523 /// for their own strange codes.
524 void AsmPrinter::PrintSpecial(const MachineInstr *MI, raw_ostream &OS,
525                               const char *Code) const {
526   if (!strcmp(Code, "private")) {
527     const DataLayout &DL = MF->getDataLayout();
528     OS << DL.getPrivateGlobalPrefix();
529   } else if (!strcmp(Code, "comment")) {
530     OS << MAI->getCommentString();
531   } else if (!strcmp(Code, "uid")) {
532     // Comparing the address of MI isn't sufficient, because machineinstrs may
533     // be allocated to the same address across functions.
534 
535     // If this is a new LastFn instruction, bump the counter.
536     if (LastMI != MI || LastFn != getFunctionNumber()) {
537       ++Counter;
538       LastMI = MI;
539       LastFn = getFunctionNumber();
540     }
541     OS << Counter;
542   } else {
543     std::string msg;
544     raw_string_ostream Msg(msg);
545     Msg << "Unknown special formatter '" << Code
546          << "' for machine instr: " << *MI;
547     report_fatal_error(Msg.str());
548   }
549 }
550 
551 /// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
552 /// instruction, using the specified assembler variant.  Targets should
553 /// override this to format as appropriate.
554 bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
555                                  unsigned AsmVariant, const char *ExtraCode,
556                                  raw_ostream &O) {
557   // Does this asm operand have a single letter operand modifier?
558   if (ExtraCode && ExtraCode[0]) {
559     if (ExtraCode[1] != 0) return true; // Unknown modifier.
560 
561     const MachineOperand &MO = MI->getOperand(OpNo);
562     switch (ExtraCode[0]) {
563     default:
564       return true;  // Unknown modifier.
565     case 'c': // Substitute immediate value without immediate syntax
566       if (MO.getType() != MachineOperand::MO_Immediate)
567         return true;
568       O << MO.getImm();
569       return false;
570     case 'n':  // Negate the immediate constant.
571       if (MO.getType() != MachineOperand::MO_Immediate)
572         return true;
573       O << -MO.getImm();
574       return false;
575     case 's':  // The GCC deprecated s modifier
576       if (MO.getType() != MachineOperand::MO_Immediate)
577         return true;
578       O << ((32 - MO.getImm()) & 31);
579       return false;
580     }
581   }
582   return true;
583 }
584 
585 bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
586                                        unsigned AsmVariant,
587                                        const char *ExtraCode, raw_ostream &O) {
588   // Target doesn't support this yet!
589   return true;
590 }
591 
592 void AsmPrinter::emitInlineAsmStart() const {}
593 
594 void AsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
595                                   const MCSubtargetInfo *EndInfo) const {}
596