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