Fix build with gcc. This has a -Wsequence-point error on 'MII', which is a good point.
[oota-llvm.git] / lib / CodeGen / AsmPrinter / AsmPrinterInlineAsm.cpp
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/MCStreamer.h"
27 #include "llvm/MC/MCSubtargetInfo.h"
28 #include "llvm/MC/MCSymbol.h"
29 #include "llvm/MC/MCTargetAsmParser.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 namespace {
44   struct SrcMgrDiagInfo {
45     const MDNode *LocInfo;
46     LLVMContext::InlineAsmDiagHandlerTy DiagHandler;
47     void *DiagContext;
48   };
49 }
50
51 /// srcMgrDiagHandler - This callback is invoked when the SourceMgr for an
52 /// inline asm has an error in it.  diagInfo is a pointer to the SrcMgrDiagInfo
53 /// struct above.
54 static void srcMgrDiagHandler(const SMDiagnostic &Diag, void *diagInfo) {
55   SrcMgrDiagInfo *DiagInfo = static_cast<SrcMgrDiagInfo *>(diagInfo);
56   assert(DiagInfo && "Diagnostic context not passed down?");
57
58   // If the inline asm had metadata associated with it, pull out a location
59   // cookie corresponding to which line the error occurred on.
60   unsigned LocCookie = 0;
61   if (const MDNode *LocInfo = DiagInfo->LocInfo) {
62     unsigned ErrorLine = Diag.getLineNo()-1;
63     if (ErrorLine >= LocInfo->getNumOperands())
64       ErrorLine = 0;
65
66     if (LocInfo->getNumOperands() != 0)
67       if (const ConstantInt *CI =
68               mdconst::dyn_extract<ConstantInt>(LocInfo->getOperand(ErrorLine)))
69         LocCookie = CI->getZExtValue();
70   }
71
72   DiagInfo->DiagHandler(Diag, DiagInfo->DiagContext, LocCookie);
73 }
74
75 /// EmitInlineAsm - Emit a blob of inline asm to the output streamer.
76 void AsmPrinter::EmitInlineAsm(StringRef Str, const MDNode *LocMDNode,
77                                InlineAsm::AsmDialect Dialect) const {
78   assert(!Str.empty() && "Can't emit empty inline asm block");
79
80   // Remember if the buffer is nul terminated or not so we can avoid a copy.
81   bool isNullTerminated = Str.back() == 0;
82   if (isNullTerminated)
83     Str = Str.substr(0, Str.size()-1);
84
85   // If the output streamer does not have mature MC support or the integrated
86   // assembler has been disabled, just emit the blob textually.
87   // Otherwise parse the asm and emit it via MC support.
88   // This is useful in case the asm parser doesn't handle something but the
89   // system assembler does.
90   const MCAsmInfo *MCAI = TM.getMCAsmInfo();
91   assert(MCAI && "No MCAsmInfo");
92   if (!MCAI->useIntegratedAssembler() &&
93       !OutStreamer.isIntegratedAssemblerRequired()) {
94     emitInlineAsmStart();
95     OutStreamer.EmitRawText(Str);
96     // If we have a machine function then grab the MCSubtarget off of that,
97     // otherwise we're at the module level and want to construct one from
98     // the default CPU and target triple.
99     if (MF) {
100       emitInlineAsmEnd(MF->getSubtarget<MCSubtargetInfo>(), nullptr);
101     } else {
102       std::unique_ptr<MCSubtargetInfo> STI(TM.getTarget().createMCSubtargetInfo(
103           TM.getTargetTriple(), TM.getTargetCPU(),
104           TM.getTargetFeatureString()));
105       emitInlineAsmEnd(*STI, nullptr);
106     }
107     return;
108   }
109
110   SourceMgr SrcMgr;
111   SrcMgrDiagInfo DiagInfo;
112
113   // If the current LLVMContext has an inline asm handler, set it in SourceMgr.
114   LLVMContext &LLVMCtx = MMI->getModule()->getContext();
115   bool HasDiagHandler = false;
116   if (LLVMCtx.getInlineAsmDiagnosticHandler() != nullptr) {
117     // If the source manager has an issue, we arrange for srcMgrDiagHandler
118     // to be invoked, getting DiagInfo passed into it.
119     DiagInfo.LocInfo = LocMDNode;
120     DiagInfo.DiagHandler = LLVMCtx.getInlineAsmDiagnosticHandler();
121     DiagInfo.DiagContext = LLVMCtx.getInlineAsmDiagnosticContext();
122     SrcMgr.setDiagHandler(srcMgrDiagHandler, &DiagInfo);
123     HasDiagHandler = true;
124   }
125
126   std::unique_ptr<MemoryBuffer> Buffer;
127   if (isNullTerminated)
128     Buffer = MemoryBuffer::getMemBuffer(Str, "<inline asm>");
129   else
130     Buffer = MemoryBuffer::getMemBufferCopy(Str, "<inline asm>");
131
132   // Tell SrcMgr about this buffer, it takes ownership of the buffer.
133   SrcMgr.AddNewSourceBuffer(std::move(Buffer), SMLoc());
134
135   std::unique_ptr<MCAsmParser> Parser(
136       createMCAsmParser(SrcMgr, OutContext, OutStreamer, *MAI));
137
138   // Initialize the parser with a fresh subtarget info. It is better to use a
139   // new STI here because the parser may modify it and we do not want those
140   // modifications to persist after parsing the inlineasm. The modifications
141   // made by the parser will be seen by the code emitters because it passes
142   // the current STI down to the EncodeInstruction() method.
143   std::unique_ptr<MCSubtargetInfo> STI(TM.getTarget().createMCSubtargetInfo(
144       TM.getTargetTriple(), TM.getTargetCPU(), TM.getTargetFeatureString()));
145
146   // Preserve a copy of the original STI because the parser may modify it.  For
147   // example, when switching between arm and thumb mode. If the target needs to
148   // emit code to return to the original state it can do so in
149   // emitInlineAsmEnd().
150   MCSubtargetInfo STIOrig = *STI;
151
152   // We may create a new MCInstrInfo here since we might be at the module level
153   // and not have a MachineFunction to initialize the TargetInstrInfo from and
154   // we only need MCInstrInfo for asm parsing.
155   const MCInstrInfo *MII =
156       MF ? static_cast<const MCInstrInfo *>(MF->getSubtarget().getInstrInfo())
157          : static_cast<const MCInstrInfo *>(TM.getTarget().createMCInstrInfo());
158   std::unique_ptr<MCTargetAsmParser> TAP(TM.getTarget().createMCAsmParser(
159       *STI, *Parser, *MII, TM.Options.MCOptions));
160   if (!TAP)
161     report_fatal_error("Inline asm not supported by this streamer because"
162                        " we don't have an asm parser for this target\n");
163   Parser->setAssemblerDialect(Dialect);
164   Parser->setTargetParser(*TAP.get());
165   if (MF) {
166     const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
167     TAP->SetFrameRegister(TRI->getFrameRegister(*MF));
168   }
169
170   emitInlineAsmStart();
171   // Don't implicitly switch to the text section before the asm.
172   int Res = Parser->Run(/*NoInitialTextSection*/ true,
173                         /*NoFinalize*/ true);
174   emitInlineAsmEnd(STIOrig, STI.get());
175   if (Res && !HasDiagHandler)
176     report_fatal_error("Error parsing inline asm\n");
177 }
178
179 static void EmitMSInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
180                                MachineModuleInfo *MMI, int InlineAsmVariant,
181                                AsmPrinter *AP, unsigned LocCookie,
182                                raw_ostream &OS) {
183   // Switch to the inline assembly variant.
184   OS << "\t.intel_syntax\n\t";
185
186   const char *LastEmitted = AsmStr; // One past the last character emitted.
187   unsigned NumOperands = MI->getNumOperands();
188
189   while (*LastEmitted) {
190     switch (*LastEmitted) {
191     default: {
192       // Not a special case, emit the string section literally.
193       const char *LiteralEnd = LastEmitted+1;
194       while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
195              *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
196         ++LiteralEnd;
197
198       OS.write(LastEmitted, LiteralEnd-LastEmitted);
199       LastEmitted = LiteralEnd;
200       break;
201     }
202     case '\n':
203       ++LastEmitted;   // Consume newline character.
204       OS << '\n';      // Indent code with newline.
205       break;
206     case '$': {
207       ++LastEmitted;   // Consume '$' character.
208       bool Done = true;
209
210       // Handle escapes.
211       switch (*LastEmitted) {
212       default: Done = false; break;
213       case '$':
214         ++LastEmitted;  // Consume second '$' character.
215         break;
216       }
217       if (Done) break;
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             OS << *MI->getOperand(OpNo).getMBB()->getSymbol();
425           else {
426             if (InlineAsm::isMemKind(OpFlags)) {
427               Error = AP->PrintAsmMemoryOperand(MI, OpNo, InlineAsmVariant,
428                                                 Modifier[0] ? Modifier : nullptr,
429                                                 OS);
430             } else {
431               Error = AP->PrintAsmOperand(MI, OpNo, InlineAsmVariant,
432                                           Modifier[0] ? Modifier : nullptr, OS);
433             }
434           }
435         }
436         if (Error) {
437           std::string msg;
438           raw_string_ostream Msg(msg);
439           Msg << "invalid operand in inline asm: '" << AsmStr << "'";
440           MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
441         }
442       }
443       break;
444     }
445     }
446   }
447   OS << '\n' << (char)0;  // null terminate string.
448 }
449
450 /// EmitInlineAsm - This method formats and emits the specified machine
451 /// instruction that is an inline asm.
452 void AsmPrinter::EmitInlineAsm(const MachineInstr *MI) const {
453   assert(MI->isInlineAsm() && "printInlineAsm only works on inline asms");
454
455   // Count the number of register definitions to find the asm string.
456   unsigned NumDefs = 0;
457   for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef();
458        ++NumDefs)
459     assert(NumDefs != MI->getNumOperands()-2 && "No asm string?");
460
461   assert(MI->getOperand(NumDefs).isSymbol() && "No asm string?");
462
463   // Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
464   const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
465
466   // If this asmstr is empty, just print the #APP/#NOAPP markers.
467   // These are useful to see where empty asm's wound up.
468   if (AsmStr[0] == 0) {
469     OutStreamer.emitRawComment(MAI->getInlineAsmStart());
470     OutStreamer.emitRawComment(MAI->getInlineAsmEnd());
471     return;
472   }
473
474   // Emit the #APP start marker.  This has to happen even if verbose-asm isn't
475   // enabled, so we use emitRawComment.
476   OutStreamer.emitRawComment(MAI->getInlineAsmStart());
477
478   // Get the !srcloc metadata node if we have it, and decode the loc cookie from
479   // it.
480   unsigned LocCookie = 0;
481   const MDNode *LocMD = nullptr;
482   for (unsigned i = MI->getNumOperands(); i != 0; --i) {
483     if (MI->getOperand(i-1).isMetadata() &&
484         (LocMD = MI->getOperand(i-1).getMetadata()) &&
485         LocMD->getNumOperands() != 0) {
486       if (const ConstantInt *CI =
487               mdconst::dyn_extract<ConstantInt>(LocMD->getOperand(0))) {
488         LocCookie = CI->getZExtValue();
489         break;
490       }
491     }
492   }
493
494   // Emit the inline asm to a temporary string so we can emit it through
495   // EmitInlineAsm.
496   SmallString<256> StringData;
497   raw_svector_ostream OS(StringData);
498
499   // The variant of the current asmprinter.
500   int AsmPrinterVariant = MAI->getAssemblerDialect();
501   InlineAsm::AsmDialect InlineAsmVariant = MI->getInlineAsmDialect();
502   AsmPrinter *AP = const_cast<AsmPrinter*>(this);
503   if (InlineAsmVariant == InlineAsm::AD_ATT)
504     EmitGCCInlineAsmStr(AsmStr, MI, MMI, InlineAsmVariant, AsmPrinterVariant,
505                         AP, LocCookie, OS);
506   else
507     EmitMSInlineAsmStr(AsmStr, MI, MMI, InlineAsmVariant, AP, LocCookie, OS);
508
509   EmitInlineAsm(OS.str(), LocMD, MI->getInlineAsmDialect());
510
511   // Emit the #NOAPP end marker.  This has to happen even if verbose-asm isn't
512   // enabled, so we use emitRawComment.
513   OutStreamer.emitRawComment(MAI->getInlineAsmEnd());
514 }
515
516
517 /// PrintSpecial - Print information related to the specified machine instr
518 /// that is independent of the operand, and may be independent of the instr
519 /// itself.  This can be useful for portably encoding the comment character
520 /// or other bits of target-specific knowledge into the asmstrings.  The
521 /// syntax used is ${:comment}.  Targets can override this to add support
522 /// for their own strange codes.
523 void AsmPrinter::PrintSpecial(const MachineInstr *MI, raw_ostream &OS,
524                               const char *Code) const {
525   const DataLayout *DL = TM.getDataLayout();
526   if (!strcmp(Code, "private")) {
527     OS << DL->getPrivateGlobalPrefix();
528   } else if (!strcmp(Code, "comment")) {
529     OS << MAI->getCommentString();
530   } else if (!strcmp(Code, "uid")) {
531     // Comparing the address of MI isn't sufficient, because machineinstrs may
532     // be allocated to the same address across functions.
533
534     // If this is a new LastFn instruction, bump the counter.
535     if (LastMI != MI || LastFn != getFunctionNumber()) {
536       ++Counter;
537       LastMI = MI;
538       LastFn = getFunctionNumber();
539     }
540     OS << Counter;
541   } else {
542     std::string msg;
543     raw_string_ostream Msg(msg);
544     Msg << "Unknown special formatter '" << Code
545          << "' for machine instr: " << *MI;
546     report_fatal_error(Msg.str());
547   }
548 }
549
550 /// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
551 /// instruction, using the specified assembler variant.  Targets should
552 /// override this to format as appropriate.
553 bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
554                                  unsigned AsmVariant, const char *ExtraCode,
555                                  raw_ostream &O) {
556   // Does this asm operand have a single letter operand modifier?
557   if (ExtraCode && ExtraCode[0]) {
558     if (ExtraCode[1] != 0) return true; // Unknown modifier.
559
560     const MachineOperand &MO = MI->getOperand(OpNo);
561     switch (ExtraCode[0]) {
562     default:
563       return true;  // Unknown modifier.
564     case 'c': // Substitute immediate value without immediate syntax
565       if (MO.getType() != MachineOperand::MO_Immediate)
566         return true;
567       O << MO.getImm();
568       return false;
569     case 'n':  // Negate the immediate constant.
570       if (MO.getType() != MachineOperand::MO_Immediate)
571         return true;
572       O << -MO.getImm();
573       return false;
574     }
575   }
576   return true;
577 }
578
579 bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
580                                        unsigned AsmVariant,
581                                        const char *ExtraCode, raw_ostream &O) {
582   // Target doesn't support this yet!
583   return true;
584 }
585
586 void AsmPrinter::emitInlineAsmStart() const {}
587
588 void AsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
589                                   const MCSubtargetInfo *EndInfo) const {}