blob: a0f377c63fc6ceef09759bde5404ceac97a8dd05 [file] [log] [blame]
Chris Lattner6a8e0f52004-08-16 23:15:22 +00001//===-- AsmPrinter.cpp - Common AsmPrinter code ---------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the AsmPrinter class.
11//
12//===----------------------------------------------------------------------===//
13
Evan Cheng993e9cf2006-03-03 02:04:29 +000014#include "llvm/CodeGen/AsmPrinter.h"
Evan Cheng38d5e762006-03-01 22:18:09 +000015#include "llvm/Assembly/Writer.h"
Nate Begeman41b1cdc2005-12-06 06:18:55 +000016#include "llvm/DerivedTypes.h"
Chris Lattner6a8e0f52004-08-16 23:15:22 +000017#include "llvm/Constants.h"
Chris Lattnerc0a1eba2005-11-10 18:36:17 +000018#include "llvm/Module.h"
Chris Lattnerf2991ce2005-11-21 08:25:09 +000019#include "llvm/CodeGen/MachineConstantPool.h"
Nate Begeman4ca2ea52006-04-22 18:53:45 +000020#include "llvm/CodeGen/MachineJumpTableInfo.h"
Chris Lattner6a8e0f52004-08-16 23:15:22 +000021#include "llvm/Support/Mangler.h"
Jim Laskeyb74c6662005-08-17 19:34:49 +000022#include "llvm/Support/MathExtras.h"
Owen Anderson8c2c1e92006-05-12 06:33:49 +000023#include "llvm/Target/TargetData.h"
Chris Lattner6a8e0f52004-08-16 23:15:22 +000024#include "llvm/Target/TargetMachine.h"
Duraid Madina26b037e2005-12-28 06:29:02 +000025#include <iostream>
Chris Lattneraa23fa92006-02-01 22:41:11 +000026#include <cerrno>
Chris Lattner6a8e0f52004-08-16 23:15:22 +000027using namespace llvm;
28
Chris Lattnerf0e9aef2005-12-13 06:32:10 +000029AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm)
30: FunctionNumber(0), O(o), TM(tm),
31 CommentString("#"),
32 GlobalPrefix(""),
33 PrivateGlobalPrefix("."),
34 GlobalVarAddrPrefix(""),
35 GlobalVarAddrSuffix(""),
36 FunctionAddrPrefix(""),
37 FunctionAddrSuffix(""),
Chris Lattnera633c3132006-05-05 21:47:05 +000038 InlineAsmStart("#APP"),
39 InlineAsmEnd("#NO_APP"),
Chris Lattnerf0e9aef2005-12-13 06:32:10 +000040 ZeroDirective("\t.zero\t"),
Jeff Cohenf34ddb12006-05-02 03:46:13 +000041 ZeroDirectiveSuffix(0),
Chris Lattnerf0e9aef2005-12-13 06:32:10 +000042 AsciiDirective("\t.ascii\t"),
43 AscizDirective("\t.asciz\t"),
44 Data8bitsDirective("\t.byte\t"),
45 Data16bitsDirective("\t.short\t"),
46 Data32bitsDirective("\t.long\t"),
47 Data64bitsDirective("\t.quad\t"),
48 AlignDirective("\t.align\t"),
49 AlignmentIsInBytes(true),
50 SwitchToSectionDirective("\t.section\t"),
Chris Lattner4ebc6a22006-05-09 05:33:48 +000051 TextSectionStartSuffix(""),
52 DataSectionStartSuffix(""),
53 SectionEndDirectiveSuffix(0),
Chris Lattnerf0e9aef2005-12-13 06:32:10 +000054 ConstantPoolSection("\t.section .rodata\n"),
Nate Begeman78756502006-07-27 01:13:04 +000055 JumpTableDataSection("\t.section .rodata\n"),
56 JumpTableTextSection("\t.text\n"),
Chris Lattnerf0e9aef2005-12-13 06:32:10 +000057 StaticCtorsSection("\t.section .ctors,\"aw\",@progbits"),
58 StaticDtorsSection("\t.section .dtors,\"aw\",@progbits"),
Evan Chengec1d60b2006-06-29 00:26:09 +000059 FourByteConstantSection(0),
60 EightByteConstantSection(0),
61 SixteenByteConstantSection(0),
Chris Lattnerf0e9aef2005-12-13 06:32:10 +000062 LCOMMDirective(0),
63 COMMDirective("\t.comm\t"),
64 COMMDirectiveTakesAlignment(true),
65 HasDotTypeDotSizeDirective(true) {
66}
67
68
Chris Lattner8488ba22006-05-09 04:59:56 +000069/// SwitchToTextSection - Switch to the specified text section of the executable
70/// if we are not already in it!
Chris Lattner2ea5c992005-11-21 07:06:27 +000071///
Chris Lattner8488ba22006-05-09 04:59:56 +000072void AsmPrinter::SwitchToTextSection(const char *NewSection,
73 const GlobalValue *GV) {
Chris Lattner2ea5c992005-11-21 07:06:27 +000074 std::string NS;
Chris Lattner8c2bfc02006-05-09 05:24:50 +000075 if (GV && GV->hasSection())
Chris Lattnerf8017922006-05-09 16:41:59 +000076 NS = SwitchToSectionDirective + GV->getSection();
Chris Lattner8c2bfc02006-05-09 05:24:50 +000077 else
78 NS = NewSection;
79
80 // If we're already in this section, we're done.
81 if (CurrentSection == NS) return;
Jeff Cohen470f4312006-05-02 03:58:45 +000082
Chris Lattner4ebc6a22006-05-09 05:33:48 +000083 // Close the current section, if applicable.
84 if (SectionEndDirectiveSuffix && !CurrentSection.empty())
85 O << CurrentSection << SectionEndDirectiveSuffix << "\n";
Jeff Cohen470f4312006-05-02 03:58:45 +000086
Chris Lattner4ebc6a22006-05-09 05:33:48 +000087 CurrentSection = NS;
88
89 if (!CurrentSection.empty())
90 O << CurrentSection << TextSectionStartSuffix << '\n';
Chris Lattner2ea5c992005-11-21 07:06:27 +000091}
92
Nate Begeman78756502006-07-27 01:13:04 +000093/// SwitchToDataSection - Switch to the specified data section of the executable
Chris Lattner8488ba22006-05-09 04:59:56 +000094/// if we are not already in it!
95///
96void AsmPrinter::SwitchToDataSection(const char *NewSection,
97 const GlobalValue *GV) {
98 std::string NS;
Chris Lattner6341df82006-05-09 05:23:12 +000099 if (GV && GV->hasSection())
100 NS = SwitchToSectionDirective + GV->getSection();
101 else
102 NS = NewSection;
Chris Lattner8488ba22006-05-09 04:59:56 +0000103
Chris Lattner6341df82006-05-09 05:23:12 +0000104 // If we're already in this section, we're done.
105 if (CurrentSection == NS) return;
106
Chris Lattner4ebc6a22006-05-09 05:33:48 +0000107 // Close the current section, if applicable.
108 if (SectionEndDirectiveSuffix && !CurrentSection.empty())
109 O << CurrentSection << SectionEndDirectiveSuffix << "\n";
110
111 CurrentSection = NS;
Chris Lattner8488ba22006-05-09 04:59:56 +0000112
Chris Lattner4ebc6a22006-05-09 05:33:48 +0000113 if (!CurrentSection.empty())
114 O << CurrentSection << DataSectionStartSuffix << '\n';
Chris Lattner8488ba22006-05-09 04:59:56 +0000115}
116
117
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000118bool AsmPrinter::doInitialization(Module &M) {
Chris Lattner6d42cbd2004-08-17 06:06:19 +0000119 Mang = new Mangler(M, GlobalPrefix);
Chris Lattnere3a79262006-01-23 23:47:53 +0000120
Chris Lattner00fcdfe2006-01-24 04:16:34 +0000121 if (!M.getModuleInlineAsm().empty())
122 O << CommentString << " Start of file scope inline assembly\n"
123 << M.getModuleInlineAsm()
124 << "\n" << CommentString << " End of file scope inline assembly\n";
Chris Lattnere3a79262006-01-23 23:47:53 +0000125
Chris Lattner8488ba22006-05-09 04:59:56 +0000126 SwitchToDataSection("", 0); // Reset back to no section.
Jim Laskey0bbdc552006-01-26 20:21:46 +0000127
128 if (MachineDebugInfo *DebugInfo = getAnalysisToUpdate<MachineDebugInfo>()) {
129 DebugInfo->AnalyzeModule(M);
130 }
131
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000132 return false;
133}
134
135bool AsmPrinter::doFinalization(Module &M) {
136 delete Mang; Mang = 0;
137 return false;
138}
139
Chris Lattnerbb644e32005-11-21 07:51:36 +0000140void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000141 // What's my mangled name?
Chris Lattnerc0a1eba2005-11-10 18:36:17 +0000142 CurrentFnName = Mang->getValueName(MF.getFunction());
Chris Lattner08adbd132005-11-21 08:13:27 +0000143 IncrementFunctionNumber();
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000144}
145
Chris Lattnerf2991ce2005-11-21 08:25:09 +0000146/// EmitConstantPool - Print to the current output stream assembly
147/// representations of the constants in the constant pool MCP. This is
148/// used to print out constants which have been "spilled to memory" by
149/// the code generator.
150///
151void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
Chris Lattnerba972642006-02-09 04:22:52 +0000152 const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
Chris Lattnerf2991ce2005-11-21 08:25:09 +0000153 if (CP.empty()) return;
Evan Chengec1d60b2006-06-29 00:26:09 +0000154
155 // Some targets require 4-, 8-, and 16- byte constant literals to be placed
156 // in special sections.
157 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > FourByteCPs;
158 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > EightByteCPs;
159 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > SixteenByteCPs;
160 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > OtherCPs;
Chris Lattnerf2991ce2005-11-21 08:25:09 +0000161 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
Evan Chengec1d60b2006-06-29 00:26:09 +0000162 MachineConstantPoolEntry CPE = CP[i];
163 const Constant *CV = CPE.Val;
164 const Type *Ty = CV->getType();
165 if (FourByteConstantSection &&
166 TM.getTargetData()->getTypeSize(Ty) == 4)
167 FourByteCPs.push_back(std::make_pair(CPE, i));
168 else if (EightByteConstantSection &&
169 TM.getTargetData()->getTypeSize(Ty) == 8)
170 EightByteCPs.push_back(std::make_pair(CPE, i));
171 else if (SixteenByteConstantSection &&
172 TM.getTargetData()->getTypeSize(Ty) == 16)
173 SixteenByteCPs.push_back(std::make_pair(CPE, i));
174 else
175 OtherCPs.push_back(std::make_pair(CPE, i));
176 }
177
178 unsigned Alignment = MCP->getConstantPoolAlignment();
179 EmitConstantPool(Alignment, FourByteConstantSection, FourByteCPs);
180 EmitConstantPool(Alignment, EightByteConstantSection, EightByteCPs);
181 EmitConstantPool(Alignment, SixteenByteConstantSection, SixteenByteCPs);
182 EmitConstantPool(Alignment, ConstantPoolSection, OtherCPs);
183}
184
185void AsmPrinter::EmitConstantPool(unsigned Alignment, const char *Section,
186 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > &CP) {
187 if (CP.empty()) return;
188
189 SwitchToDataSection(Section, 0);
190 EmitAlignment(Alignment);
191 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
192 O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << '_'
193 << CP[i].second << ":\t\t\t\t\t" << CommentString << " ";
194 WriteTypeSymbolic(O, CP[i].first.Val->getType(), 0) << '\n';
195 EmitGlobalConstant(CP[i].first.Val);
Chris Lattnerf6190822006-02-09 04:46:04 +0000196 if (i != e-1) {
Evan Chengec1d60b2006-06-29 00:26:09 +0000197 unsigned EntSize =
198 TM.getTargetData()->getTypeSize(CP[i].first.Val->getType());
199 unsigned ValEnd = CP[i].first.Offset + EntSize;
Chris Lattnerf6190822006-02-09 04:46:04 +0000200 // Emit inter-object padding for alignment.
Evan Chengec1d60b2006-06-29 00:26:09 +0000201 EmitZeros(CP[i+1].first.Offset-ValEnd);
Chris Lattnerf6190822006-02-09 04:46:04 +0000202 }
Chris Lattnerf2991ce2005-11-21 08:25:09 +0000203 }
204}
205
Nate Begeman4ca2ea52006-04-22 18:53:45 +0000206/// EmitJumpTableInfo - Print assembly representations of the jump tables used
207/// by the current function to the current output stream.
208///
209void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI) {
210 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
211 if (JT.empty()) return;
Owen Anderson20a631f2006-05-03 01:29:57 +0000212 const TargetData *TD = TM.getTargetData();
Nate Begeman78756502006-07-27 01:13:04 +0000213 const char *PtrDataDirective = Data32bitsDirective;
Nate Begeman4ca2ea52006-04-22 18:53:45 +0000214
Nate Begeman78756502006-07-27 01:13:04 +0000215 // Pick the directive to use to print the jump table entries, and switch to
216 // the appropriate section.
217 if (TM.getRelocationModel() == Reloc::PIC_) {
218 SwitchToTextSection(JumpTableTextSection, 0);
219 } else {
220 SwitchToDataSection(JumpTableDataSection, 0);
221 if (TD->getPointerSize() == 8)
222 PtrDataDirective = Data64bitsDirective;
223 }
Owen Anderson20a631f2006-05-03 01:29:57 +0000224 EmitAlignment(Log2_32(TD->getPointerAlignment()));
Chris Lattnerfd5a8eb2006-07-15 01:34:12 +0000225
Nate Begeman4ca2ea52006-04-22 18:53:45 +0000226 for (unsigned i = 0, e = JT.size(); i != e; ++i) {
227 O << PrivateGlobalPrefix << "JTI" << getFunctionNumber() << '_' << i
228 << ":\n";
229 const std::vector<MachineBasicBlock*> &JTBBs = JT[i].MBBs;
230 for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) {
Chris Lattnerfd5a8eb2006-07-15 01:34:12 +0000231 O << PtrDataDirective << ' ';
Nate Begeman78756502006-07-27 01:13:04 +0000232 printBasicBlockLabel(JTBBs[ii], false, false);
233 if (TM.getRelocationModel() == Reloc::PIC_) {
234 O << '-' << PrivateGlobalPrefix << "JTI" << getFunctionNumber()
235 << '_' << i;
236 }
Nate Begeman4ca2ea52006-04-22 18:53:45 +0000237 O << '\n';
238 }
239 }
240}
241
Chris Lattnerf0e9aef2005-12-13 06:32:10 +0000242/// EmitSpecialLLVMGlobal - Check to see if the specified global is a
243/// special global used by LLVM. If so, emit it and return true, otherwise
244/// do nothing and return false.
245bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
Jim Laskey313570f2006-03-07 22:00:35 +0000246 // Ignore debug and non-emitted data.
247 if (GV->getSection() == "llvm.metadata") return true;
248
249 if (!GV->hasAppendingLinkage()) return false;
250
251 assert(GV->hasInitializer() && "Not a special LLVM global!");
Chris Lattnerf0e9aef2005-12-13 06:32:10 +0000252
253 if (GV->getName() == "llvm.used")
254 return true; // No need to emit this at all.
255
Chris Lattner3760e902006-01-12 19:17:23 +0000256 if (GV->getName() == "llvm.global_ctors" && GV->use_empty()) {
Chris Lattner8488ba22006-05-09 04:59:56 +0000257 SwitchToDataSection(StaticCtorsSection, 0);
Chris Lattnerf0e9aef2005-12-13 06:32:10 +0000258 EmitAlignment(2, 0);
259 EmitXXStructorList(GV->getInitializer());
260 return true;
261 }
262
Chris Lattner3760e902006-01-12 19:17:23 +0000263 if (GV->getName() == "llvm.global_dtors" && GV->use_empty()) {
Chris Lattner8488ba22006-05-09 04:59:56 +0000264 SwitchToDataSection(StaticDtorsSection, 0);
Chris Lattnerf0e9aef2005-12-13 06:32:10 +0000265 EmitAlignment(2, 0);
266 EmitXXStructorList(GV->getInitializer());
267 return true;
268 }
269
270 return false;
271}
272
273/// EmitXXStructorList - Emit the ctor or dtor list. This just prints out the
274/// function pointers, ignoring the init priority.
275void AsmPrinter::EmitXXStructorList(Constant *List) {
276 // Should be an array of '{ int, void ()* }' structs. The first value is the
277 // init priority, which we ignore.
278 if (!isa<ConstantArray>(List)) return;
279 ConstantArray *InitList = cast<ConstantArray>(List);
280 for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
281 if (ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i))){
282 if (CS->getNumOperands() != 2) return; // Not array of 2-element structs.
Chris Lattner434ffe42005-12-21 01:17:37 +0000283
284 if (CS->getOperand(1)->isNullValue())
285 return; // Found a null terminator, exit printing.
286 // Emit the function pointer.
Chris Lattnerf0e9aef2005-12-13 06:32:10 +0000287 EmitGlobalConstant(CS->getOperand(1));
288 }
289}
Chris Lattnerf2991ce2005-11-21 08:25:09 +0000290
Chris Lattnera9b25252006-02-05 01:29:18 +0000291/// getPreferredAlignmentLog - Return the preferred alignment of the
292/// specified global, returned in log form. This includes an explicitly
293/// requested alignment (if the global has one).
294unsigned AsmPrinter::getPreferredAlignmentLog(const GlobalVariable *GV) const {
Jim Laskeydce07562006-06-15 13:10:58 +0000295 const Type *ElemType = GV->getType()->getElementType();
296 unsigned Alignment = TM.getTargetData()->getTypeAlignmentShift(ElemType);
Chris Lattnera9b25252006-02-05 01:29:18 +0000297 if (GV->getAlignment() > (1U << Alignment))
298 Alignment = Log2_32(GV->getAlignment());
299
Chris Lattnercbab2842006-02-05 01:46:49 +0000300 if (GV->hasInitializer()) {
Jim Laskey3519b872006-06-15 19:37:14 +0000301 // Always round up alignment of global doubles to 8 bytes.
302 if (GV->getType()->getElementType() == Type::DoubleTy && Alignment < 3)
303 Alignment = 3;
Chris Lattnercbab2842006-02-05 01:46:49 +0000304 if (Alignment < 4) {
305 // If the global is not external, see if it is large. If so, give it a
306 // larger alignment.
Jim Laskeydce07562006-06-15 13:10:58 +0000307 if (TM.getTargetData()->getTypeSize(ElemType) > 128)
Chris Lattnercbab2842006-02-05 01:46:49 +0000308 Alignment = 4; // 16-byte alignment.
309 }
Chris Lattnera9b25252006-02-05 01:29:18 +0000310 }
311 return Alignment;
312}
Chris Lattnerf2991ce2005-11-21 08:25:09 +0000313
Chris Lattnerbb644e32005-11-21 07:51:36 +0000314// EmitAlignment - Emit an alignment directive to the specified power of two.
315void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV) const {
Chris Lattnerdd8eeed2005-11-14 19:00:06 +0000316 if (GV && GV->getAlignment())
317 NumBits = Log2_32(GV->getAlignment());
Chris Lattner747960d2005-11-10 18:09:27 +0000318 if (NumBits == 0) return; // No need to emit alignment.
Chris Lattner1d35c162004-08-17 19:14:29 +0000319 if (AlignmentIsInBytes) NumBits = 1 << NumBits;
320 O << AlignDirective << NumBits << "\n";
321}
322
Chris Lattnerbb644e32005-11-21 07:51:36 +0000323/// EmitZeros - Emit a block of zeros.
Chris Lattnerea751992004-08-17 21:38:40 +0000324///
Chris Lattnerbb644e32005-11-21 07:51:36 +0000325void AsmPrinter::EmitZeros(uint64_t NumZeros) const {
Chris Lattnerea751992004-08-17 21:38:40 +0000326 if (NumZeros) {
Jeff Cohenf34ddb12006-05-02 03:46:13 +0000327 if (ZeroDirective) {
328 O << ZeroDirective << NumZeros;
329 if (ZeroDirectiveSuffix)
330 O << ZeroDirectiveSuffix;
331 O << "\n";
332 } else {
Chris Lattnerea751992004-08-17 21:38:40 +0000333 for (; NumZeros; --NumZeros)
334 O << Data8bitsDirective << "0\n";
335 }
336 }
337}
338
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000339// Print out the specified constant, without a storage class. Only the
340// constants valid in constant expressions can occur here.
Chris Lattnerbb644e32005-11-21 07:51:36 +0000341void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
Chris Lattner61753bf2004-10-16 18:19:26 +0000342 if (CV->isNullValue() || isa<UndefValue>(CV))
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000343 O << "0";
344 else if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) {
345 assert(CB == ConstantBool::True);
346 O << "1";
347 } else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV))
348 if (((CI->getValue() << 32) >> 32) == CI->getValue())
349 O << CI->getValue();
350 else
Duraid Madina73c4dba2005-05-15 13:05:48 +0000351 O << (uint64_t)CI->getValue();
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000352 else if (const ConstantUInt *CI = dyn_cast<ConstantUInt>(CV))
353 O << CI->getValue();
Chris Lattnerc0a1eba2005-11-10 18:36:17 +0000354 else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
Duraid Madina73a316d2005-04-02 12:21:51 +0000355 // This is a constant address for a global variable or function. Use the
356 // name of the variable or function as the address value, possibly
357 // decorating it with GlobalVarAddrPrefix/Suffix or
358 // FunctionAddrPrefix/Suffix (these all default to "" )
Chris Lattnerc0a1eba2005-11-10 18:36:17 +0000359 if (isa<Function>(GV))
360 O << FunctionAddrPrefix << Mang->getValueName(GV) << FunctionAddrSuffix;
Duraid Madina73a316d2005-04-02 12:21:51 +0000361 else
Chris Lattnerc0a1eba2005-11-10 18:36:17 +0000362 O << GlobalVarAddrPrefix << Mang->getValueName(GV) << GlobalVarAddrSuffix;
Duraid Madina73a316d2005-04-02 12:21:51 +0000363 } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
Owen Anderson20a631f2006-05-03 01:29:57 +0000364 const TargetData *TD = TM.getTargetData();
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000365 switch(CE->getOpcode()) {
366 case Instruction::GetElementPtr: {
367 // generate a symbolic expression for the byte address
368 const Constant *ptrVal = CE->getOperand(0);
369 std::vector<Value*> idxVec(CE->op_begin()+1, CE->op_end());
Owen Anderson20a631f2006-05-03 01:29:57 +0000370 if (int64_t Offset = TD->getIndexedOffset(ptrVal->getType(), idxVec)) {
Chris Lattner145569b2005-02-14 21:40:26 +0000371 if (Offset)
372 O << "(";
Chris Lattnerbb644e32005-11-21 07:51:36 +0000373 EmitConstantValueOnly(ptrVal);
Chris Lattner145569b2005-02-14 21:40:26 +0000374 if (Offset > 0)
375 O << ") + " << Offset;
376 else if (Offset < 0)
377 O << ") - " << -Offset;
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000378 } else {
Chris Lattnerbb644e32005-11-21 07:51:36 +0000379 EmitConstantValueOnly(ptrVal);
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000380 }
381 break;
382 }
383 case Instruction::Cast: {
384 // Support only non-converting or widening casts for now, that is, ones
385 // that do not involve a change in value. This assertion is really gross,
386 // and may not even be a complete check.
387 Constant *Op = CE->getOperand(0);
388 const Type *OpTy = Op->getType(), *Ty = CE->getType();
389
390 // Remember, kids, pointers can be losslessly converted back and forth
391 // into 32-bit or wider integers, regardless of signedness. :-P
392 assert(((isa<PointerType>(OpTy)
393 && (Ty == Type::LongTy || Ty == Type::ULongTy
394 || Ty == Type::IntTy || Ty == Type::UIntTy))
395 || (isa<PointerType>(Ty)
396 && (OpTy == Type::LongTy || OpTy == Type::ULongTy
397 || OpTy == Type::IntTy || OpTy == Type::UIntTy))
Owen Anderson20a631f2006-05-03 01:29:57 +0000398 || (((TD->getTypeSize(Ty) >= TD->getTypeSize(OpTy))
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000399 && OpTy->isLosslesslyConvertibleTo(Ty))))
400 && "FIXME: Don't yet support this kind of constant cast expr");
Chris Lattnerbb644e32005-11-21 07:51:36 +0000401 EmitConstantValueOnly(Op);
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000402 break;
403 }
404 case Instruction::Add:
405 O << "(";
Chris Lattnerbb644e32005-11-21 07:51:36 +0000406 EmitConstantValueOnly(CE->getOperand(0));
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000407 O << ") + (";
Chris Lattnerbb644e32005-11-21 07:51:36 +0000408 EmitConstantValueOnly(CE->getOperand(1));
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000409 O << ")";
410 break;
411 default:
412 assert(0 && "Unsupported operator!");
413 }
414 } else {
415 assert(0 && "Unknown constant value!");
416 }
417}
Chris Lattner8452a1f2004-08-17 06:36:49 +0000418
419/// toOctal - Convert the low order bits of X into an octal digit.
420///
421static inline char toOctal(int X) {
422 return (X&7)+'0';
423}
424
Chris Lattner55a6d902005-11-10 18:06:33 +0000425/// printAsCString - Print the specified array as a C compatible string, only if
Chris Lattner8452a1f2004-08-17 06:36:49 +0000426/// the predicate isString is true.
427///
Chris Lattner55a6d902005-11-10 18:06:33 +0000428static void printAsCString(std::ostream &O, const ConstantArray *CVA,
429 unsigned LastElt) {
Chris Lattner8452a1f2004-08-17 06:36:49 +0000430 assert(CVA->isString() && "Array is not string compatible!");
431
432 O << "\"";
Chris Lattner55a6d902005-11-10 18:06:33 +0000433 for (unsigned i = 0; i != LastElt; ++i) {
Misha Brukman835702a2005-04-21 22:36:52 +0000434 unsigned char C =
Chris Lattner0b955fd2005-01-08 19:59:10 +0000435 (unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getRawValue();
Chris Lattner8452a1f2004-08-17 06:36:49 +0000436
437 if (C == '"') {
438 O << "\\\"";
439 } else if (C == '\\') {
440 O << "\\\\";
441 } else if (isprint(C)) {
442 O << C;
443 } else {
444 switch(C) {
445 case '\b': O << "\\b"; break;
446 case '\f': O << "\\f"; break;
447 case '\n': O << "\\n"; break;
448 case '\r': O << "\\r"; break;
449 case '\t': O << "\\t"; break;
450 default:
451 O << '\\';
452 O << toOctal(C >> 6);
453 O << toOctal(C >> 3);
454 O << toOctal(C >> 0);
455 break;
456 }
457 }
458 }
459 O << "\"";
460}
461
Jeff Cohen24a62a92006-05-02 01:16:28 +0000462/// EmitString - Emit a zero-byte-terminated string constant.
463///
464void AsmPrinter::EmitString(const ConstantArray *CVA) const {
465 unsigned NumElts = CVA->getNumOperands();
466 if (AscizDirective && NumElts &&
467 cast<ConstantInt>(CVA->getOperand(NumElts-1))->getRawValue() == 0) {
468 O << AscizDirective;
469 printAsCString(O, CVA, NumElts-1);
470 } else {
471 O << AsciiDirective;
472 printAsCString(O, CVA, NumElts);
473 }
474 O << "\n";
475}
476
Chris Lattnerbb644e32005-11-21 07:51:36 +0000477/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
Chris Lattner8452a1f2004-08-17 06:36:49 +0000478///
Chris Lattnerbb644e32005-11-21 07:51:36 +0000479void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
Owen Anderson20a631f2006-05-03 01:29:57 +0000480 const TargetData *TD = TM.getTargetData();
Chris Lattner8452a1f2004-08-17 06:36:49 +0000481
Chris Lattner61753bf2004-10-16 18:19:26 +0000482 if (CV->isNullValue() || isa<UndefValue>(CV)) {
Owen Anderson20a631f2006-05-03 01:29:57 +0000483 EmitZeros(TD->getTypeSize(CV->getType()));
Chris Lattner8452a1f2004-08-17 06:36:49 +0000484 return;
485 } else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
486 if (CVA->isString()) {
Jeff Cohen24a62a92006-05-02 01:16:28 +0000487 EmitString(CVA);
Chris Lattner8452a1f2004-08-17 06:36:49 +0000488 } else { // Not a string. Print the values in successive locations
489 for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
Chris Lattnerbb644e32005-11-21 07:51:36 +0000490 EmitGlobalConstant(CVA->getOperand(i));
Chris Lattner8452a1f2004-08-17 06:36:49 +0000491 }
492 return;
493 } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
494 // Print the fields in successive locations. Pad to align if needed!
Owen Anderson20a631f2006-05-03 01:29:57 +0000495 const StructLayout *cvsLayout = TD->getStructLayout(CVS->getType());
Chris Lattner0b955fd2005-01-08 19:59:10 +0000496 uint64_t sizeSoFar = 0;
Chris Lattner8452a1f2004-08-17 06:36:49 +0000497 for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
498 const Constant* field = CVS->getOperand(i);
499
500 // Check if padding is needed and insert one or more 0s.
Owen Anderson20a631f2006-05-03 01:29:57 +0000501 uint64_t fieldSize = TD->getTypeSize(field->getType());
Chris Lattner0b955fd2005-01-08 19:59:10 +0000502 uint64_t padSize = ((i == e-1? cvsLayout->StructSize
Chris Lattner8452a1f2004-08-17 06:36:49 +0000503 : cvsLayout->MemberOffsets[i+1])
504 - cvsLayout->MemberOffsets[i]) - fieldSize;
505 sizeSoFar += fieldSize + padSize;
506
507 // Now print the actual field value
Chris Lattnerbb644e32005-11-21 07:51:36 +0000508 EmitGlobalConstant(field);
Chris Lattner8452a1f2004-08-17 06:36:49 +0000509
510 // Insert the field padding unless it's zero bytes...
Chris Lattnerbb644e32005-11-21 07:51:36 +0000511 EmitZeros(padSize);
Chris Lattner8452a1f2004-08-17 06:36:49 +0000512 }
513 assert(sizeSoFar == cvsLayout->StructSize &&
514 "Layout of constant struct may be incorrect!");
515 return;
516 } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
517 // FP Constants are printed as integer constants to avoid losing
518 // precision...
519 double Val = CFP->getValue();
520 if (CFP->getType() == Type::DoubleTy) {
Chris Lattner9fa0fc42004-08-17 06:48:16 +0000521 if (Data64bitsDirective)
Jim Laskeyb74c6662005-08-17 19:34:49 +0000522 O << Data64bitsDirective << DoubleToBits(Val) << "\t" << CommentString
Chris Lattnerea751992004-08-17 21:38:40 +0000523 << " double value: " << Val << "\n";
Owen Anderson20a631f2006-05-03 01:29:57 +0000524 else if (TD->isBigEndian()) {
Jim Laskeyb74c6662005-08-17 19:34:49 +0000525 O << Data32bitsDirective << unsigned(DoubleToBits(Val) >> 32)
Chris Lattner10262ab2004-08-18 02:22:55 +0000526 << "\t" << CommentString << " double most significant word "
Chris Lattnerda6beac2004-08-17 16:27:05 +0000527 << Val << "\n";
Jim Laskeyb74c6662005-08-17 19:34:49 +0000528 O << Data32bitsDirective << unsigned(DoubleToBits(Val))
Chris Lattner10262ab2004-08-18 02:22:55 +0000529 << "\t" << CommentString << " double least significant word "
Chris Lattnerda6beac2004-08-17 16:27:05 +0000530 << Val << "\n";
Chris Lattner8452a1f2004-08-17 06:36:49 +0000531 } else {
Jim Laskeyb74c6662005-08-17 19:34:49 +0000532 O << Data32bitsDirective << unsigned(DoubleToBits(Val))
Chris Lattner10262ab2004-08-18 02:22:55 +0000533 << "\t" << CommentString << " double least significant word " << Val
Chris Lattnerda6beac2004-08-17 16:27:05 +0000534 << "\n";
Jim Laskeyb74c6662005-08-17 19:34:49 +0000535 O << Data32bitsDirective << unsigned(DoubleToBits(Val) >> 32)
Chris Lattner10262ab2004-08-18 02:22:55 +0000536 << "\t" << CommentString << " double most significant word " << Val
Chris Lattnerda6beac2004-08-17 16:27:05 +0000537 << "\n";
Chris Lattner8452a1f2004-08-17 06:36:49 +0000538 }
539 return;
540 } else {
Jim Laskeyb74c6662005-08-17 19:34:49 +0000541 O << Data32bitsDirective << FloatToBits(Val) << "\t" << CommentString
Chris Lattnerda6beac2004-08-17 16:27:05 +0000542 << " float " << Val << "\n";
Chris Lattner8452a1f2004-08-17 06:36:49 +0000543 return;
544 }
545 } else if (CV->getType() == Type::ULongTy || CV->getType() == Type::LongTy) {
546 if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
547 uint64_t Val = CI->getRawValue();
Misha Brukman835702a2005-04-21 22:36:52 +0000548
Chris Lattner9fa0fc42004-08-17 06:48:16 +0000549 if (Data64bitsDirective)
550 O << Data64bitsDirective << Val << "\n";
Owen Anderson20a631f2006-05-03 01:29:57 +0000551 else if (TD->isBigEndian()) {
Chris Lattner8452a1f2004-08-17 06:36:49 +0000552 O << Data32bitsDirective << unsigned(Val >> 32)
Chris Lattner10262ab2004-08-18 02:22:55 +0000553 << "\t" << CommentString << " Double-word most significant word "
Chris Lattnerda6beac2004-08-17 16:27:05 +0000554 << Val << "\n";
Chris Lattner8452a1f2004-08-17 06:36:49 +0000555 O << Data32bitsDirective << unsigned(Val)
Chris Lattner10262ab2004-08-18 02:22:55 +0000556 << "\t" << CommentString << " Double-word least significant word "
Chris Lattnerda6beac2004-08-17 16:27:05 +0000557 << Val << "\n";
Chris Lattner8452a1f2004-08-17 06:36:49 +0000558 } else {
559 O << Data32bitsDirective << unsigned(Val)
Chris Lattner10262ab2004-08-18 02:22:55 +0000560 << "\t" << CommentString << " Double-word least significant word "
Chris Lattnerda6beac2004-08-17 16:27:05 +0000561 << Val << "\n";
Chris Lattner8452a1f2004-08-17 06:36:49 +0000562 O << Data32bitsDirective << unsigned(Val >> 32)
Chris Lattner10262ab2004-08-18 02:22:55 +0000563 << "\t" << CommentString << " Double-word most significant word "
Chris Lattnerda6beac2004-08-17 16:27:05 +0000564 << Val << "\n";
Chris Lattner8452a1f2004-08-17 06:36:49 +0000565 }
566 return;
567 }
Nate Begeman41b1cdc2005-12-06 06:18:55 +0000568 } else if (const ConstantPacked *CP = dyn_cast<ConstantPacked>(CV)) {
569 const PackedType *PTy = CP->getType();
570
571 for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I)
572 EmitGlobalConstant(CP->getOperand(I));
573
574 return;
Chris Lattner8452a1f2004-08-17 06:36:49 +0000575 }
576
577 const Type *type = CV->getType();
Chris Lattner8452a1f2004-08-17 06:36:49 +0000578 switch (type->getTypeID()) {
Misha Brukman835702a2005-04-21 22:36:52 +0000579 case Type::BoolTyID:
Chris Lattner8452a1f2004-08-17 06:36:49 +0000580 case Type::UByteTyID: case Type::SByteTyID:
581 O << Data8bitsDirective;
582 break;
583 case Type::UShortTyID: case Type::ShortTyID:
584 O << Data16bitsDirective;
585 break;
Chris Lattner8452a1f2004-08-17 06:36:49 +0000586 case Type::PointerTyID:
Owen Anderson20a631f2006-05-03 01:29:57 +0000587 if (TD->getPointerSize() == 8) {
Evan Chengdf631792006-06-15 08:10:56 +0000588 assert(Data64bitsDirective &&
589 "Target cannot handle 64-bit pointer exprs!");
Andrew Lenharthc8770aa2005-02-04 13:47:16 +0000590 O << Data64bitsDirective;
591 break;
592 }
593 //Fall through for pointer size == int size
Chris Lattner8452a1f2004-08-17 06:36:49 +0000594 case Type::UIntTyID: case Type::IntTyID:
595 O << Data32bitsDirective;
596 break;
Misha Brukman835702a2005-04-21 22:36:52 +0000597 case Type::ULongTyID: case Type::LongTyID:
Chris Lattner88e2d2e2005-08-08 04:26:32 +0000598 assert(Data64bitsDirective &&"Target cannot handle 64-bit constant exprs!");
599 O << Data64bitsDirective;
600 break;
Chris Lattner8452a1f2004-08-17 06:36:49 +0000601 case Type::FloatTyID: case Type::DoubleTyID:
602 assert (0 && "Should have already output floating point constant.");
603 default:
604 assert (0 && "Can't handle printing this type of thing");
605 break;
606 }
Chris Lattnerbb644e32005-11-21 07:51:36 +0000607 EmitConstantValueOnly(CV);
Chris Lattner8452a1f2004-08-17 06:36:49 +0000608 O << "\n";
609}
Chris Lattner061d9e22006-01-27 02:10:10 +0000610
611/// printInlineAsm - This method formats and prints the specified machine
612/// instruction that is an inline asm.
613void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
Chris Lattnera633c3132006-05-05 21:47:05 +0000614 O << InlineAsmStart << "\n\t";
Chris Lattner57ecb562006-01-30 23:00:08 +0000615 unsigned NumOperands = MI->getNumOperands();
616
617 // Count the number of register definitions.
618 unsigned NumDefs = 0;
619 for (; MI->getOperand(NumDefs).isDef(); ++NumDefs)
620 assert(NumDefs != NumOperands-1 && "No asm string?");
621
622 assert(MI->getOperand(NumDefs).isExternalSymbol() && "No asm string?");
Chris Lattneraa23fa92006-02-01 22:41:11 +0000623
624 // Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
Chris Lattner57ecb562006-01-30 23:00:08 +0000625 const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
Chris Lattneraa23fa92006-02-01 22:41:11 +0000626
627 // The variant of the current asmprinter: FIXME: change.
628 int AsmPrinterVariant = 0;
Chris Lattner57ecb562006-01-30 23:00:08 +0000629
Chris Lattneraa23fa92006-02-01 22:41:11 +0000630 int CurVariant = -1; // The number of the {.|.|.} region we are in.
631 const char *LastEmitted = AsmStr; // One past the last character emitted.
Chris Lattner3a5ed552006-02-01 01:28:23 +0000632
Chris Lattneraa23fa92006-02-01 22:41:11 +0000633 while (*LastEmitted) {
634 switch (*LastEmitted) {
635 default: {
636 // Not a special case, emit the string section literally.
637 const char *LiteralEnd = LastEmitted+1;
638 while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
Chris Lattnera633c3132006-05-05 21:47:05 +0000639 *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
Chris Lattneraa23fa92006-02-01 22:41:11 +0000640 ++LiteralEnd;
641 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
642 O.write(LastEmitted, LiteralEnd-LastEmitted);
643 LastEmitted = LiteralEnd;
644 break;
645 }
Chris Lattnera633c3132006-05-05 21:47:05 +0000646 case '\n':
647 ++LastEmitted; // Consume newline character.
648 O << "\n\t"; // Indent code with newline.
649 break;
Chris Lattneraa23fa92006-02-01 22:41:11 +0000650 case '$': {
651 ++LastEmitted; // Consume '$' character.
652 if (*LastEmitted == '$') { // $$ -> $
653 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
654 O << '$';
655 ++LastEmitted; // Consume second '$' character.
656 break;
657 }
658
659 bool HasCurlyBraces = false;
660 if (*LastEmitted == '{') { // ${variable}
661 ++LastEmitted; // Consume '{' character.
662 HasCurlyBraces = true;
663 }
664
665 const char *IDStart = LastEmitted;
666 char *IDEnd;
667 long Val = strtol(IDStart, &IDEnd, 10); // We only accept numbers for IDs.
668 if (!isdigit(*IDStart) || (Val == 0 && errno == EINVAL)) {
669 std::cerr << "Bad $ operand number in inline asm string: '"
670 << AsmStr << "'\n";
671 exit(1);
672 }
673 LastEmitted = IDEnd;
674
Chris Lattner34f74c12006-02-06 22:17:23 +0000675 char Modifier[2] = { 0, 0 };
676
Chris Lattneraa23fa92006-02-01 22:41:11 +0000677 if (HasCurlyBraces) {
Chris Lattner34f74c12006-02-06 22:17:23 +0000678 // If we have curly braces, check for a modifier character. This
679 // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
680 if (*LastEmitted == ':') {
681 ++LastEmitted; // Consume ':' character.
682 if (*LastEmitted == 0) {
683 std::cerr << "Bad ${:} expression in inline asm string: '"
684 << AsmStr << "'\n";
685 exit(1);
686 }
687
688 Modifier[0] = *LastEmitted;
689 ++LastEmitted; // Consume modifier character.
690 }
691
Chris Lattneraa23fa92006-02-01 22:41:11 +0000692 if (*LastEmitted != '}') {
693 std::cerr << "Bad ${} expression in inline asm string: '"
694 << AsmStr << "'\n";
695 exit(1);
696 }
697 ++LastEmitted; // Consume '}' character.
698 }
699
700 if ((unsigned)Val >= NumOperands-1) {
701 std::cerr << "Invalid $ operand number in inline asm string: '"
702 << AsmStr << "'\n";
703 exit(1);
704 }
705
Chris Lattner571d9642006-02-23 19:21:04 +0000706 // Okay, we finally have a value number. Ask the target to print this
Chris Lattneraa23fa92006-02-01 22:41:11 +0000707 // operand!
Chris Lattner571d9642006-02-23 19:21:04 +0000708 if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
709 unsigned OpNo = 1;
Chris Lattner8f8b5e42006-06-08 18:00:47 +0000710
711 bool Error = false;
712
Chris Lattner571d9642006-02-23 19:21:04 +0000713 // Scan to find the machine operand number for the operand.
Chris Lattner5af3fde2006-02-24 19:50:58 +0000714 for (; Val; --Val) {
Chris Lattner8f8b5e42006-06-08 18:00:47 +0000715 if (OpNo >= MI->getNumOperands()) break;
Chris Lattner5af3fde2006-02-24 19:50:58 +0000716 unsigned OpFlags = MI->getOperand(OpNo).getImmedValue();
717 OpNo += (OpFlags >> 3) + 1;
718 }
Chris Lattner1d08c652006-02-24 20:21:58 +0000719
Chris Lattner8f8b5e42006-06-08 18:00:47 +0000720 if (OpNo >= MI->getNumOperands()) {
721 Error = true;
Chris Lattner1d08c652006-02-24 20:21:58 +0000722 } else {
Chris Lattner8f8b5e42006-06-08 18:00:47 +0000723 unsigned OpFlags = MI->getOperand(OpNo).getImmedValue();
724 ++OpNo; // Skip over the ID number.
725
726 AsmPrinter *AP = const_cast<AsmPrinter*>(this);
727 if ((OpFlags & 7) == 4 /*ADDR MODE*/) {
728 Error = AP->PrintAsmMemoryOperand(MI, OpNo, AsmPrinterVariant,
729 Modifier[0] ? Modifier : 0);
730 } else {
731 Error = AP->PrintAsmOperand(MI, OpNo, AsmPrinterVariant,
732 Modifier[0] ? Modifier : 0);
733 }
Chris Lattner1d08c652006-02-24 20:21:58 +0000734 }
735 if (Error) {
Chris Lattneraa23fa92006-02-01 22:41:11 +0000736 std::cerr << "Invalid operand found in inline asm: '"
737 << AsmStr << "'\n";
738 MI->dump();
739 exit(1);
740 }
Chris Lattner571d9642006-02-23 19:21:04 +0000741 }
Chris Lattneraa23fa92006-02-01 22:41:11 +0000742 break;
743 }
744 case '{':
745 ++LastEmitted; // Consume '{' character.
746 if (CurVariant != -1) {
747 std::cerr << "Nested variants found in inline asm string: '"
748 << AsmStr << "'\n";
749 exit(1);
750 }
751 CurVariant = 0; // We're in the first variant now.
752 break;
753 case '|':
754 ++LastEmitted; // consume '|' character.
755 if (CurVariant == -1) {
756 std::cerr << "Found '|' character outside of variant in inline asm "
757 << "string: '" << AsmStr << "'\n";
758 exit(1);
759 }
760 ++CurVariant; // We're in the next variant.
761 break;
762 case '}':
763 ++LastEmitted; // consume '}' character.
764 if (CurVariant == -1) {
765 std::cerr << "Found '}' character outside of variant in inline asm "
766 << "string: '" << AsmStr << "'\n";
767 exit(1);
768 }
769 CurVariant = -1;
770 break;
771 }
772 }
Chris Lattnera633c3132006-05-05 21:47:05 +0000773 O << "\n\t" << InlineAsmEnd << "\n";
Chris Lattneraa23fa92006-02-01 22:41:11 +0000774}
775
776/// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
777/// instruction, using the specified assembler variant. Targets should
778/// overried this to format as appropriate.
779bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
Chris Lattner34f74c12006-02-06 22:17:23 +0000780 unsigned AsmVariant, const char *ExtraCode) {
Chris Lattneraa23fa92006-02-01 22:41:11 +0000781 // Target doesn't support this yet!
782 return true;
Chris Lattner061d9e22006-01-27 02:10:10 +0000783}
Chris Lattner1d08c652006-02-24 20:21:58 +0000784
785bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
786 unsigned AsmVariant,
787 const char *ExtraCode) {
788 // Target doesn't support this yet!
789 return true;
790}
Nate Begeman4ca2ea52006-04-22 18:53:45 +0000791
792/// printBasicBlockLabel - This method prints the label for the specified
793/// MachineBasicBlock
Nate Begemanb9d4f832006-05-02 05:37:32 +0000794void AsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB,
795 bool printColon,
796 bool printComment) const {
Nate Begeman4971ba52006-05-02 17:36:46 +0000797 O << PrivateGlobalPrefix << "BB" << FunctionNumber << "_"
798 << MBB->getNumber();
Nate Begemanb9d4f832006-05-02 05:37:32 +0000799 if (printColon)
800 O << ':';
801 if (printComment)
802 O << '\t' << CommentString << MBB->getBasicBlock()->getName();
Nate Begeman4ca2ea52006-04-22 18:53:45 +0000803}