blob: 5ac455e1a1a11d75fee41536e20451297ac10515 [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"
Evan Chengffc0e732011-07-09 05:47:46 +000024#include "llvm/MC/MCSubtargetInfo.h"
Chris Lattner736e31d2010-04-04 18:34:07 +000025#include "llvm/MC/MCSymbol.h"
Chris Lattneraf632c92010-04-05 23:11:24 +000026#include "llvm/Target/TargetAsmParser.h"
27#include "llvm/Target/TargetMachine.h"
28#include "llvm/Target/TargetRegistry.h"
29#include "llvm/ADT/OwningPtr.h"
Chris Lattner736e31d2010-04-04 18:34:07 +000030#include "llvm/ADT/SmallString.h"
31#include "llvm/ADT/Twine.h"
32#include "llvm/Support/ErrorHandling.h"
Chris Lattneraf632c92010-04-05 23:11:24 +000033#include "llvm/Support/MemoryBuffer.h"
34#include "llvm/Support/SourceMgr.h"
Chris Lattner736e31d2010-04-04 18:34:07 +000035#include "llvm/Support/raw_ostream.h"
Chris Lattner736e31d2010-04-04 18:34:07 +000036using namespace llvm;
37
Chris Lattner6e30c6a2010-11-17 08:03:32 +000038namespace {
39 struct SrcMgrDiagInfo {
40 const MDNode *LocInfo;
Chris Lattner4afa1282010-11-17 08:13:01 +000041 LLVMContext::InlineAsmDiagHandlerTy DiagHandler;
Chris Lattner6e30c6a2010-11-17 08:03:32 +000042 void *DiagContext;
43 };
44}
45
46/// SrcMgrDiagHandler - This callback is invoked when the SourceMgr for an
47/// inline asm has an error in it. diagInfo is a pointer to the SrcMgrDiagInfo
48/// struct above.
Chris Lattner4afa1282010-11-17 08:13:01 +000049static void SrcMgrDiagHandler(const SMDiagnostic &Diag, void *diagInfo) {
Chris Lattner6e30c6a2010-11-17 08:03:32 +000050 SrcMgrDiagInfo *DiagInfo = static_cast<SrcMgrDiagInfo *>(diagInfo);
51 assert(DiagInfo && "Diagnostic context not passed down?");
52
Chris Lattnerce1b9ad2010-11-17 08:20:42 +000053 // If the inline asm had metadata associated with it, pull out a location
54 // cookie corresponding to which line the error occurred on.
Chris Lattner6e30c6a2010-11-17 08:03:32 +000055 unsigned LocCookie = 0;
Chris Lattnerce1b9ad2010-11-17 08:20:42 +000056 if (const MDNode *LocInfo = DiagInfo->LocInfo) {
57 unsigned ErrorLine = Diag.getLineNo()-1;
58 if (ErrorLine >= LocInfo->getNumOperands())
59 ErrorLine = 0;
60
61 if (LocInfo->getNumOperands() != 0)
62 if (const ConstantInt *CI =
63 dyn_cast<ConstantInt>(LocInfo->getOperand(ErrorLine)))
Chris Lattner6e30c6a2010-11-17 08:03:32 +000064 LocCookie = CI->getZExtValue();
Chris Lattnerce1b9ad2010-11-17 08:20:42 +000065 }
Chris Lattner6e30c6a2010-11-17 08:03:32 +000066
Chris Lattner4afa1282010-11-17 08:13:01 +000067 DiagInfo->DiagHandler(Diag, DiagInfo->DiagContext, LocCookie);
Chris Lattner6e30c6a2010-11-17 08:03:32 +000068}
69
Chris Lattner736e31d2010-04-04 18:34:07 +000070/// EmitInlineAsm - Emit a blob of inline asm to the output streamer.
Chris Lattnera38941d2010-11-17 07:53:40 +000071void AsmPrinter::EmitInlineAsm(StringRef Str, const MDNode *LocMDNode) const {
Chris Lattner736e31d2010-04-04 18:34:07 +000072 assert(!Str.empty() && "Can't emit empty inline asm block");
Jim Grosbach2b2de242010-10-01 23:29:12 +000073
Chris Lattneraf632c92010-04-05 23:11:24 +000074 // Remember if the buffer is nul terminated or not so we can avoid a copy.
75 bool isNullTerminated = Str.back() == 0;
76 if (isNullTerminated)
77 Str = Str.substr(0, Str.size()-1);
Jim Grosbach2b2de242010-10-01 23:29:12 +000078
Chris Lattner736e31d2010-04-04 18:34:07 +000079 // If the output streamer is actually a .s file, just emit the blob textually.
80 // This is useful in case the asm parser doesn't handle something but the
81 // system assembler does.
82 if (OutStreamer.hasRawTextSupport()) {
83 OutStreamer.EmitRawText(Str);
84 return;
85 }
Jim Grosbach2b2de242010-10-01 23:29:12 +000086
Chris Lattneraf632c92010-04-05 23:11:24 +000087 SourceMgr SrcMgr;
Chris Lattner6e30c6a2010-11-17 08:03:32 +000088 SrcMgrDiagInfo DiagInfo;
Jim Grosbach2b2de242010-10-01 23:29:12 +000089
Chris Lattner6eb78062010-04-06 00:55:39 +000090 // If the current LLVMContext has an inline asm handler, set it in SourceMgr.
91 LLVMContext &LLVMCtx = MMI->getModule()->getContext();
92 bool HasDiagHandler = false;
Chris Lattner4afa1282010-11-17 08:13:01 +000093 if (LLVMCtx.getInlineAsmDiagnosticHandler() != 0) {
Chris Lattner6e30c6a2010-11-17 08:03:32 +000094 // If the source manager has an issue, we arrange for SrcMgrDiagHandler
95 // to be invoked, getting DiagInfo passed into it.
96 DiagInfo.LocInfo = LocMDNode;
Chris Lattner4afa1282010-11-17 08:13:01 +000097 DiagInfo.DiagHandler = LLVMCtx.getInlineAsmDiagnosticHandler();
Chris Lattner6e30c6a2010-11-17 08:03:32 +000098 DiagInfo.DiagContext = LLVMCtx.getInlineAsmDiagnosticContext();
99 SrcMgr.setDiagHandler(SrcMgrDiagHandler, &DiagInfo);
Chris Lattner6eb78062010-04-06 00:55:39 +0000100 HasDiagHandler = true;
101 }
Jim Grosbach2b2de242010-10-01 23:29:12 +0000102
Chris Lattneraf632c92010-04-05 23:11:24 +0000103 MemoryBuffer *Buffer;
104 if (isNullTerminated)
105 Buffer = MemoryBuffer::getMemBuffer(Str, "<inline asm>");
106 else
107 Buffer = MemoryBuffer::getMemBufferCopy(Str, "<inline asm>");
108
109 // Tell SrcMgr about this buffer, it takes ownership of the buffer.
110 SrcMgr.AddNewSourceBuffer(Buffer, SMLoc());
Jim Grosbach2b2de242010-10-01 23:29:12 +0000111
Daniel Dunbar9fbb37e2010-07-18 18:31:33 +0000112 OwningPtr<MCAsmParser> Parser(createMCAsmParser(TM.getTarget(), SrcMgr,
113 OutContext, OutStreamer,
114 *MAI));
Evan Chengebdeeab2011-07-08 01:53:10 +0000115
Evan Chengffc0e732011-07-09 05:47:46 +0000116 // FIXME: It would be nice if we can avoid createing a new instance of
117 // MCSubtargetInfo here given TargetSubtargetInfo is available. However,
118 // we have to watch out for asm directives which can change subtarget
119 // state. e.g. .code 16, .code 32.
120 OwningPtr<MCSubtargetInfo>
121 STI(TM.getTarget().createMCSubtargetInfo(TM.getTargetTriple(),
122 TM.getTargetCPU(),
123 TM.getTargetFeatureString()));
124 OwningPtr<TargetAsmParser> TAP(TM.getTarget().createAsmParser(*STI, *Parser));
Chris Lattneraf632c92010-04-05 23:11:24 +0000125 if (!TAP)
Chris Lattner75361b62010-04-07 22:58:41 +0000126 report_fatal_error("Inline asm not supported by this streamer because"
Benjamin Kramer1bd73352010-04-08 10:44:28 +0000127 " we don't have an asm parser for this target\n");
Daniel Dunbar9fbb37e2010-07-18 18:31:33 +0000128 Parser->setTargetParser(*TAP.get());
Chris Lattneraf632c92010-04-05 23:11:24 +0000129
130 // Don't implicitly switch to the text section before the asm.
Daniel Dunbar9fbb37e2010-07-18 18:31:33 +0000131 int Res = Parser->Run(/*NoInitialTextSection*/ true,
132 /*NoFinalize*/ true);
Chris Lattner6eb78062010-04-06 00:55:39 +0000133 if (Res && !HasDiagHandler)
Chris Lattner75361b62010-04-07 22:58:41 +0000134 report_fatal_error("Error parsing inline asm\n");
Chris Lattner736e31d2010-04-04 18:34:07 +0000135}
136
137
138/// EmitInlineAsm - This method formats and emits the specified machine
139/// instruction that is an inline asm.
140void AsmPrinter::EmitInlineAsm(const MachineInstr *MI) const {
141 assert(MI->isInlineAsm() && "printInlineAsm only works on inline asms");
Jim Grosbach2b2de242010-10-01 23:29:12 +0000142
Chris Lattner736e31d2010-04-04 18:34:07 +0000143 unsigned NumOperands = MI->getNumOperands();
Jim Grosbach2b2de242010-10-01 23:29:12 +0000144
Chris Lattner736e31d2010-04-04 18:34:07 +0000145 // Count the number of register definitions to find the asm string.
146 unsigned NumDefs = 0;
147 for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef();
148 ++NumDefs)
Chris Lattnercf9a4152010-04-07 05:38:05 +0000149 assert(NumDefs != NumOperands-2 && "No asm string?");
Jim Grosbach2b2de242010-10-01 23:29:12 +0000150
Chris Lattner736e31d2010-04-04 18:34:07 +0000151 assert(MI->getOperand(NumDefs).isSymbol() && "No asm string?");
152
153 // Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
154 const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
155
156 // If this asmstr is empty, just print the #APP/#NOAPP markers.
157 // These are useful to see where empty asm's wound up.
158 if (AsmStr[0] == 0) {
Chris Lattner4c842dd2010-04-05 22:42:30 +0000159 // Don't emit the comments if writing to a .o file.
Chris Lattner736e31d2010-04-04 18:34:07 +0000160 if (!OutStreamer.hasRawTextSupport()) return;
161
162 OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
163 MAI->getInlineAsmStart());
164 OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
165 MAI->getInlineAsmEnd());
166 return;
167 }
168
169 // Emit the #APP start marker. This has to happen even if verbose-asm isn't
170 // enabled, so we use EmitRawText.
171 if (OutStreamer.hasRawTextSupport())
172 OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
173 MAI->getInlineAsmStart());
174
Chris Lattnercf9a4152010-04-07 05:38:05 +0000175 // Get the !srcloc metadata node if we have it, and decode the loc cookie from
176 // it.
177 unsigned LocCookie = 0;
Chris Lattnera38941d2010-11-17 07:53:40 +0000178 const MDNode *LocMD = 0;
Chris Lattnerd0024fe2010-04-08 18:20:52 +0000179 for (unsigned i = MI->getNumOperands(); i != 0; --i) {
Chris Lattnera38941d2010-11-17 07:53:40 +0000180 if (MI->getOperand(i-1).isMetadata() &&
181 (LocMD = MI->getOperand(i-1).getMetadata()) &&
182 LocMD->getNumOperands() != 0) {
183 if (const ConstantInt *CI = dyn_cast<ConstantInt>(LocMD->getOperand(0))) {
184 LocCookie = CI->getZExtValue();
185 break;
186 }
187 }
Chris Lattnercf9a4152010-04-07 05:38:05 +0000188 }
Jim Grosbach2b2de242010-10-01 23:29:12 +0000189
Chris Lattner736e31d2010-04-04 18:34:07 +0000190 // Emit the inline asm to a temporary string so we can emit it through
191 // EmitInlineAsm.
192 SmallString<256> StringData;
193 raw_svector_ostream OS(StringData);
Jim Grosbach2b2de242010-10-01 23:29:12 +0000194
Chris Lattner736e31d2010-04-04 18:34:07 +0000195 OS << '\t';
196
197 // The variant of the current asmprinter.
198 int AsmPrinterVariant = MAI->getAssemblerDialect();
199
200 int CurVariant = -1; // The number of the {.|.|.} region we are in.
201 const char *LastEmitted = AsmStr; // One past the last character emitted.
Jim Grosbach2b2de242010-10-01 23:29:12 +0000202
Chris Lattner736e31d2010-04-04 18:34:07 +0000203 while (*LastEmitted) {
204 switch (*LastEmitted) {
205 default: {
206 // Not a special case, emit the string section literally.
207 const char *LiteralEnd = LastEmitted+1;
208 while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
209 *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
210 ++LiteralEnd;
211 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
212 OS.write(LastEmitted, LiteralEnd-LastEmitted);
213 LastEmitted = LiteralEnd;
214 break;
215 }
216 case '\n':
217 ++LastEmitted; // Consume newline character.
Chris Lattner4c842dd2010-04-05 22:42:30 +0000218 OS << '\n'; // Indent code with newline.
Chris Lattner736e31d2010-04-04 18:34:07 +0000219 break;
220 case '$': {
221 ++LastEmitted; // Consume '$' character.
222 bool Done = true;
223
224 // Handle escapes.
225 switch (*LastEmitted) {
226 default: Done = false; break;
227 case '$': // $$ -> $
228 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
229 OS << '$';
230 ++LastEmitted; // Consume second '$' character.
231 break;
232 case '(': // $( -> same as GCC's { character.
233 ++LastEmitted; // Consume '(' character.
Chris Lattnerfee455e2010-04-07 05:27:36 +0000234 if (CurVariant != -1)
Benjamin Kramer1bd73352010-04-08 10:44:28 +0000235 report_fatal_error("Nested variants found in inline asm string: '" +
236 Twine(AsmStr) + "'");
Chris Lattner736e31d2010-04-04 18:34:07 +0000237 CurVariant = 0; // We're in the first variant now.
238 break;
239 case '|':
240 ++LastEmitted; // consume '|' character.
241 if (CurVariant == -1)
242 OS << '|'; // this is gcc's behavior for | outside a variant
243 else
244 ++CurVariant; // We're in the next variant.
245 break;
246 case ')': // $) -> same as GCC's } char.
247 ++LastEmitted; // consume ')' character.
248 if (CurVariant == -1)
249 OS << '}'; // this is gcc's behavior for } outside a variant
Jim Grosbach2b2de242010-10-01 23:29:12 +0000250 else
Chris Lattner736e31d2010-04-04 18:34:07 +0000251 CurVariant = -1;
252 break;
253 }
254 if (Done) break;
Jim Grosbach2b2de242010-10-01 23:29:12 +0000255
Chris Lattner736e31d2010-04-04 18:34:07 +0000256 bool HasCurlyBraces = false;
257 if (*LastEmitted == '{') { // ${variable}
258 ++LastEmitted; // Consume '{' character.
259 HasCurlyBraces = true;
260 }
Jim Grosbach2b2de242010-10-01 23:29:12 +0000261
Chris Lattner736e31d2010-04-04 18:34:07 +0000262 // If we have ${:foo}, then this is not a real operand reference, it is a
263 // "magic" string reference, just like in .td files. Arrange to call
264 // PrintSpecial.
265 if (HasCurlyBraces && *LastEmitted == ':') {
266 ++LastEmitted;
267 const char *StrStart = LastEmitted;
268 const char *StrEnd = strchr(StrStart, '}');
269 if (StrEnd == 0)
Benjamin Kramer1bd73352010-04-08 10:44:28 +0000270 report_fatal_error("Unterminated ${:foo} operand in inline asm"
271 " string: '" + Twine(AsmStr) + "'");
Jim Grosbach2b2de242010-10-01 23:29:12 +0000272
Chris Lattner736e31d2010-04-04 18:34:07 +0000273 std::string Val(StrStart, StrEnd);
274 PrintSpecial(MI, OS, Val.c_str());
275 LastEmitted = StrEnd+1;
276 break;
277 }
Jim Grosbach2b2de242010-10-01 23:29:12 +0000278
Chris Lattner736e31d2010-04-04 18:34:07 +0000279 const char *IDStart = LastEmitted;
Chris Lattner65eeaad2010-04-04 18:42:18 +0000280 const char *IDEnd = IDStart;
Jim Grosbach2b2de242010-10-01 23:29:12 +0000281 while (*IDEnd >= '0' && *IDEnd <= '9') ++IDEnd;
282
Chris Lattner65eeaad2010-04-04 18:42:18 +0000283 unsigned Val;
284 if (StringRef(IDStart, IDEnd-IDStart).getAsInteger(10, Val))
Benjamin Kramer1bd73352010-04-08 10:44:28 +0000285 report_fatal_error("Bad $ operand number in inline asm string: '" +
286 Twine(AsmStr) + "'");
Chris Lattner736e31d2010-04-04 18:34:07 +0000287 LastEmitted = IDEnd;
Jim Grosbach2b2de242010-10-01 23:29:12 +0000288
Chris Lattner736e31d2010-04-04 18:34:07 +0000289 char Modifier[2] = { 0, 0 };
Jim Grosbach2b2de242010-10-01 23:29:12 +0000290
Chris Lattner736e31d2010-04-04 18:34:07 +0000291 if (HasCurlyBraces) {
292 // If we have curly braces, check for a modifier character. This
293 // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
294 if (*LastEmitted == ':') {
295 ++LastEmitted; // Consume ':' character.
Chris Lattner4c842dd2010-04-05 22:42:30 +0000296 if (*LastEmitted == 0)
Chris Lattner75361b62010-04-07 22:58:41 +0000297 report_fatal_error("Bad ${:} expression in inline asm string: '" +
Benjamin Kramer1bd73352010-04-08 10:44:28 +0000298 Twine(AsmStr) + "'");
Jim Grosbach2b2de242010-10-01 23:29:12 +0000299
Chris Lattner736e31d2010-04-04 18:34:07 +0000300 Modifier[0] = *LastEmitted;
301 ++LastEmitted; // Consume modifier character.
302 }
Jim Grosbach2b2de242010-10-01 23:29:12 +0000303
Chris Lattner4c842dd2010-04-05 22:42:30 +0000304 if (*LastEmitted != '}')
Benjamin Kramer1bd73352010-04-08 10:44:28 +0000305 report_fatal_error("Bad ${} expression in inline asm string: '" +
306 Twine(AsmStr) + "'");
Chris Lattner736e31d2010-04-04 18:34:07 +0000307 ++LastEmitted; // Consume '}' character.
308 }
Jim Grosbach2b2de242010-10-01 23:29:12 +0000309
Chris Lattner4c842dd2010-04-05 22:42:30 +0000310 if (Val >= NumOperands-1)
Benjamin Kramer1bd73352010-04-08 10:44:28 +0000311 report_fatal_error("Invalid $ operand number in inline asm string: '" +
312 Twine(AsmStr) + "'");
Jim Grosbach2b2de242010-10-01 23:29:12 +0000313
Chris Lattner736e31d2010-04-04 18:34:07 +0000314 // Okay, we finally have a value number. Ask the target to print this
315 // operand!
316 if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
Evan Chengc36b7062011-01-07 23:50:32 +0000317 unsigned OpNo = InlineAsm::MIOp_FirstOperand;
Chris Lattner736e31d2010-04-04 18:34:07 +0000318
319 bool Error = false;
320
321 // Scan to find the machine operand number for the operand.
322 for (; Val; --Val) {
323 if (OpNo >= MI->getNumOperands()) break;
324 unsigned OpFlags = MI->getOperand(OpNo).getImm();
325 OpNo += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
326 }
327
328 if (OpNo >= MI->getNumOperands()) {
329 Error = true;
330 } else {
331 unsigned OpFlags = MI->getOperand(OpNo).getImm();
332 ++OpNo; // Skip over the ID number.
333
334 if (Modifier[0] == 'l') // labels are target independent
335 // FIXME: What if the operand isn't an MBB, report error?
336 OS << *MI->getOperand(OpNo).getMBB()->getSymbol();
337 else {
338 AsmPrinter *AP = const_cast<AsmPrinter*>(this);
Chris Lattnerfee455e2010-04-07 05:27:36 +0000339 if (InlineAsm::isMemKind(OpFlags)) {
Chris Lattner736e31d2010-04-04 18:34:07 +0000340 Error = AP->PrintAsmMemoryOperand(MI, OpNo, AsmPrinterVariant,
341 Modifier[0] ? Modifier : 0,
342 OS);
343 } else {
344 Error = AP->PrintAsmOperand(MI, OpNo, AsmPrinterVariant,
345 Modifier[0] ? Modifier : 0, OS);
346 }
347 }
348 }
349 if (Error) {
350 std::string msg;
351 raw_string_ostream Msg(msg);
Chris Lattner38686bd2010-04-07 23:40:44 +0000352 Msg << "invalid operand in inline asm: '" << AsmStr << "'";
353 MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
Chris Lattner736e31d2010-04-04 18:34:07 +0000354 }
355 }
356 break;
357 }
358 }
359 }
Chris Lattneraf632c92010-04-05 23:11:24 +0000360 OS << '\n' << (char)0; // null terminate string.
Chris Lattnera38941d2010-11-17 07:53:40 +0000361 EmitInlineAsm(OS.str(), LocMD);
Jim Grosbach2b2de242010-10-01 23:29:12 +0000362
Chris Lattner736e31d2010-04-04 18:34:07 +0000363 // Emit the #NOAPP end marker. This has to happen even if verbose-asm isn't
364 // enabled, so we use EmitRawText.
365 if (OutStreamer.hasRawTextSupport())
366 OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
367 MAI->getInlineAsmEnd());
368}
369
370
371/// PrintSpecial - Print information related to the specified machine instr
372/// that is independent of the operand, and may be independent of the instr
373/// itself. This can be useful for portably encoding the comment character
374/// or other bits of target-specific knowledge into the asmstrings. The
375/// syntax used is ${:comment}. Targets can override this to add support
376/// for their own strange codes.
377void AsmPrinter::PrintSpecial(const MachineInstr *MI, raw_ostream &OS,
378 const char *Code) const {
379 if (!strcmp(Code, "private")) {
380 OS << MAI->getPrivateGlobalPrefix();
381 } else if (!strcmp(Code, "comment")) {
382 OS << MAI->getCommentString();
383 } else if (!strcmp(Code, "uid")) {
384 // Comparing the address of MI isn't sufficient, because machineinstrs may
385 // be allocated to the same address across functions.
Jim Grosbach2b2de242010-10-01 23:29:12 +0000386
Chris Lattner736e31d2010-04-04 18:34:07 +0000387 // If this is a new LastFn instruction, bump the counter.
388 if (LastMI != MI || LastFn != getFunctionNumber()) {
389 ++Counter;
390 LastMI = MI;
391 LastFn = getFunctionNumber();
392 }
393 OS << Counter;
394 } else {
395 std::string msg;
396 raw_string_ostream Msg(msg);
397 Msg << "Unknown special formatter '" << Code
398 << "' for machine instr: " << *MI;
Chris Lattner75361b62010-04-07 22:58:41 +0000399 report_fatal_error(Msg.str());
Jim Grosbach2b2de242010-10-01 23:29:12 +0000400 }
Chris Lattner736e31d2010-04-04 18:34:07 +0000401}
402
403/// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
404/// instruction, using the specified assembler variant. Targets should
405/// override this to format as appropriate.
406bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
407 unsigned AsmVariant, const char *ExtraCode,
408 raw_ostream &O) {
409 // Target doesn't support this yet!
410 return true;
411}
412
413bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
414 unsigned AsmVariant,
415 const char *ExtraCode, raw_ostream &O) {
416 // Target doesn't support this yet!
417 return true;
418}
419