AsmPrinter.cpp revision e53a600f065075731d0aeb9dc8f4f3d75f5a05f8
1//===-- AsmPrinter.cpp - Common AsmPrinter code ---------------------------===//
2//
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//
10// This file implements the AsmPrinter class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/CodeGen/AsmPrinter.h"
15#include "llvm/Assembly/Writer.h"
16#include "llvm/DerivedTypes.h"
17#include "llvm/Constants.h"
18#include "llvm/Module.h"
19#include "llvm/CodeGen/GCMetadataPrinter.h"
20#include "llvm/CodeGen/MachineConstantPool.h"
21#include "llvm/CodeGen/MachineJumpTableInfo.h"
22#include "llvm/CodeGen/MachineModuleInfo.h"
23#include "llvm/CodeGen/DwarfWriter.h"
24#include "llvm/Analysis/DebugInfo.h"
25#include "llvm/MC/MCContext.h"
26#include "llvm/MC/MCStreamer.h"
27#include "llvm/MC/MCInst.h"
28#include "llvm/Support/CommandLine.h"
29#include "llvm/Support/ErrorHandling.h"
30#include "llvm/Support/FormattedStream.h"
31#include "llvm/Support/Mangler.h"
32#include "llvm/Target/TargetAsmInfo.h"
33#include "llvm/Target/TargetData.h"
34#include "llvm/Target/TargetLowering.h"
35#include "llvm/Target/TargetLoweringObjectFile.h"
36#include "llvm/Target/TargetOptions.h"
37#include "llvm/Target/TargetRegisterInfo.h"
38#include "llvm/ADT/SmallPtrSet.h"
39#include "llvm/ADT/SmallString.h"
40#include "llvm/ADT/StringExtras.h"
41#include <cerrno>
42using namespace llvm;
43
44static cl::opt<cl::boolOrDefault>
45AsmVerbose("asm-verbose", cl::desc("Add comments to directives."),
46           cl::init(cl::BOU_UNSET));
47
48char AsmPrinter::ID = 0;
49AsmPrinter::AsmPrinter(formatted_raw_ostream &o, TargetMachine &tm,
50                       const TargetAsmInfo *T, bool VDef)
51  : MachineFunctionPass(&ID), FunctionNumber(0), O(o),
52    TM(tm), TAI(T), TRI(tm.getRegisterInfo()),
53
54    OutContext(*new MCContext()),
55    OutStreamer(*createAsmStreamer(OutContext, O)),
56
57    IsInTextSection(false), LastMI(0), LastFn(0), Counter(~0U),
58    PrevDLT(0, ~0U, ~0U) {
59  DW = 0; MMI = 0;
60  switch (AsmVerbose) {
61  case cl::BOU_UNSET: VerboseAsm = VDef;  break;
62  case cl::BOU_TRUE:  VerboseAsm = true;  break;
63  case cl::BOU_FALSE: VerboseAsm = false; break;
64  }
65}
66
67AsmPrinter::~AsmPrinter() {
68  for (gcp_iterator I = GCMetadataPrinters.begin(),
69                    E = GCMetadataPrinters.end(); I != E; ++I)
70    delete I->second;
71
72  delete &OutStreamer;
73  delete &OutContext;
74}
75
76const TargetLoweringObjectFile &AsmPrinter::getObjFileLowering() const {
77  return TM.getTargetLowering()->getObjFileLowering();
78}
79
80
81/// SwitchToTextSection - Switch to the specified text section of the executable
82/// if we are not already in it!
83///
84void AsmPrinter::SwitchToTextSection(const char *NewSection,
85                                     const GlobalValue *GV) {
86  std::string NS;
87  if (GV && GV->hasSection())
88    NS = TAI->getSwitchToSectionDirective() + GV->getSection();
89  else
90    NS = NewSection;
91
92  // If we're already in this section, we're done.
93  if (CurrentSection == NS) return;
94
95  // Close the current section, if applicable.
96  if (TAI->getSectionEndDirectiveSuffix() && !CurrentSection.empty())
97    O << CurrentSection << TAI->getSectionEndDirectiveSuffix() << '\n';
98
99  CurrentSection = NS;
100
101  if (!CurrentSection.empty())
102    O << CurrentSection << TAI->getTextSectionStartSuffix() << '\n';
103
104  IsInTextSection = true;
105}
106
107/// SwitchToDataSection - Switch to the specified data section of the executable
108/// if we are not already in it!
109///
110void AsmPrinter::SwitchToDataSection(const char *NewSection,
111                                     const GlobalValue *GV) {
112  std::string NS;
113  if (GV && GV->hasSection())
114    NS = TAI->getSwitchToSectionDirective() + GV->getSection();
115  else
116    NS = NewSection;
117
118  // If we're already in this section, we're done.
119  if (CurrentSection == NS) return;
120
121  // Close the current section, if applicable.
122  if (TAI->getSectionEndDirectiveSuffix() && !CurrentSection.empty())
123    O << CurrentSection << TAI->getSectionEndDirectiveSuffix() << '\n';
124
125  CurrentSection = NS;
126
127  if (!CurrentSection.empty())
128    O << CurrentSection << TAI->getDataSectionStartSuffix() << '\n';
129
130  IsInTextSection = false;
131}
132
133/// SwitchToSection - Switch to the specified section of the executable if we
134/// are not already in it!
135void AsmPrinter::SwitchToSection(const Section *NS) {
136  const std::string &NewSection = NS->getName();
137
138  // If we're already in this section, we're done.
139  if (CurrentSection == NewSection) return;
140
141  // Close the current section, if applicable.
142  if (TAI->getSectionEndDirectiveSuffix() && !CurrentSection.empty())
143    O << CurrentSection << TAI->getSectionEndDirectiveSuffix() << '\n';
144
145  // FIXME: Make CurrentSection a Section* in the future
146  CurrentSection = NewSection;
147  CurrentSection_ = NS;
148
149  if (!CurrentSection.empty()) {
150    // If section is named we need to switch into it via special '.section'
151    // directive and also append funky flags. Otherwise - section name is just
152    // some magic assembler directive.
153    if (NS->getKind().hasExplicitSection()) {
154      SmallString<32> FlagsStr;
155
156      getObjFileLowering().getSectionFlagsAsString(NS->getKind(), FlagsStr);
157
158      O << TAI->getSwitchToSectionDirective()
159        << CurrentSection
160        << FlagsStr.c_str();
161    } else {
162      O << CurrentSection;
163    }
164    O << TAI->getDataSectionStartSuffix() << '\n';
165  }
166
167  IsInTextSection = NS->getKind().isText();
168}
169
170void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
171  MachineFunctionPass::getAnalysisUsage(AU);
172  AU.addRequired<GCModuleInfo>();
173}
174
175bool AsmPrinter::doInitialization(Module &M) {
176  Mang = new Mangler(M, TAI->getGlobalPrefix(), TAI->getPrivateGlobalPrefix(),
177                     TAI->getLinkerPrivateGlobalPrefix());
178
179  if (TAI->doesAllowQuotesInName())
180    Mang->setUseQuotes(true);
181
182  GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
183  assert(MI && "AsmPrinter didn't require GCModuleInfo?");
184
185  if (TAI->hasSingleParameterDotFile()) {
186    /* Very minimal debug info. It is ignored if we emit actual
187       debug info. If we don't, this at helps the user find where
188       a function came from. */
189    O << "\t.file\t\"" << M.getModuleIdentifier() << "\"\n";
190  }
191
192  for (GCModuleInfo::iterator I = MI->begin(), E = MI->end(); I != E; ++I)
193    if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*I))
194      MP->beginAssembly(O, *this, *TAI);
195
196  if (!M.getModuleInlineAsm().empty())
197    O << TAI->getCommentString() << " Start of file scope inline assembly\n"
198      << M.getModuleInlineAsm()
199      << '\n' << TAI->getCommentString()
200      << " End of file scope inline assembly\n";
201
202  SwitchToDataSection("");   // Reset back to no section.
203
204  if (TAI->doesSupportDebugInformation() ||
205      TAI->doesSupportExceptionHandling()) {
206    MMI = getAnalysisIfAvailable<MachineModuleInfo>();
207    if (MMI)
208      MMI->AnalyzeModule(M);
209    DW = getAnalysisIfAvailable<DwarfWriter>();
210    if (DW)
211      DW->BeginModule(&M, MMI, O, this, TAI);
212  }
213
214  return false;
215}
216
217bool AsmPrinter::doFinalization(Module &M) {
218  // Emit global variables.
219  for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
220       I != E; ++I)
221    PrintGlobalVariable(I);
222
223  // Emit final debug information.
224  if (TAI->doesSupportDebugInformation() || TAI->doesSupportExceptionHandling())
225    DW->EndModule();
226
227  // If the target wants to know about weak references, print them all.
228  if (TAI->getWeakRefDirective()) {
229    // FIXME: This is not lazy, it would be nice to only print weak references
230    // to stuff that is actually used.  Note that doing so would require targets
231    // to notice uses in operands (due to constant exprs etc).  This should
232    // happen with the MC stuff eventually.
233    SwitchToDataSection("");
234
235    // Print out module-level global variables here.
236    for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
237         I != E; ++I) {
238      if (I->hasExternalWeakLinkage())
239        O << TAI->getWeakRefDirective() << Mang->getMangledName(I) << '\n';
240    }
241
242    for (Module::const_iterator I = M.begin(), E = M.end();
243         I != E; ++I) {
244      if (I->hasExternalWeakLinkage())
245        O << TAI->getWeakRefDirective() << Mang->getMangledName(I) << '\n';
246    }
247  }
248
249  if (TAI->getSetDirective()) {
250    O << '\n';
251    for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
252         I != E; ++I) {
253      std::string Name = Mang->getMangledName(I);
254
255      const GlobalValue *GV = cast<GlobalValue>(I->getAliasedGlobal());
256      std::string Target = Mang->getMangledName(GV);
257
258      if (I->hasExternalLinkage() || !TAI->getWeakRefDirective())
259        O << "\t.globl\t" << Name << '\n';
260      else if (I->hasWeakLinkage())
261        O << TAI->getWeakRefDirective() << Name << '\n';
262      else if (!I->hasLocalLinkage())
263        llvm_unreachable("Invalid alias linkage");
264
265      printVisibility(Name, I->getVisibility());
266
267      O << TAI->getSetDirective() << ' ' << Name << ", " << Target << '\n';
268    }
269  }
270
271  GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
272  assert(MI && "AsmPrinter didn't require GCModuleInfo?");
273  for (GCModuleInfo::iterator I = MI->end(), E = MI->begin(); I != E; )
274    if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*--I))
275      MP->finishAssembly(O, *this, *TAI);
276
277  // If we don't have any trampolines, then we don't require stack memory
278  // to be executable. Some targets have a directive to declare this.
279  Function *InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline");
280  if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty())
281    if (TAI->getNonexecutableStackDirective())
282      O << TAI->getNonexecutableStackDirective() << '\n';
283
284  delete Mang; Mang = 0;
285  DW = 0; MMI = 0;
286
287  OutStreamer.Finish();
288  return false;
289}
290
291std::string
292AsmPrinter::getCurrentFunctionEHName(const MachineFunction *MF) const {
293  assert(MF && "No machine function?");
294  return Mang->getMangledName(MF->getFunction(), ".eh",
295                              TAI->is_EHSymbolPrivate());
296}
297
298void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
299  // What's my mangled name?
300  CurrentFnName = Mang->getMangledName(MF.getFunction());
301  IncrementFunctionNumber();
302}
303
304namespace {
305  // SectionCPs - Keep track the alignment, constpool entries per Section.
306  struct SectionCPs {
307    const Section *S;
308    unsigned Alignment;
309    SmallVector<unsigned, 4> CPEs;
310    SectionCPs(const Section *s, unsigned a) : S(s), Alignment(a) {};
311  };
312}
313
314/// EmitConstantPool - Print to the current output stream assembly
315/// representations of the constants in the constant pool MCP. This is
316/// used to print out constants which have been "spilled to memory" by
317/// the code generator.
318///
319void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
320  const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
321  if (CP.empty()) return;
322
323  // Calculate sections for constant pool entries. We collect entries to go into
324  // the same section together to reduce amount of section switch statements.
325  SmallVector<SectionCPs, 4> CPSections;
326  for (unsigned i = 0, e = CP.size(); i != e; ++i) {
327    const MachineConstantPoolEntry &CPE = CP[i];
328    unsigned Align = CPE.getAlignment();
329
330    SectionKind Kind;
331    switch (CPE.getRelocationInfo()) {
332    default: llvm_unreachable("Unknown section kind");
333    case 2: Kind = SectionKind::get(SectionKind::ReadOnlyWithRel, false); break;
334    case 1:
335      Kind = SectionKind::get(SectionKind::ReadOnlyWithRelLocal,false);
336      break;
337    case 0:
338    switch (TM.getTargetData()->getTypeAllocSize(CPE.getType())) {
339    case 4:  Kind = SectionKind::get(SectionKind::MergeableConst4,false); break;
340    case 8:  Kind = SectionKind::get(SectionKind::MergeableConst8,false); break;
341    case 16: Kind = SectionKind::get(SectionKind::MergeableConst16,false);break;
342    default: Kind = SectionKind::get(SectionKind::MergeableConst,false); break;
343    }
344    }
345
346    const Section *S =getObjFileLowering().getSectionForMergeableConstant(Kind);
347
348    // The number of sections are small, just do a linear search from the
349    // last section to the first.
350    bool Found = false;
351    unsigned SecIdx = CPSections.size();
352    while (SecIdx != 0) {
353      if (CPSections[--SecIdx].S == S) {
354        Found = true;
355        break;
356      }
357    }
358    if (!Found) {
359      SecIdx = CPSections.size();
360      CPSections.push_back(SectionCPs(S, Align));
361    }
362
363    if (Align > CPSections[SecIdx].Alignment)
364      CPSections[SecIdx].Alignment = Align;
365    CPSections[SecIdx].CPEs.push_back(i);
366  }
367
368  // Now print stuff into the calculated sections.
369  for (unsigned i = 0, e = CPSections.size(); i != e; ++i) {
370    SwitchToSection(CPSections[i].S);
371    EmitAlignment(Log2_32(CPSections[i].Alignment));
372
373    unsigned Offset = 0;
374    for (unsigned j = 0, ee = CPSections[i].CPEs.size(); j != ee; ++j) {
375      unsigned CPI = CPSections[i].CPEs[j];
376      MachineConstantPoolEntry CPE = CP[CPI];
377
378      // Emit inter-object padding for alignment.
379      unsigned AlignMask = CPE.getAlignment() - 1;
380      unsigned NewOffset = (Offset + AlignMask) & ~AlignMask;
381      EmitZeros(NewOffset - Offset);
382
383      const Type *Ty = CPE.getType();
384      Offset = NewOffset + TM.getTargetData()->getTypeAllocSize(Ty);
385
386      O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
387        << CPI << ":\t\t\t\t\t";
388      if (VerboseAsm) {
389        O << TAI->getCommentString() << ' ';
390        WriteTypeSymbolic(O, CPE.getType(), 0);
391      }
392      O << '\n';
393      if (CPE.isMachineConstantPoolEntry())
394        EmitMachineConstantPoolValue(CPE.Val.MachineCPVal);
395      else
396        EmitGlobalConstant(CPE.Val.ConstVal);
397    }
398  }
399}
400
401/// EmitJumpTableInfo - Print assembly representations of the jump tables used
402/// by the current function to the current output stream.
403///
404void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI,
405                                   MachineFunction &MF) {
406  const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
407  if (JT.empty()) return;
408
409  bool IsPic = TM.getRelocationModel() == Reloc::PIC_;
410
411  // Pick the directive to use to print the jump table entries, and switch to
412  // the appropriate section.
413  TargetLowering *LoweringInfo = TM.getTargetLowering();
414
415  const char *JumpTableDataSection = TAI->getJumpTableDataSection();
416  const Function *F = MF.getFunction();
417
418  const Section *FuncSection =
419    getObjFileLowering().SectionForGlobal(F, Mang, TM);
420
421  bool JTInDiffSection = false;
422  if ((IsPic && !(LoweringInfo && LoweringInfo->usesGlobalOffsetTable())) ||
423      !JumpTableDataSection ||
424      FuncSection->getKind().isWeak()) {
425    // In PIC mode, we need to emit the jump table to the same section as the
426    // function body itself, otherwise the label differences won't make sense.
427    // We should also do if the section name is NULL or function is declared in
428    // discardable section.
429    SwitchToSection(FuncSection);
430  } else {
431    SwitchToDataSection(JumpTableDataSection);
432    JTInDiffSection = true;
433  }
434
435  EmitAlignment(Log2_32(MJTI->getAlignment()));
436
437  for (unsigned i = 0, e = JT.size(); i != e; ++i) {
438    const std::vector<MachineBasicBlock*> &JTBBs = JT[i].MBBs;
439
440    // If this jump table was deleted, ignore it.
441    if (JTBBs.empty()) continue;
442
443    // For PIC codegen, if possible we want to use the SetDirective to reduce
444    // the number of relocations the assembler will generate for the jump table.
445    // Set directives are all printed before the jump table itself.
446    SmallPtrSet<MachineBasicBlock*, 16> EmittedSets;
447    if (TAI->getSetDirective() && IsPic)
448      for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii)
449        if (EmittedSets.insert(JTBBs[ii]))
450          printPICJumpTableSetLabel(i, JTBBs[ii]);
451
452    // On some targets (e.g. darwin) we want to emit two consequtive labels
453    // before each jump table.  The first label is never referenced, but tells
454    // the assembler and linker the extents of the jump table object.  The
455    // second label is actually referenced by the code.
456    if (JTInDiffSection) {
457      if (const char *JTLabelPrefix = TAI->getJumpTableSpecialLabelPrefix())
458        O << JTLabelPrefix << "JTI" << getFunctionNumber() << '_' << i << ":\n";
459    }
460
461    O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
462      << '_' << i << ":\n";
463
464    for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) {
465      printPICJumpTableEntry(MJTI, JTBBs[ii], i);
466      O << '\n';
467    }
468  }
469}
470
471void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
472                                        const MachineBasicBlock *MBB,
473                                        unsigned uid)  const {
474  bool IsPic = TM.getRelocationModel() == Reloc::PIC_;
475
476  // Use JumpTableDirective otherwise honor the entry size from the jump table
477  // info.
478  const char *JTEntryDirective = TAI->getJumpTableDirective();
479  bool HadJTEntryDirective = JTEntryDirective != NULL;
480  if (!HadJTEntryDirective) {
481    JTEntryDirective = MJTI->getEntrySize() == 4 ?
482      TAI->getData32bitsDirective() : TAI->getData64bitsDirective();
483  }
484
485  O << JTEntryDirective << ' ';
486
487  // If we have emitted set directives for the jump table entries, print
488  // them rather than the entries themselves.  If we're emitting PIC, then
489  // emit the table entries as differences between two text section labels.
490  // If we're emitting non-PIC code, then emit the entries as direct
491  // references to the target basic blocks.
492  if (IsPic) {
493    if (TAI->getSetDirective()) {
494      O << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
495        << '_' << uid << "_set_" << MBB->getNumber();
496    } else {
497      printBasicBlockLabel(MBB, false, false, false);
498      // If the arch uses custom Jump Table directives, don't calc relative to
499      // JT
500      if (!HadJTEntryDirective)
501        O << '-' << TAI->getPrivateGlobalPrefix() << "JTI"
502          << getFunctionNumber() << '_' << uid;
503    }
504  } else {
505    printBasicBlockLabel(MBB, false, false, false);
506  }
507}
508
509
510/// EmitSpecialLLVMGlobal - Check to see if the specified global is a
511/// special global used by LLVM.  If so, emit it and return true, otherwise
512/// do nothing and return false.
513bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
514  if (GV->getName() == "llvm.used") {
515    if (TAI->getUsedDirective() != 0)    // No need to emit this at all.
516      EmitLLVMUsedList(GV->getInitializer());
517    return true;
518  }
519
520  // Ignore debug and non-emitted data.  This handles llvm.compiler.used.
521  if (GV->getSection() == "llvm.metadata" ||
522      GV->hasAvailableExternallyLinkage())
523    return true;
524
525  if (!GV->hasAppendingLinkage()) return false;
526
527  assert(GV->hasInitializer() && "Not a special LLVM global!");
528
529  const TargetData *TD = TM.getTargetData();
530  unsigned Align = Log2_32(TD->getPointerPrefAlignment());
531  if (GV->getName() == "llvm.global_ctors") {
532    SwitchToDataSection(TAI->getStaticCtorsSection());
533    EmitAlignment(Align, 0);
534    EmitXXStructorList(GV->getInitializer());
535    return true;
536  }
537
538  if (GV->getName() == "llvm.global_dtors") {
539    SwitchToDataSection(TAI->getStaticDtorsSection());
540    EmitAlignment(Align, 0);
541    EmitXXStructorList(GV->getInitializer());
542    return true;
543  }
544
545  return false;
546}
547
548/// EmitLLVMUsedList - For targets that define a TAI::UsedDirective, mark each
549/// global in the specified llvm.used list for which emitUsedDirectiveFor
550/// is true, as being used with this directive.
551void AsmPrinter::EmitLLVMUsedList(Constant *List) {
552  const char *Directive = TAI->getUsedDirective();
553
554  // Should be an array of 'i8*'.
555  ConstantArray *InitList = dyn_cast<ConstantArray>(List);
556  if (InitList == 0) return;
557
558  for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
559    const GlobalValue *GV =
560      dyn_cast<GlobalValue>(InitList->getOperand(i)->stripPointerCasts());
561    if (GV && TAI->emitUsedDirectiveFor(GV, Mang)) {
562      O << Directive;
563      EmitConstantValueOnly(InitList->getOperand(i));
564      O << '\n';
565    }
566  }
567}
568
569/// EmitXXStructorList - Emit the ctor or dtor list.  This just prints out the
570/// function pointers, ignoring the init priority.
571void AsmPrinter::EmitXXStructorList(Constant *List) {
572  // Should be an array of '{ int, void ()* }' structs.  The first value is the
573  // init priority, which we ignore.
574  if (!isa<ConstantArray>(List)) return;
575  ConstantArray *InitList = cast<ConstantArray>(List);
576  for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
577    if (ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i))){
578      if (CS->getNumOperands() != 2) return;  // Not array of 2-element structs.
579
580      if (CS->getOperand(1)->isNullValue())
581        return;  // Found a null terminator, exit printing.
582      // Emit the function pointer.
583      EmitGlobalConstant(CS->getOperand(1));
584    }
585}
586
587/// getGlobalLinkName - Returns the asm/link name of of the specified
588/// global variable.  Should be overridden by each target asm printer to
589/// generate the appropriate value.
590const std::string &AsmPrinter::getGlobalLinkName(const GlobalVariable *GV,
591                                                 std::string &LinkName) const {
592  if (isa<Function>(GV)) {
593    LinkName += TAI->getFunctionAddrPrefix();
594    LinkName += Mang->getMangledName(GV);
595    LinkName += TAI->getFunctionAddrSuffix();
596  } else {
597    LinkName += TAI->getGlobalVarAddrPrefix();
598    LinkName += Mang->getMangledName(GV);
599    LinkName += TAI->getGlobalVarAddrSuffix();
600  }
601
602  return LinkName;
603}
604
605/// EmitExternalGlobal - Emit the external reference to a global variable.
606/// Should be overridden if an indirect reference should be used.
607void AsmPrinter::EmitExternalGlobal(const GlobalVariable *GV) {
608  std::string GLN;
609  O << getGlobalLinkName(GV, GLN);
610}
611
612
613
614//===----------------------------------------------------------------------===//
615/// LEB 128 number encoding.
616
617/// PrintULEB128 - Print a series of hexidecimal values (separated by commas)
618/// representing an unsigned leb128 value.
619void AsmPrinter::PrintULEB128(unsigned Value) const {
620  char Buffer[20];
621  do {
622    unsigned char Byte = static_cast<unsigned char>(Value & 0x7f);
623    Value >>= 7;
624    if (Value) Byte |= 0x80;
625    O << "0x" << utohex_buffer(Byte, Buffer+20);
626    if (Value) O << ", ";
627  } while (Value);
628}
629
630/// PrintSLEB128 - Print a series of hexidecimal values (separated by commas)
631/// representing a signed leb128 value.
632void AsmPrinter::PrintSLEB128(int Value) const {
633  int Sign = Value >> (8 * sizeof(Value) - 1);
634  bool IsMore;
635  char Buffer[20];
636
637  do {
638    unsigned char Byte = static_cast<unsigned char>(Value & 0x7f);
639    Value >>= 7;
640    IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
641    if (IsMore) Byte |= 0x80;
642    O << "0x" << utohex_buffer(Byte, Buffer+20);
643    if (IsMore) O << ", ";
644  } while (IsMore);
645}
646
647//===--------------------------------------------------------------------===//
648// Emission and print routines
649//
650
651/// PrintHex - Print a value as a hexidecimal value.
652///
653void AsmPrinter::PrintHex(int Value) const {
654  char Buffer[20];
655  O << "0x" << utohex_buffer(static_cast<unsigned>(Value), Buffer+20);
656}
657
658/// EOL - Print a newline character to asm stream.  If a comment is present
659/// then it will be printed first.  Comments should not contain '\n'.
660void AsmPrinter::EOL() const {
661  O << '\n';
662}
663
664void AsmPrinter::EOL(const std::string &Comment) const {
665  if (VerboseAsm && !Comment.empty()) {
666    O << '\t'
667      << TAI->getCommentString()
668      << ' '
669      << Comment;
670  }
671  O << '\n';
672}
673
674void AsmPrinter::EOL(const char* Comment) const {
675  if (VerboseAsm && *Comment) {
676    O << '\t'
677      << TAI->getCommentString()
678      << ' '
679      << Comment;
680  }
681  O << '\n';
682}
683
684/// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
685/// unsigned leb128 value.
686void AsmPrinter::EmitULEB128Bytes(unsigned Value) const {
687  if (TAI->hasLEB128()) {
688    O << "\t.uleb128\t"
689      << Value;
690  } else {
691    O << TAI->getData8bitsDirective();
692    PrintULEB128(Value);
693  }
694}
695
696/// EmitSLEB128Bytes - print an assembler byte data directive to compose a
697/// signed leb128 value.
698void AsmPrinter::EmitSLEB128Bytes(int Value) const {
699  if (TAI->hasLEB128()) {
700    O << "\t.sleb128\t"
701      << Value;
702  } else {
703    O << TAI->getData8bitsDirective();
704    PrintSLEB128(Value);
705  }
706}
707
708/// EmitInt8 - Emit a byte directive and value.
709///
710void AsmPrinter::EmitInt8(int Value) const {
711  O << TAI->getData8bitsDirective();
712  PrintHex(Value & 0xFF);
713}
714
715/// EmitInt16 - Emit a short directive and value.
716///
717void AsmPrinter::EmitInt16(int Value) const {
718  O << TAI->getData16bitsDirective();
719  PrintHex(Value & 0xFFFF);
720}
721
722/// EmitInt32 - Emit a long directive and value.
723///
724void AsmPrinter::EmitInt32(int Value) const {
725  O << TAI->getData32bitsDirective();
726  PrintHex(Value);
727}
728
729/// EmitInt64 - Emit a long long directive and value.
730///
731void AsmPrinter::EmitInt64(uint64_t Value) const {
732  if (TAI->getData64bitsDirective()) {
733    O << TAI->getData64bitsDirective();
734    PrintHex(Value);
735  } else {
736    if (TM.getTargetData()->isBigEndian()) {
737      EmitInt32(unsigned(Value >> 32)); O << '\n';
738      EmitInt32(unsigned(Value));
739    } else {
740      EmitInt32(unsigned(Value)); O << '\n';
741      EmitInt32(unsigned(Value >> 32));
742    }
743  }
744}
745
746/// toOctal - Convert the low order bits of X into an octal digit.
747///
748static inline char toOctal(int X) {
749  return (X&7)+'0';
750}
751
752/// printStringChar - Print a char, escaped if necessary.
753///
754static void printStringChar(formatted_raw_ostream &O, unsigned char C) {
755  if (C == '"') {
756    O << "\\\"";
757  } else if (C == '\\') {
758    O << "\\\\";
759  } else if (isprint((unsigned char)C)) {
760    O << C;
761  } else {
762    switch(C) {
763    case '\b': O << "\\b"; break;
764    case '\f': O << "\\f"; break;
765    case '\n': O << "\\n"; break;
766    case '\r': O << "\\r"; break;
767    case '\t': O << "\\t"; break;
768    default:
769      O << '\\';
770      O << toOctal(C >> 6);
771      O << toOctal(C >> 3);
772      O << toOctal(C >> 0);
773      break;
774    }
775  }
776}
777
778/// EmitString - Emit a string with quotes and a null terminator.
779/// Special characters are emitted properly.
780/// \literal (Eg. '\t') \endliteral
781void AsmPrinter::EmitString(const std::string &String) const {
782  EmitString(String.c_str(), String.size());
783}
784
785void AsmPrinter::EmitString(const char *String, unsigned Size) const {
786  const char* AscizDirective = TAI->getAscizDirective();
787  if (AscizDirective)
788    O << AscizDirective;
789  else
790    O << TAI->getAsciiDirective();
791  O << '\"';
792  for (unsigned i = 0; i < Size; ++i)
793    printStringChar(O, String[i]);
794  if (AscizDirective)
795    O << '\"';
796  else
797    O << "\\0\"";
798}
799
800
801/// EmitFile - Emit a .file directive.
802void AsmPrinter::EmitFile(unsigned Number, const std::string &Name) const {
803  O << "\t.file\t" << Number << " \"";
804  for (unsigned i = 0, N = Name.size(); i < N; ++i)
805    printStringChar(O, Name[i]);
806  O << '\"';
807}
808
809
810//===----------------------------------------------------------------------===//
811
812// EmitAlignment - Emit an alignment directive to the specified power of
813// two boundary.  For example, if you pass in 3 here, you will get an 8
814// byte alignment.  If a global value is specified, and if that global has
815// an explicit alignment requested, it will unconditionally override the
816// alignment request.  However, if ForcedAlignBits is specified, this value
817// has final say: the ultimate alignment will be the max of ForcedAlignBits
818// and the alignment computed with NumBits and the global.
819//
820// The algorithm is:
821//     Align = NumBits;
822//     if (GV && GV->hasalignment) Align = GV->getalignment();
823//     Align = std::max(Align, ForcedAlignBits);
824//
825void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV,
826                               unsigned ForcedAlignBits,
827                               bool UseFillExpr) const {
828  if (GV && GV->getAlignment())
829    NumBits = Log2_32(GV->getAlignment());
830  NumBits = std::max(NumBits, ForcedAlignBits);
831
832  if (NumBits == 0) return;   // No need to emit alignment.
833  if (TAI->getAlignmentIsInBytes()) NumBits = 1 << NumBits;
834  O << TAI->getAlignDirective() << NumBits;
835
836  unsigned FillValue = TAI->getTextAlignFillValue();
837  UseFillExpr &= IsInTextSection && FillValue;
838  if (UseFillExpr) {
839    O << ',';
840    PrintHex(FillValue);
841  }
842  O << '\n';
843}
844
845
846/// EmitZeros - Emit a block of zeros.
847///
848void AsmPrinter::EmitZeros(uint64_t NumZeros, unsigned AddrSpace) const {
849  if (NumZeros) {
850    if (TAI->getZeroDirective()) {
851      O << TAI->getZeroDirective() << NumZeros;
852      if (TAI->getZeroDirectiveSuffix())
853        O << TAI->getZeroDirectiveSuffix();
854      O << '\n';
855    } else {
856      for (; NumZeros; --NumZeros)
857        O << TAI->getData8bitsDirective(AddrSpace) << "0\n";
858    }
859  }
860}
861
862// Print out the specified constant, without a storage class.  Only the
863// constants valid in constant expressions can occur here.
864void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
865  if (CV->isNullValue() || isa<UndefValue>(CV))
866    O << '0';
867  else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
868    O << CI->getZExtValue();
869  } else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
870    // This is a constant address for a global variable or function. Use the
871    // name of the variable or function as the address value, possibly
872    // decorating it with GlobalVarAddrPrefix/Suffix or
873    // FunctionAddrPrefix/Suffix (these all default to "" )
874    if (isa<Function>(GV)) {
875      O << TAI->getFunctionAddrPrefix()
876        << Mang->getMangledName(GV)
877        << TAI->getFunctionAddrSuffix();
878    } else {
879      O << TAI->getGlobalVarAddrPrefix()
880        << Mang->getMangledName(GV)
881        << TAI->getGlobalVarAddrSuffix();
882    }
883  } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
884    const TargetData *TD = TM.getTargetData();
885    unsigned Opcode = CE->getOpcode();
886    switch (Opcode) {
887    case Instruction::GetElementPtr: {
888      // generate a symbolic expression for the byte address
889      const Constant *ptrVal = CE->getOperand(0);
890      SmallVector<Value*, 8> idxVec(CE->op_begin()+1, CE->op_end());
891      if (int64_t Offset = TD->getIndexedOffset(ptrVal->getType(), &idxVec[0],
892                                                idxVec.size())) {
893        // Truncate/sext the offset to the pointer size.
894        if (TD->getPointerSizeInBits() != 64) {
895          int SExtAmount = 64-TD->getPointerSizeInBits();
896          Offset = (Offset << SExtAmount) >> SExtAmount;
897        }
898
899        if (Offset)
900          O << '(';
901        EmitConstantValueOnly(ptrVal);
902        if (Offset > 0)
903          O << ") + " << Offset;
904        else if (Offset < 0)
905          O << ") - " << -Offset;
906      } else {
907        EmitConstantValueOnly(ptrVal);
908      }
909      break;
910    }
911    case Instruction::Trunc:
912    case Instruction::ZExt:
913    case Instruction::SExt:
914    case Instruction::FPTrunc:
915    case Instruction::FPExt:
916    case Instruction::UIToFP:
917    case Instruction::SIToFP:
918    case Instruction::FPToUI:
919    case Instruction::FPToSI:
920      llvm_unreachable("FIXME: Don't yet support this kind of constant cast expr");
921      break;
922    case Instruction::BitCast:
923      return EmitConstantValueOnly(CE->getOperand(0));
924
925    case Instruction::IntToPtr: {
926      // Handle casts to pointers by changing them into casts to the appropriate
927      // integer type.  This promotes constant folding and simplifies this code.
928      Constant *Op = CE->getOperand(0);
929      Op = ConstantExpr::getIntegerCast(Op, TD->getIntPtrType(), false/*ZExt*/);
930      return EmitConstantValueOnly(Op);
931    }
932
933
934    case Instruction::PtrToInt: {
935      // Support only foldable casts to/from pointers that can be eliminated by
936      // changing the pointer to the appropriately sized integer type.
937      Constant *Op = CE->getOperand(0);
938      const Type *Ty = CE->getType();
939
940      // We can emit the pointer value into this slot if the slot is an
941      // integer slot greater or equal to the size of the pointer.
942      if (TD->getTypeAllocSize(Ty) >= TD->getTypeAllocSize(Op->getType()))
943        return EmitConstantValueOnly(Op);
944
945      O << "((";
946      EmitConstantValueOnly(Op);
947      APInt ptrMask = APInt::getAllOnesValue(TD->getTypeAllocSizeInBits(Ty));
948
949      SmallString<40> S;
950      ptrMask.toStringUnsigned(S);
951      O << ") & " << S.c_str() << ')';
952      break;
953    }
954    case Instruction::Add:
955    case Instruction::Sub:
956    case Instruction::And:
957    case Instruction::Or:
958    case Instruction::Xor:
959      O << '(';
960      EmitConstantValueOnly(CE->getOperand(0));
961      O << ')';
962      switch (Opcode) {
963      case Instruction::Add:
964       O << " + ";
965       break;
966      case Instruction::Sub:
967       O << " - ";
968       break;
969      case Instruction::And:
970       O << " & ";
971       break;
972      case Instruction::Or:
973       O << " | ";
974       break;
975      case Instruction::Xor:
976       O << " ^ ";
977       break;
978      default:
979       break;
980      }
981      O << '(';
982      EmitConstantValueOnly(CE->getOperand(1));
983      O << ')';
984      break;
985    default:
986      llvm_unreachable("Unsupported operator!");
987    }
988  } else {
989    llvm_unreachable("Unknown constant value!");
990  }
991}
992
993/// printAsCString - Print the specified array as a C compatible string, only if
994/// the predicate isString is true.
995///
996static void printAsCString(formatted_raw_ostream &O, const ConstantArray *CVA,
997                           unsigned LastElt) {
998  assert(CVA->isString() && "Array is not string compatible!");
999
1000  O << '\"';
1001  for (unsigned i = 0; i != LastElt; ++i) {
1002    unsigned char C =
1003        (unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getZExtValue();
1004    printStringChar(O, C);
1005  }
1006  O << '\"';
1007}
1008
1009/// EmitString - Emit a zero-byte-terminated string constant.
1010///
1011void AsmPrinter::EmitString(const ConstantArray *CVA) const {
1012  unsigned NumElts = CVA->getNumOperands();
1013  if (TAI->getAscizDirective() && NumElts &&
1014      cast<ConstantInt>(CVA->getOperand(NumElts-1))->getZExtValue() == 0) {
1015    O << TAI->getAscizDirective();
1016    printAsCString(O, CVA, NumElts-1);
1017  } else {
1018    O << TAI->getAsciiDirective();
1019    printAsCString(O, CVA, NumElts);
1020  }
1021  O << '\n';
1022}
1023
1024void AsmPrinter::EmitGlobalConstantArray(const ConstantArray *CVA,
1025                                         unsigned AddrSpace) {
1026  if (CVA->isString()) {
1027    EmitString(CVA);
1028  } else { // Not a string.  Print the values in successive locations
1029    for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
1030      EmitGlobalConstant(CVA->getOperand(i), AddrSpace);
1031  }
1032}
1033
1034void AsmPrinter::EmitGlobalConstantVector(const ConstantVector *CP) {
1035  const VectorType *PTy = CP->getType();
1036
1037  for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I)
1038    EmitGlobalConstant(CP->getOperand(I));
1039}
1040
1041void AsmPrinter::EmitGlobalConstantStruct(const ConstantStruct *CVS,
1042                                          unsigned AddrSpace) {
1043  // Print the fields in successive locations. Pad to align if needed!
1044  const TargetData *TD = TM.getTargetData();
1045  unsigned Size = TD->getTypeAllocSize(CVS->getType());
1046  const StructLayout *cvsLayout = TD->getStructLayout(CVS->getType());
1047  uint64_t sizeSoFar = 0;
1048  for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
1049    const Constant* field = CVS->getOperand(i);
1050
1051    // Check if padding is needed and insert one or more 0s.
1052    uint64_t fieldSize = TD->getTypeAllocSize(field->getType());
1053    uint64_t padSize = ((i == e-1 ? Size : cvsLayout->getElementOffset(i+1))
1054                        - cvsLayout->getElementOffset(i)) - fieldSize;
1055    sizeSoFar += fieldSize + padSize;
1056
1057    // Now print the actual field value.
1058    EmitGlobalConstant(field, AddrSpace);
1059
1060    // Insert padding - this may include padding to increase the size of the
1061    // current field up to the ABI size (if the struct is not packed) as well
1062    // as padding to ensure that the next field starts at the right offset.
1063    EmitZeros(padSize, AddrSpace);
1064  }
1065  assert(sizeSoFar == cvsLayout->getSizeInBytes() &&
1066         "Layout of constant struct may be incorrect!");
1067}
1068
1069void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP,
1070                                      unsigned AddrSpace) {
1071  // FP Constants are printed as integer constants to avoid losing
1072  // precision...
1073  const TargetData *TD = TM.getTargetData();
1074  if (CFP->getType() == Type::DoubleTy) {
1075    double Val = CFP->getValueAPF().convertToDouble();  // for comment only
1076    uint64_t i = CFP->getValueAPF().bitcastToAPInt().getZExtValue();
1077    if (TAI->getData64bitsDirective(AddrSpace)) {
1078      O << TAI->getData64bitsDirective(AddrSpace) << i;
1079      if (VerboseAsm)
1080        O << '\t' << TAI->getCommentString() << " double value: " << Val;
1081      O << '\n';
1082    } else if (TD->isBigEndian()) {
1083      O << TAI->getData32bitsDirective(AddrSpace) << unsigned(i >> 32);
1084      if (VerboseAsm)
1085        O << '\t' << TAI->getCommentString()
1086          << " double most significant word " << Val;
1087      O << '\n';
1088      O << TAI->getData32bitsDirective(AddrSpace) << unsigned(i);
1089      if (VerboseAsm)
1090        O << '\t' << TAI->getCommentString()
1091          << " double least significant word " << Val;
1092      O << '\n';
1093    } else {
1094      O << TAI->getData32bitsDirective(AddrSpace) << unsigned(i);
1095      if (VerboseAsm)
1096        O << '\t' << TAI->getCommentString()
1097          << " double least significant word " << Val;
1098      O << '\n';
1099      O << TAI->getData32bitsDirective(AddrSpace) << unsigned(i >> 32);
1100      if (VerboseAsm)
1101        O << '\t' << TAI->getCommentString()
1102          << " double most significant word " << Val;
1103      O << '\n';
1104    }
1105    return;
1106  } else if (CFP->getType() == Type::FloatTy) {
1107    float Val = CFP->getValueAPF().convertToFloat();  // for comment only
1108    O << TAI->getData32bitsDirective(AddrSpace)
1109      << CFP->getValueAPF().bitcastToAPInt().getZExtValue();
1110    if (VerboseAsm)
1111      O << '\t' << TAI->getCommentString() << " float " << Val;
1112    O << '\n';
1113    return;
1114  } else if (CFP->getType() == Type::X86_FP80Ty) {
1115    // all long double variants are printed as hex
1116    // api needed to prevent premature destruction
1117    APInt api = CFP->getValueAPF().bitcastToAPInt();
1118    const uint64_t *p = api.getRawData();
1119    // Convert to double so we can print the approximate val as a comment.
1120    APFloat DoubleVal = CFP->getValueAPF();
1121    bool ignored;
1122    DoubleVal.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
1123                      &ignored);
1124    if (TD->isBigEndian()) {
1125      O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[1]);
1126      if (VerboseAsm)
1127        O << '\t' << TAI->getCommentString()
1128          << " long double most significant halfword of ~"
1129          << DoubleVal.convertToDouble();
1130      O << '\n';
1131      O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 48);
1132      if (VerboseAsm)
1133        O << '\t' << TAI->getCommentString() << " long double next halfword";
1134      O << '\n';
1135      O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 32);
1136      if (VerboseAsm)
1137        O << '\t' << TAI->getCommentString() << " long double next halfword";
1138      O << '\n';
1139      O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 16);
1140      if (VerboseAsm)
1141        O << '\t' << TAI->getCommentString() << " long double next halfword";
1142      O << '\n';
1143      O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0]);
1144      if (VerboseAsm)
1145        O << '\t' << TAI->getCommentString()
1146          << " long double least significant halfword";
1147      O << '\n';
1148     } else {
1149      O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0]);
1150      if (VerboseAsm)
1151        O << '\t' << TAI->getCommentString()
1152          << " long double least significant halfword of ~"
1153          << DoubleVal.convertToDouble();
1154      O << '\n';
1155      O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 16);
1156      if (VerboseAsm)
1157        O << '\t' << TAI->getCommentString()
1158          << " long double next halfword";
1159      O << '\n';
1160      O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 32);
1161      if (VerboseAsm)
1162        O << '\t' << TAI->getCommentString()
1163          << " long double next halfword";
1164      O << '\n';
1165      O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 48);
1166      if (VerboseAsm)
1167        O << '\t' << TAI->getCommentString()
1168          << " long double next halfword";
1169      O << '\n';
1170      O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[1]);
1171      if (VerboseAsm)
1172        O << '\t' << TAI->getCommentString()
1173          << " long double most significant halfword";
1174      O << '\n';
1175    }
1176    EmitZeros(TD->getTypeAllocSize(Type::X86_FP80Ty) -
1177              TD->getTypeStoreSize(Type::X86_FP80Ty), AddrSpace);
1178    return;
1179  } else if (CFP->getType() == Type::PPC_FP128Ty) {
1180    // all long double variants are printed as hex
1181    // api needed to prevent premature destruction
1182    APInt api = CFP->getValueAPF().bitcastToAPInt();
1183    const uint64_t *p = api.getRawData();
1184    if (TD->isBigEndian()) {
1185      O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0] >> 32);
1186      if (VerboseAsm)
1187        O << '\t' << TAI->getCommentString()
1188          << " long double most significant word";
1189      O << '\n';
1190      O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0]);
1191      if (VerboseAsm)
1192        O << '\t' << TAI->getCommentString()
1193        << " long double next word";
1194      O << '\n';
1195      O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1] >> 32);
1196      if (VerboseAsm)
1197        O << '\t' << TAI->getCommentString()
1198          << " long double next word";
1199      O << '\n';
1200      O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1]);
1201      if (VerboseAsm)
1202        O << '\t' << TAI->getCommentString()
1203          << " long double least significant word";
1204      O << '\n';
1205     } else {
1206      O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1]);
1207      if (VerboseAsm)
1208        O << '\t' << TAI->getCommentString()
1209          << " long double least significant word";
1210      O << '\n';
1211      O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1] >> 32);
1212      if (VerboseAsm)
1213        O << '\t' << TAI->getCommentString()
1214          << " long double next word";
1215      O << '\n';
1216      O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0]);
1217      if (VerboseAsm)
1218        O << '\t' << TAI->getCommentString()
1219          << " long double next word";
1220      O << '\n';
1221      O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0] >> 32);
1222      if (VerboseAsm)
1223        O << '\t' << TAI->getCommentString()
1224          << " long double most significant word";
1225      O << '\n';
1226    }
1227    return;
1228  } else llvm_unreachable("Floating point constant type not handled");
1229}
1230
1231void AsmPrinter::EmitGlobalConstantLargeInt(const ConstantInt *CI,
1232                                            unsigned AddrSpace) {
1233  const TargetData *TD = TM.getTargetData();
1234  unsigned BitWidth = CI->getBitWidth();
1235  assert(isPowerOf2_32(BitWidth) &&
1236         "Non-power-of-2-sized integers not handled!");
1237
1238  // We don't expect assemblers to support integer data directives
1239  // for more than 64 bits, so we emit the data in at most 64-bit
1240  // quantities at a time.
1241  const uint64_t *RawData = CI->getValue().getRawData();
1242  for (unsigned i = 0, e = BitWidth / 64; i != e; ++i) {
1243    uint64_t Val;
1244    if (TD->isBigEndian())
1245      Val = RawData[e - i - 1];
1246    else
1247      Val = RawData[i];
1248
1249    if (TAI->getData64bitsDirective(AddrSpace))
1250      O << TAI->getData64bitsDirective(AddrSpace) << Val << '\n';
1251    else if (TD->isBigEndian()) {
1252      O << TAI->getData32bitsDirective(AddrSpace) << unsigned(Val >> 32);
1253      if (VerboseAsm)
1254        O << '\t' << TAI->getCommentString()
1255          << " Double-word most significant word " << Val;
1256      O << '\n';
1257      O << TAI->getData32bitsDirective(AddrSpace) << unsigned(Val);
1258      if (VerboseAsm)
1259        O << '\t' << TAI->getCommentString()
1260          << " Double-word least significant word " << Val;
1261      O << '\n';
1262    } else {
1263      O << TAI->getData32bitsDirective(AddrSpace) << unsigned(Val);
1264      if (VerboseAsm)
1265        O << '\t' << TAI->getCommentString()
1266          << " Double-word least significant word " << Val;
1267      O << '\n';
1268      O << TAI->getData32bitsDirective(AddrSpace) << unsigned(Val >> 32);
1269      if (VerboseAsm)
1270        O << '\t' << TAI->getCommentString()
1271          << " Double-word most significant word " << Val;
1272      O << '\n';
1273    }
1274  }
1275}
1276
1277/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
1278void AsmPrinter::EmitGlobalConstant(const Constant *CV, unsigned AddrSpace) {
1279  const TargetData *TD = TM.getTargetData();
1280  const Type *type = CV->getType();
1281  unsigned Size = TD->getTypeAllocSize(type);
1282
1283  if (CV->isNullValue() || isa<UndefValue>(CV)) {
1284    EmitZeros(Size, AddrSpace);
1285    return;
1286  } else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
1287    EmitGlobalConstantArray(CVA , AddrSpace);
1288    return;
1289  } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
1290    EmitGlobalConstantStruct(CVS, AddrSpace);
1291    return;
1292  } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
1293    EmitGlobalConstantFP(CFP, AddrSpace);
1294    return;
1295  } else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
1296    // Small integers are handled below; large integers are handled here.
1297    if (Size > 4) {
1298      EmitGlobalConstantLargeInt(CI, AddrSpace);
1299      return;
1300    }
1301  } else if (const ConstantVector *CP = dyn_cast<ConstantVector>(CV)) {
1302    EmitGlobalConstantVector(CP);
1303    return;
1304  }
1305
1306  printDataDirective(type, AddrSpace);
1307  EmitConstantValueOnly(CV);
1308  if (VerboseAsm) {
1309    if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
1310      SmallString<40> S;
1311      CI->getValue().toStringUnsigned(S, 16);
1312      O << "\t\t\t" << TAI->getCommentString() << " 0x" << S.c_str();
1313    }
1314  }
1315  O << '\n';
1316}
1317
1318void AsmPrinter::EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
1319  // Target doesn't support this yet!
1320  llvm_unreachable("Target does not support EmitMachineConstantPoolValue");
1321}
1322
1323/// PrintSpecial - Print information related to the specified machine instr
1324/// that is independent of the operand, and may be independent of the instr
1325/// itself.  This can be useful for portably encoding the comment character
1326/// or other bits of target-specific knowledge into the asmstrings.  The
1327/// syntax used is ${:comment}.  Targets can override this to add support
1328/// for their own strange codes.
1329void AsmPrinter::PrintSpecial(const MachineInstr *MI, const char *Code) const {
1330  if (!strcmp(Code, "private")) {
1331    O << TAI->getPrivateGlobalPrefix();
1332  } else if (!strcmp(Code, "comment")) {
1333    if (VerboseAsm)
1334      O << TAI->getCommentString();
1335  } else if (!strcmp(Code, "uid")) {
1336    // Comparing the address of MI isn't sufficient, because machineinstrs may
1337    // be allocated to the same address across functions.
1338    const Function *ThisF = MI->getParent()->getParent()->getFunction();
1339
1340    // If this is a new LastFn instruction, bump the counter.
1341    if (LastMI != MI || LastFn != ThisF) {
1342      ++Counter;
1343      LastMI = MI;
1344      LastFn = ThisF;
1345    }
1346    O << Counter;
1347  } else {
1348    std::string msg;
1349    raw_string_ostream Msg(msg);
1350    Msg << "Unknown special formatter '" << Code
1351         << "' for machine instr: " << *MI;
1352    llvm_report_error(Msg.str());
1353  }
1354}
1355
1356/// processDebugLoc - Processes the debug information of each machine
1357/// instruction's DebugLoc.
1358void AsmPrinter::processDebugLoc(DebugLoc DL) {
1359  if (TAI->doesSupportDebugInformation() && DW->ShouldEmitDwarfDebug()) {
1360    if (!DL.isUnknown()) {
1361      DebugLocTuple CurDLT = MF->getDebugLocTuple(DL);
1362
1363      if (CurDLT.CompileUnit != 0 && PrevDLT != CurDLT)
1364        printLabel(DW->RecordSourceLine(CurDLT.Line, CurDLT.Col,
1365                                        DICompileUnit(CurDLT.CompileUnit)));
1366
1367      PrevDLT = CurDLT;
1368    }
1369  }
1370}
1371
1372/// printInlineAsm - This method formats and prints the specified machine
1373/// instruction that is an inline asm.
1374void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
1375  unsigned NumOperands = MI->getNumOperands();
1376
1377  // Count the number of register definitions.
1378  unsigned NumDefs = 0;
1379  for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef();
1380       ++NumDefs)
1381    assert(NumDefs != NumOperands-1 && "No asm string?");
1382
1383  assert(MI->getOperand(NumDefs).isSymbol() && "No asm string?");
1384
1385  // Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
1386  const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
1387
1388  // If this asmstr is empty, just print the #APP/#NOAPP markers.
1389  // These are useful to see where empty asm's wound up.
1390  if (AsmStr[0] == 0) {
1391    O << TAI->getInlineAsmStart() << "\n\t" << TAI->getInlineAsmEnd() << '\n';
1392    return;
1393  }
1394
1395  O << TAI->getInlineAsmStart() << "\n\t";
1396
1397  // The variant of the current asmprinter.
1398  int AsmPrinterVariant = TAI->getAssemblerDialect();
1399
1400  int CurVariant = -1;            // The number of the {.|.|.} region we are in.
1401  const char *LastEmitted = AsmStr; // One past the last character emitted.
1402
1403  while (*LastEmitted) {
1404    switch (*LastEmitted) {
1405    default: {
1406      // Not a special case, emit the string section literally.
1407      const char *LiteralEnd = LastEmitted+1;
1408      while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
1409             *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
1410        ++LiteralEnd;
1411      if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
1412        O.write(LastEmitted, LiteralEnd-LastEmitted);
1413      LastEmitted = LiteralEnd;
1414      break;
1415    }
1416    case '\n':
1417      ++LastEmitted;   // Consume newline character.
1418      O << '\n';       // Indent code with newline.
1419      break;
1420    case '$': {
1421      ++LastEmitted;   // Consume '$' character.
1422      bool Done = true;
1423
1424      // Handle escapes.
1425      switch (*LastEmitted) {
1426      default: Done = false; break;
1427      case '$':     // $$ -> $
1428        if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
1429          O << '$';
1430        ++LastEmitted;  // Consume second '$' character.
1431        break;
1432      case '(':             // $( -> same as GCC's { character.
1433        ++LastEmitted;      // Consume '(' character.
1434        if (CurVariant != -1) {
1435          llvm_report_error("Nested variants found in inline asm string: '"
1436                            + std::string(AsmStr) + "'");
1437        }
1438        CurVariant = 0;     // We're in the first variant now.
1439        break;
1440      case '|':
1441        ++LastEmitted;  // consume '|' character.
1442        if (CurVariant == -1)
1443          O << '|';       // this is gcc's behavior for | outside a variant
1444        else
1445          ++CurVariant;   // We're in the next variant.
1446        break;
1447      case ')':         // $) -> same as GCC's } char.
1448        ++LastEmitted;  // consume ')' character.
1449        if (CurVariant == -1)
1450          O << '}';     // this is gcc's behavior for } outside a variant
1451        else
1452          CurVariant = -1;
1453        break;
1454      }
1455      if (Done) break;
1456
1457      bool HasCurlyBraces = false;
1458      if (*LastEmitted == '{') {     // ${variable}
1459        ++LastEmitted;               // Consume '{' character.
1460        HasCurlyBraces = true;
1461      }
1462
1463      // If we have ${:foo}, then this is not a real operand reference, it is a
1464      // "magic" string reference, just like in .td files.  Arrange to call
1465      // PrintSpecial.
1466      if (HasCurlyBraces && *LastEmitted == ':') {
1467        ++LastEmitted;
1468        const char *StrStart = LastEmitted;
1469        const char *StrEnd = strchr(StrStart, '}');
1470        if (StrEnd == 0) {
1471          llvm_report_error("Unterminated ${:foo} operand in inline asm string: '"
1472                            + std::string(AsmStr) + "'");
1473        }
1474
1475        std::string Val(StrStart, StrEnd);
1476        PrintSpecial(MI, Val.c_str());
1477        LastEmitted = StrEnd+1;
1478        break;
1479      }
1480
1481      const char *IDStart = LastEmitted;
1482      char *IDEnd;
1483      errno = 0;
1484      long Val = strtol(IDStart, &IDEnd, 10); // We only accept numbers for IDs.
1485      if (!isdigit(*IDStart) || (Val == 0 && errno == EINVAL)) {
1486        llvm_report_error("Bad $ operand number in inline asm string: '"
1487                          + std::string(AsmStr) + "'");
1488      }
1489      LastEmitted = IDEnd;
1490
1491      char Modifier[2] = { 0, 0 };
1492
1493      if (HasCurlyBraces) {
1494        // If we have curly braces, check for a modifier character.  This
1495        // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
1496        if (*LastEmitted == ':') {
1497          ++LastEmitted;    // Consume ':' character.
1498          if (*LastEmitted == 0) {
1499            llvm_report_error("Bad ${:} expression in inline asm string: '"
1500                              + std::string(AsmStr) + "'");
1501          }
1502
1503          Modifier[0] = *LastEmitted;
1504          ++LastEmitted;    // Consume modifier character.
1505        }
1506
1507        if (*LastEmitted != '}') {
1508          llvm_report_error("Bad ${} expression in inline asm string: '"
1509                            + std::string(AsmStr) + "'");
1510        }
1511        ++LastEmitted;    // Consume '}' character.
1512      }
1513
1514      if ((unsigned)Val >= NumOperands-1) {
1515        llvm_report_error("Invalid $ operand number in inline asm string: '"
1516                          + std::string(AsmStr) + "'");
1517      }
1518
1519      // Okay, we finally have a value number.  Ask the target to print this
1520      // operand!
1521      if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
1522        unsigned OpNo = 1;
1523
1524        bool Error = false;
1525
1526        // Scan to find the machine operand number for the operand.
1527        for (; Val; --Val) {
1528          if (OpNo >= MI->getNumOperands()) break;
1529          unsigned OpFlags = MI->getOperand(OpNo).getImm();
1530          OpNo += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
1531        }
1532
1533        if (OpNo >= MI->getNumOperands()) {
1534          Error = true;
1535        } else {
1536          unsigned OpFlags = MI->getOperand(OpNo).getImm();
1537          ++OpNo;  // Skip over the ID number.
1538
1539          if (Modifier[0]=='l')  // labels are target independent
1540            printBasicBlockLabel(MI->getOperand(OpNo).getMBB(),
1541                                 false, false, false);
1542          else {
1543            AsmPrinter *AP = const_cast<AsmPrinter*>(this);
1544            if ((OpFlags & 7) == 4) {
1545              Error = AP->PrintAsmMemoryOperand(MI, OpNo, AsmPrinterVariant,
1546                                                Modifier[0] ? Modifier : 0);
1547            } else {
1548              Error = AP->PrintAsmOperand(MI, OpNo, AsmPrinterVariant,
1549                                          Modifier[0] ? Modifier : 0);
1550            }
1551          }
1552        }
1553        if (Error) {
1554          std::string msg;
1555          raw_string_ostream Msg(msg);
1556          Msg << "Invalid operand found in inline asm: '"
1557               << AsmStr << "'\n";
1558          MI->print(Msg);
1559          llvm_report_error(Msg.str());
1560        }
1561      }
1562      break;
1563    }
1564    }
1565  }
1566  O << "\n\t" << TAI->getInlineAsmEnd() << '\n';
1567}
1568
1569/// printImplicitDef - This method prints the specified machine instruction
1570/// that is an implicit def.
1571void AsmPrinter::printImplicitDef(const MachineInstr *MI) const {
1572  if (VerboseAsm)
1573    O << '\t' << TAI->getCommentString() << " implicit-def: "
1574      << TRI->getAsmName(MI->getOperand(0).getReg()) << '\n';
1575}
1576
1577/// printLabel - This method prints a local label used by debug and
1578/// exception handling tables.
1579void AsmPrinter::printLabel(const MachineInstr *MI) const {
1580  printLabel(MI->getOperand(0).getImm());
1581}
1582
1583void AsmPrinter::printLabel(unsigned Id) const {
1584  O << TAI->getPrivateGlobalPrefix() << "label" << Id << ":\n";
1585}
1586
1587/// printDeclare - This method prints a local variable declaration used by
1588/// debug tables.
1589/// FIXME: It doesn't really print anything rather it inserts a DebugVariable
1590/// entry into dwarf table.
1591void AsmPrinter::printDeclare(const MachineInstr *MI) const {
1592  unsigned FI = MI->getOperand(0).getIndex();
1593  GlobalValue *GV = MI->getOperand(1).getGlobal();
1594  DW->RecordVariable(cast<GlobalVariable>(GV), FI, MI);
1595}
1596
1597/// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
1598/// instruction, using the specified assembler variant.  Targets should
1599/// overried this to format as appropriate.
1600bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
1601                                 unsigned AsmVariant, const char *ExtraCode) {
1602  // Target doesn't support this yet!
1603  return true;
1604}
1605
1606bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
1607                                       unsigned AsmVariant,
1608                                       const char *ExtraCode) {
1609  // Target doesn't support this yet!
1610  return true;
1611}
1612
1613/// printBasicBlockLabel - This method prints the label for the specified
1614/// MachineBasicBlock
1615void AsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB,
1616                                      bool printAlign,
1617                                      bool printColon,
1618                                      bool printComment) const {
1619  if (printAlign) {
1620    unsigned Align = MBB->getAlignment();
1621    if (Align)
1622      EmitAlignment(Log2_32(Align));
1623  }
1624
1625  O << TAI->getPrivateGlobalPrefix() << "BB" << getFunctionNumber() << '_'
1626    << MBB->getNumber();
1627  if (printColon)
1628    O << ':';
1629  if (printComment && MBB->getBasicBlock())
1630    O << '\t' << TAI->getCommentString() << ' '
1631      << MBB->getBasicBlock()->getNameStr();
1632}
1633
1634/// printPICJumpTableSetLabel - This method prints a set label for the
1635/// specified MachineBasicBlock for a jumptable entry.
1636void AsmPrinter::printPICJumpTableSetLabel(unsigned uid,
1637                                           const MachineBasicBlock *MBB) const {
1638  if (!TAI->getSetDirective())
1639    return;
1640
1641  O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
1642    << getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',';
1643  printBasicBlockLabel(MBB, false, false, false);
1644  O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
1645    << '_' << uid << '\n';
1646}
1647
1648void AsmPrinter::printPICJumpTableSetLabel(unsigned uid, unsigned uid2,
1649                                           const MachineBasicBlock *MBB) const {
1650  if (!TAI->getSetDirective())
1651    return;
1652
1653  O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
1654    << getFunctionNumber() << '_' << uid << '_' << uid2
1655    << "_set_" << MBB->getNumber() << ',';
1656  printBasicBlockLabel(MBB, false, false, false);
1657  O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
1658    << '_' << uid << '_' << uid2 << '\n';
1659}
1660
1661/// printDataDirective - This method prints the asm directive for the
1662/// specified type.
1663void AsmPrinter::printDataDirective(const Type *type, unsigned AddrSpace) {
1664  const TargetData *TD = TM.getTargetData();
1665  switch (type->getTypeID()) {
1666  case Type::FloatTyID: case Type::DoubleTyID:
1667  case Type::X86_FP80TyID: case Type::FP128TyID: case Type::PPC_FP128TyID:
1668    assert(0 && "Should have already output floating point constant.");
1669  default:
1670    assert(0 && "Can't handle printing this type of thing");
1671  case Type::IntegerTyID: {
1672    unsigned BitWidth = cast<IntegerType>(type)->getBitWidth();
1673    if (BitWidth <= 8)
1674      O << TAI->getData8bitsDirective(AddrSpace);
1675    else if (BitWidth <= 16)
1676      O << TAI->getData16bitsDirective(AddrSpace);
1677    else if (BitWidth <= 32)
1678      O << TAI->getData32bitsDirective(AddrSpace);
1679    else if (BitWidth <= 64) {
1680      assert(TAI->getData64bitsDirective(AddrSpace) &&
1681             "Target cannot handle 64-bit constant exprs!");
1682      O << TAI->getData64bitsDirective(AddrSpace);
1683    } else {
1684      llvm_unreachable("Target cannot handle given data directive width!");
1685    }
1686    break;
1687  }
1688  case Type::PointerTyID:
1689    if (TD->getPointerSize() == 8) {
1690      assert(TAI->getData64bitsDirective(AddrSpace) &&
1691             "Target cannot handle 64-bit pointer exprs!");
1692      O << TAI->getData64bitsDirective(AddrSpace);
1693    } else if (TD->getPointerSize() == 2) {
1694      O << TAI->getData16bitsDirective(AddrSpace);
1695    } else if (TD->getPointerSize() == 1) {
1696      O << TAI->getData8bitsDirective(AddrSpace);
1697    } else {
1698      O << TAI->getData32bitsDirective(AddrSpace);
1699    }
1700    break;
1701  }
1702}
1703
1704void AsmPrinter::printVisibility(const std::string& Name,
1705                                 unsigned Visibility) const {
1706  if (Visibility == GlobalValue::HiddenVisibility) {
1707    if (const char *Directive = TAI->getHiddenDirective())
1708      O << Directive << Name << '\n';
1709  } else if (Visibility == GlobalValue::ProtectedVisibility) {
1710    if (const char *Directive = TAI->getProtectedDirective())
1711      O << Directive << Name << '\n';
1712  }
1713}
1714
1715void AsmPrinter::printOffset(int64_t Offset) const {
1716  if (Offset > 0)
1717    O << '+' << Offset;
1718  else if (Offset < 0)
1719    O << Offset;
1720}
1721
1722GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(GCStrategy *S) {
1723  if (!S->usesMetadata())
1724    return 0;
1725
1726  gcp_iterator GCPI = GCMetadataPrinters.find(S);
1727  if (GCPI != GCMetadataPrinters.end())
1728    return GCPI->second;
1729
1730  const char *Name = S->getName().c_str();
1731
1732  for (GCMetadataPrinterRegistry::iterator
1733         I = GCMetadataPrinterRegistry::begin(),
1734         E = GCMetadataPrinterRegistry::end(); I != E; ++I)
1735    if (strcmp(Name, I->getName()) == 0) {
1736      GCMetadataPrinter *GMP = I->instantiate();
1737      GMP->S = S;
1738      GCMetadataPrinters.insert(std::make_pair(S, GMP));
1739      return GMP;
1740    }
1741
1742  cerr << "no GCMetadataPrinter registered for GC: " << Name << "\n";
1743  llvm_unreachable(0);
1744}
1745
1746/// EmitComments - Pretty-print comments for instructions
1747void AsmPrinter::EmitComments(const MachineInstr &MI) const
1748{
1749  if (VerboseAsm) {
1750    if (!MI.getDebugLoc().isUnknown()) {
1751      DebugLocTuple DLT = MF->getDebugLocTuple(MI.getDebugLoc());
1752
1753      // Print source line info
1754      O.PadToColumn(TAI->getCommentColumn(), 1);
1755      O << TAI->getCommentString() << " SrcLine ";
1756      if (DLT.CompileUnit->hasInitializer()) {
1757        Constant *Name = DLT.CompileUnit->getInitializer();
1758        if (ConstantArray *NameString = dyn_cast<ConstantArray>(Name))
1759          if (NameString->isString()) {
1760            O << NameString->getAsString() << " ";
1761          }
1762      }
1763      O << DLT.Line;
1764      if (DLT.Col != 0)
1765        O << ":" << DLT.Col;
1766    }
1767  }
1768}
1769
1770/// EmitComments - Pretty-print comments for instructions
1771void AsmPrinter::EmitComments(const MCInst &MI) const
1772{
1773  if (VerboseAsm) {
1774    if (!MI.getDebugLoc().isUnknown()) {
1775      DebugLocTuple DLT = MF->getDebugLocTuple(MI.getDebugLoc());
1776
1777      // Print source line info
1778      O.PadToColumn(TAI->getCommentColumn(), 1);
1779      O << TAI->getCommentString() << " SrcLine ";
1780      if (DLT.CompileUnit->hasInitializer()) {
1781        Constant *Name = DLT.CompileUnit->getInitializer();
1782        if (ConstantArray *NameString = dyn_cast<ConstantArray>(Name))
1783          if (NameString->isString()) {
1784            O << NameString->getAsString() << " ";
1785          }
1786      }
1787      O << DLT.Line;
1788      if (DLT.Col != 0)
1789        O << ":" << DLT.Col;
1790    }
1791  }
1792}
1793