xref: /freebsd/contrib/llvm-project/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp (revision 8bcb0991864975618c09697b1aca10683346d9f0)
10b57cec5SDimitry Andric //===-- AsmPrinterInlineAsm.cpp - AsmPrinter Inline Asm Handling ----------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file implements the inline assembler pieces of the AsmPrinter class.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #include "llvm/ADT/SmallString.h"
140b57cec5SDimitry Andric #include "llvm/ADT/Twine.h"
150b57cec5SDimitry Andric #include "llvm/CodeGen/AsmPrinter.h"
160b57cec5SDimitry Andric #include "llvm/CodeGen/MachineBasicBlock.h"
170b57cec5SDimitry Andric #include "llvm/CodeGen/MachineFunction.h"
180b57cec5SDimitry Andric #include "llvm/CodeGen/MachineModuleInfo.h"
190b57cec5SDimitry Andric #include "llvm/CodeGen/TargetInstrInfo.h"
200b57cec5SDimitry Andric #include "llvm/CodeGen/TargetRegisterInfo.h"
210b57cec5SDimitry Andric #include "llvm/IR/Constants.h"
220b57cec5SDimitry Andric #include "llvm/IR/DataLayout.h"
230b57cec5SDimitry Andric #include "llvm/IR/InlineAsm.h"
240b57cec5SDimitry Andric #include "llvm/IR/LLVMContext.h"
250b57cec5SDimitry Andric #include "llvm/IR/Module.h"
260b57cec5SDimitry Andric #include "llvm/MC/MCAsmInfo.h"
270b57cec5SDimitry Andric #include "llvm/MC/MCParser/MCTargetAsmParser.h"
280b57cec5SDimitry Andric #include "llvm/MC/MCStreamer.h"
290b57cec5SDimitry Andric #include "llvm/MC/MCSubtargetInfo.h"
300b57cec5SDimitry Andric #include "llvm/MC/MCSymbol.h"
310b57cec5SDimitry Andric #include "llvm/Support/ErrorHandling.h"
320b57cec5SDimitry Andric #include "llvm/Support/MemoryBuffer.h"
330b57cec5SDimitry Andric #include "llvm/Support/SourceMgr.h"
340b57cec5SDimitry Andric #include "llvm/Support/TargetRegistry.h"
350b57cec5SDimitry Andric #include "llvm/Support/raw_ostream.h"
360b57cec5SDimitry Andric #include "llvm/Target/TargetMachine.h"
370b57cec5SDimitry Andric using namespace llvm;
380b57cec5SDimitry Andric 
390b57cec5SDimitry Andric #define DEBUG_TYPE "asm-printer"
400b57cec5SDimitry Andric 
410b57cec5SDimitry Andric /// srcMgrDiagHandler - This callback is invoked when the SourceMgr for an
420b57cec5SDimitry Andric /// inline asm has an error in it.  diagInfo is a pointer to the SrcMgrDiagInfo
430b57cec5SDimitry Andric /// struct above.
440b57cec5SDimitry Andric static void srcMgrDiagHandler(const SMDiagnostic &Diag, void *diagInfo) {
450b57cec5SDimitry Andric   AsmPrinter::SrcMgrDiagInfo *DiagInfo =
460b57cec5SDimitry Andric       static_cast<AsmPrinter::SrcMgrDiagInfo *>(diagInfo);
470b57cec5SDimitry Andric   assert(DiagInfo && "Diagnostic context not passed down?");
480b57cec5SDimitry Andric 
490b57cec5SDimitry Andric   // Look up a LocInfo for the buffer this diagnostic is coming from.
500b57cec5SDimitry Andric   unsigned BufNum = DiagInfo->SrcMgr.FindBufferContainingLoc(Diag.getLoc());
510b57cec5SDimitry Andric   const MDNode *LocInfo = nullptr;
520b57cec5SDimitry Andric   if (BufNum > 0 && BufNum <= DiagInfo->LocInfos.size())
530b57cec5SDimitry Andric     LocInfo = DiagInfo->LocInfos[BufNum-1];
540b57cec5SDimitry Andric 
550b57cec5SDimitry Andric   // If the inline asm had metadata associated with it, pull out a location
560b57cec5SDimitry Andric   // cookie corresponding to which line the error occurred on.
570b57cec5SDimitry Andric   unsigned LocCookie = 0;
580b57cec5SDimitry Andric   if (LocInfo) {
590b57cec5SDimitry Andric     unsigned ErrorLine = Diag.getLineNo()-1;
600b57cec5SDimitry Andric     if (ErrorLine >= LocInfo->getNumOperands())
610b57cec5SDimitry Andric       ErrorLine = 0;
620b57cec5SDimitry Andric 
630b57cec5SDimitry Andric     if (LocInfo->getNumOperands() != 0)
640b57cec5SDimitry Andric       if (const ConstantInt *CI =
650b57cec5SDimitry Andric               mdconst::dyn_extract<ConstantInt>(LocInfo->getOperand(ErrorLine)))
660b57cec5SDimitry Andric         LocCookie = CI->getZExtValue();
670b57cec5SDimitry Andric   }
680b57cec5SDimitry Andric 
690b57cec5SDimitry Andric   DiagInfo->DiagHandler(Diag, DiagInfo->DiagContext, LocCookie);
700b57cec5SDimitry Andric }
710b57cec5SDimitry Andric 
720b57cec5SDimitry Andric unsigned AsmPrinter::addInlineAsmDiagBuffer(StringRef AsmStr,
730b57cec5SDimitry Andric                                             const MDNode *LocMDNode) const {
740b57cec5SDimitry Andric   if (!DiagInfo) {
75*8bcb0991SDimitry Andric     DiagInfo = std::make_unique<SrcMgrDiagInfo>();
760b57cec5SDimitry Andric 
770b57cec5SDimitry Andric     MCContext &Context = MMI->getContext();
780b57cec5SDimitry Andric     Context.setInlineSourceManager(&DiagInfo->SrcMgr);
790b57cec5SDimitry Andric 
800b57cec5SDimitry Andric     LLVMContext &LLVMCtx = MMI->getModule()->getContext();
810b57cec5SDimitry Andric     if (LLVMCtx.getInlineAsmDiagnosticHandler()) {
820b57cec5SDimitry Andric       DiagInfo->DiagHandler = LLVMCtx.getInlineAsmDiagnosticHandler();
830b57cec5SDimitry Andric       DiagInfo->DiagContext = LLVMCtx.getInlineAsmDiagnosticContext();
840b57cec5SDimitry Andric       DiagInfo->SrcMgr.setDiagHandler(srcMgrDiagHandler, DiagInfo.get());
850b57cec5SDimitry Andric     }
860b57cec5SDimitry Andric   }
870b57cec5SDimitry Andric 
880b57cec5SDimitry Andric   SourceMgr &SrcMgr = DiagInfo->SrcMgr;
890b57cec5SDimitry Andric 
900b57cec5SDimitry Andric   std::unique_ptr<MemoryBuffer> Buffer;
910b57cec5SDimitry Andric   // The inline asm source manager will outlive AsmStr, so make a copy of the
920b57cec5SDimitry Andric   // string for SourceMgr to own.
930b57cec5SDimitry Andric   Buffer = MemoryBuffer::getMemBufferCopy(AsmStr, "<inline asm>");
940b57cec5SDimitry Andric 
950b57cec5SDimitry Andric   // Tell SrcMgr about this buffer, it takes ownership of the buffer.
960b57cec5SDimitry Andric   unsigned BufNum = SrcMgr.AddNewSourceBuffer(std::move(Buffer), SMLoc());
970b57cec5SDimitry Andric 
980b57cec5SDimitry Andric   // Store LocMDNode in DiagInfo, using BufNum as an identifier.
990b57cec5SDimitry Andric   if (LocMDNode) {
1000b57cec5SDimitry Andric     DiagInfo->LocInfos.resize(BufNum);
1010b57cec5SDimitry Andric     DiagInfo->LocInfos[BufNum - 1] = LocMDNode;
1020b57cec5SDimitry Andric   }
1030b57cec5SDimitry Andric 
1040b57cec5SDimitry Andric   return BufNum;
1050b57cec5SDimitry Andric }
1060b57cec5SDimitry Andric 
1070b57cec5SDimitry Andric 
1080b57cec5SDimitry Andric /// EmitInlineAsm - Emit a blob of inline asm to the output streamer.
1090b57cec5SDimitry Andric void AsmPrinter::EmitInlineAsm(StringRef Str, const MCSubtargetInfo &STI,
1100b57cec5SDimitry Andric                                const MCTargetOptions &MCOptions,
1110b57cec5SDimitry Andric                                const MDNode *LocMDNode,
1120b57cec5SDimitry Andric                                InlineAsm::AsmDialect Dialect) const {
1130b57cec5SDimitry Andric   assert(!Str.empty() && "Can't emit empty inline asm block");
1140b57cec5SDimitry Andric 
1150b57cec5SDimitry Andric   // Remember if the buffer is nul terminated or not so we can avoid a copy.
1160b57cec5SDimitry Andric   bool isNullTerminated = Str.back() == 0;
1170b57cec5SDimitry Andric   if (isNullTerminated)
1180b57cec5SDimitry Andric     Str = Str.substr(0, Str.size()-1);
1190b57cec5SDimitry Andric 
1200b57cec5SDimitry Andric   // If the output streamer does not have mature MC support or the integrated
1210b57cec5SDimitry Andric   // assembler has been disabled, just emit the blob textually.
1220b57cec5SDimitry Andric   // Otherwise parse the asm and emit it via MC support.
1230b57cec5SDimitry Andric   // This is useful in case the asm parser doesn't handle something but the
1240b57cec5SDimitry Andric   // system assembler does.
1250b57cec5SDimitry Andric   const MCAsmInfo *MCAI = TM.getMCAsmInfo();
1260b57cec5SDimitry Andric   assert(MCAI && "No MCAsmInfo");
1270b57cec5SDimitry Andric   if (!MCAI->useIntegratedAssembler() &&
1280b57cec5SDimitry Andric       !OutStreamer->isIntegratedAssemblerRequired()) {
1290b57cec5SDimitry Andric     emitInlineAsmStart();
1300b57cec5SDimitry Andric     OutStreamer->EmitRawText(Str);
1310b57cec5SDimitry Andric     emitInlineAsmEnd(STI, nullptr);
1320b57cec5SDimitry Andric     return;
1330b57cec5SDimitry Andric   }
1340b57cec5SDimitry Andric 
1350b57cec5SDimitry Andric   unsigned BufNum = addInlineAsmDiagBuffer(Str, LocMDNode);
1360b57cec5SDimitry Andric   DiagInfo->SrcMgr.setIncludeDirs(MCOptions.IASSearchPaths);
1370b57cec5SDimitry Andric 
1380b57cec5SDimitry Andric   std::unique_ptr<MCAsmParser> Parser(createMCAsmParser(
1390b57cec5SDimitry Andric           DiagInfo->SrcMgr, OutContext, *OutStreamer, *MAI, BufNum));
1400b57cec5SDimitry Andric 
1410b57cec5SDimitry Andric   // Do not use assembler-level information for parsing inline assembly.
1420b57cec5SDimitry Andric   OutStreamer->setUseAssemblerInfoForParsing(false);
1430b57cec5SDimitry Andric 
1440b57cec5SDimitry Andric   // We create a new MCInstrInfo here since we might be at the module level
1450b57cec5SDimitry Andric   // and not have a MachineFunction to initialize the TargetInstrInfo from and
1460b57cec5SDimitry Andric   // we only need MCInstrInfo for asm parsing. We create one unconditionally
1470b57cec5SDimitry Andric   // because it's not subtarget dependent.
1480b57cec5SDimitry Andric   std::unique_ptr<MCInstrInfo> MII(TM.getTarget().createMCInstrInfo());
1490b57cec5SDimitry Andric   std::unique_ptr<MCTargetAsmParser> TAP(TM.getTarget().createMCAsmParser(
1500b57cec5SDimitry Andric       STI, *Parser, *MII, MCOptions));
1510b57cec5SDimitry Andric   if (!TAP)
1520b57cec5SDimitry Andric     report_fatal_error("Inline asm not supported by this streamer because"
1530b57cec5SDimitry Andric                        " we don't have an asm parser for this target\n");
1540b57cec5SDimitry Andric   Parser->setAssemblerDialect(Dialect);
1550b57cec5SDimitry Andric   Parser->setTargetParser(*TAP.get());
1560b57cec5SDimitry Andric   // Enable lexing Masm binary and hex integer literals in intel inline
1570b57cec5SDimitry Andric   // assembly.
1580b57cec5SDimitry Andric   if (Dialect == InlineAsm::AD_Intel)
1590b57cec5SDimitry Andric     Parser->getLexer().setLexMasmIntegers(true);
1600b57cec5SDimitry Andric 
1610b57cec5SDimitry Andric   emitInlineAsmStart();
1620b57cec5SDimitry Andric   // Don't implicitly switch to the text section before the asm.
1630b57cec5SDimitry Andric   int Res = Parser->Run(/*NoInitialTextSection*/ true,
1640b57cec5SDimitry Andric                         /*NoFinalize*/ true);
1650b57cec5SDimitry Andric   emitInlineAsmEnd(STI, &TAP->getSTI());
1660b57cec5SDimitry Andric 
1670b57cec5SDimitry Andric   if (Res && !DiagInfo->DiagHandler)
1680b57cec5SDimitry Andric     report_fatal_error("Error parsing inline asm\n");
1690b57cec5SDimitry Andric }
1700b57cec5SDimitry Andric 
1710b57cec5SDimitry Andric static void EmitMSInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
1720b57cec5SDimitry Andric                                MachineModuleInfo *MMI, AsmPrinter *AP,
1730b57cec5SDimitry Andric                                unsigned LocCookie, raw_ostream &OS) {
1740b57cec5SDimitry Andric   // Switch to the inline assembly variant.
1750b57cec5SDimitry Andric   OS << "\t.intel_syntax\n\t";
1760b57cec5SDimitry Andric 
1770b57cec5SDimitry Andric   const char *LastEmitted = AsmStr; // One past the last character emitted.
1780b57cec5SDimitry Andric   unsigned NumOperands = MI->getNumOperands();
1790b57cec5SDimitry Andric 
1800b57cec5SDimitry Andric   while (*LastEmitted) {
1810b57cec5SDimitry Andric     switch (*LastEmitted) {
1820b57cec5SDimitry Andric     default: {
1830b57cec5SDimitry Andric       // Not a special case, emit the string section literally.
1840b57cec5SDimitry Andric       const char *LiteralEnd = LastEmitted+1;
1850b57cec5SDimitry Andric       while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
1860b57cec5SDimitry Andric              *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
1870b57cec5SDimitry Andric         ++LiteralEnd;
1880b57cec5SDimitry Andric 
1890b57cec5SDimitry Andric       OS.write(LastEmitted, LiteralEnd-LastEmitted);
1900b57cec5SDimitry Andric       LastEmitted = LiteralEnd;
1910b57cec5SDimitry Andric       break;
1920b57cec5SDimitry Andric     }
1930b57cec5SDimitry Andric     case '\n':
1940b57cec5SDimitry Andric       ++LastEmitted;   // Consume newline character.
1950b57cec5SDimitry Andric       OS << '\n';      // Indent code with newline.
1960b57cec5SDimitry Andric       break;
1970b57cec5SDimitry Andric     case '$': {
1980b57cec5SDimitry Andric       ++LastEmitted;   // Consume '$' character.
1990b57cec5SDimitry Andric       bool Done = true;
2000b57cec5SDimitry Andric 
2010b57cec5SDimitry Andric       // Handle escapes.
2020b57cec5SDimitry Andric       switch (*LastEmitted) {
2030b57cec5SDimitry Andric       default: Done = false; break;
2040b57cec5SDimitry Andric       case '$':
2050b57cec5SDimitry Andric         ++LastEmitted;  // Consume second '$' character.
2060b57cec5SDimitry Andric         break;
2070b57cec5SDimitry Andric       }
2080b57cec5SDimitry Andric       if (Done) break;
2090b57cec5SDimitry Andric 
2100b57cec5SDimitry Andric       // If we have ${:foo}, then this is not a real operand reference, it is a
2110b57cec5SDimitry Andric       // "magic" string reference, just like in .td files.  Arrange to call
2120b57cec5SDimitry Andric       // PrintSpecial.
2130b57cec5SDimitry Andric       if (LastEmitted[0] == '{' && LastEmitted[1] == ':') {
2140b57cec5SDimitry Andric         LastEmitted += 2;
2150b57cec5SDimitry Andric         const char *StrStart = LastEmitted;
2160b57cec5SDimitry Andric         const char *StrEnd = strchr(StrStart, '}');
2170b57cec5SDimitry Andric         if (!StrEnd)
2180b57cec5SDimitry Andric           report_fatal_error("Unterminated ${:foo} operand in inline asm"
2190b57cec5SDimitry Andric                              " string: '" + Twine(AsmStr) + "'");
2200b57cec5SDimitry Andric 
2210b57cec5SDimitry Andric         std::string Val(StrStart, StrEnd);
2220b57cec5SDimitry Andric         AP->PrintSpecial(MI, OS, Val.c_str());
2230b57cec5SDimitry Andric         LastEmitted = StrEnd+1;
2240b57cec5SDimitry Andric         break;
2250b57cec5SDimitry Andric       }
2260b57cec5SDimitry Andric 
2270b57cec5SDimitry Andric       const char *IDStart = LastEmitted;
2280b57cec5SDimitry Andric       const char *IDEnd = IDStart;
2290b57cec5SDimitry Andric       while (*IDEnd >= '0' && *IDEnd <= '9') ++IDEnd;
2300b57cec5SDimitry Andric 
2310b57cec5SDimitry Andric       unsigned Val;
2320b57cec5SDimitry Andric       if (StringRef(IDStart, IDEnd-IDStart).getAsInteger(10, Val))
2330b57cec5SDimitry Andric         report_fatal_error("Bad $ operand number in inline asm string: '" +
2340b57cec5SDimitry Andric                            Twine(AsmStr) + "'");
2350b57cec5SDimitry Andric       LastEmitted = IDEnd;
2360b57cec5SDimitry Andric 
2370b57cec5SDimitry Andric       if (Val >= NumOperands-1)
2380b57cec5SDimitry Andric         report_fatal_error("Invalid $ operand number in inline asm string: '" +
2390b57cec5SDimitry Andric                            Twine(AsmStr) + "'");
2400b57cec5SDimitry Andric 
2410b57cec5SDimitry Andric       // Okay, we finally have a value number.  Ask the target to print this
2420b57cec5SDimitry Andric       // operand!
2430b57cec5SDimitry Andric       unsigned OpNo = InlineAsm::MIOp_FirstOperand;
2440b57cec5SDimitry Andric 
2450b57cec5SDimitry Andric       bool Error = false;
2460b57cec5SDimitry Andric 
2470b57cec5SDimitry Andric       // Scan to find the machine operand number for the operand.
2480b57cec5SDimitry Andric       for (; Val; --Val) {
2490b57cec5SDimitry Andric         if (OpNo >= MI->getNumOperands()) break;
2500b57cec5SDimitry Andric         unsigned OpFlags = MI->getOperand(OpNo).getImm();
2510b57cec5SDimitry Andric         OpNo += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
2520b57cec5SDimitry Andric       }
2530b57cec5SDimitry Andric 
2540b57cec5SDimitry Andric       // We may have a location metadata attached to the end of the
2550b57cec5SDimitry Andric       // instruction, and at no point should see metadata at any
2560b57cec5SDimitry Andric       // other point while processing. It's an error if so.
2570b57cec5SDimitry Andric       if (OpNo >= MI->getNumOperands() ||
2580b57cec5SDimitry Andric           MI->getOperand(OpNo).isMetadata()) {
2590b57cec5SDimitry Andric         Error = true;
2600b57cec5SDimitry Andric       } else {
2610b57cec5SDimitry Andric         unsigned OpFlags = MI->getOperand(OpNo).getImm();
2620b57cec5SDimitry Andric         ++OpNo;  // Skip over the ID number.
2630b57cec5SDimitry Andric 
2640b57cec5SDimitry Andric         if (InlineAsm::isMemKind(OpFlags)) {
2650b57cec5SDimitry Andric           Error = AP->PrintAsmMemoryOperand(MI, OpNo, /*Modifier*/ nullptr, OS);
2660b57cec5SDimitry Andric         } else {
2670b57cec5SDimitry Andric           Error = AP->PrintAsmOperand(MI, OpNo, /*Modifier*/ nullptr, OS);
2680b57cec5SDimitry Andric         }
2690b57cec5SDimitry Andric       }
2700b57cec5SDimitry Andric       if (Error) {
2710b57cec5SDimitry Andric         std::string msg;
2720b57cec5SDimitry Andric         raw_string_ostream Msg(msg);
2730b57cec5SDimitry Andric         Msg << "invalid operand in inline asm: '" << AsmStr << "'";
2740b57cec5SDimitry Andric         MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
2750b57cec5SDimitry Andric       }
2760b57cec5SDimitry Andric       break;
2770b57cec5SDimitry Andric     }
2780b57cec5SDimitry Andric     }
2790b57cec5SDimitry Andric   }
2800b57cec5SDimitry Andric   OS << "\n\t.att_syntax\n" << (char)0;  // null terminate string.
2810b57cec5SDimitry Andric }
2820b57cec5SDimitry Andric 
2830b57cec5SDimitry Andric static void EmitGCCInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
2840b57cec5SDimitry Andric                                 MachineModuleInfo *MMI, int AsmPrinterVariant,
2850b57cec5SDimitry Andric                                 AsmPrinter *AP, unsigned LocCookie,
2860b57cec5SDimitry Andric                                 raw_ostream &OS) {
2870b57cec5SDimitry Andric   int CurVariant = -1;            // The number of the {.|.|.} region we are in.
2880b57cec5SDimitry Andric   const char *LastEmitted = AsmStr; // One past the last character emitted.
2890b57cec5SDimitry Andric   unsigned NumOperands = MI->getNumOperands();
2900b57cec5SDimitry Andric 
2910b57cec5SDimitry Andric   OS << '\t';
2920b57cec5SDimitry Andric 
2930b57cec5SDimitry Andric   while (*LastEmitted) {
2940b57cec5SDimitry Andric     switch (*LastEmitted) {
2950b57cec5SDimitry Andric     default: {
2960b57cec5SDimitry Andric       // Not a special case, emit the string section literally.
2970b57cec5SDimitry Andric       const char *LiteralEnd = LastEmitted+1;
2980b57cec5SDimitry Andric       while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
2990b57cec5SDimitry Andric              *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
3000b57cec5SDimitry Andric         ++LiteralEnd;
3010b57cec5SDimitry Andric       if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
3020b57cec5SDimitry Andric         OS.write(LastEmitted, LiteralEnd-LastEmitted);
3030b57cec5SDimitry Andric       LastEmitted = LiteralEnd;
3040b57cec5SDimitry Andric       break;
3050b57cec5SDimitry Andric     }
3060b57cec5SDimitry Andric     case '\n':
3070b57cec5SDimitry Andric       ++LastEmitted;   // Consume newline character.
3080b57cec5SDimitry Andric       OS << '\n';      // Indent code with newline.
3090b57cec5SDimitry Andric       break;
3100b57cec5SDimitry Andric     case '$': {
3110b57cec5SDimitry Andric       ++LastEmitted;   // Consume '$' character.
3120b57cec5SDimitry Andric       bool Done = true;
3130b57cec5SDimitry Andric 
3140b57cec5SDimitry Andric       // Handle escapes.
3150b57cec5SDimitry Andric       switch (*LastEmitted) {
3160b57cec5SDimitry Andric       default: Done = false; break;
3170b57cec5SDimitry Andric       case '$':     // $$ -> $
3180b57cec5SDimitry Andric         if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
3190b57cec5SDimitry Andric           OS << '$';
3200b57cec5SDimitry Andric         ++LastEmitted;  // Consume second '$' character.
3210b57cec5SDimitry Andric         break;
3220b57cec5SDimitry Andric       case '(':             // $( -> same as GCC's { character.
3230b57cec5SDimitry Andric         ++LastEmitted;      // Consume '(' character.
3240b57cec5SDimitry Andric         if (CurVariant != -1)
3250b57cec5SDimitry Andric           report_fatal_error("Nested variants found in inline asm string: '" +
3260b57cec5SDimitry Andric                              Twine(AsmStr) + "'");
3270b57cec5SDimitry Andric         CurVariant = 0;     // We're in the first variant now.
3280b57cec5SDimitry Andric         break;
3290b57cec5SDimitry Andric       case '|':
3300b57cec5SDimitry Andric         ++LastEmitted;  // consume '|' character.
3310b57cec5SDimitry Andric         if (CurVariant == -1)
3320b57cec5SDimitry Andric           OS << '|';       // this is gcc's behavior for | outside a variant
3330b57cec5SDimitry Andric         else
3340b57cec5SDimitry Andric           ++CurVariant;   // We're in the next variant.
3350b57cec5SDimitry Andric         break;
3360b57cec5SDimitry Andric       case ')':         // $) -> same as GCC's } char.
3370b57cec5SDimitry Andric         ++LastEmitted;  // consume ')' character.
3380b57cec5SDimitry Andric         if (CurVariant == -1)
3390b57cec5SDimitry Andric           OS << '}';     // this is gcc's behavior for } outside a variant
3400b57cec5SDimitry Andric         else
3410b57cec5SDimitry Andric           CurVariant = -1;
3420b57cec5SDimitry Andric         break;
3430b57cec5SDimitry Andric       }
3440b57cec5SDimitry Andric       if (Done) break;
3450b57cec5SDimitry Andric 
3460b57cec5SDimitry Andric       bool HasCurlyBraces = false;
3470b57cec5SDimitry Andric       if (*LastEmitted == '{') {     // ${variable}
3480b57cec5SDimitry Andric         ++LastEmitted;               // Consume '{' character.
3490b57cec5SDimitry Andric         HasCurlyBraces = true;
3500b57cec5SDimitry Andric       }
3510b57cec5SDimitry Andric 
3520b57cec5SDimitry Andric       // If we have ${:foo}, then this is not a real operand reference, it is a
3530b57cec5SDimitry Andric       // "magic" string reference, just like in .td files.  Arrange to call
3540b57cec5SDimitry Andric       // PrintSpecial.
3550b57cec5SDimitry Andric       if (HasCurlyBraces && *LastEmitted == ':') {
3560b57cec5SDimitry Andric         ++LastEmitted;
3570b57cec5SDimitry Andric         const char *StrStart = LastEmitted;
3580b57cec5SDimitry Andric         const char *StrEnd = strchr(StrStart, '}');
3590b57cec5SDimitry Andric         if (!StrEnd)
3600b57cec5SDimitry Andric           report_fatal_error("Unterminated ${:foo} operand in inline asm"
3610b57cec5SDimitry Andric                              " string: '" + Twine(AsmStr) + "'");
3620b57cec5SDimitry Andric 
3630b57cec5SDimitry Andric         std::string Val(StrStart, StrEnd);
3640b57cec5SDimitry Andric         AP->PrintSpecial(MI, OS, Val.c_str());
3650b57cec5SDimitry Andric         LastEmitted = StrEnd+1;
3660b57cec5SDimitry Andric         break;
3670b57cec5SDimitry Andric       }
3680b57cec5SDimitry Andric 
3690b57cec5SDimitry Andric       const char *IDStart = LastEmitted;
3700b57cec5SDimitry Andric       const char *IDEnd = IDStart;
3710b57cec5SDimitry Andric       while (*IDEnd >= '0' && *IDEnd <= '9') ++IDEnd;
3720b57cec5SDimitry Andric 
3730b57cec5SDimitry Andric       unsigned Val;
3740b57cec5SDimitry Andric       if (StringRef(IDStart, IDEnd-IDStart).getAsInteger(10, Val))
3750b57cec5SDimitry Andric         report_fatal_error("Bad $ operand number in inline asm string: '" +
3760b57cec5SDimitry Andric                            Twine(AsmStr) + "'");
3770b57cec5SDimitry Andric       LastEmitted = IDEnd;
3780b57cec5SDimitry Andric 
3790b57cec5SDimitry Andric       char Modifier[2] = { 0, 0 };
3800b57cec5SDimitry Andric 
3810b57cec5SDimitry Andric       if (HasCurlyBraces) {
3820b57cec5SDimitry Andric         // If we have curly braces, check for a modifier character.  This
3830b57cec5SDimitry Andric         // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
3840b57cec5SDimitry Andric         if (*LastEmitted == ':') {
3850b57cec5SDimitry Andric           ++LastEmitted;    // Consume ':' character.
3860b57cec5SDimitry Andric           if (*LastEmitted == 0)
3870b57cec5SDimitry Andric             report_fatal_error("Bad ${:} expression in inline asm string: '" +
3880b57cec5SDimitry Andric                                Twine(AsmStr) + "'");
3890b57cec5SDimitry Andric 
3900b57cec5SDimitry Andric           Modifier[0] = *LastEmitted;
3910b57cec5SDimitry Andric           ++LastEmitted;    // Consume modifier character.
3920b57cec5SDimitry Andric         }
3930b57cec5SDimitry Andric 
3940b57cec5SDimitry Andric         if (*LastEmitted != '}')
3950b57cec5SDimitry Andric           report_fatal_error("Bad ${} expression in inline asm string: '" +
3960b57cec5SDimitry Andric                              Twine(AsmStr) + "'");
3970b57cec5SDimitry Andric         ++LastEmitted;    // Consume '}' character.
3980b57cec5SDimitry Andric       }
3990b57cec5SDimitry Andric 
4000b57cec5SDimitry Andric       if (Val >= NumOperands-1)
4010b57cec5SDimitry Andric         report_fatal_error("Invalid $ operand number in inline asm string: '" +
4020b57cec5SDimitry Andric                            Twine(AsmStr) + "'");
4030b57cec5SDimitry Andric 
4040b57cec5SDimitry Andric       // Okay, we finally have a value number.  Ask the target to print this
4050b57cec5SDimitry Andric       // operand!
4060b57cec5SDimitry Andric       if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
4070b57cec5SDimitry Andric         unsigned OpNo = InlineAsm::MIOp_FirstOperand;
4080b57cec5SDimitry Andric 
4090b57cec5SDimitry Andric         bool Error = false;
4100b57cec5SDimitry Andric 
4110b57cec5SDimitry Andric         // Scan to find the machine operand number for the operand.
4120b57cec5SDimitry Andric         for (; Val; --Val) {
4130b57cec5SDimitry Andric           if (OpNo >= MI->getNumOperands()) break;
4140b57cec5SDimitry Andric           unsigned OpFlags = MI->getOperand(OpNo).getImm();
4150b57cec5SDimitry Andric           OpNo += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
4160b57cec5SDimitry Andric         }
4170b57cec5SDimitry Andric 
4180b57cec5SDimitry Andric         // We may have a location metadata attached to the end of the
4190b57cec5SDimitry Andric         // instruction, and at no point should see metadata at any
4200b57cec5SDimitry Andric         // other point while processing. It's an error if so.
4210b57cec5SDimitry Andric         if (OpNo >= MI->getNumOperands() ||
4220b57cec5SDimitry Andric             MI->getOperand(OpNo).isMetadata()) {
4230b57cec5SDimitry Andric           Error = true;
4240b57cec5SDimitry Andric         } else {
4250b57cec5SDimitry Andric           unsigned OpFlags = MI->getOperand(OpNo).getImm();
4260b57cec5SDimitry Andric           ++OpNo;  // Skip over the ID number.
4270b57cec5SDimitry Andric 
4280b57cec5SDimitry Andric           // FIXME: Shouldn't arch-independent output template handling go into
4290b57cec5SDimitry Andric           // PrintAsmOperand?
4300b57cec5SDimitry Andric           if (Modifier[0] == 'l') { // Labels are target independent.
4310b57cec5SDimitry Andric             if (MI->getOperand(OpNo).isBlockAddress()) {
4320b57cec5SDimitry Andric               const BlockAddress *BA = MI->getOperand(OpNo).getBlockAddress();
4330b57cec5SDimitry Andric               MCSymbol *Sym = AP->GetBlockAddressSymbol(BA);
4340b57cec5SDimitry Andric               Sym->print(OS, AP->MAI);
4350b57cec5SDimitry Andric               MMI->getContext().registerInlineAsmLabel(Sym);
4360b57cec5SDimitry Andric             } else if (MI->getOperand(OpNo).isMBB()) {
4370b57cec5SDimitry Andric               const MCSymbol *Sym = MI->getOperand(OpNo).getMBB()->getSymbol();
4380b57cec5SDimitry Andric               Sym->print(OS, AP->MAI);
4390b57cec5SDimitry Andric             } else {
4400b57cec5SDimitry Andric               Error = true;
4410b57cec5SDimitry Andric             }
4420b57cec5SDimitry Andric           } else {
4430b57cec5SDimitry Andric             if (InlineAsm::isMemKind(OpFlags)) {
4440b57cec5SDimitry Andric               Error = AP->PrintAsmMemoryOperand(
4450b57cec5SDimitry Andric                   MI, OpNo, Modifier[0] ? Modifier : nullptr, OS);
4460b57cec5SDimitry Andric             } else {
4470b57cec5SDimitry Andric               Error = AP->PrintAsmOperand(MI, OpNo,
4480b57cec5SDimitry Andric                                           Modifier[0] ? Modifier : nullptr, OS);
4490b57cec5SDimitry Andric             }
4500b57cec5SDimitry Andric           }
4510b57cec5SDimitry Andric         }
4520b57cec5SDimitry Andric         if (Error) {
4530b57cec5SDimitry Andric           std::string msg;
4540b57cec5SDimitry Andric           raw_string_ostream Msg(msg);
4550b57cec5SDimitry Andric           Msg << "invalid operand in inline asm: '" << AsmStr << "'";
4560b57cec5SDimitry Andric           MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
4570b57cec5SDimitry Andric         }
4580b57cec5SDimitry Andric       }
4590b57cec5SDimitry Andric       break;
4600b57cec5SDimitry Andric     }
4610b57cec5SDimitry Andric     }
4620b57cec5SDimitry Andric   }
4630b57cec5SDimitry Andric   OS << '\n' << (char)0;  // null terminate string.
4640b57cec5SDimitry Andric }
4650b57cec5SDimitry Andric 
4660b57cec5SDimitry Andric /// EmitInlineAsm - This method formats and emits the specified machine
4670b57cec5SDimitry Andric /// instruction that is an inline asm.
4680b57cec5SDimitry Andric void AsmPrinter::EmitInlineAsm(const MachineInstr *MI) const {
4690b57cec5SDimitry Andric   assert(MI->isInlineAsm() && "printInlineAsm only works on inline asms");
4700b57cec5SDimitry Andric 
4710b57cec5SDimitry Andric   // Count the number of register definitions to find the asm string.
4720b57cec5SDimitry Andric   unsigned NumDefs = 0;
4730b57cec5SDimitry Andric   for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef();
4740b57cec5SDimitry Andric        ++NumDefs)
4750b57cec5SDimitry Andric     assert(NumDefs != MI->getNumOperands()-2 && "No asm string?");
4760b57cec5SDimitry Andric 
4770b57cec5SDimitry Andric   assert(MI->getOperand(NumDefs).isSymbol() && "No asm string?");
4780b57cec5SDimitry Andric 
4790b57cec5SDimitry Andric   // Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
4800b57cec5SDimitry Andric   const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
4810b57cec5SDimitry Andric 
4820b57cec5SDimitry Andric   // If this asmstr is empty, just print the #APP/#NOAPP markers.
4830b57cec5SDimitry Andric   // These are useful to see where empty asm's wound up.
4840b57cec5SDimitry Andric   if (AsmStr[0] == 0) {
4850b57cec5SDimitry Andric     OutStreamer->emitRawComment(MAI->getInlineAsmStart());
4860b57cec5SDimitry Andric     OutStreamer->emitRawComment(MAI->getInlineAsmEnd());
4870b57cec5SDimitry Andric     return;
4880b57cec5SDimitry Andric   }
4890b57cec5SDimitry Andric 
4900b57cec5SDimitry Andric   // Emit the #APP start marker.  This has to happen even if verbose-asm isn't
4910b57cec5SDimitry Andric   // enabled, so we use emitRawComment.
4920b57cec5SDimitry Andric   OutStreamer->emitRawComment(MAI->getInlineAsmStart());
4930b57cec5SDimitry Andric 
4940b57cec5SDimitry Andric   // Get the !srcloc metadata node if we have it, and decode the loc cookie from
4950b57cec5SDimitry Andric   // it.
4960b57cec5SDimitry Andric   unsigned LocCookie = 0;
4970b57cec5SDimitry Andric   const MDNode *LocMD = nullptr;
4980b57cec5SDimitry Andric   for (unsigned i = MI->getNumOperands(); i != 0; --i) {
4990b57cec5SDimitry Andric     if (MI->getOperand(i-1).isMetadata() &&
5000b57cec5SDimitry Andric         (LocMD = MI->getOperand(i-1).getMetadata()) &&
5010b57cec5SDimitry Andric         LocMD->getNumOperands() != 0) {
5020b57cec5SDimitry Andric       if (const ConstantInt *CI =
5030b57cec5SDimitry Andric               mdconst::dyn_extract<ConstantInt>(LocMD->getOperand(0))) {
5040b57cec5SDimitry Andric         LocCookie = CI->getZExtValue();
5050b57cec5SDimitry Andric         break;
5060b57cec5SDimitry Andric       }
5070b57cec5SDimitry Andric     }
5080b57cec5SDimitry Andric   }
5090b57cec5SDimitry Andric 
5100b57cec5SDimitry Andric   // Emit the inline asm to a temporary string so we can emit it through
5110b57cec5SDimitry Andric   // EmitInlineAsm.
5120b57cec5SDimitry Andric   SmallString<256> StringData;
5130b57cec5SDimitry Andric   raw_svector_ostream OS(StringData);
5140b57cec5SDimitry Andric 
5150b57cec5SDimitry Andric   // The variant of the current asmprinter.
5160b57cec5SDimitry Andric   int AsmPrinterVariant = MAI->getAssemblerDialect();
5170b57cec5SDimitry Andric   AsmPrinter *AP = const_cast<AsmPrinter*>(this);
5180b57cec5SDimitry Andric   if (MI->getInlineAsmDialect() == InlineAsm::AD_ATT)
5190b57cec5SDimitry Andric     EmitGCCInlineAsmStr(AsmStr, MI, MMI, AsmPrinterVariant, AP, LocCookie, OS);
5200b57cec5SDimitry Andric   else
5210b57cec5SDimitry Andric     EmitMSInlineAsmStr(AsmStr, MI, MMI, AP, LocCookie, OS);
5220b57cec5SDimitry Andric 
5230b57cec5SDimitry Andric   // Emit warnings if we use reserved registers on the clobber list, as
5240b57cec5SDimitry Andric   // that might give surprising results.
5250b57cec5SDimitry Andric   std::vector<std::string> RestrRegs;
5260b57cec5SDimitry Andric   // Start with the first operand descriptor, and iterate over them.
5270b57cec5SDimitry Andric   for (unsigned I = InlineAsm::MIOp_FirstOperand, NumOps = MI->getNumOperands();
5280b57cec5SDimitry Andric        I < NumOps; ++I) {
5290b57cec5SDimitry Andric     const MachineOperand &MO = MI->getOperand(I);
5300b57cec5SDimitry Andric     if (MO.isImm()) {
5310b57cec5SDimitry Andric       unsigned Flags = MO.getImm();
5320b57cec5SDimitry Andric       const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
5330b57cec5SDimitry Andric       if (InlineAsm::getKind(Flags) == InlineAsm::Kind_Clobber &&
5340b57cec5SDimitry Andric           !TRI->isAsmClobberable(*MF, MI->getOperand(I + 1).getReg())) {
5350b57cec5SDimitry Andric         RestrRegs.push_back(TRI->getName(MI->getOperand(I + 1).getReg()));
5360b57cec5SDimitry Andric       }
5370b57cec5SDimitry Andric       // Skip to one before the next operand descriptor, if it exists.
5380b57cec5SDimitry Andric       I += InlineAsm::getNumOperandRegisters(Flags);
5390b57cec5SDimitry Andric     }
5400b57cec5SDimitry Andric   }
5410b57cec5SDimitry Andric 
5420b57cec5SDimitry Andric   if (!RestrRegs.empty()) {
5430b57cec5SDimitry Andric     unsigned BufNum = addInlineAsmDiagBuffer(OS.str(), LocMD);
5440b57cec5SDimitry Andric     auto &SrcMgr = DiagInfo->SrcMgr;
5450b57cec5SDimitry Andric     SMLoc Loc = SMLoc::getFromPointer(
5460b57cec5SDimitry Andric         SrcMgr.getMemoryBuffer(BufNum)->getBuffer().begin());
5470b57cec5SDimitry Andric 
5480b57cec5SDimitry Andric     std::string Msg = "inline asm clobber list contains reserved registers: ";
5490b57cec5SDimitry Andric     for (auto I = RestrRegs.begin(), E = RestrRegs.end(); I != E; I++) {
5500b57cec5SDimitry Andric       if(I != RestrRegs.begin())
5510b57cec5SDimitry Andric         Msg += ", ";
5520b57cec5SDimitry Andric       Msg += *I;
5530b57cec5SDimitry Andric     }
5540b57cec5SDimitry Andric     std::string Note = "Reserved registers on the clobber list may not be "
5550b57cec5SDimitry Andric                 "preserved across the asm statement, and clobbering them may "
5560b57cec5SDimitry Andric                 "lead to undefined behaviour.";
5570b57cec5SDimitry Andric     SrcMgr.PrintMessage(Loc, SourceMgr::DK_Warning, Msg);
5580b57cec5SDimitry Andric     SrcMgr.PrintMessage(Loc, SourceMgr::DK_Note, Note);
5590b57cec5SDimitry Andric   }
5600b57cec5SDimitry Andric 
5610b57cec5SDimitry Andric   EmitInlineAsm(OS.str(), getSubtargetInfo(), TM.Options.MCOptions, LocMD,
5620b57cec5SDimitry Andric                 MI->getInlineAsmDialect());
5630b57cec5SDimitry Andric 
5640b57cec5SDimitry Andric   // Emit the #NOAPP end marker.  This has to happen even if verbose-asm isn't
5650b57cec5SDimitry Andric   // enabled, so we use emitRawComment.
5660b57cec5SDimitry Andric   OutStreamer->emitRawComment(MAI->getInlineAsmEnd());
5670b57cec5SDimitry Andric }
5680b57cec5SDimitry Andric 
5690b57cec5SDimitry Andric 
5700b57cec5SDimitry Andric /// PrintSpecial - Print information related to the specified machine instr
5710b57cec5SDimitry Andric /// that is independent of the operand, and may be independent of the instr
5720b57cec5SDimitry Andric /// itself.  This can be useful for portably encoding the comment character
5730b57cec5SDimitry Andric /// or other bits of target-specific knowledge into the asmstrings.  The
5740b57cec5SDimitry Andric /// syntax used is ${:comment}.  Targets can override this to add support
5750b57cec5SDimitry Andric /// for their own strange codes.
5760b57cec5SDimitry Andric void AsmPrinter::PrintSpecial(const MachineInstr *MI, raw_ostream &OS,
5770b57cec5SDimitry Andric                               const char *Code) const {
5780b57cec5SDimitry Andric   if (!strcmp(Code, "private")) {
5790b57cec5SDimitry Andric     const DataLayout &DL = MF->getDataLayout();
5800b57cec5SDimitry Andric     OS << DL.getPrivateGlobalPrefix();
5810b57cec5SDimitry Andric   } else if (!strcmp(Code, "comment")) {
5820b57cec5SDimitry Andric     OS << MAI->getCommentString();
5830b57cec5SDimitry Andric   } else if (!strcmp(Code, "uid")) {
5840b57cec5SDimitry Andric     // Comparing the address of MI isn't sufficient, because machineinstrs may
5850b57cec5SDimitry Andric     // be allocated to the same address across functions.
5860b57cec5SDimitry Andric 
5870b57cec5SDimitry Andric     // If this is a new LastFn instruction, bump the counter.
5880b57cec5SDimitry Andric     if (LastMI != MI || LastFn != getFunctionNumber()) {
5890b57cec5SDimitry Andric       ++Counter;
5900b57cec5SDimitry Andric       LastMI = MI;
5910b57cec5SDimitry Andric       LastFn = getFunctionNumber();
5920b57cec5SDimitry Andric     }
5930b57cec5SDimitry Andric     OS << Counter;
5940b57cec5SDimitry Andric   } else {
5950b57cec5SDimitry Andric     std::string msg;
5960b57cec5SDimitry Andric     raw_string_ostream Msg(msg);
5970b57cec5SDimitry Andric     Msg << "Unknown special formatter '" << Code
5980b57cec5SDimitry Andric          << "' for machine instr: " << *MI;
5990b57cec5SDimitry Andric     report_fatal_error(Msg.str());
6000b57cec5SDimitry Andric   }
6010b57cec5SDimitry Andric }
6020b57cec5SDimitry Andric 
6030b57cec5SDimitry Andric void AsmPrinter::PrintSymbolOperand(const MachineOperand &MO, raw_ostream &OS) {
6040b57cec5SDimitry Andric   assert(MO.isGlobal() && "caller should check MO.isGlobal");
6050b57cec5SDimitry Andric   getSymbol(MO.getGlobal())->print(OS, MAI);
6060b57cec5SDimitry Andric   printOffset(MO.getOffset(), OS);
6070b57cec5SDimitry Andric }
6080b57cec5SDimitry Andric 
6090b57cec5SDimitry Andric /// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
6100b57cec5SDimitry Andric /// instruction, using the specified assembler variant.  Targets should
6110b57cec5SDimitry Andric /// override this to format as appropriate for machine specific ExtraCodes
6120b57cec5SDimitry Andric /// or when the arch-independent handling would be too complex otherwise.
6130b57cec5SDimitry Andric bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
6140b57cec5SDimitry Andric                                  const char *ExtraCode, raw_ostream &O) {
6150b57cec5SDimitry Andric   // Does this asm operand have a single letter operand modifier?
6160b57cec5SDimitry Andric   if (ExtraCode && ExtraCode[0]) {
6170b57cec5SDimitry Andric     if (ExtraCode[1] != 0) return true; // Unknown modifier.
6180b57cec5SDimitry Andric 
6190b57cec5SDimitry Andric     // https://gcc.gnu.org/onlinedocs/gccint/Output-Template.html
6200b57cec5SDimitry Andric     const MachineOperand &MO = MI->getOperand(OpNo);
6210b57cec5SDimitry Andric     switch (ExtraCode[0]) {
6220b57cec5SDimitry Andric     default:
6230b57cec5SDimitry Andric       return true;  // Unknown modifier.
6240b57cec5SDimitry Andric     case 'a': // Print as memory address.
6250b57cec5SDimitry Andric       if (MO.isReg()) {
6260b57cec5SDimitry Andric         PrintAsmMemoryOperand(MI, OpNo, nullptr, O);
6270b57cec5SDimitry Andric         return false;
6280b57cec5SDimitry Andric       }
6290b57cec5SDimitry Andric       LLVM_FALLTHROUGH; // GCC allows '%a' to behave like '%c' with immediates.
6300b57cec5SDimitry Andric     case 'c': // Substitute immediate value without immediate syntax
6310b57cec5SDimitry Andric       if (MO.isImm()) {
6320b57cec5SDimitry Andric         O << MO.getImm();
6330b57cec5SDimitry Andric         return false;
6340b57cec5SDimitry Andric       }
6350b57cec5SDimitry Andric       if (MO.isGlobal()) {
6360b57cec5SDimitry Andric         PrintSymbolOperand(MO, O);
6370b57cec5SDimitry Andric         return false;
6380b57cec5SDimitry Andric       }
6390b57cec5SDimitry Andric       return true;
6400b57cec5SDimitry Andric     case 'n':  // Negate the immediate constant.
6410b57cec5SDimitry Andric       if (!MO.isImm())
6420b57cec5SDimitry Andric         return true;
6430b57cec5SDimitry Andric       O << -MO.getImm();
6440b57cec5SDimitry Andric       return false;
6450b57cec5SDimitry Andric     case 's':  // The GCC deprecated s modifier
6460b57cec5SDimitry Andric       if (!MO.isImm())
6470b57cec5SDimitry Andric         return true;
6480b57cec5SDimitry Andric       O << ((32 - MO.getImm()) & 31);
6490b57cec5SDimitry Andric       return false;
6500b57cec5SDimitry Andric     }
6510b57cec5SDimitry Andric   }
6520b57cec5SDimitry Andric   return true;
6530b57cec5SDimitry Andric }
6540b57cec5SDimitry Andric 
6550b57cec5SDimitry Andric bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
6560b57cec5SDimitry Andric                                        const char *ExtraCode, raw_ostream &O) {
6570b57cec5SDimitry Andric   // Target doesn't support this yet!
6580b57cec5SDimitry Andric   return true;
6590b57cec5SDimitry Andric }
6600b57cec5SDimitry Andric 
6610b57cec5SDimitry Andric void AsmPrinter::emitInlineAsmStart() const {}
6620b57cec5SDimitry Andric 
6630b57cec5SDimitry Andric void AsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
6640b57cec5SDimitry Andric                                   const MCSubtargetInfo *EndInfo) const {}
665