blob: dc843856cd64de39c641a6bf0d907aa7264917f5 [file] [log] [blame]
Chris Lattner7e1a8f82010-04-04 19:09:29 +00001//===-- AsmPrinterInlineAsm.cpp - AsmPrinter Inline Asm Handling ----------===//
Chris Lattner736e31d2010-04-04 18:34:07 +00002//
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//
Chris Lattner7e1a8f82010-04-04 19:09:29 +000010// This file implements the inline assembler pieces of the AsmPrinter class.
Chris Lattner736e31d2010-04-04 18:34:07 +000011//
12//===----------------------------------------------------------------------===//
13
14#define DEBUG_TYPE "asm-printer"
Chris Lattner736e31d2010-04-04 18:34:07 +000015#include "llvm/CodeGen/AsmPrinter.h"
Chris Lattnercf9a4152010-04-07 05:38:05 +000016#include "llvm/Constants.h"
Chris Lattner7e1a8f82010-04-04 19:09:29 +000017#include "llvm/InlineAsm.h"
Chris Lattner6eb78062010-04-06 00:55:39 +000018#include "llvm/LLVMContext.h"
19#include "llvm/Module.h"
Chris Lattner736e31d2010-04-04 18:34:07 +000020#include "llvm/CodeGen/MachineBasicBlock.h"
Chris Lattner6eb78062010-04-06 00:55:39 +000021#include "llvm/CodeGen/MachineModuleInfo.h"
Chris Lattner736e31d2010-04-04 18:34:07 +000022#include "llvm/MC/MCAsmInfo.h"
23#include "llvm/MC/MCStreamer.h"
24#include "llvm/MC/MCSymbol.h"
Chris Lattneraf632c92010-04-05 23:11:24 +000025#include "llvm/Target/TargetAsmParser.h"
26#include "llvm/Target/TargetMachine.h"
27#include "llvm/Target/TargetRegistry.h"
28#include "llvm/ADT/OwningPtr.h"
Chris Lattner736e31d2010-04-04 18:34:07 +000029#include "llvm/ADT/SmallString.h"
30#include "llvm/ADT/Twine.h"
31#include "llvm/Support/ErrorHandling.h"
Chris Lattneraf632c92010-04-05 23:11:24 +000032#include "llvm/Support/MemoryBuffer.h"
33#include "llvm/Support/SourceMgr.h"
Chris Lattner736e31d2010-04-04 18:34:07 +000034#include "llvm/Support/raw_ostream.h"
Chris Lattner736e31d2010-04-04 18:34:07 +000035using namespace llvm;
36
Chris Lattner6e30c6a2010-11-17 08:03:32 +000037namespace {
38 struct SrcMgrDiagInfo {
39 const MDNode *LocInfo;
Chris Lattner4afa1282010-11-17 08:13:01 +000040 LLVMContext::InlineAsmDiagHandlerTy DiagHandler;
Chris Lattner6e30c6a2010-11-17 08:03:32 +000041 void *DiagContext;
42 };
43}
44
45/// SrcMgrDiagHandler - This callback is invoked when the SourceMgr for an
46/// inline asm has an error in it. diagInfo is a pointer to the SrcMgrDiagInfo
47/// struct above.
Chris Lattner4afa1282010-11-17 08:13:01 +000048static void SrcMgrDiagHandler(const SMDiagnostic &Diag, void *diagInfo) {
Chris Lattner6e30c6a2010-11-17 08:03:32 +000049 SrcMgrDiagInfo *DiagInfo = static_cast<SrcMgrDiagInfo *>(diagInfo);
50 assert(DiagInfo && "Diagnostic context not passed down?");
51
Chris Lattnerce1b9ad2010-11-17 08:20:42 +000052 // If the inline asm had metadata associated with it, pull out a location
53 // cookie corresponding to which line the error occurred on.
Chris Lattner6e30c6a2010-11-17 08:03:32 +000054 unsigned LocCookie = 0;
Chris Lattnerce1b9ad2010-11-17 08:20:42 +000055 if (const MDNode *LocInfo = DiagInfo->LocInfo) {
56 unsigned ErrorLine = Diag.getLineNo()-1;
57 if (ErrorLine >= LocInfo->getNumOperands())
58 ErrorLine = 0;
59
60 if (LocInfo->getNumOperands() != 0)
61 if (const ConstantInt *CI =
62 dyn_cast<ConstantInt>(LocInfo->getOperand(ErrorLine)))
Chris Lattner6e30c6a2010-11-17 08:03:32 +000063 LocCookie = CI->getZExtValue();
Chris Lattnerce1b9ad2010-11-17 08:20:42 +000064 }
Chris Lattner6e30c6a2010-11-17 08:03:32 +000065
Chris Lattner4afa1282010-11-17 08:13:01 +000066 DiagInfo->DiagHandler(Diag, DiagInfo->DiagContext, LocCookie);
Chris Lattner6e30c6a2010-11-17 08:03:32 +000067}
68
Chris Lattner736e31d2010-04-04 18:34:07 +000069/// EmitInlineAsm - Emit a blob of inline asm to the output streamer.
Chris Lattnera38941d2010-11-17 07:53:40 +000070void AsmPrinter::EmitInlineAsm(StringRef Str, const MDNode *LocMDNode) const {
Chris Lattner736e31d2010-04-04 18:34:07 +000071 assert(!Str.empty() && "Can't emit empty inline asm block");
Jim Grosbach2b2de242010-10-01 23:29:12 +000072
Chris Lattneraf632c92010-04-05 23:11:24 +000073 // Remember if the buffer is nul terminated or not so we can avoid a copy.
74 bool isNullTerminated = Str.back() == 0;
75 if (isNullTerminated)
76 Str = Str.substr(0, Str.size()-1);
Jim Grosbach2b2de242010-10-01 23:29:12 +000077
Chris Lattner736e31d2010-04-04 18:34:07 +000078 // If the output streamer is actually a .s file, just emit the blob textually.
79 // This is useful in case the asm parser doesn't handle something but the
80 // system assembler does.
81 if (OutStreamer.hasRawTextSupport()) {
82 OutStreamer.EmitRawText(Str);
83 return;
84 }
Jim Grosbach2b2de242010-10-01 23:29:12 +000085
Chris Lattneraf632c92010-04-05 23:11:24 +000086 SourceMgr SrcMgr;
Chris Lattner6e30c6a2010-11-17 08:03:32 +000087 SrcMgrDiagInfo DiagInfo;
Jim Grosbach2b2de242010-10-01 23:29:12 +000088
Chris Lattner6eb78062010-04-06 00:55:39 +000089 // If the current LLVMContext has an inline asm handler, set it in SourceMgr.
90 LLVMContext &LLVMCtx = MMI->getModule()->getContext();
91 bool HasDiagHandler = false;
Chris Lattner4afa1282010-11-17 08:13:01 +000092 if (LLVMCtx.getInlineAsmDiagnosticHandler() != 0) {
Chris Lattner6e30c6a2010-11-17 08:03:32 +000093 // If the source manager has an issue, we arrange for SrcMgrDiagHandler
94 // to be invoked, getting DiagInfo passed into it.
95 DiagInfo.LocInfo = LocMDNode;
Chris Lattner4afa1282010-11-17 08:13:01 +000096 DiagInfo.DiagHandler = LLVMCtx.getInlineAsmDiagnosticHandler();
Chris Lattner6e30c6a2010-11-17 08:03:32 +000097 DiagInfo.DiagContext = LLVMCtx.getInlineAsmDiagnosticContext();
98 SrcMgr.setDiagHandler(SrcMgrDiagHandler, &DiagInfo);
Chris Lattner6eb78062010-04-06 00:55:39 +000099 HasDiagHandler = true;
100 }
Jim Grosbach2b2de242010-10-01 23:29:12 +0000101
Chris Lattneraf632c92010-04-05 23:11:24 +0000102 MemoryBuffer *Buffer;
103 if (isNullTerminated)
104 Buffer = MemoryBuffer::getMemBuffer(Str, "<inline asm>");
105 else
106 Buffer = MemoryBuffer::getMemBufferCopy(Str, "<inline asm>");
107
108 // Tell SrcMgr about this buffer, it takes ownership of the buffer.
109 SrcMgr.AddNewSourceBuffer(Buffer, SMLoc());
Jim Grosbach2b2de242010-10-01 23:29:12 +0000110
Daniel Dunbar9fbb37e2010-07-18 18:31:33 +0000111 OwningPtr<MCAsmParser> Parser(createMCAsmParser(TM.getTarget(), SrcMgr,
112 OutContext, OutStreamer,
113 *MAI));
Evan Chengebdeeab2011-07-08 01:53:10 +0000114
115 OwningPtr<TargetAsmParser>
116 TAP(TM.getTarget().createAsmParser(TM.getTargetTriple(),
117 TM.getTargetCPU(),
118 TM.getTargetFeatureString(),
119 *Parser));
Chris Lattneraf632c92010-04-05 23:11:24 +0000120 if (!TAP)
Chris Lattner75361b62010-04-07 22:58:41 +0000121 report_fatal_error("Inline asm not supported by this streamer because"
Benjamin Kramer1bd73352010-04-08 10:44:28 +0000122 " we don't have an asm parser for this target\n");
Daniel Dunbar9fbb37e2010-07-18 18:31:33 +0000123 Parser->setTargetParser(*TAP.get());
Chris Lattneraf632c92010-04-05 23:11:24 +0000124
125 // Don't implicitly switch to the text section before the asm.
Daniel Dunbar9fbb37e2010-07-18 18:31:33 +0000126 int Res = Parser->Run(/*NoInitialTextSection*/ true,
127 /*NoFinalize*/ true);
Chris Lattner6eb78062010-04-06 00:55:39 +0000128 if (Res && !HasDiagHandler)
Chris Lattner75361b62010-04-07 22:58:41 +0000129 report_fatal_error("Error parsing inline asm\n");
Chris Lattner736e31d2010-04-04 18:34:07 +0000130}
131
132
133/// EmitInlineAsm - This method formats and emits the specified machine
134/// instruction that is an inline asm.
135void AsmPrinter::EmitInlineAsm(const MachineInstr *MI) const {
136 assert(MI->isInlineAsm() && "printInlineAsm only works on inline asms");
Jim Grosbach2b2de242010-10-01 23:29:12 +0000137
Chris Lattner736e31d2010-04-04 18:34:07 +0000138 unsigned NumOperands = MI->getNumOperands();
Jim Grosbach2b2de242010-10-01 23:29:12 +0000139
Chris Lattner736e31d2010-04-04 18:34:07 +0000140 // Count the number of register definitions to find the asm string.
141 unsigned NumDefs = 0;
142 for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef();
143 ++NumDefs)
Chris Lattnercf9a4152010-04-07 05:38:05 +0000144 assert(NumDefs != NumOperands-2 && "No asm string?");
Jim Grosbach2b2de242010-10-01 23:29:12 +0000145
Chris Lattner736e31d2010-04-04 18:34:07 +0000146 assert(MI->getOperand(NumDefs).isSymbol() && "No asm string?");
147
148 // Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
149 const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
150
151 // If this asmstr is empty, just print the #APP/#NOAPP markers.
152 // These are useful to see where empty asm's wound up.
153 if (AsmStr[0] == 0) {
Chris Lattner4c842dd2010-04-05 22:42:30 +0000154 // Don't emit the comments if writing to a .o file.
Chris Lattner736e31d2010-04-04 18:34:07 +0000155 if (!OutStreamer.hasRawTextSupport()) return;
156
157 OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
158 MAI->getInlineAsmStart());
159 OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
160 MAI->getInlineAsmEnd());
161 return;
162 }
163
164 // Emit the #APP start marker. This has to happen even if verbose-asm isn't
165 // enabled, so we use EmitRawText.
166 if (OutStreamer.hasRawTextSupport())
167 OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
168 MAI->getInlineAsmStart());
169
Chris Lattnercf9a4152010-04-07 05:38:05 +0000170 // Get the !srcloc metadata node if we have it, and decode the loc cookie from
171 // it.
172 unsigned LocCookie = 0;
Chris Lattnera38941d2010-11-17 07:53:40 +0000173 const MDNode *LocMD = 0;
Chris Lattnerd0024fe2010-04-08 18:20:52 +0000174 for (unsigned i = MI->getNumOperands(); i != 0; --i) {
Chris Lattnera38941d2010-11-17 07:53:40 +0000175 if (MI->getOperand(i-1).isMetadata() &&
176 (LocMD = MI->getOperand(i-1).getMetadata()) &&
177 LocMD->getNumOperands() != 0) {
178 if (const ConstantInt *CI = dyn_cast<ConstantInt>(LocMD->getOperand(0))) {
179 LocCookie = CI->getZExtValue();
180 break;
181 }
182 }
Chris Lattnercf9a4152010-04-07 05:38:05 +0000183 }
Jim Grosbach2b2de242010-10-01 23:29:12 +0000184
Chris Lattner736e31d2010-04-04 18:34:07 +0000185 // Emit the inline asm to a temporary string so we can emit it through
186 // EmitInlineAsm.
187 SmallString<256> StringData;
188 raw_svector_ostream OS(StringData);
Jim Grosbach2b2de242010-10-01 23:29:12 +0000189
Chris Lattner736e31d2010-04-04 18:34:07 +0000190 OS << '\t';
191
192 // The variant of the current asmprinter.
193 int AsmPrinterVariant = MAI->getAssemblerDialect();
194
195 int CurVariant = -1; // The number of the {.|.|.} region we are in.
196 const char *LastEmitted = AsmStr; // One past the last character emitted.
Jim Grosbach2b2de242010-10-01 23:29:12 +0000197
Chris Lattner736e31d2010-04-04 18:34:07 +0000198 while (*LastEmitted) {
199 switch (*LastEmitted) {
200 default: {
201 // Not a special case, emit the string section literally.
202 const char *LiteralEnd = LastEmitted+1;
203 while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
204 *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
205 ++LiteralEnd;
206 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
207 OS.write(LastEmitted, LiteralEnd-LastEmitted);
208 LastEmitted = LiteralEnd;
209 break;
210 }
211 case '\n':
212 ++LastEmitted; // Consume newline character.
Chris Lattner4c842dd2010-04-05 22:42:30 +0000213 OS << '\n'; // Indent code with newline.
Chris Lattner736e31d2010-04-04 18:34:07 +0000214 break;
215 case '$': {
216 ++LastEmitted; // Consume '$' character.
217 bool Done = true;
218
219 // Handle escapes.
220 switch (*LastEmitted) {
221 default: Done = false; break;
222 case '$': // $$ -> $
223 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
224 OS << '$';
225 ++LastEmitted; // Consume second '$' character.
226 break;
227 case '(': // $( -> same as GCC's { character.
228 ++LastEmitted; // Consume '(' character.
Chris Lattnerfee455e2010-04-07 05:27:36 +0000229 if (CurVariant != -1)
Benjamin Kramer1bd73352010-04-08 10:44:28 +0000230 report_fatal_error("Nested variants found in inline asm string: '" +
231 Twine(AsmStr) + "'");
Chris Lattner736e31d2010-04-04 18:34:07 +0000232 CurVariant = 0; // We're in the first variant now.
233 break;
234 case '|':
235 ++LastEmitted; // consume '|' character.
236 if (CurVariant == -1)
237 OS << '|'; // this is gcc's behavior for | outside a variant
238 else
239 ++CurVariant; // We're in the next variant.
240 break;
241 case ')': // $) -> same as GCC's } char.
242 ++LastEmitted; // consume ')' character.
243 if (CurVariant == -1)
244 OS << '}'; // this is gcc's behavior for } outside a variant
Jim Grosbach2b2de242010-10-01 23:29:12 +0000245 else
Chris Lattner736e31d2010-04-04 18:34:07 +0000246 CurVariant = -1;
247 break;
248 }
249 if (Done) break;
Jim Grosbach2b2de242010-10-01 23:29:12 +0000250
Chris Lattner736e31d2010-04-04 18:34:07 +0000251 bool HasCurlyBraces = false;
252 if (*LastEmitted == '{') { // ${variable}
253 ++LastEmitted; // Consume '{' character.
254 HasCurlyBraces = true;
255 }
Jim Grosbach2b2de242010-10-01 23:29:12 +0000256
Chris Lattner736e31d2010-04-04 18:34:07 +0000257 // If we have ${:foo}, then this is not a real operand reference, it is a
258 // "magic" string reference, just like in .td files. Arrange to call
259 // PrintSpecial.
260 if (HasCurlyBraces && *LastEmitted == ':') {
261 ++LastEmitted;
262 const char *StrStart = LastEmitted;
263 const char *StrEnd = strchr(StrStart, '}');
264 if (StrEnd == 0)
Benjamin Kramer1bd73352010-04-08 10:44:28 +0000265 report_fatal_error("Unterminated ${:foo} operand in inline asm"
266 " string: '" + Twine(AsmStr) + "'");
Jim Grosbach2b2de242010-10-01 23:29:12 +0000267
Chris Lattner736e31d2010-04-04 18:34:07 +0000268 std::string Val(StrStart, StrEnd);
269 PrintSpecial(MI, OS, Val.c_str());
270 LastEmitted = StrEnd+1;
271 break;
272 }
Jim Grosbach2b2de242010-10-01 23:29:12 +0000273
Chris Lattner736e31d2010-04-04 18:34:07 +0000274 const char *IDStart = LastEmitted;
Chris Lattner65eeaad2010-04-04 18:42:18 +0000275 const char *IDEnd = IDStart;
Jim Grosbach2b2de242010-10-01 23:29:12 +0000276 while (*IDEnd >= '0' && *IDEnd <= '9') ++IDEnd;
277
Chris Lattner65eeaad2010-04-04 18:42:18 +0000278 unsigned Val;
279 if (StringRef(IDStart, IDEnd-IDStart).getAsInteger(10, Val))
Benjamin Kramer1bd73352010-04-08 10:44:28 +0000280 report_fatal_error("Bad $ operand number in inline asm string: '" +
281 Twine(AsmStr) + "'");
Chris Lattner736e31d2010-04-04 18:34:07 +0000282 LastEmitted = IDEnd;
Jim Grosbach2b2de242010-10-01 23:29:12 +0000283
Chris Lattner736e31d2010-04-04 18:34:07 +0000284 char Modifier[2] = { 0, 0 };
Jim Grosbach2b2de242010-10-01 23:29:12 +0000285
Chris Lattner736e31d2010-04-04 18:34:07 +0000286 if (HasCurlyBraces) {
287 // If we have curly braces, check for a modifier character. This
288 // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
289 if (*LastEmitted == ':') {
290 ++LastEmitted; // Consume ':' character.
Chris Lattner4c842dd2010-04-05 22:42:30 +0000291 if (*LastEmitted == 0)
Chris Lattner75361b62010-04-07 22:58:41 +0000292 report_fatal_error("Bad ${:} expression in inline asm string: '" +
Benjamin Kramer1bd73352010-04-08 10:44:28 +0000293 Twine(AsmStr) + "'");
Jim Grosbach2b2de242010-10-01 23:29:12 +0000294
Chris Lattner736e31d2010-04-04 18:34:07 +0000295 Modifier[0] = *LastEmitted;
296 ++LastEmitted; // Consume modifier character.
297 }
Jim Grosbach2b2de242010-10-01 23:29:12 +0000298
Chris Lattner4c842dd2010-04-05 22:42:30 +0000299 if (*LastEmitted != '}')
Benjamin Kramer1bd73352010-04-08 10:44:28 +0000300 report_fatal_error("Bad ${} expression in inline asm string: '" +
301 Twine(AsmStr) + "'");
Chris Lattner736e31d2010-04-04 18:34:07 +0000302 ++LastEmitted; // Consume '}' character.
303 }
Jim Grosbach2b2de242010-10-01 23:29:12 +0000304
Chris Lattner4c842dd2010-04-05 22:42:30 +0000305 if (Val >= NumOperands-1)
Benjamin Kramer1bd73352010-04-08 10:44:28 +0000306 report_fatal_error("Invalid $ operand number in inline asm string: '" +
307 Twine(AsmStr) + "'");
Jim Grosbach2b2de242010-10-01 23:29:12 +0000308
Chris Lattner736e31d2010-04-04 18:34:07 +0000309 // Okay, we finally have a value number. Ask the target to print this
310 // operand!
311 if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
Evan Chengc36b7062011-01-07 23:50:32 +0000312 unsigned OpNo = InlineAsm::MIOp_FirstOperand;
Chris Lattner736e31d2010-04-04 18:34:07 +0000313
314 bool Error = false;
315
316 // Scan to find the machine operand number for the operand.
317 for (; Val; --Val) {
318 if (OpNo >= MI->getNumOperands()) break;
319 unsigned OpFlags = MI->getOperand(OpNo).getImm();
320 OpNo += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
321 }
322
323 if (OpNo >= MI->getNumOperands()) {
324 Error = true;
325 } else {
326 unsigned OpFlags = MI->getOperand(OpNo).getImm();
327 ++OpNo; // Skip over the ID number.
328
329 if (Modifier[0] == 'l') // labels are target independent
330 // FIXME: What if the operand isn't an MBB, report error?
331 OS << *MI->getOperand(OpNo).getMBB()->getSymbol();
332 else {
333 AsmPrinter *AP = const_cast<AsmPrinter*>(this);
Chris Lattnerfee455e2010-04-07 05:27:36 +0000334 if (InlineAsm::isMemKind(OpFlags)) {
Chris Lattner736e31d2010-04-04 18:34:07 +0000335 Error = AP->PrintAsmMemoryOperand(MI, OpNo, AsmPrinterVariant,
336 Modifier[0] ? Modifier : 0,
337 OS);
338 } else {
339 Error = AP->PrintAsmOperand(MI, OpNo, AsmPrinterVariant,
340 Modifier[0] ? Modifier : 0, OS);
341 }
342 }
343 }
344 if (Error) {
345 std::string msg;
346 raw_string_ostream Msg(msg);
Chris Lattner38686bd2010-04-07 23:40:44 +0000347 Msg << "invalid operand in inline asm: '" << AsmStr << "'";
348 MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
Chris Lattner736e31d2010-04-04 18:34:07 +0000349 }
350 }
351 break;
352 }
353 }
354 }
Chris Lattneraf632c92010-04-05 23:11:24 +0000355 OS << '\n' << (char)0; // null terminate string.
Chris Lattnera38941d2010-11-17 07:53:40 +0000356 EmitInlineAsm(OS.str(), LocMD);
Jim Grosbach2b2de242010-10-01 23:29:12 +0000357
Chris Lattner736e31d2010-04-04 18:34:07 +0000358 // Emit the #NOAPP end marker. This has to happen even if verbose-asm isn't
359 // enabled, so we use EmitRawText.
360 if (OutStreamer.hasRawTextSupport())
361 OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
362 MAI->getInlineAsmEnd());
363}
364
365
366/// PrintSpecial - Print information related to the specified machine instr
367/// that is independent of the operand, and may be independent of the instr
368/// itself. This can be useful for portably encoding the comment character
369/// or other bits of target-specific knowledge into the asmstrings. The
370/// syntax used is ${:comment}. Targets can override this to add support
371/// for their own strange codes.
372void AsmPrinter::PrintSpecial(const MachineInstr *MI, raw_ostream &OS,
373 const char *Code) const {
374 if (!strcmp(Code, "private")) {
375 OS << MAI->getPrivateGlobalPrefix();
376 } else if (!strcmp(Code, "comment")) {
377 OS << MAI->getCommentString();
378 } else if (!strcmp(Code, "uid")) {
379 // Comparing the address of MI isn't sufficient, because machineinstrs may
380 // be allocated to the same address across functions.
Jim Grosbach2b2de242010-10-01 23:29:12 +0000381
Chris Lattner736e31d2010-04-04 18:34:07 +0000382 // If this is a new LastFn instruction, bump the counter.
383 if (LastMI != MI || LastFn != getFunctionNumber()) {
384 ++Counter;
385 LastMI = MI;
386 LastFn = getFunctionNumber();
387 }
388 OS << Counter;
389 } else {
390 std::string msg;
391 raw_string_ostream Msg(msg);
392 Msg << "Unknown special formatter '" << Code
393 << "' for machine instr: " << *MI;
Chris Lattner75361b62010-04-07 22:58:41 +0000394 report_fatal_error(Msg.str());
Jim Grosbach2b2de242010-10-01 23:29:12 +0000395 }
Chris Lattner736e31d2010-04-04 18:34:07 +0000396}
397
398/// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
399/// instruction, using the specified assembler variant. Targets should
400/// override this to format as appropriate.
401bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
402 unsigned AsmVariant, const char *ExtraCode,
403 raw_ostream &O) {
404 // Target doesn't support this yet!
405 return true;
406}
407
408bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
409 unsigned AsmVariant,
410 const char *ExtraCode, raw_ostream &O) {
411 // Target doesn't support this yet!
412 return true;
413}
414