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" 14e8d8bef9SDimitry Andric #include "llvm/ADT/SmallVector.h" 150b57cec5SDimitry Andric #include "llvm/ADT/Twine.h" 160b57cec5SDimitry Andric #include "llvm/CodeGen/AsmPrinter.h" 170b57cec5SDimitry Andric #include "llvm/CodeGen/MachineBasicBlock.h" 180b57cec5SDimitry Andric #include "llvm/CodeGen/MachineFunction.h" 190b57cec5SDimitry Andric #include "llvm/CodeGen/MachineModuleInfo.h" 200b57cec5SDimitry Andric #include "llvm/CodeGen/TargetInstrInfo.h" 210b57cec5SDimitry Andric #include "llvm/CodeGen/TargetRegisterInfo.h" 220b57cec5SDimitry Andric #include "llvm/IR/Constants.h" 230b57cec5SDimitry Andric #include "llvm/IR/DataLayout.h" 24fe6060f1SDimitry Andric #include "llvm/IR/DiagnosticInfo.h" 250b57cec5SDimitry Andric #include "llvm/IR/InlineAsm.h" 260b57cec5SDimitry Andric #include "llvm/IR/LLVMContext.h" 270b57cec5SDimitry Andric #include "llvm/IR/Module.h" 280b57cec5SDimitry Andric #include "llvm/MC/MCAsmInfo.h" 290b57cec5SDimitry Andric #include "llvm/MC/MCParser/MCTargetAsmParser.h" 300b57cec5SDimitry Andric #include "llvm/MC/MCStreamer.h" 310b57cec5SDimitry Andric #include "llvm/MC/MCSubtargetInfo.h" 320b57cec5SDimitry Andric #include "llvm/MC/MCSymbol.h" 33*349cc55cSDimitry Andric #include "llvm/MC/TargetRegistry.h" 340b57cec5SDimitry Andric #include "llvm/Support/ErrorHandling.h" 350b57cec5SDimitry Andric #include "llvm/Support/MemoryBuffer.h" 360b57cec5SDimitry Andric #include "llvm/Support/SourceMgr.h" 370b57cec5SDimitry Andric #include "llvm/Support/raw_ostream.h" 380b57cec5SDimitry Andric #include "llvm/Target/TargetMachine.h" 390b57cec5SDimitry Andric using namespace llvm; 400b57cec5SDimitry Andric 410b57cec5SDimitry Andric #define DEBUG_TYPE "asm-printer" 420b57cec5SDimitry Andric 430b57cec5SDimitry Andric unsigned AsmPrinter::addInlineAsmDiagBuffer(StringRef AsmStr, 440b57cec5SDimitry Andric const MDNode *LocMDNode) const { 450b57cec5SDimitry Andric MCContext &Context = MMI->getContext(); 46fe6060f1SDimitry Andric Context.initInlineSourceManager(); 47fe6060f1SDimitry Andric SourceMgr &SrcMgr = *Context.getInlineSourceManager(); 48fe6060f1SDimitry Andric std::vector<const MDNode *> &LocInfos = Context.getLocInfos(); 490b57cec5SDimitry Andric 500b57cec5SDimitry Andric std::unique_ptr<MemoryBuffer> Buffer; 510b57cec5SDimitry Andric // The inline asm source manager will outlive AsmStr, so make a copy of the 520b57cec5SDimitry Andric // string for SourceMgr to own. 530b57cec5SDimitry Andric Buffer = MemoryBuffer::getMemBufferCopy(AsmStr, "<inline asm>"); 540b57cec5SDimitry Andric 550b57cec5SDimitry Andric // Tell SrcMgr about this buffer, it takes ownership of the buffer. 560b57cec5SDimitry Andric unsigned BufNum = SrcMgr.AddNewSourceBuffer(std::move(Buffer), SMLoc()); 570b57cec5SDimitry Andric 580b57cec5SDimitry Andric // Store LocMDNode in DiagInfo, using BufNum as an identifier. 590b57cec5SDimitry Andric if (LocMDNode) { 60fe6060f1SDimitry Andric LocInfos.resize(BufNum); 61fe6060f1SDimitry Andric LocInfos[BufNum - 1] = LocMDNode; 620b57cec5SDimitry Andric } 630b57cec5SDimitry Andric 640b57cec5SDimitry Andric return BufNum; 650b57cec5SDimitry Andric } 660b57cec5SDimitry Andric 670b57cec5SDimitry Andric 680b57cec5SDimitry Andric /// EmitInlineAsm - Emit a blob of inline asm to the output streamer. 695ffd83dbSDimitry Andric void AsmPrinter::emitInlineAsm(StringRef Str, const MCSubtargetInfo &STI, 700b57cec5SDimitry Andric const MCTargetOptions &MCOptions, 710b57cec5SDimitry Andric const MDNode *LocMDNode, 720b57cec5SDimitry Andric InlineAsm::AsmDialect Dialect) const { 730b57cec5SDimitry Andric assert(!Str.empty() && "Can't emit empty inline asm block"); 740b57cec5SDimitry Andric 750b57cec5SDimitry Andric // Remember if the buffer is nul terminated or not so we can avoid a copy. 760b57cec5SDimitry Andric bool isNullTerminated = Str.back() == 0; 770b57cec5SDimitry Andric if (isNullTerminated) 780b57cec5SDimitry Andric Str = Str.substr(0, Str.size()-1); 790b57cec5SDimitry Andric 800b57cec5SDimitry Andric // If the output streamer does not have mature MC support or the integrated 81fe6060f1SDimitry Andric // assembler has been disabled or not required, just emit the blob textually. 820b57cec5SDimitry Andric // Otherwise parse the asm and emit it via MC support. 830b57cec5SDimitry Andric // This is useful in case the asm parser doesn't handle something but the 840b57cec5SDimitry Andric // system assembler does. 850b57cec5SDimitry Andric const MCAsmInfo *MCAI = TM.getMCAsmInfo(); 860b57cec5SDimitry Andric assert(MCAI && "No MCAsmInfo"); 870b57cec5SDimitry Andric if (!MCAI->useIntegratedAssembler() && 88fe6060f1SDimitry Andric !MCAI->parseInlineAsmUsingAsmParser() && 890b57cec5SDimitry Andric !OutStreamer->isIntegratedAssemblerRequired()) { 900b57cec5SDimitry Andric emitInlineAsmStart(); 915ffd83dbSDimitry Andric OutStreamer->emitRawText(Str); 920b57cec5SDimitry Andric emitInlineAsmEnd(STI, nullptr); 930b57cec5SDimitry Andric return; 940b57cec5SDimitry Andric } 950b57cec5SDimitry Andric 960b57cec5SDimitry Andric unsigned BufNum = addInlineAsmDiagBuffer(Str, LocMDNode); 97fe6060f1SDimitry Andric SourceMgr &SrcMgr = *MMI->getContext().getInlineSourceManager(); 98fe6060f1SDimitry Andric SrcMgr.setIncludeDirs(MCOptions.IASSearchPaths); 990b57cec5SDimitry Andric 100fe6060f1SDimitry Andric std::unique_ptr<MCAsmParser> Parser( 101fe6060f1SDimitry Andric createMCAsmParser(SrcMgr, OutContext, *OutStreamer, *MAI, BufNum)); 1020b57cec5SDimitry Andric 1030b57cec5SDimitry Andric // Do not use assembler-level information for parsing inline assembly. 1040b57cec5SDimitry Andric OutStreamer->setUseAssemblerInfoForParsing(false); 1050b57cec5SDimitry Andric 1060b57cec5SDimitry Andric // We create a new MCInstrInfo here since we might be at the module level 1070b57cec5SDimitry Andric // and not have a MachineFunction to initialize the TargetInstrInfo from and 1080b57cec5SDimitry Andric // we only need MCInstrInfo for asm parsing. We create one unconditionally 1090b57cec5SDimitry Andric // because it's not subtarget dependent. 1100b57cec5SDimitry Andric std::unique_ptr<MCInstrInfo> MII(TM.getTarget().createMCInstrInfo()); 111e8d8bef9SDimitry Andric assert(MII && "Failed to create instruction info"); 1120b57cec5SDimitry Andric std::unique_ptr<MCTargetAsmParser> TAP(TM.getTarget().createMCAsmParser( 1130b57cec5SDimitry Andric STI, *Parser, *MII, MCOptions)); 1140b57cec5SDimitry Andric if (!TAP) 1150b57cec5SDimitry Andric report_fatal_error("Inline asm not supported by this streamer because" 1160b57cec5SDimitry Andric " we don't have an asm parser for this target\n"); 1170b57cec5SDimitry Andric Parser->setAssemblerDialect(Dialect); 1180b57cec5SDimitry Andric Parser->setTargetParser(*TAP.get()); 1190b57cec5SDimitry Andric // Enable lexing Masm binary and hex integer literals in intel inline 1200b57cec5SDimitry Andric // assembly. 1210b57cec5SDimitry Andric if (Dialect == InlineAsm::AD_Intel) 1220b57cec5SDimitry Andric Parser->getLexer().setLexMasmIntegers(true); 1230b57cec5SDimitry Andric 1240b57cec5SDimitry Andric emitInlineAsmStart(); 1250b57cec5SDimitry Andric // Don't implicitly switch to the text section before the asm. 126fe6060f1SDimitry Andric (void)Parser->Run(/*NoInitialTextSection*/ true, 1270b57cec5SDimitry Andric /*NoFinalize*/ true); 1280b57cec5SDimitry Andric emitInlineAsmEnd(STI, &TAP->getSTI()); 1290b57cec5SDimitry Andric } 1300b57cec5SDimitry Andric 1310b57cec5SDimitry Andric static void EmitMSInlineAsmStr(const char *AsmStr, const MachineInstr *MI, 132*349cc55cSDimitry Andric MachineModuleInfo *MMI, const MCAsmInfo *MAI, 133*349cc55cSDimitry Andric AsmPrinter *AP, uint64_t LocCookie, 134*349cc55cSDimitry Andric raw_ostream &OS) { 1350b57cec5SDimitry Andric // Switch to the inline assembly variant. 1360b57cec5SDimitry Andric OS << "\t.intel_syntax\n\t"; 1370b57cec5SDimitry Andric 138*349cc55cSDimitry Andric int CurVariant = -1; // The number of the {.|.|.} region we are in. 1390b57cec5SDimitry Andric const char *LastEmitted = AsmStr; // One past the last character emitted. 1400b57cec5SDimitry Andric unsigned NumOperands = MI->getNumOperands(); 141*349cc55cSDimitry Andric int AsmPrinterVariant = 1; // X86MCAsmInfo.cpp's AsmWriterFlavorTy::Intel. 1420b57cec5SDimitry Andric 1430b57cec5SDimitry Andric while (*LastEmitted) { 1440b57cec5SDimitry Andric switch (*LastEmitted) { 1450b57cec5SDimitry Andric default: { 1460b57cec5SDimitry Andric // Not a special case, emit the string section literally. 1470b57cec5SDimitry Andric const char *LiteralEnd = LastEmitted+1; 1480b57cec5SDimitry Andric while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' && 1490b57cec5SDimitry Andric *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n') 1500b57cec5SDimitry Andric ++LiteralEnd; 151*349cc55cSDimitry Andric if (CurVariant == -1 || CurVariant == AsmPrinterVariant) 1520b57cec5SDimitry Andric OS.write(LastEmitted, LiteralEnd - LastEmitted); 1530b57cec5SDimitry Andric LastEmitted = LiteralEnd; 1540b57cec5SDimitry Andric break; 1550b57cec5SDimitry Andric } 1560b57cec5SDimitry Andric case '\n': 1570b57cec5SDimitry Andric ++LastEmitted; // Consume newline character. 1580b57cec5SDimitry Andric OS << '\n'; // Indent code with newline. 1590b57cec5SDimitry Andric break; 1600b57cec5SDimitry Andric case '$': { 1610b57cec5SDimitry Andric ++LastEmitted; // Consume '$' character. 1620b57cec5SDimitry Andric bool Done = true; 1630b57cec5SDimitry Andric 1640b57cec5SDimitry Andric // Handle escapes. 1650b57cec5SDimitry Andric switch (*LastEmitted) { 1660b57cec5SDimitry Andric default: Done = false; break; 1670b57cec5SDimitry Andric case '$': 1680b57cec5SDimitry Andric ++LastEmitted; // Consume second '$' character. 1690b57cec5SDimitry Andric break; 170*349cc55cSDimitry Andric case '(': // $( -> same as GCC's { character. 171*349cc55cSDimitry Andric ++LastEmitted; // Consume '(' character. 172*349cc55cSDimitry Andric if (CurVariant != -1) 173*349cc55cSDimitry Andric report_fatal_error("Nested variants found in inline asm string: '" + 174*349cc55cSDimitry Andric Twine(AsmStr) + "'"); 175*349cc55cSDimitry Andric CurVariant = 0; // We're in the first variant now. 176*349cc55cSDimitry Andric break; 177*349cc55cSDimitry Andric case '|': 178*349cc55cSDimitry Andric ++LastEmitted; // Consume '|' character. 179*349cc55cSDimitry Andric if (CurVariant == -1) 180*349cc55cSDimitry Andric OS << '|'; // This is gcc's behavior for | outside a variant. 181*349cc55cSDimitry Andric else 182*349cc55cSDimitry Andric ++CurVariant; // We're in the next variant. 183*349cc55cSDimitry Andric break; 184*349cc55cSDimitry Andric case ')': // $) -> same as GCC's } char. 185*349cc55cSDimitry Andric ++LastEmitted; // Consume ')' character. 186*349cc55cSDimitry Andric if (CurVariant == -1) 187*349cc55cSDimitry Andric OS << '}'; // This is gcc's behavior for } outside a variant. 188*349cc55cSDimitry Andric else 189*349cc55cSDimitry Andric CurVariant = -1; 190*349cc55cSDimitry Andric break; 1910b57cec5SDimitry Andric } 1920b57cec5SDimitry Andric if (Done) break; 1930b57cec5SDimitry Andric 194480093f4SDimitry Andric bool HasCurlyBraces = false; 195480093f4SDimitry Andric if (*LastEmitted == '{') { // ${variable} 196480093f4SDimitry Andric ++LastEmitted; // Consume '{' character. 197480093f4SDimitry Andric HasCurlyBraces = true; 198480093f4SDimitry Andric } 199480093f4SDimitry Andric 2000b57cec5SDimitry Andric // If we have ${:foo}, then this is not a real operand reference, it is a 2010b57cec5SDimitry Andric // "magic" string reference, just like in .td files. Arrange to call 2020b57cec5SDimitry Andric // PrintSpecial. 203*349cc55cSDimitry Andric if (HasCurlyBraces && *LastEmitted == ':') { 204480093f4SDimitry Andric ++LastEmitted; 2050b57cec5SDimitry Andric const char *StrStart = LastEmitted; 2060b57cec5SDimitry Andric const char *StrEnd = strchr(StrStart, '}'); 2070b57cec5SDimitry Andric if (!StrEnd) 2080b57cec5SDimitry Andric report_fatal_error("Unterminated ${:foo} operand in inline asm" 2090b57cec5SDimitry Andric " string: '" + Twine(AsmStr) + "'"); 210*349cc55cSDimitry Andric if (CurVariant == -1 || CurVariant == AsmPrinterVariant) 211*349cc55cSDimitry Andric AP->PrintSpecial(MI, OS, StringRef(StrStart, StrEnd - StrStart)); 2120b57cec5SDimitry Andric LastEmitted = StrEnd+1; 2130b57cec5SDimitry Andric break; 2140b57cec5SDimitry Andric } 2150b57cec5SDimitry Andric 2160b57cec5SDimitry Andric const char *IDStart = LastEmitted; 2170b57cec5SDimitry Andric const char *IDEnd = IDStart; 218e8d8bef9SDimitry Andric while (isDigit(*IDEnd)) 219e8d8bef9SDimitry Andric ++IDEnd; 2200b57cec5SDimitry Andric 2210b57cec5SDimitry Andric unsigned Val; 2220b57cec5SDimitry Andric if (StringRef(IDStart, IDEnd-IDStart).getAsInteger(10, Val)) 2230b57cec5SDimitry Andric report_fatal_error("Bad $ operand number in inline asm string: '" + 2240b57cec5SDimitry Andric Twine(AsmStr) + "'"); 2250b57cec5SDimitry Andric LastEmitted = IDEnd; 2260b57cec5SDimitry Andric 2270b57cec5SDimitry Andric if (Val >= NumOperands - 1) 2280b57cec5SDimitry Andric report_fatal_error("Invalid $ operand number in inline asm string: '" + 2290b57cec5SDimitry Andric Twine(AsmStr) + "'"); 2300b57cec5SDimitry Andric 231480093f4SDimitry Andric char Modifier[2] = { 0, 0 }; 232480093f4SDimitry Andric 233480093f4SDimitry Andric if (HasCurlyBraces) { 234480093f4SDimitry Andric // If we have curly braces, check for a modifier character. This 235480093f4SDimitry Andric // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm. 236480093f4SDimitry Andric if (*LastEmitted == ':') { 237480093f4SDimitry Andric ++LastEmitted; // Consume ':' character. 238480093f4SDimitry Andric if (*LastEmitted == 0) 239480093f4SDimitry Andric report_fatal_error("Bad ${:} expression in inline asm string: '" + 240480093f4SDimitry Andric Twine(AsmStr) + "'"); 241480093f4SDimitry Andric 242480093f4SDimitry Andric Modifier[0] = *LastEmitted; 243480093f4SDimitry Andric ++LastEmitted; // Consume modifier character. 244480093f4SDimitry Andric } 245480093f4SDimitry Andric 246480093f4SDimitry Andric if (*LastEmitted != '}') 247480093f4SDimitry Andric report_fatal_error("Bad ${} expression in inline asm string: '" + 248480093f4SDimitry Andric Twine(AsmStr) + "'"); 249480093f4SDimitry Andric ++LastEmitted; // Consume '}' character. 250480093f4SDimitry Andric } 251480093f4SDimitry Andric 2520b57cec5SDimitry Andric // Okay, we finally have a value number. Ask the target to print this 2530b57cec5SDimitry Andric // operand! 254*349cc55cSDimitry Andric if (CurVariant == -1 || CurVariant == AsmPrinterVariant) { 2550b57cec5SDimitry Andric unsigned OpNo = InlineAsm::MIOp_FirstOperand; 2560b57cec5SDimitry Andric 2570b57cec5SDimitry Andric bool Error = false; 2580b57cec5SDimitry Andric 2590b57cec5SDimitry Andric // Scan to find the machine operand number for the operand. 2600b57cec5SDimitry Andric for (; Val; --Val) { 261*349cc55cSDimitry Andric if (OpNo >= MI->getNumOperands()) 262*349cc55cSDimitry Andric break; 2630b57cec5SDimitry Andric unsigned OpFlags = MI->getOperand(OpNo).getImm(); 2640b57cec5SDimitry Andric OpNo += InlineAsm::getNumOperandRegisters(OpFlags) + 1; 2650b57cec5SDimitry Andric } 2660b57cec5SDimitry Andric 2670b57cec5SDimitry Andric // We may have a location metadata attached to the end of the 2680b57cec5SDimitry Andric // instruction, and at no point should see metadata at any 2690b57cec5SDimitry Andric // other point while processing. It's an error if so. 270*349cc55cSDimitry Andric if (OpNo >= MI->getNumOperands() || MI->getOperand(OpNo).isMetadata()) { 2710b57cec5SDimitry Andric Error = true; 2720b57cec5SDimitry Andric } else { 2730b57cec5SDimitry Andric unsigned OpFlags = MI->getOperand(OpNo).getImm(); 2740b57cec5SDimitry Andric ++OpNo; // Skip over the ID number. 2750b57cec5SDimitry Andric 276*349cc55cSDimitry Andric // FIXME: Shouldn't arch-independent output template handling go into 277*349cc55cSDimitry Andric // PrintAsmOperand? 278*349cc55cSDimitry Andric // Labels are target independent. 279*349cc55cSDimitry Andric if (MI->getOperand(OpNo).isBlockAddress()) { 280*349cc55cSDimitry Andric const BlockAddress *BA = MI->getOperand(OpNo).getBlockAddress(); 281*349cc55cSDimitry Andric MCSymbol *Sym = AP->GetBlockAddressSymbol(BA); 282*349cc55cSDimitry Andric Sym->print(OS, AP->MAI); 283*349cc55cSDimitry Andric MMI->getContext().registerInlineAsmLabel(Sym); 284*349cc55cSDimitry Andric } else if (InlineAsm::isMemKind(OpFlags)) { 285480093f4SDimitry Andric Error = AP->PrintAsmMemoryOperand( 286480093f4SDimitry Andric MI, OpNo, Modifier[0] ? Modifier : nullptr, OS); 2870b57cec5SDimitry Andric } else { 288480093f4SDimitry Andric Error = AP->PrintAsmOperand(MI, OpNo, 289480093f4SDimitry Andric Modifier[0] ? Modifier : nullptr, OS); 2900b57cec5SDimitry Andric } 2910b57cec5SDimitry Andric } 2920b57cec5SDimitry Andric if (Error) { 2930b57cec5SDimitry Andric std::string msg; 2940b57cec5SDimitry Andric raw_string_ostream Msg(msg); 2950b57cec5SDimitry Andric Msg << "invalid operand in inline asm: '" << AsmStr << "'"; 2960b57cec5SDimitry Andric MMI->getModule()->getContext().emitError(LocCookie, Msg.str()); 2970b57cec5SDimitry Andric } 298*349cc55cSDimitry Andric } 2990b57cec5SDimitry Andric break; 3000b57cec5SDimitry Andric } 3010b57cec5SDimitry Andric } 3020b57cec5SDimitry Andric } 3030b57cec5SDimitry Andric OS << "\n\t.att_syntax\n" << (char)0; // null terminate string. 3040b57cec5SDimitry Andric } 3050b57cec5SDimitry Andric 3060b57cec5SDimitry Andric static void EmitGCCInlineAsmStr(const char *AsmStr, const MachineInstr *MI, 307fe6060f1SDimitry Andric MachineModuleInfo *MMI, const MCAsmInfo *MAI, 308fe6060f1SDimitry Andric AsmPrinter *AP, uint64_t LocCookie, 3090b57cec5SDimitry Andric raw_ostream &OS) { 3100b57cec5SDimitry Andric int CurVariant = -1; // The number of the {.|.|.} region we are in. 3110b57cec5SDimitry Andric const char *LastEmitted = AsmStr; // One past the last character emitted. 3120b57cec5SDimitry Andric unsigned NumOperands = MI->getNumOperands(); 313*349cc55cSDimitry Andric int AsmPrinterVariant = MMI->getTarget().unqualifiedInlineAsmVariant(); 3140b57cec5SDimitry Andric 315fe6060f1SDimitry Andric if (MAI->getEmitGNUAsmStartIndentationMarker()) 3160b57cec5SDimitry Andric OS << '\t'; 3170b57cec5SDimitry Andric 3180b57cec5SDimitry Andric while (*LastEmitted) { 3190b57cec5SDimitry Andric switch (*LastEmitted) { 3200b57cec5SDimitry Andric default: { 3210b57cec5SDimitry Andric // Not a special case, emit the string section literally. 3220b57cec5SDimitry Andric const char *LiteralEnd = LastEmitted+1; 3230b57cec5SDimitry Andric while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' && 3240b57cec5SDimitry Andric *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n') 3250b57cec5SDimitry Andric ++LiteralEnd; 3260b57cec5SDimitry Andric if (CurVariant == -1 || CurVariant == AsmPrinterVariant) 3270b57cec5SDimitry Andric OS.write(LastEmitted, LiteralEnd - LastEmitted); 3280b57cec5SDimitry Andric LastEmitted = LiteralEnd; 3290b57cec5SDimitry Andric break; 3300b57cec5SDimitry Andric } 3310b57cec5SDimitry Andric case '\n': 3320b57cec5SDimitry Andric ++LastEmitted; // Consume newline character. 3330b57cec5SDimitry Andric OS << '\n'; // Indent code with newline. 3340b57cec5SDimitry Andric break; 3350b57cec5SDimitry Andric case '$': { 3360b57cec5SDimitry Andric ++LastEmitted; // Consume '$' character. 3370b57cec5SDimitry Andric bool Done = true; 3380b57cec5SDimitry Andric 3390b57cec5SDimitry Andric // Handle escapes. 3400b57cec5SDimitry Andric switch (*LastEmitted) { 3410b57cec5SDimitry Andric default: Done = false; break; 3420b57cec5SDimitry Andric case '$': // $$ -> $ 3430b57cec5SDimitry Andric if (CurVariant == -1 || CurVariant == AsmPrinterVariant) 3440b57cec5SDimitry Andric OS << '$'; 3450b57cec5SDimitry Andric ++LastEmitted; // Consume second '$' character. 3460b57cec5SDimitry Andric break; 3470b57cec5SDimitry Andric case '(': // $( -> same as GCC's { character. 3480b57cec5SDimitry Andric ++LastEmitted; // Consume '(' character. 3490b57cec5SDimitry Andric if (CurVariant != -1) 3500b57cec5SDimitry Andric report_fatal_error("Nested variants found in inline asm string: '" + 3510b57cec5SDimitry Andric Twine(AsmStr) + "'"); 3520b57cec5SDimitry Andric CurVariant = 0; // We're in the first variant now. 3530b57cec5SDimitry Andric break; 3540b57cec5SDimitry Andric case '|': 355*349cc55cSDimitry Andric ++LastEmitted; // Consume '|' character. 3560b57cec5SDimitry Andric if (CurVariant == -1) 357*349cc55cSDimitry Andric OS << '|'; // This is gcc's behavior for | outside a variant. 3580b57cec5SDimitry Andric else 3590b57cec5SDimitry Andric ++CurVariant; // We're in the next variant. 3600b57cec5SDimitry Andric break; 3610b57cec5SDimitry Andric case ')': // $) -> same as GCC's } char. 362*349cc55cSDimitry Andric ++LastEmitted; // Consume ')' character. 3630b57cec5SDimitry Andric if (CurVariant == -1) 364*349cc55cSDimitry Andric OS << '}'; // This is gcc's behavior for } outside a variant. 3650b57cec5SDimitry Andric else 3660b57cec5SDimitry Andric CurVariant = -1; 3670b57cec5SDimitry Andric break; 3680b57cec5SDimitry Andric } 3690b57cec5SDimitry Andric if (Done) break; 3700b57cec5SDimitry Andric 3710b57cec5SDimitry Andric bool HasCurlyBraces = false; 3720b57cec5SDimitry Andric if (*LastEmitted == '{') { // ${variable} 3730b57cec5SDimitry Andric ++LastEmitted; // Consume '{' character. 3740b57cec5SDimitry Andric HasCurlyBraces = true; 3750b57cec5SDimitry Andric } 3760b57cec5SDimitry Andric 3770b57cec5SDimitry Andric // If we have ${:foo}, then this is not a real operand reference, it is a 3780b57cec5SDimitry Andric // "magic" string reference, just like in .td files. Arrange to call 3790b57cec5SDimitry Andric // PrintSpecial. 3800b57cec5SDimitry Andric if (HasCurlyBraces && *LastEmitted == ':') { 3810b57cec5SDimitry Andric ++LastEmitted; 3820b57cec5SDimitry Andric const char *StrStart = LastEmitted; 3830b57cec5SDimitry Andric const char *StrEnd = strchr(StrStart, '}'); 3840b57cec5SDimitry Andric if (!StrEnd) 3850b57cec5SDimitry Andric report_fatal_error("Unterminated ${:foo} operand in inline asm" 3860b57cec5SDimitry Andric " string: '" + Twine(AsmStr) + "'"); 387*349cc55cSDimitry Andric if (CurVariant == -1 || CurVariant == AsmPrinterVariant) 388*349cc55cSDimitry Andric AP->PrintSpecial(MI, OS, StringRef(StrStart, StrEnd - StrStart)); 3890b57cec5SDimitry Andric LastEmitted = StrEnd+1; 3900b57cec5SDimitry Andric break; 3910b57cec5SDimitry Andric } 3920b57cec5SDimitry Andric 3930b57cec5SDimitry Andric const char *IDStart = LastEmitted; 3940b57cec5SDimitry Andric const char *IDEnd = IDStart; 395e8d8bef9SDimitry Andric while (isDigit(*IDEnd)) 396e8d8bef9SDimitry Andric ++IDEnd; 3970b57cec5SDimitry Andric 3980b57cec5SDimitry Andric unsigned Val; 3990b57cec5SDimitry Andric if (StringRef(IDStart, IDEnd-IDStart).getAsInteger(10, Val)) 4000b57cec5SDimitry Andric report_fatal_error("Bad $ operand number in inline asm string: '" + 4010b57cec5SDimitry Andric Twine(AsmStr) + "'"); 4020b57cec5SDimitry Andric LastEmitted = IDEnd; 4030b57cec5SDimitry Andric 404*349cc55cSDimitry Andric if (Val >= NumOperands - 1) 405*349cc55cSDimitry Andric report_fatal_error("Invalid $ operand number in inline asm string: '" + 406*349cc55cSDimitry Andric Twine(AsmStr) + "'"); 407*349cc55cSDimitry Andric 4080b57cec5SDimitry Andric char Modifier[2] = { 0, 0 }; 4090b57cec5SDimitry Andric 4100b57cec5SDimitry Andric if (HasCurlyBraces) { 4110b57cec5SDimitry Andric // If we have curly braces, check for a modifier character. This 4120b57cec5SDimitry Andric // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm. 4130b57cec5SDimitry Andric if (*LastEmitted == ':') { 4140b57cec5SDimitry Andric ++LastEmitted; // Consume ':' character. 4150b57cec5SDimitry Andric if (*LastEmitted == 0) 4160b57cec5SDimitry Andric report_fatal_error("Bad ${:} expression in inline asm string: '" + 4170b57cec5SDimitry Andric Twine(AsmStr) + "'"); 4180b57cec5SDimitry Andric 4190b57cec5SDimitry Andric Modifier[0] = *LastEmitted; 4200b57cec5SDimitry Andric ++LastEmitted; // Consume modifier character. 4210b57cec5SDimitry Andric } 4220b57cec5SDimitry Andric 4230b57cec5SDimitry Andric if (*LastEmitted != '}') 4240b57cec5SDimitry Andric report_fatal_error("Bad ${} expression in inline asm string: '" + 4250b57cec5SDimitry Andric Twine(AsmStr) + "'"); 4260b57cec5SDimitry Andric ++LastEmitted; // Consume '}' character. 4270b57cec5SDimitry Andric } 4280b57cec5SDimitry Andric 4290b57cec5SDimitry Andric // Okay, we finally have a value number. Ask the target to print this 4300b57cec5SDimitry Andric // operand! 4310b57cec5SDimitry Andric if (CurVariant == -1 || CurVariant == AsmPrinterVariant) { 4320b57cec5SDimitry Andric unsigned OpNo = InlineAsm::MIOp_FirstOperand; 4330b57cec5SDimitry Andric 4340b57cec5SDimitry Andric bool Error = false; 4350b57cec5SDimitry Andric 4360b57cec5SDimitry Andric // Scan to find the machine operand number for the operand. 4370b57cec5SDimitry Andric for (; Val; --Val) { 438*349cc55cSDimitry Andric if (OpNo >= MI->getNumOperands()) 439*349cc55cSDimitry Andric break; 4400b57cec5SDimitry Andric unsigned OpFlags = MI->getOperand(OpNo).getImm(); 4410b57cec5SDimitry Andric OpNo += InlineAsm::getNumOperandRegisters(OpFlags) + 1; 4420b57cec5SDimitry Andric } 4430b57cec5SDimitry Andric 4440b57cec5SDimitry Andric // We may have a location metadata attached to the end of the 4450b57cec5SDimitry Andric // instruction, and at no point should see metadata at any 4460b57cec5SDimitry Andric // other point while processing. It's an error if so. 447*349cc55cSDimitry Andric if (OpNo >= MI->getNumOperands() || MI->getOperand(OpNo).isMetadata()) { 4480b57cec5SDimitry Andric Error = true; 4490b57cec5SDimitry Andric } else { 4500b57cec5SDimitry Andric unsigned OpFlags = MI->getOperand(OpNo).getImm(); 4510b57cec5SDimitry Andric ++OpNo; // Skip over the ID number. 4520b57cec5SDimitry Andric 4530b57cec5SDimitry Andric // FIXME: Shouldn't arch-independent output template handling go into 4540b57cec5SDimitry Andric // PrintAsmOperand? 455480093f4SDimitry Andric // Labels are target independent. 4560b57cec5SDimitry Andric if (MI->getOperand(OpNo).isBlockAddress()) { 4570b57cec5SDimitry Andric const BlockAddress *BA = MI->getOperand(OpNo).getBlockAddress(); 4580b57cec5SDimitry Andric MCSymbol *Sym = AP->GetBlockAddressSymbol(BA); 4590b57cec5SDimitry Andric Sym->print(OS, AP->MAI); 4600b57cec5SDimitry Andric MMI->getContext().registerInlineAsmLabel(Sym); 4610b57cec5SDimitry Andric } else if (MI->getOperand(OpNo).isMBB()) { 4620b57cec5SDimitry Andric const MCSymbol *Sym = MI->getOperand(OpNo).getMBB()->getSymbol(); 4630b57cec5SDimitry Andric Sym->print(OS, AP->MAI); 464480093f4SDimitry Andric } else if (InlineAsm::isMemKind(OpFlags)) { 4650b57cec5SDimitry Andric Error = AP->PrintAsmMemoryOperand( 4660b57cec5SDimitry Andric MI, OpNo, Modifier[0] ? Modifier : nullptr, OS); 4670b57cec5SDimitry Andric } else { 4680b57cec5SDimitry Andric Error = AP->PrintAsmOperand(MI, OpNo, 4690b57cec5SDimitry Andric Modifier[0] ? Modifier : nullptr, OS); 4700b57cec5SDimitry Andric } 4710b57cec5SDimitry Andric } 4720b57cec5SDimitry Andric if (Error) { 4730b57cec5SDimitry Andric std::string msg; 4740b57cec5SDimitry Andric raw_string_ostream Msg(msg); 4750b57cec5SDimitry Andric Msg << "invalid operand in inline asm: '" << AsmStr << "'"; 4760b57cec5SDimitry Andric MMI->getModule()->getContext().emitError(LocCookie, Msg.str()); 4770b57cec5SDimitry Andric } 4780b57cec5SDimitry Andric } 4790b57cec5SDimitry Andric break; 4800b57cec5SDimitry Andric } 4810b57cec5SDimitry Andric } 4820b57cec5SDimitry Andric } 4830b57cec5SDimitry Andric OS << '\n' << (char)0; // null terminate string. 4840b57cec5SDimitry Andric } 4850b57cec5SDimitry Andric 4865ffd83dbSDimitry Andric /// This method formats and emits the specified machine instruction that is an 4875ffd83dbSDimitry Andric /// inline asm. 4885ffd83dbSDimitry Andric void AsmPrinter::emitInlineAsm(const MachineInstr *MI) const { 4890b57cec5SDimitry Andric assert(MI->isInlineAsm() && "printInlineAsm only works on inline asms"); 4900b57cec5SDimitry Andric 4910b57cec5SDimitry Andric // Count the number of register definitions to find the asm string. 4920b57cec5SDimitry Andric unsigned NumDefs = 0; 4930b57cec5SDimitry Andric for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef(); 4940b57cec5SDimitry Andric ++NumDefs) 4950b57cec5SDimitry Andric assert(NumDefs != MI->getNumOperands()-2 && "No asm string?"); 4960b57cec5SDimitry Andric 4970b57cec5SDimitry Andric assert(MI->getOperand(NumDefs).isSymbol() && "No asm string?"); 4980b57cec5SDimitry Andric 4990b57cec5SDimitry Andric // Disassemble the AsmStr, printing out the literal pieces, the operands, etc. 5000b57cec5SDimitry Andric const char *AsmStr = MI->getOperand(NumDefs).getSymbolName(); 5010b57cec5SDimitry Andric 5020b57cec5SDimitry Andric // If this asmstr is empty, just print the #APP/#NOAPP markers. 5030b57cec5SDimitry Andric // These are useful to see where empty asm's wound up. 5040b57cec5SDimitry Andric if (AsmStr[0] == 0) { 5050b57cec5SDimitry Andric OutStreamer->emitRawComment(MAI->getInlineAsmStart()); 5060b57cec5SDimitry Andric OutStreamer->emitRawComment(MAI->getInlineAsmEnd()); 5070b57cec5SDimitry Andric return; 5080b57cec5SDimitry Andric } 5090b57cec5SDimitry Andric 5100b57cec5SDimitry Andric // Emit the #APP start marker. This has to happen even if verbose-asm isn't 5110b57cec5SDimitry Andric // enabled, so we use emitRawComment. 5120b57cec5SDimitry Andric OutStreamer->emitRawComment(MAI->getInlineAsmStart()); 5130b57cec5SDimitry Andric 5140b57cec5SDimitry Andric // Get the !srcloc metadata node if we have it, and decode the loc cookie from 5150b57cec5SDimitry Andric // it. 516fe6060f1SDimitry Andric uint64_t LocCookie = 0; 5170b57cec5SDimitry Andric const MDNode *LocMD = nullptr; 5180b57cec5SDimitry Andric for (unsigned i = MI->getNumOperands(); i != 0; --i) { 5190b57cec5SDimitry Andric if (MI->getOperand(i-1).isMetadata() && 5200b57cec5SDimitry Andric (LocMD = MI->getOperand(i-1).getMetadata()) && 5210b57cec5SDimitry Andric LocMD->getNumOperands() != 0) { 5220b57cec5SDimitry Andric if (const ConstantInt *CI = 5230b57cec5SDimitry Andric mdconst::dyn_extract<ConstantInt>(LocMD->getOperand(0))) { 5240b57cec5SDimitry Andric LocCookie = CI->getZExtValue(); 5250b57cec5SDimitry Andric break; 5260b57cec5SDimitry Andric } 5270b57cec5SDimitry Andric } 5280b57cec5SDimitry Andric } 5290b57cec5SDimitry Andric 5300b57cec5SDimitry Andric // Emit the inline asm to a temporary string so we can emit it through 5310b57cec5SDimitry Andric // EmitInlineAsm. 5320b57cec5SDimitry Andric SmallString<256> StringData; 5330b57cec5SDimitry Andric raw_svector_ostream OS(StringData); 5340b57cec5SDimitry Andric 5350b57cec5SDimitry Andric AsmPrinter *AP = const_cast<AsmPrinter*>(this); 5360b57cec5SDimitry Andric if (MI->getInlineAsmDialect() == InlineAsm::AD_ATT) 537fe6060f1SDimitry Andric EmitGCCInlineAsmStr(AsmStr, MI, MMI, MAI, AP, LocCookie, OS); 5380b57cec5SDimitry Andric else 539*349cc55cSDimitry Andric EmitMSInlineAsmStr(AsmStr, MI, MMI, MAI, AP, LocCookie, OS); 5400b57cec5SDimitry Andric 5410b57cec5SDimitry Andric // Emit warnings if we use reserved registers on the clobber list, as 542e8d8bef9SDimitry Andric // that might lead to undefined behaviour. 543e8d8bef9SDimitry Andric SmallVector<Register, 8> RestrRegs; 544e8d8bef9SDimitry Andric const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo(); 5450b57cec5SDimitry Andric // Start with the first operand descriptor, and iterate over them. 5460b57cec5SDimitry Andric for (unsigned I = InlineAsm::MIOp_FirstOperand, NumOps = MI->getNumOperands(); 5470b57cec5SDimitry Andric I < NumOps; ++I) { 5480b57cec5SDimitry Andric const MachineOperand &MO = MI->getOperand(I); 549e8d8bef9SDimitry Andric if (!MO.isImm()) 550e8d8bef9SDimitry Andric continue; 5510b57cec5SDimitry Andric unsigned Flags = MO.getImm(); 552e8d8bef9SDimitry Andric if (InlineAsm::getKind(Flags) == InlineAsm::Kind_Clobber) { 553e8d8bef9SDimitry Andric Register Reg = MI->getOperand(I + 1).getReg(); 554e8d8bef9SDimitry Andric if (!TRI->isAsmClobberable(*MF, Reg)) 555e8d8bef9SDimitry Andric RestrRegs.push_back(Reg); 5560b57cec5SDimitry Andric } 5570b57cec5SDimitry Andric // Skip to one before the next operand descriptor, if it exists. 5580b57cec5SDimitry Andric I += InlineAsm::getNumOperandRegisters(Flags); 5590b57cec5SDimitry Andric } 5600b57cec5SDimitry Andric 5610b57cec5SDimitry Andric if (!RestrRegs.empty()) { 5620b57cec5SDimitry Andric std::string Msg = "inline asm clobber list contains reserved registers: "; 563fe6060f1SDimitry Andric ListSeparator LS; 564fe6060f1SDimitry Andric for (const Register &RR : RestrRegs) { 565fe6060f1SDimitry Andric Msg += LS; 566fe6060f1SDimitry Andric Msg += TRI->getName(RR); 5670b57cec5SDimitry Andric } 568e8d8bef9SDimitry Andric const char *Note = 569e8d8bef9SDimitry Andric "Reserved registers on the clobber list may not be " 5700b57cec5SDimitry Andric "preserved across the asm statement, and clobbering them may " 5710b57cec5SDimitry Andric "lead to undefined behaviour."; 572fe6060f1SDimitry Andric MMI->getModule()->getContext().diagnose(DiagnosticInfoInlineAsm( 573*349cc55cSDimitry Andric LocCookie, Msg, DiagnosticSeverity::DS_Warning)); 574fe6060f1SDimitry Andric MMI->getModule()->getContext().diagnose( 575fe6060f1SDimitry Andric DiagnosticInfoInlineAsm(LocCookie, Note, DiagnosticSeverity::DS_Note)); 5760b57cec5SDimitry Andric } 5770b57cec5SDimitry Andric 5785ffd83dbSDimitry Andric emitInlineAsm(OS.str(), getSubtargetInfo(), TM.Options.MCOptions, LocMD, 5790b57cec5SDimitry Andric MI->getInlineAsmDialect()); 5800b57cec5SDimitry Andric 5810b57cec5SDimitry Andric // Emit the #NOAPP end marker. This has to happen even if verbose-asm isn't 5820b57cec5SDimitry Andric // enabled, so we use emitRawComment. 5830b57cec5SDimitry Andric OutStreamer->emitRawComment(MAI->getInlineAsmEnd()); 5840b57cec5SDimitry Andric } 5850b57cec5SDimitry Andric 5860b57cec5SDimitry Andric /// PrintSpecial - Print information related to the specified machine instr 5870b57cec5SDimitry Andric /// that is independent of the operand, and may be independent of the instr 5880b57cec5SDimitry Andric /// itself. This can be useful for portably encoding the comment character 5890b57cec5SDimitry Andric /// or other bits of target-specific knowledge into the asmstrings. The 5900b57cec5SDimitry Andric /// syntax used is ${:comment}. Targets can override this to add support 5910b57cec5SDimitry Andric /// for their own strange codes. 5920b57cec5SDimitry Andric void AsmPrinter::PrintSpecial(const MachineInstr *MI, raw_ostream &OS, 593*349cc55cSDimitry Andric StringRef Code) const { 594*349cc55cSDimitry Andric if (Code == "private") { 5950b57cec5SDimitry Andric const DataLayout &DL = MF->getDataLayout(); 5960b57cec5SDimitry Andric OS << DL.getPrivateGlobalPrefix(); 597*349cc55cSDimitry Andric } else if (Code == "comment") { 5980b57cec5SDimitry Andric OS << MAI->getCommentString(); 599*349cc55cSDimitry Andric } else if (Code == "uid") { 6000b57cec5SDimitry Andric // Comparing the address of MI isn't sufficient, because machineinstrs may 6010b57cec5SDimitry Andric // be allocated to the same address across functions. 6020b57cec5SDimitry Andric 6030b57cec5SDimitry Andric // If this is a new LastFn instruction, bump the counter. 6040b57cec5SDimitry Andric if (LastMI != MI || LastFn != getFunctionNumber()) { 6050b57cec5SDimitry Andric ++Counter; 6060b57cec5SDimitry Andric LastMI = MI; 6070b57cec5SDimitry Andric LastFn = getFunctionNumber(); 6080b57cec5SDimitry Andric } 6090b57cec5SDimitry Andric OS << Counter; 6100b57cec5SDimitry Andric } else { 6110b57cec5SDimitry Andric std::string msg; 6120b57cec5SDimitry Andric raw_string_ostream Msg(msg); 6130b57cec5SDimitry Andric Msg << "Unknown special formatter '" << Code 6140b57cec5SDimitry Andric << "' for machine instr: " << *MI; 615*349cc55cSDimitry Andric report_fatal_error(Twine(Msg.str())); 6160b57cec5SDimitry Andric } 6170b57cec5SDimitry Andric } 6180b57cec5SDimitry Andric 6190b57cec5SDimitry Andric void AsmPrinter::PrintSymbolOperand(const MachineOperand &MO, raw_ostream &OS) { 6200b57cec5SDimitry Andric assert(MO.isGlobal() && "caller should check MO.isGlobal"); 621fe6060f1SDimitry Andric getSymbolPreferLocal(*MO.getGlobal())->print(OS, MAI); 6220b57cec5SDimitry Andric printOffset(MO.getOffset(), OS); 6230b57cec5SDimitry Andric } 6240b57cec5SDimitry Andric 6250b57cec5SDimitry Andric /// PrintAsmOperand - Print the specified operand of MI, an INLINEASM 6260b57cec5SDimitry Andric /// instruction, using the specified assembler variant. Targets should 6270b57cec5SDimitry Andric /// override this to format as appropriate for machine specific ExtraCodes 6280b57cec5SDimitry Andric /// or when the arch-independent handling would be too complex otherwise. 6290b57cec5SDimitry Andric bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, 6300b57cec5SDimitry Andric const char *ExtraCode, raw_ostream &O) { 6310b57cec5SDimitry Andric // Does this asm operand have a single letter operand modifier? 6320b57cec5SDimitry Andric if (ExtraCode && ExtraCode[0]) { 6330b57cec5SDimitry Andric if (ExtraCode[1] != 0) return true; // Unknown modifier. 6340b57cec5SDimitry Andric 6350b57cec5SDimitry Andric // https://gcc.gnu.org/onlinedocs/gccint/Output-Template.html 6360b57cec5SDimitry Andric const MachineOperand &MO = MI->getOperand(OpNo); 6370b57cec5SDimitry Andric switch (ExtraCode[0]) { 6380b57cec5SDimitry Andric default: 6390b57cec5SDimitry Andric return true; // Unknown modifier. 6400b57cec5SDimitry Andric case 'a': // Print as memory address. 6410b57cec5SDimitry Andric if (MO.isReg()) { 6420b57cec5SDimitry Andric PrintAsmMemoryOperand(MI, OpNo, nullptr, O); 6430b57cec5SDimitry Andric return false; 6440b57cec5SDimitry Andric } 6450b57cec5SDimitry Andric LLVM_FALLTHROUGH; // GCC allows '%a' to behave like '%c' with immediates. 6460b57cec5SDimitry Andric case 'c': // Substitute immediate value without immediate syntax 6470b57cec5SDimitry Andric if (MO.isImm()) { 6480b57cec5SDimitry Andric O << MO.getImm(); 6490b57cec5SDimitry Andric return false; 6500b57cec5SDimitry Andric } 6510b57cec5SDimitry Andric if (MO.isGlobal()) { 6520b57cec5SDimitry Andric PrintSymbolOperand(MO, O); 6530b57cec5SDimitry Andric return false; 6540b57cec5SDimitry Andric } 6550b57cec5SDimitry Andric return true; 6560b57cec5SDimitry Andric case 'n': // Negate the immediate constant. 6570b57cec5SDimitry Andric if (!MO.isImm()) 6580b57cec5SDimitry Andric return true; 6590b57cec5SDimitry Andric O << -MO.getImm(); 6600b57cec5SDimitry Andric return false; 6610b57cec5SDimitry Andric case 's': // The GCC deprecated s modifier 6620b57cec5SDimitry Andric if (!MO.isImm()) 6630b57cec5SDimitry Andric return true; 6640b57cec5SDimitry Andric O << ((32 - MO.getImm()) & 31); 6650b57cec5SDimitry Andric return false; 6660b57cec5SDimitry Andric } 6670b57cec5SDimitry Andric } 6680b57cec5SDimitry Andric return true; 6690b57cec5SDimitry Andric } 6700b57cec5SDimitry Andric 6710b57cec5SDimitry Andric bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, 6720b57cec5SDimitry Andric const char *ExtraCode, raw_ostream &O) { 6730b57cec5SDimitry Andric // Target doesn't support this yet! 6740b57cec5SDimitry Andric return true; 6750b57cec5SDimitry Andric } 6760b57cec5SDimitry Andric 6770b57cec5SDimitry Andric void AsmPrinter::emitInlineAsmStart() const {} 6780b57cec5SDimitry Andric 6790b57cec5SDimitry Andric void AsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo, 6800b57cec5SDimitry Andric const MCSubtargetInfo *EndInfo) const {} 681