blob: d4facd27a4fd537c498374c27e6576e1a89c777c [file] [log] [blame]
Chris Lattnera80ba712004-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 Cheng932f0222006-03-03 02:04:29 +000014#include "llvm/CodeGen/AsmPrinter.h"
Evan Cheng246ae0d2006-03-01 22:18:09 +000015#include "llvm/Assembly/Writer.h"
Nate Begeman8cfa57b2005-12-06 06:18:55 +000016#include "llvm/DerivedTypes.h"
Chris Lattnera80ba712004-08-16 23:15:22 +000017#include "llvm/Constants.h"
Chris Lattner450de392005-11-10 18:36:17 +000018#include "llvm/Module.h"
Chris Lattner3b4fd322005-11-21 08:25:09 +000019#include "llvm/CodeGen/MachineConstantPool.h"
Nate Begeman37efe672006-04-22 18:53:45 +000020#include "llvm/CodeGen/MachineJumpTableInfo.h"
Chris Lattnera80ba712004-08-16 23:15:22 +000021#include "llvm/Support/Mangler.h"
Jim Laskeycb6682f2005-08-17 19:34:49 +000022#include "llvm/Support/MathExtras.h"
Owen Anderson07000c62006-05-12 06:33:49 +000023#include "llvm/Target/TargetData.h"
Chris Lattnera80ba712004-08-16 23:15:22 +000024#include "llvm/Target/TargetMachine.h"
Duraid Madina2e096c12005-12-28 06:29:02 +000025#include <iostream>
Chris Lattner66099132006-02-01 22:41:11 +000026#include <cerrno>
Chris Lattnera80ba712004-08-16 23:15:22 +000027using namespace llvm;
28
Chris Lattnered138932005-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 Lattner1c059972006-05-05 21:47:05 +000038 InlineAsmStart("#APP"),
39 InlineAsmEnd("#NO_APP"),
Chris Lattnered138932005-12-13 06:32:10 +000040 ZeroDirective("\t.zero\t"),
Jeff Cohenc6a057b2006-05-02 03:46:13 +000041 ZeroDirectiveSuffix(0),
Chris Lattnered138932005-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 Lattner7faec9b2006-05-09 05:33:48 +000051 TextSectionStartSuffix(""),
52 DataSectionStartSuffix(""),
53 SectionEndDirectiveSuffix(0),
Chris Lattnered138932005-12-13 06:32:10 +000054 ConstantPoolSection("\t.section .rodata\n"),
Nate Begeman37efe672006-04-22 18:53:45 +000055 JumpTableSection("\t.section .rodata\n"),
Chris Lattnered138932005-12-13 06:32:10 +000056 StaticCtorsSection("\t.section .ctors,\"aw\",@progbits"),
57 StaticDtorsSection("\t.section .dtors,\"aw\",@progbits"),
Evan Cheng2d2cec12006-06-29 00:26:09 +000058 FourByteConstantSection(0),
59 EightByteConstantSection(0),
60 SixteenByteConstantSection(0),
Chris Lattnered138932005-12-13 06:32:10 +000061 LCOMMDirective(0),
62 COMMDirective("\t.comm\t"),
63 COMMDirectiveTakesAlignment(true),
64 HasDotTypeDotSizeDirective(true) {
65}
66
67
Chris Lattner4632d7a2006-05-09 04:59:56 +000068/// SwitchToTextSection - Switch to the specified text section of the executable
69/// if we are not already in it!
Chris Lattnerac28fbd2005-11-21 07:06:27 +000070///
Chris Lattner4632d7a2006-05-09 04:59:56 +000071void AsmPrinter::SwitchToTextSection(const char *NewSection,
72 const GlobalValue *GV) {
Chris Lattnerac28fbd2005-11-21 07:06:27 +000073 std::string NS;
Chris Lattnera7090ae2006-05-09 05:24:50 +000074 if (GV && GV->hasSection())
Chris Lattnerc8d37c62006-05-09 16:41:59 +000075 NS = SwitchToSectionDirective + GV->getSection();
Chris Lattnera7090ae2006-05-09 05:24:50 +000076 else
77 NS = NewSection;
78
79 // If we're already in this section, we're done.
80 if (CurrentSection == NS) return;
Jeff Cohen51b776d2006-05-02 03:58:45 +000081
Chris Lattner7faec9b2006-05-09 05:33:48 +000082 // Close the current section, if applicable.
83 if (SectionEndDirectiveSuffix && !CurrentSection.empty())
84 O << CurrentSection << SectionEndDirectiveSuffix << "\n";
Jeff Cohen51b776d2006-05-02 03:58:45 +000085
Chris Lattner7faec9b2006-05-09 05:33:48 +000086 CurrentSection = NS;
87
88 if (!CurrentSection.empty())
89 O << CurrentSection << TextSectionStartSuffix << '\n';
Chris Lattnerac28fbd2005-11-21 07:06:27 +000090}
91
Chris Lattner4632d7a2006-05-09 04:59:56 +000092/// SwitchToTextSection - Switch to the specified text section of the executable
93/// if we are not already in it!
94///
95void AsmPrinter::SwitchToDataSection(const char *NewSection,
96 const GlobalValue *GV) {
97 std::string NS;
Chris Lattnerb81cb612006-05-09 05:23:12 +000098 if (GV && GV->hasSection())
99 NS = SwitchToSectionDirective + GV->getSection();
100 else
101 NS = NewSection;
Chris Lattner4632d7a2006-05-09 04:59:56 +0000102
Chris Lattnerb81cb612006-05-09 05:23:12 +0000103 // If we're already in this section, we're done.
104 if (CurrentSection == NS) return;
105
Chris Lattner7faec9b2006-05-09 05:33:48 +0000106 // Close the current section, if applicable.
107 if (SectionEndDirectiveSuffix && !CurrentSection.empty())
108 O << CurrentSection << SectionEndDirectiveSuffix << "\n";
109
110 CurrentSection = NS;
Chris Lattner4632d7a2006-05-09 04:59:56 +0000111
Chris Lattner7faec9b2006-05-09 05:33:48 +0000112 if (!CurrentSection.empty())
113 O << CurrentSection << DataSectionStartSuffix << '\n';
Chris Lattner4632d7a2006-05-09 04:59:56 +0000114}
115
116
Chris Lattnera80ba712004-08-16 23:15:22 +0000117bool AsmPrinter::doInitialization(Module &M) {
Chris Lattneraf2bf0a2004-08-17 06:06:19 +0000118 Mang = new Mangler(M, GlobalPrefix);
Chris Lattner2c1b1592006-01-23 23:47:53 +0000119
Chris Lattner3e2fa7a2006-01-24 04:16:34 +0000120 if (!M.getModuleInlineAsm().empty())
121 O << CommentString << " Start of file scope inline assembly\n"
122 << M.getModuleInlineAsm()
123 << "\n" << CommentString << " End of file scope inline assembly\n";
Chris Lattner2c1b1592006-01-23 23:47:53 +0000124
Chris Lattner4632d7a2006-05-09 04:59:56 +0000125 SwitchToDataSection("", 0); // Reset back to no section.
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000126
127 if (MachineDebugInfo *DebugInfo = getAnalysisToUpdate<MachineDebugInfo>()) {
128 DebugInfo->AnalyzeModule(M);
129 }
130
Chris Lattnera80ba712004-08-16 23:15:22 +0000131 return false;
132}
133
134bool AsmPrinter::doFinalization(Module &M) {
135 delete Mang; Mang = 0;
136 return false;
137}
138
Chris Lattner25045bd2005-11-21 07:51:36 +0000139void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
Chris Lattnera80ba712004-08-16 23:15:22 +0000140 // What's my mangled name?
Chris Lattner450de392005-11-10 18:36:17 +0000141 CurrentFnName = Mang->getValueName(MF.getFunction());
Chris Lattner77bc2282005-11-21 08:13:27 +0000142 IncrementFunctionNumber();
Chris Lattnera80ba712004-08-16 23:15:22 +0000143}
144
Chris Lattner3b4fd322005-11-21 08:25:09 +0000145/// EmitConstantPool - Print to the current output stream assembly
146/// representations of the constants in the constant pool MCP. This is
147/// used to print out constants which have been "spilled to memory" by
148/// the code generator.
149///
150void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
Chris Lattnerfa77d432006-02-09 04:22:52 +0000151 const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
Chris Lattner3b4fd322005-11-21 08:25:09 +0000152 if (CP.empty()) return;
Evan Cheng2d2cec12006-06-29 00:26:09 +0000153
154 // Some targets require 4-, 8-, and 16- byte constant literals to be placed
155 // in special sections.
156 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > FourByteCPs;
157 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > EightByteCPs;
158 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > SixteenByteCPs;
159 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > OtherCPs;
Chris Lattner3b4fd322005-11-21 08:25:09 +0000160 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
Evan Cheng2d2cec12006-06-29 00:26:09 +0000161 MachineConstantPoolEntry CPE = CP[i];
162 const Constant *CV = CPE.Val;
163 const Type *Ty = CV->getType();
164 if (FourByteConstantSection &&
165 TM.getTargetData()->getTypeSize(Ty) == 4)
166 FourByteCPs.push_back(std::make_pair(CPE, i));
167 else if (EightByteConstantSection &&
168 TM.getTargetData()->getTypeSize(Ty) == 8)
169 EightByteCPs.push_back(std::make_pair(CPE, i));
170 else if (SixteenByteConstantSection &&
171 TM.getTargetData()->getTypeSize(Ty) == 16)
172 SixteenByteCPs.push_back(std::make_pair(CPE, i));
173 else
174 OtherCPs.push_back(std::make_pair(CPE, i));
175 }
176
177 unsigned Alignment = MCP->getConstantPoolAlignment();
178 EmitConstantPool(Alignment, FourByteConstantSection, FourByteCPs);
179 EmitConstantPool(Alignment, EightByteConstantSection, EightByteCPs);
180 EmitConstantPool(Alignment, SixteenByteConstantSection, SixteenByteCPs);
181 EmitConstantPool(Alignment, ConstantPoolSection, OtherCPs);
182}
183
184void AsmPrinter::EmitConstantPool(unsigned Alignment, const char *Section,
185 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > &CP) {
186 if (CP.empty()) return;
187
188 SwitchToDataSection(Section, 0);
189 EmitAlignment(Alignment);
190 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
191 O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << '_'
192 << CP[i].second << ":\t\t\t\t\t" << CommentString << " ";
193 WriteTypeSymbolic(O, CP[i].first.Val->getType(), 0) << '\n';
194 EmitGlobalConstant(CP[i].first.Val);
Chris Lattner3029f922006-02-09 04:46:04 +0000195 if (i != e-1) {
Evan Cheng2d2cec12006-06-29 00:26:09 +0000196 unsigned EntSize =
197 TM.getTargetData()->getTypeSize(CP[i].first.Val->getType());
198 unsigned ValEnd = CP[i].first.Offset + EntSize;
Chris Lattner3029f922006-02-09 04:46:04 +0000199 // Emit inter-object padding for alignment.
Evan Cheng2d2cec12006-06-29 00:26:09 +0000200 EmitZeros(CP[i+1].first.Offset-ValEnd);
Chris Lattner3029f922006-02-09 04:46:04 +0000201 }
Chris Lattner3b4fd322005-11-21 08:25:09 +0000202 }
203}
204
Nate Begeman37efe672006-04-22 18:53:45 +0000205/// EmitJumpTableInfo - Print assembly representations of the jump tables used
206/// by the current function to the current output stream.
207///
208void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI) {
209 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
210 if (JT.empty()) return;
Owen Andersona69571c2006-05-03 01:29:57 +0000211 const TargetData *TD = TM.getTargetData();
Nate Begeman37efe672006-04-22 18:53:45 +0000212
213 // FIXME: someday we need to handle PIC jump tables
214 assert((TM.getRelocationModel() == Reloc::Static ||
215 TM.getRelocationModel() == Reloc::DynamicNoPIC) &&
216 "Unhandled relocation model emitting jump table information!");
217
Chris Lattner4632d7a2006-05-09 04:59:56 +0000218 SwitchToDataSection(JumpTableSection, 0);
Owen Andersona69571c2006-05-03 01:29:57 +0000219 EmitAlignment(Log2_32(TD->getPointerAlignment()));
Nate Begeman37efe672006-04-22 18:53:45 +0000220 for (unsigned i = 0, e = JT.size(); i != e; ++i) {
221 O << PrivateGlobalPrefix << "JTI" << getFunctionNumber() << '_' << i
222 << ":\n";
223 const std::vector<MachineBasicBlock*> &JTBBs = JT[i].MBBs;
224 for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) {
225 O << Data32bitsDirective << ' ';
226 printBasicBlockLabel(JTBBs[ii]);
227 O << '\n';
228 }
229 }
230}
231
Chris Lattnered138932005-12-13 06:32:10 +0000232/// EmitSpecialLLVMGlobal - Check to see if the specified global is a
233/// special global used by LLVM. If so, emit it and return true, otherwise
234/// do nothing and return false.
235bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
Jim Laskey78098112006-03-07 22:00:35 +0000236 // Ignore debug and non-emitted data.
237 if (GV->getSection() == "llvm.metadata") return true;
238
239 if (!GV->hasAppendingLinkage()) return false;
240
241 assert(GV->hasInitializer() && "Not a special LLVM global!");
Chris Lattnered138932005-12-13 06:32:10 +0000242
243 if (GV->getName() == "llvm.used")
244 return true; // No need to emit this at all.
245
Chris Lattner5166b822006-01-12 19:17:23 +0000246 if (GV->getName() == "llvm.global_ctors" && GV->use_empty()) {
Chris Lattner4632d7a2006-05-09 04:59:56 +0000247 SwitchToDataSection(StaticCtorsSection, 0);
Chris Lattnered138932005-12-13 06:32:10 +0000248 EmitAlignment(2, 0);
249 EmitXXStructorList(GV->getInitializer());
250 return true;
251 }
252
Chris Lattner5166b822006-01-12 19:17:23 +0000253 if (GV->getName() == "llvm.global_dtors" && GV->use_empty()) {
Chris Lattner4632d7a2006-05-09 04:59:56 +0000254 SwitchToDataSection(StaticDtorsSection, 0);
Chris Lattnered138932005-12-13 06:32:10 +0000255 EmitAlignment(2, 0);
256 EmitXXStructorList(GV->getInitializer());
257 return true;
258 }
259
260 return false;
261}
262
263/// EmitXXStructorList - Emit the ctor or dtor list. This just prints out the
264/// function pointers, ignoring the init priority.
265void AsmPrinter::EmitXXStructorList(Constant *List) {
266 // Should be an array of '{ int, void ()* }' structs. The first value is the
267 // init priority, which we ignore.
268 if (!isa<ConstantArray>(List)) return;
269 ConstantArray *InitList = cast<ConstantArray>(List);
270 for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
271 if (ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i))){
272 if (CS->getNumOperands() != 2) return; // Not array of 2-element structs.
Chris Lattner8de324b2005-12-21 01:17:37 +0000273
274 if (CS->getOperand(1)->isNullValue())
275 return; // Found a null terminator, exit printing.
276 // Emit the function pointer.
Chris Lattnered138932005-12-13 06:32:10 +0000277 EmitGlobalConstant(CS->getOperand(1));
278 }
279}
Chris Lattner3b4fd322005-11-21 08:25:09 +0000280
Chris Lattner4d57e0c2006-02-05 01:29:18 +0000281/// getPreferredAlignmentLog - Return the preferred alignment of the
282/// specified global, returned in log form. This includes an explicitly
283/// requested alignment (if the global has one).
284unsigned AsmPrinter::getPreferredAlignmentLog(const GlobalVariable *GV) const {
Jim Laskey35f8c202006-06-15 13:10:58 +0000285 const Type *ElemType = GV->getType()->getElementType();
286 unsigned Alignment = TM.getTargetData()->getTypeAlignmentShift(ElemType);
Chris Lattner4d57e0c2006-02-05 01:29:18 +0000287 if (GV->getAlignment() > (1U << Alignment))
288 Alignment = Log2_32(GV->getAlignment());
289
Chris Lattner519ea2a2006-02-05 01:46:49 +0000290 if (GV->hasInitializer()) {
Jim Laskeyd5a932b2006-06-15 19:37:14 +0000291 // Always round up alignment of global doubles to 8 bytes.
292 if (GV->getType()->getElementType() == Type::DoubleTy && Alignment < 3)
293 Alignment = 3;
Chris Lattner519ea2a2006-02-05 01:46:49 +0000294 if (Alignment < 4) {
295 // If the global is not external, see if it is large. If so, give it a
296 // larger alignment.
Jim Laskey35f8c202006-06-15 13:10:58 +0000297 if (TM.getTargetData()->getTypeSize(ElemType) > 128)
Chris Lattner519ea2a2006-02-05 01:46:49 +0000298 Alignment = 4; // 16-byte alignment.
299 }
Chris Lattner4d57e0c2006-02-05 01:29:18 +0000300 }
301 return Alignment;
302}
Chris Lattner3b4fd322005-11-21 08:25:09 +0000303
Chris Lattner25045bd2005-11-21 07:51:36 +0000304// EmitAlignment - Emit an alignment directive to the specified power of two.
305void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV) const {
Chris Lattnera1ab72d2005-11-14 19:00:06 +0000306 if (GV && GV->getAlignment())
307 NumBits = Log2_32(GV->getAlignment());
Chris Lattner2a21c6e2005-11-10 18:09:27 +0000308 if (NumBits == 0) return; // No need to emit alignment.
Chris Lattnerbfddc202004-08-17 19:14:29 +0000309 if (AlignmentIsInBytes) NumBits = 1 << NumBits;
310 O << AlignDirective << NumBits << "\n";
311}
312
Chris Lattner25045bd2005-11-21 07:51:36 +0000313/// EmitZeros - Emit a block of zeros.
Chris Lattner7d057a32004-08-17 21:38:40 +0000314///
Chris Lattner25045bd2005-11-21 07:51:36 +0000315void AsmPrinter::EmitZeros(uint64_t NumZeros) const {
Chris Lattner7d057a32004-08-17 21:38:40 +0000316 if (NumZeros) {
Jeff Cohenc6a057b2006-05-02 03:46:13 +0000317 if (ZeroDirective) {
318 O << ZeroDirective << NumZeros;
319 if (ZeroDirectiveSuffix)
320 O << ZeroDirectiveSuffix;
321 O << "\n";
322 } else {
Chris Lattner7d057a32004-08-17 21:38:40 +0000323 for (; NumZeros; --NumZeros)
324 O << Data8bitsDirective << "0\n";
325 }
326 }
327}
328
Chris Lattnera80ba712004-08-16 23:15:22 +0000329// Print out the specified constant, without a storage class. Only the
330// constants valid in constant expressions can occur here.
Chris Lattner25045bd2005-11-21 07:51:36 +0000331void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
Chris Lattnerbd1d3822004-10-16 18:19:26 +0000332 if (CV->isNullValue() || isa<UndefValue>(CV))
Chris Lattnera80ba712004-08-16 23:15:22 +0000333 O << "0";
334 else if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) {
335 assert(CB == ConstantBool::True);
336 O << "1";
337 } else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV))
338 if (((CI->getValue() << 32) >> 32) == CI->getValue())
339 O << CI->getValue();
340 else
Duraid Madina45606572005-05-15 13:05:48 +0000341 O << (uint64_t)CI->getValue();
Chris Lattnera80ba712004-08-16 23:15:22 +0000342 else if (const ConstantUInt *CI = dyn_cast<ConstantUInt>(CV))
343 O << CI->getValue();
Chris Lattner450de392005-11-10 18:36:17 +0000344 else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
Duraid Madina855a5192005-04-02 12:21:51 +0000345 // This is a constant address for a global variable or function. Use the
346 // name of the variable or function as the address value, possibly
347 // decorating it with GlobalVarAddrPrefix/Suffix or
348 // FunctionAddrPrefix/Suffix (these all default to "" )
Chris Lattner450de392005-11-10 18:36:17 +0000349 if (isa<Function>(GV))
350 O << FunctionAddrPrefix << Mang->getValueName(GV) << FunctionAddrSuffix;
Duraid Madina855a5192005-04-02 12:21:51 +0000351 else
Chris Lattner450de392005-11-10 18:36:17 +0000352 O << GlobalVarAddrPrefix << Mang->getValueName(GV) << GlobalVarAddrSuffix;
Duraid Madina855a5192005-04-02 12:21:51 +0000353 } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
Owen Andersona69571c2006-05-03 01:29:57 +0000354 const TargetData *TD = TM.getTargetData();
Chris Lattnera80ba712004-08-16 23:15:22 +0000355 switch(CE->getOpcode()) {
356 case Instruction::GetElementPtr: {
357 // generate a symbolic expression for the byte address
358 const Constant *ptrVal = CE->getOperand(0);
359 std::vector<Value*> idxVec(CE->op_begin()+1, CE->op_end());
Owen Andersona69571c2006-05-03 01:29:57 +0000360 if (int64_t Offset = TD->getIndexedOffset(ptrVal->getType(), idxVec)) {
Chris Lattner27e19212005-02-14 21:40:26 +0000361 if (Offset)
362 O << "(";
Chris Lattner25045bd2005-11-21 07:51:36 +0000363 EmitConstantValueOnly(ptrVal);
Chris Lattner27e19212005-02-14 21:40:26 +0000364 if (Offset > 0)
365 O << ") + " << Offset;
366 else if (Offset < 0)
367 O << ") - " << -Offset;
Chris Lattnera80ba712004-08-16 23:15:22 +0000368 } else {
Chris Lattner25045bd2005-11-21 07:51:36 +0000369 EmitConstantValueOnly(ptrVal);
Chris Lattnera80ba712004-08-16 23:15:22 +0000370 }
371 break;
372 }
373 case Instruction::Cast: {
374 // Support only non-converting or widening casts for now, that is, ones
375 // that do not involve a change in value. This assertion is really gross,
376 // and may not even be a complete check.
377 Constant *Op = CE->getOperand(0);
378 const Type *OpTy = Op->getType(), *Ty = CE->getType();
379
380 // Remember, kids, pointers can be losslessly converted back and forth
381 // into 32-bit or wider integers, regardless of signedness. :-P
382 assert(((isa<PointerType>(OpTy)
383 && (Ty == Type::LongTy || Ty == Type::ULongTy
384 || Ty == Type::IntTy || Ty == Type::UIntTy))
385 || (isa<PointerType>(Ty)
386 && (OpTy == Type::LongTy || OpTy == Type::ULongTy
387 || OpTy == Type::IntTy || OpTy == Type::UIntTy))
Owen Andersona69571c2006-05-03 01:29:57 +0000388 || (((TD->getTypeSize(Ty) >= TD->getTypeSize(OpTy))
Chris Lattnera80ba712004-08-16 23:15:22 +0000389 && OpTy->isLosslesslyConvertibleTo(Ty))))
390 && "FIXME: Don't yet support this kind of constant cast expr");
Chris Lattner25045bd2005-11-21 07:51:36 +0000391 EmitConstantValueOnly(Op);
Chris Lattnera80ba712004-08-16 23:15:22 +0000392 break;
393 }
394 case Instruction::Add:
395 O << "(";
Chris Lattner25045bd2005-11-21 07:51:36 +0000396 EmitConstantValueOnly(CE->getOperand(0));
Chris Lattnera80ba712004-08-16 23:15:22 +0000397 O << ") + (";
Chris Lattner25045bd2005-11-21 07:51:36 +0000398 EmitConstantValueOnly(CE->getOperand(1));
Chris Lattnera80ba712004-08-16 23:15:22 +0000399 O << ")";
400 break;
401 default:
402 assert(0 && "Unsupported operator!");
403 }
404 } else {
405 assert(0 && "Unknown constant value!");
406 }
407}
Chris Lattner1b7e2352004-08-17 06:36:49 +0000408
409/// toOctal - Convert the low order bits of X into an octal digit.
410///
411static inline char toOctal(int X) {
412 return (X&7)+'0';
413}
414
Chris Lattner2980cef2005-11-10 18:06:33 +0000415/// printAsCString - Print the specified array as a C compatible string, only if
Chris Lattner1b7e2352004-08-17 06:36:49 +0000416/// the predicate isString is true.
417///
Chris Lattner2980cef2005-11-10 18:06:33 +0000418static void printAsCString(std::ostream &O, const ConstantArray *CVA,
419 unsigned LastElt) {
Chris Lattner1b7e2352004-08-17 06:36:49 +0000420 assert(CVA->isString() && "Array is not string compatible!");
421
422 O << "\"";
Chris Lattner2980cef2005-11-10 18:06:33 +0000423 for (unsigned i = 0; i != LastElt; ++i) {
Misha Brukmanedf128a2005-04-21 22:36:52 +0000424 unsigned char C =
Chris Lattnerdea18b62005-01-08 19:59:10 +0000425 (unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getRawValue();
Chris Lattner1b7e2352004-08-17 06:36:49 +0000426
427 if (C == '"') {
428 O << "\\\"";
429 } else if (C == '\\') {
430 O << "\\\\";
431 } else if (isprint(C)) {
432 O << C;
433 } else {
434 switch(C) {
435 case '\b': O << "\\b"; break;
436 case '\f': O << "\\f"; break;
437 case '\n': O << "\\n"; break;
438 case '\r': O << "\\r"; break;
439 case '\t': O << "\\t"; break;
440 default:
441 O << '\\';
442 O << toOctal(C >> 6);
443 O << toOctal(C >> 3);
444 O << toOctal(C >> 0);
445 break;
446 }
447 }
448 }
449 O << "\"";
450}
451
Jeff Cohenc884db42006-05-02 01:16:28 +0000452/// EmitString - Emit a zero-byte-terminated string constant.
453///
454void AsmPrinter::EmitString(const ConstantArray *CVA) const {
455 unsigned NumElts = CVA->getNumOperands();
456 if (AscizDirective && NumElts &&
457 cast<ConstantInt>(CVA->getOperand(NumElts-1))->getRawValue() == 0) {
458 O << AscizDirective;
459 printAsCString(O, CVA, NumElts-1);
460 } else {
461 O << AsciiDirective;
462 printAsCString(O, CVA, NumElts);
463 }
464 O << "\n";
465}
466
Chris Lattner25045bd2005-11-21 07:51:36 +0000467/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
Chris Lattner1b7e2352004-08-17 06:36:49 +0000468///
Chris Lattner25045bd2005-11-21 07:51:36 +0000469void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
Owen Andersona69571c2006-05-03 01:29:57 +0000470 const TargetData *TD = TM.getTargetData();
Chris Lattner1b7e2352004-08-17 06:36:49 +0000471
Chris Lattnerbd1d3822004-10-16 18:19:26 +0000472 if (CV->isNullValue() || isa<UndefValue>(CV)) {
Owen Andersona69571c2006-05-03 01:29:57 +0000473 EmitZeros(TD->getTypeSize(CV->getType()));
Chris Lattner1b7e2352004-08-17 06:36:49 +0000474 return;
475 } else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
476 if (CVA->isString()) {
Jeff Cohenc884db42006-05-02 01:16:28 +0000477 EmitString(CVA);
Chris Lattner1b7e2352004-08-17 06:36:49 +0000478 } else { // Not a string. Print the values in successive locations
479 for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
Chris Lattner25045bd2005-11-21 07:51:36 +0000480 EmitGlobalConstant(CVA->getOperand(i));
Chris Lattner1b7e2352004-08-17 06:36:49 +0000481 }
482 return;
483 } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
484 // Print the fields in successive locations. Pad to align if needed!
Owen Andersona69571c2006-05-03 01:29:57 +0000485 const StructLayout *cvsLayout = TD->getStructLayout(CVS->getType());
Chris Lattnerdea18b62005-01-08 19:59:10 +0000486 uint64_t sizeSoFar = 0;
Chris Lattner1b7e2352004-08-17 06:36:49 +0000487 for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
488 const Constant* field = CVS->getOperand(i);
489
490 // Check if padding is needed and insert one or more 0s.
Owen Andersona69571c2006-05-03 01:29:57 +0000491 uint64_t fieldSize = TD->getTypeSize(field->getType());
Chris Lattnerdea18b62005-01-08 19:59:10 +0000492 uint64_t padSize = ((i == e-1? cvsLayout->StructSize
Chris Lattner1b7e2352004-08-17 06:36:49 +0000493 : cvsLayout->MemberOffsets[i+1])
494 - cvsLayout->MemberOffsets[i]) - fieldSize;
495 sizeSoFar += fieldSize + padSize;
496
497 // Now print the actual field value
Chris Lattner25045bd2005-11-21 07:51:36 +0000498 EmitGlobalConstant(field);
Chris Lattner1b7e2352004-08-17 06:36:49 +0000499
500 // Insert the field padding unless it's zero bytes...
Chris Lattner25045bd2005-11-21 07:51:36 +0000501 EmitZeros(padSize);
Chris Lattner1b7e2352004-08-17 06:36:49 +0000502 }
503 assert(sizeSoFar == cvsLayout->StructSize &&
504 "Layout of constant struct may be incorrect!");
505 return;
506 } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
507 // FP Constants are printed as integer constants to avoid losing
508 // precision...
509 double Val = CFP->getValue();
510 if (CFP->getType() == Type::DoubleTy) {
Chris Lattnere85a5a92004-08-17 06:48:16 +0000511 if (Data64bitsDirective)
Jim Laskeycb6682f2005-08-17 19:34:49 +0000512 O << Data64bitsDirective << DoubleToBits(Val) << "\t" << CommentString
Chris Lattner7d057a32004-08-17 21:38:40 +0000513 << " double value: " << Val << "\n";
Owen Andersona69571c2006-05-03 01:29:57 +0000514 else if (TD->isBigEndian()) {
Jim Laskeycb6682f2005-08-17 19:34:49 +0000515 O << Data32bitsDirective << unsigned(DoubleToBits(Val) >> 32)
Chris Lattnerf746a7d2004-08-18 02:22:55 +0000516 << "\t" << CommentString << " double most significant word "
Chris Lattner0554fb62004-08-17 16:27:05 +0000517 << Val << "\n";
Jim Laskeycb6682f2005-08-17 19:34:49 +0000518 O << Data32bitsDirective << unsigned(DoubleToBits(Val))
Chris Lattnerf746a7d2004-08-18 02:22:55 +0000519 << "\t" << CommentString << " double least significant word "
Chris Lattner0554fb62004-08-17 16:27:05 +0000520 << Val << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000521 } else {
Jim Laskeycb6682f2005-08-17 19:34:49 +0000522 O << Data32bitsDirective << unsigned(DoubleToBits(Val))
Chris Lattnerf746a7d2004-08-18 02:22:55 +0000523 << "\t" << CommentString << " double least significant word " << Val
Chris Lattner0554fb62004-08-17 16:27:05 +0000524 << "\n";
Jim Laskeycb6682f2005-08-17 19:34:49 +0000525 O << Data32bitsDirective << unsigned(DoubleToBits(Val) >> 32)
Chris Lattnerf746a7d2004-08-18 02:22:55 +0000526 << "\t" << CommentString << " double most significant word " << Val
Chris Lattner0554fb62004-08-17 16:27:05 +0000527 << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000528 }
529 return;
530 } else {
Jim Laskeycb6682f2005-08-17 19:34:49 +0000531 O << Data32bitsDirective << FloatToBits(Val) << "\t" << CommentString
Chris Lattner0554fb62004-08-17 16:27:05 +0000532 << " float " << Val << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000533 return;
534 }
535 } else if (CV->getType() == Type::ULongTy || CV->getType() == Type::LongTy) {
536 if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
537 uint64_t Val = CI->getRawValue();
Misha Brukmanedf128a2005-04-21 22:36:52 +0000538
Chris Lattnere85a5a92004-08-17 06:48:16 +0000539 if (Data64bitsDirective)
540 O << Data64bitsDirective << Val << "\n";
Owen Andersona69571c2006-05-03 01:29:57 +0000541 else if (TD->isBigEndian()) {
Chris Lattner1b7e2352004-08-17 06:36:49 +0000542 O << Data32bitsDirective << unsigned(Val >> 32)
Chris Lattnerf746a7d2004-08-18 02:22:55 +0000543 << "\t" << CommentString << " Double-word most significant word "
Chris Lattner0554fb62004-08-17 16:27:05 +0000544 << Val << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000545 O << Data32bitsDirective << unsigned(Val)
Chris Lattnerf746a7d2004-08-18 02:22:55 +0000546 << "\t" << CommentString << " Double-word least significant word "
Chris Lattner0554fb62004-08-17 16:27:05 +0000547 << Val << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000548 } else {
549 O << Data32bitsDirective << unsigned(Val)
Chris Lattnerf746a7d2004-08-18 02:22:55 +0000550 << "\t" << CommentString << " Double-word least significant word "
Chris Lattner0554fb62004-08-17 16:27:05 +0000551 << Val << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000552 O << Data32bitsDirective << unsigned(Val >> 32)
Chris Lattnerf746a7d2004-08-18 02:22:55 +0000553 << "\t" << CommentString << " Double-word most significant word "
Chris Lattner0554fb62004-08-17 16:27:05 +0000554 << Val << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000555 }
556 return;
557 }
Nate Begeman8cfa57b2005-12-06 06:18:55 +0000558 } else if (const ConstantPacked *CP = dyn_cast<ConstantPacked>(CV)) {
559 const PackedType *PTy = CP->getType();
560
561 for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I)
562 EmitGlobalConstant(CP->getOperand(I));
563
564 return;
Chris Lattner1b7e2352004-08-17 06:36:49 +0000565 }
566
567 const Type *type = CV->getType();
Chris Lattner1b7e2352004-08-17 06:36:49 +0000568 switch (type->getTypeID()) {
Misha Brukmanedf128a2005-04-21 22:36:52 +0000569 case Type::BoolTyID:
Chris Lattner1b7e2352004-08-17 06:36:49 +0000570 case Type::UByteTyID: case Type::SByteTyID:
571 O << Data8bitsDirective;
572 break;
573 case Type::UShortTyID: case Type::ShortTyID:
574 O << Data16bitsDirective;
575 break;
Chris Lattner1b7e2352004-08-17 06:36:49 +0000576 case Type::PointerTyID:
Owen Andersona69571c2006-05-03 01:29:57 +0000577 if (TD->getPointerSize() == 8) {
Evan Chenga9767f62006-06-15 08:10:56 +0000578 assert(Data64bitsDirective &&
579 "Target cannot handle 64-bit pointer exprs!");
Andrew Lenharth571c9c32005-02-04 13:47:16 +0000580 O << Data64bitsDirective;
581 break;
582 }
583 //Fall through for pointer size == int size
Chris Lattner1b7e2352004-08-17 06:36:49 +0000584 case Type::UIntTyID: case Type::IntTyID:
585 O << Data32bitsDirective;
586 break;
Misha Brukmanedf128a2005-04-21 22:36:52 +0000587 case Type::ULongTyID: case Type::LongTyID:
Chris Lattner660538c2005-08-08 04:26:32 +0000588 assert(Data64bitsDirective &&"Target cannot handle 64-bit constant exprs!");
589 O << Data64bitsDirective;
590 break;
Chris Lattner1b7e2352004-08-17 06:36:49 +0000591 case Type::FloatTyID: case Type::DoubleTyID:
592 assert (0 && "Should have already output floating point constant.");
593 default:
594 assert (0 && "Can't handle printing this type of thing");
595 break;
596 }
Chris Lattner25045bd2005-11-21 07:51:36 +0000597 EmitConstantValueOnly(CV);
Chris Lattner1b7e2352004-08-17 06:36:49 +0000598 O << "\n";
599}
Chris Lattner0264d1a2006-01-27 02:10:10 +0000600
601/// printInlineAsm - This method formats and prints the specified machine
602/// instruction that is an inline asm.
603void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
Chris Lattner1c059972006-05-05 21:47:05 +0000604 O << InlineAsmStart << "\n\t";
Chris Lattnerf2b67cf2006-01-30 23:00:08 +0000605 unsigned NumOperands = MI->getNumOperands();
606
607 // Count the number of register definitions.
608 unsigned NumDefs = 0;
609 for (; MI->getOperand(NumDefs).isDef(); ++NumDefs)
610 assert(NumDefs != NumOperands-1 && "No asm string?");
611
612 assert(MI->getOperand(NumDefs).isExternalSymbol() && "No asm string?");
Chris Lattner66099132006-02-01 22:41:11 +0000613
614 // Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
Chris Lattnerf2b67cf2006-01-30 23:00:08 +0000615 const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
Chris Lattner66099132006-02-01 22:41:11 +0000616
617 // The variant of the current asmprinter: FIXME: change.
618 int AsmPrinterVariant = 0;
Chris Lattnerf2b67cf2006-01-30 23:00:08 +0000619
Chris Lattner66099132006-02-01 22:41:11 +0000620 int CurVariant = -1; // The number of the {.|.|.} region we are in.
621 const char *LastEmitted = AsmStr; // One past the last character emitted.
Chris Lattner2cc2f662006-02-01 01:28:23 +0000622
Chris Lattner66099132006-02-01 22:41:11 +0000623 while (*LastEmitted) {
624 switch (*LastEmitted) {
625 default: {
626 // Not a special case, emit the string section literally.
627 const char *LiteralEnd = LastEmitted+1;
628 while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
Chris Lattner1c059972006-05-05 21:47:05 +0000629 *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
Chris Lattner66099132006-02-01 22:41:11 +0000630 ++LiteralEnd;
631 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
632 O.write(LastEmitted, LiteralEnd-LastEmitted);
633 LastEmitted = LiteralEnd;
634 break;
635 }
Chris Lattner1c059972006-05-05 21:47:05 +0000636 case '\n':
637 ++LastEmitted; // Consume newline character.
638 O << "\n\t"; // Indent code with newline.
639 break;
Chris Lattner66099132006-02-01 22:41:11 +0000640 case '$': {
641 ++LastEmitted; // Consume '$' character.
642 if (*LastEmitted == '$') { // $$ -> $
643 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
644 O << '$';
645 ++LastEmitted; // Consume second '$' character.
646 break;
647 }
648
649 bool HasCurlyBraces = false;
650 if (*LastEmitted == '{') { // ${variable}
651 ++LastEmitted; // Consume '{' character.
652 HasCurlyBraces = true;
653 }
654
655 const char *IDStart = LastEmitted;
656 char *IDEnd;
657 long Val = strtol(IDStart, &IDEnd, 10); // We only accept numbers for IDs.
658 if (!isdigit(*IDStart) || (Val == 0 && errno == EINVAL)) {
659 std::cerr << "Bad $ operand number in inline asm string: '"
660 << AsmStr << "'\n";
661 exit(1);
662 }
663 LastEmitted = IDEnd;
664
Chris Lattnera36cb0a2006-02-06 22:17:23 +0000665 char Modifier[2] = { 0, 0 };
666
Chris Lattner66099132006-02-01 22:41:11 +0000667 if (HasCurlyBraces) {
Chris Lattnera36cb0a2006-02-06 22:17:23 +0000668 // If we have curly braces, check for a modifier character. This
669 // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
670 if (*LastEmitted == ':') {
671 ++LastEmitted; // Consume ':' character.
672 if (*LastEmitted == 0) {
673 std::cerr << "Bad ${:} expression in inline asm string: '"
674 << AsmStr << "'\n";
675 exit(1);
676 }
677
678 Modifier[0] = *LastEmitted;
679 ++LastEmitted; // Consume modifier character.
680 }
681
Chris Lattner66099132006-02-01 22:41:11 +0000682 if (*LastEmitted != '}') {
683 std::cerr << "Bad ${} expression in inline asm string: '"
684 << AsmStr << "'\n";
685 exit(1);
686 }
687 ++LastEmitted; // Consume '}' character.
688 }
689
690 if ((unsigned)Val >= NumOperands-1) {
691 std::cerr << "Invalid $ operand number in inline asm string: '"
692 << AsmStr << "'\n";
693 exit(1);
694 }
695
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +0000696 // Okay, we finally have a value number. Ask the target to print this
Chris Lattner66099132006-02-01 22:41:11 +0000697 // operand!
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +0000698 if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
699 unsigned OpNo = 1;
Chris Lattnerfd561cd2006-06-08 18:00:47 +0000700
701 bool Error = false;
702
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +0000703 // Scan to find the machine operand number for the operand.
Chris Lattnerdaf6bc62006-02-24 19:50:58 +0000704 for (; Val; --Val) {
Chris Lattnerfd561cd2006-06-08 18:00:47 +0000705 if (OpNo >= MI->getNumOperands()) break;
Chris Lattnerdaf6bc62006-02-24 19:50:58 +0000706 unsigned OpFlags = MI->getOperand(OpNo).getImmedValue();
707 OpNo += (OpFlags >> 3) + 1;
708 }
Chris Lattnerdd260332006-02-24 20:21:58 +0000709
Chris Lattnerfd561cd2006-06-08 18:00:47 +0000710 if (OpNo >= MI->getNumOperands()) {
711 Error = true;
Chris Lattnerdd260332006-02-24 20:21:58 +0000712 } else {
Chris Lattnerfd561cd2006-06-08 18:00:47 +0000713 unsigned OpFlags = MI->getOperand(OpNo).getImmedValue();
714 ++OpNo; // Skip over the ID number.
715
716 AsmPrinter *AP = const_cast<AsmPrinter*>(this);
717 if ((OpFlags & 7) == 4 /*ADDR MODE*/) {
718 Error = AP->PrintAsmMemoryOperand(MI, OpNo, AsmPrinterVariant,
719 Modifier[0] ? Modifier : 0);
720 } else {
721 Error = AP->PrintAsmOperand(MI, OpNo, AsmPrinterVariant,
722 Modifier[0] ? Modifier : 0);
723 }
Chris Lattnerdd260332006-02-24 20:21:58 +0000724 }
725 if (Error) {
Chris Lattner66099132006-02-01 22:41:11 +0000726 std::cerr << "Invalid operand found in inline asm: '"
727 << AsmStr << "'\n";
728 MI->dump();
729 exit(1);
730 }
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +0000731 }
Chris Lattner66099132006-02-01 22:41:11 +0000732 break;
733 }
734 case '{':
735 ++LastEmitted; // Consume '{' character.
736 if (CurVariant != -1) {
737 std::cerr << "Nested variants found in inline asm string: '"
738 << AsmStr << "'\n";
739 exit(1);
740 }
741 CurVariant = 0; // We're in the first variant now.
742 break;
743 case '|':
744 ++LastEmitted; // consume '|' character.
745 if (CurVariant == -1) {
746 std::cerr << "Found '|' character outside of variant in inline asm "
747 << "string: '" << AsmStr << "'\n";
748 exit(1);
749 }
750 ++CurVariant; // We're in the next variant.
751 break;
752 case '}':
753 ++LastEmitted; // consume '}' character.
754 if (CurVariant == -1) {
755 std::cerr << "Found '}' character outside of variant in inline asm "
756 << "string: '" << AsmStr << "'\n";
757 exit(1);
758 }
759 CurVariant = -1;
760 break;
761 }
762 }
Chris Lattner1c059972006-05-05 21:47:05 +0000763 O << "\n\t" << InlineAsmEnd << "\n";
Chris Lattner66099132006-02-01 22:41:11 +0000764}
765
766/// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
767/// instruction, using the specified assembler variant. Targets should
768/// overried this to format as appropriate.
769bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
Chris Lattnera36cb0a2006-02-06 22:17:23 +0000770 unsigned AsmVariant, const char *ExtraCode) {
Chris Lattner66099132006-02-01 22:41:11 +0000771 // Target doesn't support this yet!
772 return true;
Chris Lattner0264d1a2006-01-27 02:10:10 +0000773}
Chris Lattnerdd260332006-02-24 20:21:58 +0000774
775bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
776 unsigned AsmVariant,
777 const char *ExtraCode) {
778 // Target doesn't support this yet!
779 return true;
780}
Nate Begeman37efe672006-04-22 18:53:45 +0000781
782/// printBasicBlockLabel - This method prints the label for the specified
783/// MachineBasicBlock
Nate Begemancdf38c42006-05-02 05:37:32 +0000784void AsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB,
785 bool printColon,
786 bool printComment) const {
Nate Begeman9d51eeb2006-05-02 17:36:46 +0000787 O << PrivateGlobalPrefix << "BB" << FunctionNumber << "_"
788 << MBB->getNumber();
Nate Begemancdf38c42006-05-02 05:37:32 +0000789 if (printColon)
790 O << ':';
791 if (printComment)
792 O << '\t' << CommentString << MBB->getBasicBlock()->getName();
Nate Begeman37efe672006-04-22 18:53:45 +0000793}