blob: 90a98cb5a75a9f2fc8043501da95a2695310dc06 [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"
Jim Laskeyf1cdea12007-01-25 15:12:02 +000021#include "llvm/Support/CommandLine.h"
Chris Lattnera80ba712004-08-16 23:15:22 +000022#include "llvm/Support/Mangler.h"
Jim Laskeycb6682f2005-08-17 19:34:49 +000023#include "llvm/Support/MathExtras.h"
Bill Wendlingbdc679d2006-11-29 00:39:47 +000024#include "llvm/Support/Streams.h"
Jim Laskey563321a2006-09-06 18:34:40 +000025#include "llvm/Target/TargetAsmInfo.h"
Owen Anderson07000c62006-05-12 06:33:49 +000026#include "llvm/Target/TargetData.h"
Chris Lattner0336fdb2006-10-06 22:50:56 +000027#include "llvm/Target/TargetLowering.h"
Chris Lattnera80ba712004-08-16 23:15:22 +000028#include "llvm/Target/TargetMachine.h"
Chris Lattner66099132006-02-01 22:41:11 +000029#include <cerrno>
Chris Lattnera80ba712004-08-16 23:15:22 +000030using namespace llvm;
31
Jim Laskeyf1cdea12007-01-25 15:12:02 +000032static cl::opt<bool>
33AsmVerbose("asm-verbose", cl::Hidden, cl::desc("Add comments to directives."));
34
Jim Laskeya0f3d172006-09-07 22:06:40 +000035AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm,
36 const TargetAsmInfo *T)
Jim Laskey563321a2006-09-06 18:34:40 +000037: FunctionNumber(0), O(o), TM(tm), TAI(T)
38{}
Chris Lattnered138932005-12-13 06:32:10 +000039
Chris Lattner52f06702006-10-05 02:42:47 +000040std::string AsmPrinter::getSectionForFunction(const Function &F) const {
41 return TAI->getTextSection();
42}
43
Chris Lattnered138932005-12-13 06:32:10 +000044
Chris Lattner4632d7a2006-05-09 04:59:56 +000045/// SwitchToTextSection - Switch to the specified text section of the executable
46/// if we are not already in it!
Chris Lattnerac28fbd2005-11-21 07:06:27 +000047///
Chris Lattner4632d7a2006-05-09 04:59:56 +000048void AsmPrinter::SwitchToTextSection(const char *NewSection,
49 const GlobalValue *GV) {
Chris Lattnerac28fbd2005-11-21 07:06:27 +000050 std::string NS;
Chris Lattnera7090ae2006-05-09 05:24:50 +000051 if (GV && GV->hasSection())
Jim Laskey563321a2006-09-06 18:34:40 +000052 NS = TAI->getSwitchToSectionDirective() + GV->getSection();
Chris Lattnera7090ae2006-05-09 05:24:50 +000053 else
54 NS = NewSection;
55
56 // If we're already in this section, we're done.
57 if (CurrentSection == NS) return;
Jeff Cohen51b776d2006-05-02 03:58:45 +000058
Chris Lattner7faec9b2006-05-09 05:33:48 +000059 // Close the current section, if applicable.
Jim Laskey563321a2006-09-06 18:34:40 +000060 if (TAI->getSectionEndDirectiveSuffix() && !CurrentSection.empty())
61 O << CurrentSection << TAI->getSectionEndDirectiveSuffix() << "\n";
Jeff Cohen51b776d2006-05-02 03:58:45 +000062
Chris Lattner7faec9b2006-05-09 05:33:48 +000063 CurrentSection = NS;
64
65 if (!CurrentSection.empty())
Jim Laskey563321a2006-09-06 18:34:40 +000066 O << CurrentSection << TAI->getTextSectionStartSuffix() << '\n';
Chris Lattnerac28fbd2005-11-21 07:06:27 +000067}
68
Nate Begeman2f1ae882006-07-27 01:13:04 +000069/// SwitchToDataSection - Switch to the specified data section of the executable
Chris Lattner4632d7a2006-05-09 04:59:56 +000070/// if we are not already in it!
71///
72void AsmPrinter::SwitchToDataSection(const char *NewSection,
73 const GlobalValue *GV) {
74 std::string NS;
Chris Lattnerb81cb612006-05-09 05:23:12 +000075 if (GV && GV->hasSection())
Jim Laskey563321a2006-09-06 18:34:40 +000076 NS = TAI->getSwitchToSectionDirective() + GV->getSection();
Chris Lattnerb81cb612006-05-09 05:23:12 +000077 else
78 NS = NewSection;
Chris Lattner4632d7a2006-05-09 04:59:56 +000079
Chris Lattnerb81cb612006-05-09 05:23:12 +000080 // If we're already in this section, we're done.
81 if (CurrentSection == NS) return;
82
Chris Lattner7faec9b2006-05-09 05:33:48 +000083 // Close the current section, if applicable.
Jim Laskey563321a2006-09-06 18:34:40 +000084 if (TAI->getSectionEndDirectiveSuffix() && !CurrentSection.empty())
85 O << CurrentSection << TAI->getSectionEndDirectiveSuffix() << "\n";
Chris Lattner7faec9b2006-05-09 05:33:48 +000086
87 CurrentSection = NS;
Chris Lattner4632d7a2006-05-09 04:59:56 +000088
Chris Lattner7faec9b2006-05-09 05:33:48 +000089 if (!CurrentSection.empty())
Jim Laskey563321a2006-09-06 18:34:40 +000090 O << CurrentSection << TAI->getDataSectionStartSuffix() << '\n';
Chris Lattner4632d7a2006-05-09 04:59:56 +000091}
92
93
Chris Lattnera80ba712004-08-16 23:15:22 +000094bool AsmPrinter::doInitialization(Module &M) {
Jim Laskey563321a2006-09-06 18:34:40 +000095 Mang = new Mangler(M, TAI->getGlobalPrefix());
Chris Lattner2c1b1592006-01-23 23:47:53 +000096
Chris Lattner3e2fa7a2006-01-24 04:16:34 +000097 if (!M.getModuleInlineAsm().empty())
Jim Laskey563321a2006-09-06 18:34:40 +000098 O << TAI->getCommentString() << " Start of file scope inline assembly\n"
Chris Lattner3e2fa7a2006-01-24 04:16:34 +000099 << M.getModuleInlineAsm()
Jim Laskey563321a2006-09-06 18:34:40 +0000100 << "\n" << TAI->getCommentString()
101 << " End of file scope inline assembly\n";
Chris Lattner2c1b1592006-01-23 23:47:53 +0000102
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000103 SwitchToDataSection(""); // Reset back to no section.
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000104
Jim Laskey44c3b9f2007-01-26 21:22:28 +0000105 if (MachineModuleInfo *MMI = getAnalysisToUpdate<MachineModuleInfo>()) {
106 MMI->AnalyzeModule(M);
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000107 }
108
Chris Lattnera80ba712004-08-16 23:15:22 +0000109 return false;
110}
111
112bool AsmPrinter::doFinalization(Module &M) {
Rafael Espindola15404d02006-12-18 03:37:18 +0000113 if (TAI->getWeakRefDirective()) {
Anton Korobeynikov8b0a8c82007-04-25 14:27:10 +0000114 if (!ExtWeakSymbols.empty())
Rafael Espindola15404d02006-12-18 03:37:18 +0000115 SwitchToDataSection("");
116
117 for (std::set<const GlobalValue*>::iterator i = ExtWeakSymbols.begin(),
118 e = ExtWeakSymbols.end(); i != e; ++i) {
119 const GlobalValue *GV = *i;
120 std::string Name = Mang->getValueName(GV);
121 O << TAI->getWeakRefDirective() << Name << "\n";
122 }
123 }
124
Anton Korobeynikov8b0a8c82007-04-25 14:27:10 +0000125 if (TAI->getSetDirective()) {
126 if (M.alias_size())
127 SwitchToTextSection(TAI->getTextSection());
128
129 O << "\n";
130 for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
131 I!=E; ++I) {
132 const GlobalValue *Aliasee = I->getAliasee();
133 assert(Aliasee && "Aliasee cannot be null!");
134 std::string Target = Mang->getValueName(Aliasee);
135 std::string Name = Mang->getValueName(I);
136
137 // Aliases with external weak linkage was emitted already
138 if (I->hasExternalLinkage())
139 O << "\t.globl\t" << Name << "\n";
140 else if (I->hasWeakLinkage())
141 O << TAI->getWeakRefDirective() << Name << "\n";
142 else if (!I->hasInternalLinkage())
143 assert(0 && "Invalid alias linkage");
144
145 O << TAI->getSetDirective() << Name << ", " << Target << "\n";
146 }
147 }
148
Chris Lattnera80ba712004-08-16 23:15:22 +0000149 delete Mang; Mang = 0;
150 return false;
151}
152
Chris Lattner25045bd2005-11-21 07:51:36 +0000153void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
Chris Lattnera80ba712004-08-16 23:15:22 +0000154 // What's my mangled name?
Chris Lattner450de392005-11-10 18:36:17 +0000155 CurrentFnName = Mang->getValueName(MF.getFunction());
Chris Lattner77bc2282005-11-21 08:13:27 +0000156 IncrementFunctionNumber();
Chris Lattnera80ba712004-08-16 23:15:22 +0000157}
158
Chris Lattner3b4fd322005-11-21 08:25:09 +0000159/// EmitConstantPool - Print to the current output stream assembly
160/// representations of the constants in the constant pool MCP. This is
161/// used to print out constants which have been "spilled to memory" by
162/// the code generator.
163///
164void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
Chris Lattnerfa77d432006-02-09 04:22:52 +0000165 const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
Chris Lattner3b4fd322005-11-21 08:25:09 +0000166 if (CP.empty()) return;
Evan Cheng2d2cec12006-06-29 00:26:09 +0000167
168 // Some targets require 4-, 8-, and 16- byte constant literals to be placed
169 // in special sections.
170 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > FourByteCPs;
171 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > EightByteCPs;
172 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > SixteenByteCPs;
173 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > OtherCPs;
Evan Chengd6594ae2006-09-12 21:00:35 +0000174 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > TargetCPs;
Chris Lattner3b4fd322005-11-21 08:25:09 +0000175 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
Evan Cheng2d2cec12006-06-29 00:26:09 +0000176 MachineConstantPoolEntry CPE = CP[i];
Evan Chengd5a99d72006-09-14 07:35:00 +0000177 const Type *Ty = CPE.getType();
Jim Laskey563321a2006-09-06 18:34:40 +0000178 if (TAI->getFourByteConstantSection() &&
Evan Cheng2d2cec12006-06-29 00:26:09 +0000179 TM.getTargetData()->getTypeSize(Ty) == 4)
180 FourByteCPs.push_back(std::make_pair(CPE, i));
Evan Cheng61c958e2006-09-07 18:50:20 +0000181 else if (TAI->getEightByteConstantSection() &&
Evan Cheng2d2cec12006-06-29 00:26:09 +0000182 TM.getTargetData()->getTypeSize(Ty) == 8)
183 EightByteCPs.push_back(std::make_pair(CPE, i));
Evan Cheng61c958e2006-09-07 18:50:20 +0000184 else if (TAI->getSixteenByteConstantSection() &&
Evan Cheng2d2cec12006-06-29 00:26:09 +0000185 TM.getTargetData()->getTypeSize(Ty) == 16)
186 SixteenByteCPs.push_back(std::make_pair(CPE, i));
187 else
188 OtherCPs.push_back(std::make_pair(CPE, i));
189 }
190
191 unsigned Alignment = MCP->getConstantPoolAlignment();
Jim Laskey563321a2006-09-06 18:34:40 +0000192 EmitConstantPool(Alignment, TAI->getFourByteConstantSection(), FourByteCPs);
193 EmitConstantPool(Alignment, TAI->getEightByteConstantSection(), EightByteCPs);
194 EmitConstantPool(Alignment, TAI->getSixteenByteConstantSection(),
195 SixteenByteCPs);
196 EmitConstantPool(Alignment, TAI->getConstantPoolSection(), OtherCPs);
Evan Cheng2d2cec12006-06-29 00:26:09 +0000197}
198
199void AsmPrinter::EmitConstantPool(unsigned Alignment, const char *Section,
200 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > &CP) {
201 if (CP.empty()) return;
202
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000203 SwitchToDataSection(Section);
Evan Cheng2d2cec12006-06-29 00:26:09 +0000204 EmitAlignment(Alignment);
205 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
Jim Laskey563321a2006-09-06 18:34:40 +0000206 O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
207 << CP[i].second << ":\t\t\t\t\t" << TAI->getCommentString() << " ";
Evan Chengd5a99d72006-09-14 07:35:00 +0000208 WriteTypeSymbolic(O, CP[i].first.getType(), 0) << '\n';
209 if (CP[i].first.isMachineConstantPoolEntry())
Evan Chengd6594ae2006-09-12 21:00:35 +0000210 EmitMachineConstantPoolValue(CP[i].first.Val.MachineCPVal);
Evan Chengd5a99d72006-09-14 07:35:00 +0000211 else
Evan Chengd6594ae2006-09-12 21:00:35 +0000212 EmitGlobalConstant(CP[i].first.Val.ConstVal);
Chris Lattner3029f922006-02-09 04:46:04 +0000213 if (i != e-1) {
Evan Chengd5a99d72006-09-14 07:35:00 +0000214 const Type *Ty = CP[i].first.getType();
Evan Cheng2d2cec12006-06-29 00:26:09 +0000215 unsigned EntSize =
Evan Chengd6594ae2006-09-12 21:00:35 +0000216 TM.getTargetData()->getTypeSize(Ty);
Evan Chengd5a99d72006-09-14 07:35:00 +0000217 unsigned ValEnd = CP[i].first.getOffset() + EntSize;
Chris Lattner3029f922006-02-09 04:46:04 +0000218 // Emit inter-object padding for alignment.
Evan Chengd5a99d72006-09-14 07:35:00 +0000219 EmitZeros(CP[i+1].first.getOffset()-ValEnd);
Chris Lattner3029f922006-02-09 04:46:04 +0000220 }
Chris Lattner3b4fd322005-11-21 08:25:09 +0000221 }
222}
223
Nate Begeman37efe672006-04-22 18:53:45 +0000224/// EmitJumpTableInfo - Print assembly representations of the jump tables used
225/// by the current function to the current output stream.
226///
Chris Lattner1da31ee2006-10-05 03:01:21 +0000227void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI,
228 MachineFunction &MF) {
Nate Begeman37efe672006-04-22 18:53:45 +0000229 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
230 if (JT.empty()) return;
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000231 bool IsPic = TM.getRelocationModel() == Reloc::PIC_;
Nate Begeman4d9bbdc2006-07-27 16:46:58 +0000232
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000233 // Use JumpTableDirective otherwise honor the entry size from the jump table
234 // info.
Andrew Lenharthbeec30e2006-09-24 19:45:58 +0000235 const char *JTEntryDirective = TAI->getJumpTableDirective();
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000236 bool HadJTEntryDirective = JTEntryDirective != NULL;
237 if (!HadJTEntryDirective) {
238 JTEntryDirective = MJTI->getEntrySize() == 4 ?
239 TAI->getData32bitsDirective() : TAI->getData64bitsDirective();
240 }
Nate Begeman37efe672006-04-22 18:53:45 +0000241
Nate Begeman2f1ae882006-07-27 01:13:04 +0000242 // Pick the directive to use to print the jump table entries, and switch to
243 // the appropriate section.
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000244 TargetLowering *LoweringInfo = TM.getTargetLowering();
Anton Korobeynikov24287dd2006-12-19 21:04:20 +0000245
246 const char* JumpTableDataSection = TAI->getJumpTableDataSection();
247 if ((IsPic && !(LoweringInfo && LoweringInfo->usesGlobalOffsetTable())) ||
248 !JumpTableDataSection) {
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000249 // In PIC mode, we need to emit the jump table to the same section as the
250 // function body itself, otherwise the label differences won't make sense.
Anton Korobeynikov24287dd2006-12-19 21:04:20 +0000251 // We should also do if the section name is NULL.
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000252 const Function *F = MF.getFunction();
253 SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
Nate Begeman2f1ae882006-07-27 01:13:04 +0000254 } else {
Anton Korobeynikov24287dd2006-12-19 21:04:20 +0000255 SwitchToDataSection(JumpTableDataSection);
Nate Begeman2f1ae882006-07-27 01:13:04 +0000256 }
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000257
258 EmitAlignment(Log2_32(MJTI->getAlignment()));
Chris Lattner0c4e6782006-07-15 01:34:12 +0000259
Nate Begeman37efe672006-04-22 18:53:45 +0000260 for (unsigned i = 0, e = JT.size(); i != e; ++i) {
Nate Begeman52a51e382006-08-12 21:29:52 +0000261 const std::vector<MachineBasicBlock*> &JTBBs = JT[i].MBBs;
Chris Lattner07371882006-10-28 18:10:06 +0000262
263 // If this jump table was deleted, ignore it.
264 if (JTBBs.empty()) continue;
Nate Begeman52a51e382006-08-12 21:29:52 +0000265
266 // For PIC codegen, if possible we want to use the SetDirective to reduce
267 // the number of relocations the assembler will generate for the jump table.
268 // Set directives are all printed before the jump table itself.
269 std::set<MachineBasicBlock*> EmittedSets;
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000270 if (TAI->getSetDirective() && IsPic)
Nate Begeman52a51e382006-08-12 21:29:52 +0000271 for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii)
272 if (EmittedSets.insert(JTBBs[ii]).second)
273 printSetLabel(i, JTBBs[ii]);
274
Chris Lattner393a8ee2007-01-18 01:12:56 +0000275 // On some targets (e.g. darwin) we want to emit two consequtive labels
276 // before each jump table. The first label is never referenced, but tells
277 // the assembler and linker the extents of the jump table object. The
278 // second label is actually referenced by the code.
279 if (const char *JTLabelPrefix = TAI->getJumpTableSpecialLabelPrefix())
280 O << JTLabelPrefix << "JTI" << getFunctionNumber() << '_' << i << ":\n";
281
Jim Laskey563321a2006-09-06 18:34:40 +0000282 O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
283 << '_' << i << ":\n";
Nate Begeman52a51e382006-08-12 21:29:52 +0000284
Nate Begeman37efe672006-04-22 18:53:45 +0000285 for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) {
Nate Begeman4d9bbdc2006-07-27 16:46:58 +0000286 O << JTEntryDirective << ' ';
Nate Begeman52a51e382006-08-12 21:29:52 +0000287 // If we have emitted set directives for the jump table entries, print
288 // them rather than the entries themselves. If we're emitting PIC, then
289 // emit the table entries as differences between two text section labels.
290 // If we're emitting non-PIC code, then emit the entries as direct
291 // references to the target basic blocks.
292 if (!EmittedSets.empty()) {
Jim Laskey563321a2006-09-06 18:34:40 +0000293 O << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
294 << '_' << i << "_set_" << JTBBs[ii]->getNumber();
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000295 } else if (IsPic) {
Nate Begeman52a51e382006-08-12 21:29:52 +0000296 printBasicBlockLabel(JTBBs[ii], false, false);
Chris Lattner393a8ee2007-01-18 01:12:56 +0000297 // If the arch uses custom Jump Table directives, don't calc relative to
298 // JT
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000299 if (!HadJTEntryDirective)
300 O << '-' << TAI->getPrivateGlobalPrefix() << "JTI"
301 << getFunctionNumber() << '_' << i;
Nate Begeman52a51e382006-08-12 21:29:52 +0000302 } else {
303 printBasicBlockLabel(JTBBs[ii], false, false);
Nate Begeman2f1ae882006-07-27 01:13:04 +0000304 }
Nate Begeman37efe672006-04-22 18:53:45 +0000305 O << '\n';
306 }
307 }
308}
309
Chris Lattnered138932005-12-13 06:32:10 +0000310/// EmitSpecialLLVMGlobal - Check to see if the specified global is a
311/// special global used by LLVM. If so, emit it and return true, otherwise
312/// do nothing and return false.
313bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
Jim Laskey78098112006-03-07 22:00:35 +0000314 // Ignore debug and non-emitted data.
315 if (GV->getSection() == "llvm.metadata") return true;
316
317 if (!GV->hasAppendingLinkage()) return false;
318
319 assert(GV->hasInitializer() && "Not a special LLVM global!");
Chris Lattnered138932005-12-13 06:32:10 +0000320
Chris Lattnercb05af82006-09-26 03:38:18 +0000321 if (GV->getName() == "llvm.used") {
322 if (TAI->getUsedDirective() != 0) // No need to emit this at all.
323 EmitLLVMUsedList(GV->getInitializer());
324 return true;
325 }
Chris Lattnered138932005-12-13 06:32:10 +0000326
Chris Lattner5166b822006-01-12 19:17:23 +0000327 if (GV->getName() == "llvm.global_ctors" && GV->use_empty()) {
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000328 SwitchToDataSection(TAI->getStaticCtorsSection());
Chris Lattnered138932005-12-13 06:32:10 +0000329 EmitAlignment(2, 0);
330 EmitXXStructorList(GV->getInitializer());
331 return true;
332 }
333
Chris Lattner5166b822006-01-12 19:17:23 +0000334 if (GV->getName() == "llvm.global_dtors" && GV->use_empty()) {
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000335 SwitchToDataSection(TAI->getStaticDtorsSection());
Chris Lattnered138932005-12-13 06:32:10 +0000336 EmitAlignment(2, 0);
337 EmitXXStructorList(GV->getInitializer());
338 return true;
339 }
340
341 return false;
342}
343
Chris Lattnercb05af82006-09-26 03:38:18 +0000344/// EmitLLVMUsedList - For targets that define a TAI::UsedDirective, mark each
345/// global in the specified llvm.used list as being used with this directive.
346void AsmPrinter::EmitLLVMUsedList(Constant *List) {
347 const char *Directive = TAI->getUsedDirective();
348
349 // Should be an array of 'sbyte*'.
350 ConstantArray *InitList = dyn_cast<ConstantArray>(List);
351 if (InitList == 0) return;
352
353 for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
354 O << Directive;
355 EmitConstantValueOnly(InitList->getOperand(i));
356 O << "\n";
357 }
358}
359
Chris Lattnered138932005-12-13 06:32:10 +0000360/// EmitXXStructorList - Emit the ctor or dtor list. This just prints out the
361/// function pointers, ignoring the init priority.
362void AsmPrinter::EmitXXStructorList(Constant *List) {
363 // Should be an array of '{ int, void ()* }' structs. The first value is the
364 // init priority, which we ignore.
365 if (!isa<ConstantArray>(List)) return;
366 ConstantArray *InitList = cast<ConstantArray>(List);
367 for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
368 if (ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i))){
369 if (CS->getNumOperands() != 2) return; // Not array of 2-element structs.
Chris Lattner8de324b2005-12-21 01:17:37 +0000370
371 if (CS->getOperand(1)->isNullValue())
372 return; // Found a null terminator, exit printing.
373 // Emit the function pointer.
Chris Lattnered138932005-12-13 06:32:10 +0000374 EmitGlobalConstant(CS->getOperand(1));
375 }
376}
Chris Lattner3b4fd322005-11-21 08:25:09 +0000377
Jim Laskeya1a19f82006-10-17 13:41:07 +0000378/// getGlobalLinkName - Returns the asm/link name of of the specified
379/// global variable. Should be overridden by each target asm printer to
380/// generate the appropriate value.
Jim Laskey99e41ee2006-10-17 17:17:24 +0000381const std::string AsmPrinter::getGlobalLinkName(const GlobalVariable *GV) const{
382 std::string LinkName;
Jim Laskey03742482006-11-20 20:29:06 +0000383
384 if (isa<Function>(GV)) {
385 LinkName += TAI->getFunctionAddrPrefix();
386 LinkName += Mang->getValueName(GV);
387 LinkName += TAI->getFunctionAddrSuffix();
388 } else {
389 LinkName += TAI->getGlobalVarAddrPrefix();
390 LinkName += Mang->getValueName(GV);
391 LinkName += TAI->getGlobalVarAddrSuffix();
392 }
393
Jim Laskey99e41ee2006-10-17 17:17:24 +0000394 return LinkName;
Jim Laskeya1a19f82006-10-17 13:41:07 +0000395}
396
Jim Laskeybda9b0e2007-02-21 22:47:38 +0000397/// EmitExternalGlobal - Emit the external reference to a global variable.
398/// Should be overridden if an indirect reference should be used.
399void AsmPrinter::EmitExternalGlobal(const GlobalVariable *GV) {
400 O << getGlobalLinkName(GV);
401}
402
403
404
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000405//===----------------------------------------------------------------------===//
406/// LEB 128 number encoding.
407
408/// PrintULEB128 - Print a series of hexidecimal values (separated by commas)
409/// representing an unsigned leb128 value.
410void AsmPrinter::PrintULEB128(unsigned Value) const {
411 do {
412 unsigned Byte = Value & 0x7f;
413 Value >>= 7;
414 if (Value) Byte |= 0x80;
415 O << "0x" << std::hex << Byte << std::dec;
416 if (Value) O << ", ";
417 } while (Value);
418}
419
420/// SizeULEB128 - Compute the number of bytes required for an unsigned leb128
421/// value.
422unsigned AsmPrinter::SizeULEB128(unsigned Value) {
423 unsigned Size = 0;
424 do {
425 Value >>= 7;
426 Size += sizeof(int8_t);
427 } while (Value);
428 return Size;
429}
430
431/// PrintSLEB128 - Print a series of hexidecimal values (separated by commas)
432/// representing a signed leb128 value.
433void AsmPrinter::PrintSLEB128(int Value) const {
434 int Sign = Value >> (8 * sizeof(Value) - 1);
435 bool IsMore;
436
437 do {
438 unsigned Byte = Value & 0x7f;
439 Value >>= 7;
440 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
441 if (IsMore) Byte |= 0x80;
442 O << "0x" << std::hex << Byte << std::dec;
443 if (IsMore) O << ", ";
444 } while (IsMore);
445}
446
447/// SizeSLEB128 - Compute the number of bytes required for a signed leb128
448/// value.
449unsigned AsmPrinter::SizeSLEB128(int Value) {
450 unsigned Size = 0;
451 int Sign = Value >> (8 * sizeof(Value) - 1);
452 bool IsMore;
453
454 do {
455 unsigned Byte = Value & 0x7f;
456 Value >>= 7;
457 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
458 Size += sizeof(int8_t);
459 } while (IsMore);
460 return Size;
461}
462
463//===--------------------------------------------------------------------===//
464// Emission and print routines
465//
466
467/// PrintHex - Print a value as a hexidecimal value.
468///
469void AsmPrinter::PrintHex(int Value) const {
470 O << "0x" << std::hex << Value << std::dec;
471}
472
473/// EOL - Print a newline character to asm stream. If a comment is present
474/// then it will be printed first. Comments should not contain '\n'.
Jim Laskeybda9b0e2007-02-21 22:47:38 +0000475void AsmPrinter::EOL() const {
476 O << "\n";
477}
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000478void AsmPrinter::EOL(const std::string &Comment) const {
479 if (AsmVerbose && !Comment.empty()) {
480 O << "\t"
481 << TAI->getCommentString()
482 << " "
483 << Comment;
484 }
485 O << "\n";
486}
487
488/// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
489/// unsigned leb128 value.
490void AsmPrinter::EmitULEB128Bytes(unsigned Value) const {
491 if (TAI->hasLEB128()) {
492 O << "\t.uleb128\t"
493 << Value;
494 } else {
495 O << TAI->getData8bitsDirective();
496 PrintULEB128(Value);
497 }
498}
499
500/// EmitSLEB128Bytes - print an assembler byte data directive to compose a
501/// signed leb128 value.
502void AsmPrinter::EmitSLEB128Bytes(int Value) const {
503 if (TAI->hasLEB128()) {
504 O << "\t.sleb128\t"
505 << Value;
506 } else {
507 O << TAI->getData8bitsDirective();
508 PrintSLEB128(Value);
509 }
510}
511
512/// EmitInt8 - Emit a byte directive and value.
513///
514void AsmPrinter::EmitInt8(int Value) const {
515 O << TAI->getData8bitsDirective();
516 PrintHex(Value & 0xFF);
517}
518
519/// EmitInt16 - Emit a short directive and value.
520///
521void AsmPrinter::EmitInt16(int Value) const {
522 O << TAI->getData16bitsDirective();
523 PrintHex(Value & 0xFFFF);
524}
525
526/// EmitInt32 - Emit a long directive and value.
527///
528void AsmPrinter::EmitInt32(int Value) const {
529 O << TAI->getData32bitsDirective();
530 PrintHex(Value);
531}
532
533/// EmitInt64 - Emit a long long directive and value.
534///
535void AsmPrinter::EmitInt64(uint64_t Value) const {
536 if (TAI->getData64bitsDirective()) {
537 O << TAI->getData64bitsDirective();
538 PrintHex(Value);
539 } else {
540 if (TM.getTargetData()->isBigEndian()) {
541 EmitInt32(unsigned(Value >> 32)); O << "\n";
542 EmitInt32(unsigned(Value));
543 } else {
544 EmitInt32(unsigned(Value)); O << "\n";
545 EmitInt32(unsigned(Value >> 32));
546 }
547 }
548}
549
550/// toOctal - Convert the low order bits of X into an octal digit.
551///
552static inline char toOctal(int X) {
553 return (X&7)+'0';
554}
555
556/// printStringChar - Print a char, escaped if necessary.
557///
558static void printStringChar(std::ostream &O, unsigned char C) {
559 if (C == '"') {
560 O << "\\\"";
561 } else if (C == '\\') {
562 O << "\\\\";
563 } else if (isprint(C)) {
564 O << C;
565 } else {
566 switch(C) {
567 case '\b': O << "\\b"; break;
568 case '\f': O << "\\f"; break;
569 case '\n': O << "\\n"; break;
570 case '\r': O << "\\r"; break;
571 case '\t': O << "\\t"; break;
572 default:
573 O << '\\';
574 O << toOctal(C >> 6);
575 O << toOctal(C >> 3);
576 O << toOctal(C >> 0);
577 break;
578 }
579 }
580}
581
582/// EmitString - Emit a string with quotes and a null terminator.
583/// Special characters are emitted properly.
584/// \literal (Eg. '\t') \endliteral
585void AsmPrinter::EmitString(const std::string &String) const {
Anton Korobeynikovfb269cf2007-03-06 19:25:02 +0000586 const char* AscizDirective = TAI->getAscizDirective();
587 if (AscizDirective)
588 O << AscizDirective;
589 else
590 O << TAI->getAsciiDirective();
591 O << "\"";
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000592 for (unsigned i = 0, N = String.size(); i < N; ++i) {
593 unsigned char C = String[i];
594 printStringChar(O, C);
595 }
Anton Korobeynikovfb269cf2007-03-06 19:25:02 +0000596 if (AscizDirective)
597 O << "\"";
598 else
599 O << "\\0\"";
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000600}
601
602
603//===----------------------------------------------------------------------===//
604
Chris Lattner25045bd2005-11-21 07:51:36 +0000605// EmitAlignment - Emit an alignment directive to the specified power of two.
Dale Johannesen19f54692007-04-23 19:58:54 +0000606// Use the maximum of the specified alignment and the alignment from the
607// specified GlobalValue (if any).
Chris Lattner25045bd2005-11-21 07:51:36 +0000608void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV) const {
Dale Johannesen00d56b92007-04-23 23:33:31 +0000609 if (GV && GV->getAlignment())
610 NumBits = std::max(NumBits, Log2_32(GV->getAlignment()));
Chris Lattner2a21c6e2005-11-10 18:09:27 +0000611 if (NumBits == 0) return; // No need to emit alignment.
Jim Laskey563321a2006-09-06 18:34:40 +0000612 if (TAI->getAlignmentIsInBytes()) NumBits = 1 << NumBits;
613 O << TAI->getAlignDirective() << NumBits << "\n";
Chris Lattnerbfddc202004-08-17 19:14:29 +0000614}
615
Jim Laskeybda9b0e2007-02-21 22:47:38 +0000616
Chris Lattner25045bd2005-11-21 07:51:36 +0000617/// EmitZeros - Emit a block of zeros.
Chris Lattner7d057a32004-08-17 21:38:40 +0000618///
Chris Lattner25045bd2005-11-21 07:51:36 +0000619void AsmPrinter::EmitZeros(uint64_t NumZeros) const {
Chris Lattner7d057a32004-08-17 21:38:40 +0000620 if (NumZeros) {
Jim Laskey563321a2006-09-06 18:34:40 +0000621 if (TAI->getZeroDirective()) {
622 O << TAI->getZeroDirective() << NumZeros;
623 if (TAI->getZeroDirectiveSuffix())
624 O << TAI->getZeroDirectiveSuffix();
Jeff Cohenc6a057b2006-05-02 03:46:13 +0000625 O << "\n";
626 } else {
Chris Lattner7d057a32004-08-17 21:38:40 +0000627 for (; NumZeros; --NumZeros)
Jim Laskey563321a2006-09-06 18:34:40 +0000628 O << TAI->getData8bitsDirective() << "0\n";
Chris Lattner7d057a32004-08-17 21:38:40 +0000629 }
630 }
631}
632
Chris Lattnera80ba712004-08-16 23:15:22 +0000633// Print out the specified constant, without a storage class. Only the
634// constants valid in constant expressions can occur here.
Chris Lattner25045bd2005-11-21 07:51:36 +0000635void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
Chris Lattnerbd1d3822004-10-16 18:19:26 +0000636 if (CV->isNullValue() || isa<UndefValue>(CV))
Chris Lattnera80ba712004-08-16 23:15:22 +0000637 O << "0";
Zhou Sheng6b6b6ef2007-01-11 12:24:14 +0000638 else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
Chris Lattnera875df32007-01-12 18:15:09 +0000639 O << CI->getZExtValue();
Reid Spencerb83eb642006-10-20 07:07:24 +0000640 } else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
Duraid Madina855a5192005-04-02 12:21:51 +0000641 // This is a constant address for a global variable or function. Use the
642 // name of the variable or function as the address value, possibly
643 // decorating it with GlobalVarAddrPrefix/Suffix or
644 // FunctionAddrPrefix/Suffix (these all default to "" )
Jim Laskey563321a2006-09-06 18:34:40 +0000645 if (isa<Function>(GV)) {
646 O << TAI->getFunctionAddrPrefix()
647 << Mang->getValueName(GV)
648 << TAI->getFunctionAddrSuffix();
649 } else {
650 O << TAI->getGlobalVarAddrPrefix()
651 << Mang->getValueName(GV)
652 << TAI->getGlobalVarAddrSuffix();
653 }
Duraid Madina855a5192005-04-02 12:21:51 +0000654 } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
Owen Andersona69571c2006-05-03 01:29:57 +0000655 const TargetData *TD = TM.getTargetData();
Anton Korobeynikov13b7d3d2007-02-04 23:27:42 +0000656 unsigned Opcode = CE->getOpcode();
657 switch (Opcode) {
Chris Lattnera80ba712004-08-16 23:15:22 +0000658 case Instruction::GetElementPtr: {
659 // generate a symbolic expression for the byte address
660 const Constant *ptrVal = CE->getOperand(0);
Chris Lattner7f6b9d22007-02-10 20:31:59 +0000661 SmallVector<Value*, 8> idxVec(CE->op_begin()+1, CE->op_end());
662 if (int64_t Offset = TD->getIndexedOffset(ptrVal->getType(), &idxVec[0],
663 idxVec.size())) {
Chris Lattner27e19212005-02-14 21:40:26 +0000664 if (Offset)
665 O << "(";
Chris Lattner25045bd2005-11-21 07:51:36 +0000666 EmitConstantValueOnly(ptrVal);
Chris Lattner27e19212005-02-14 21:40:26 +0000667 if (Offset > 0)
668 O << ") + " << Offset;
669 else if (Offset < 0)
670 O << ") - " << -Offset;
Chris Lattnera80ba712004-08-16 23:15:22 +0000671 } else {
Chris Lattner25045bd2005-11-21 07:51:36 +0000672 EmitConstantValueOnly(ptrVal);
Chris Lattnera80ba712004-08-16 23:15:22 +0000673 }
674 break;
675 }
Reid Spencer3da59db2006-11-27 01:05:10 +0000676 case Instruction::Trunc:
677 case Instruction::ZExt:
678 case Instruction::SExt:
679 case Instruction::FPTrunc:
680 case Instruction::FPExt:
681 case Instruction::UIToFP:
682 case Instruction::SIToFP:
683 case Instruction::FPToUI:
684 case Instruction::FPToSI:
685 assert(0 && "FIXME: Don't yet support this kind of constant cast expr");
686 break;
Chris Lattnercb0a6812006-12-12 05:14:13 +0000687 case Instruction::BitCast:
688 return EmitConstantValueOnly(CE->getOperand(0));
689
Chris Lattnerddc94012006-12-12 05:18:19 +0000690 case Instruction::IntToPtr: {
691 // Handle casts to pointers by changing them into casts to the appropriate
692 // integer type. This promotes constant folding and simplifies this code.
693 Constant *Op = CE->getOperand(0);
694 Op = ConstantExpr::getIntegerCast(Op, TD->getIntPtrType(), false/*ZExt*/);
695 return EmitConstantValueOnly(Op);
696 }
697
698
699 case Instruction::PtrToInt: {
Chris Lattner4a6bd332006-07-29 01:57:19 +0000700 // Support only foldable casts to/from pointers that can be eliminated by
701 // changing the pointer to the appropriately sized integer type.
Chris Lattnera80ba712004-08-16 23:15:22 +0000702 Constant *Op = CE->getOperand(0);
Chris Lattnerddc94012006-12-12 05:18:19 +0000703 const Type *Ty = CE->getType();
Chris Lattnera80ba712004-08-16 23:15:22 +0000704
Chris Lattnerddc94012006-12-12 05:18:19 +0000705 // We can emit the pointer value into this slot if the slot is an
706 // integer slot greater or equal to the size of the pointer.
Chris Lattner42a75512007-01-15 02:27:26 +0000707 if (Ty->isInteger() &&
Reid Spencera54b7cb2007-01-12 07:05:14 +0000708 TD->getTypeSize(Ty) >= TD->getTypeSize(Op->getType()))
Chris Lattner4a6bd332006-07-29 01:57:19 +0000709 return EmitConstantValueOnly(Op);
Chris Lattner4a6bd332006-07-29 01:57:19 +0000710
711 assert(0 && "FIXME: Don't yet support this kind of constant cast expr");
Chris Lattner25045bd2005-11-21 07:51:36 +0000712 EmitConstantValueOnly(Op);
Chris Lattnera80ba712004-08-16 23:15:22 +0000713 break;
714 }
715 case Instruction::Add:
Anton Korobeynikov13b7d3d2007-02-04 23:27:42 +0000716 case Instruction::Sub:
Chris Lattnera80ba712004-08-16 23:15:22 +0000717 O << "(";
Chris Lattner25045bd2005-11-21 07:51:36 +0000718 EmitConstantValueOnly(CE->getOperand(0));
Anton Korobeynikov13b7d3d2007-02-04 23:27:42 +0000719 O << (Opcode==Instruction::Add ? ") + (" : ") - (");
Chris Lattner25045bd2005-11-21 07:51:36 +0000720 EmitConstantValueOnly(CE->getOperand(1));
Chris Lattnera80ba712004-08-16 23:15:22 +0000721 O << ")";
722 break;
723 default:
724 assert(0 && "Unsupported operator!");
725 }
726 } else {
727 assert(0 && "Unknown constant value!");
728 }
729}
Chris Lattner1b7e2352004-08-17 06:36:49 +0000730
Chris Lattner2980cef2005-11-10 18:06:33 +0000731/// printAsCString - Print the specified array as a C compatible string, only if
Chris Lattner1b7e2352004-08-17 06:36:49 +0000732/// the predicate isString is true.
733///
Chris Lattner2980cef2005-11-10 18:06:33 +0000734static void printAsCString(std::ostream &O, const ConstantArray *CVA,
735 unsigned LastElt) {
Chris Lattner1b7e2352004-08-17 06:36:49 +0000736 assert(CVA->isString() && "Array is not string compatible!");
737
738 O << "\"";
Chris Lattner2980cef2005-11-10 18:06:33 +0000739 for (unsigned i = 0; i != LastElt; ++i) {
Misha Brukmanedf128a2005-04-21 22:36:52 +0000740 unsigned char C =
Reid Spencerb83eb642006-10-20 07:07:24 +0000741 (unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getZExtValue();
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000742 printStringChar(O, C);
Chris Lattner1b7e2352004-08-17 06:36:49 +0000743 }
744 O << "\"";
745}
746
Jeff Cohenc884db42006-05-02 01:16:28 +0000747/// EmitString - Emit a zero-byte-terminated string constant.
748///
749void AsmPrinter::EmitString(const ConstantArray *CVA) const {
750 unsigned NumElts = CVA->getNumOperands();
Jim Laskey563321a2006-09-06 18:34:40 +0000751 if (TAI->getAscizDirective() && NumElts &&
Reid Spencerb83eb642006-10-20 07:07:24 +0000752 cast<ConstantInt>(CVA->getOperand(NumElts-1))->getZExtValue() == 0) {
Jim Laskey563321a2006-09-06 18:34:40 +0000753 O << TAI->getAscizDirective();
Jeff Cohenc884db42006-05-02 01:16:28 +0000754 printAsCString(O, CVA, NumElts-1);
755 } else {
Jim Laskey563321a2006-09-06 18:34:40 +0000756 O << TAI->getAsciiDirective();
Jeff Cohenc884db42006-05-02 01:16:28 +0000757 printAsCString(O, CVA, NumElts);
758 }
759 O << "\n";
760}
761
Chris Lattner25045bd2005-11-21 07:51:36 +0000762/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
Chris Lattner1b7e2352004-08-17 06:36:49 +0000763///
Chris Lattner25045bd2005-11-21 07:51:36 +0000764void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
Owen Andersona69571c2006-05-03 01:29:57 +0000765 const TargetData *TD = TM.getTargetData();
Chris Lattner1b7e2352004-08-17 06:36:49 +0000766
Chris Lattnerbd1d3822004-10-16 18:19:26 +0000767 if (CV->isNullValue() || isa<UndefValue>(CV)) {
Owen Andersona69571c2006-05-03 01:29:57 +0000768 EmitZeros(TD->getTypeSize(CV->getType()));
Chris Lattner1b7e2352004-08-17 06:36:49 +0000769 return;
770 } else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
771 if (CVA->isString()) {
Jeff Cohenc884db42006-05-02 01:16:28 +0000772 EmitString(CVA);
Chris Lattner1b7e2352004-08-17 06:36:49 +0000773 } else { // Not a string. Print the values in successive locations
774 for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
Chris Lattner25045bd2005-11-21 07:51:36 +0000775 EmitGlobalConstant(CVA->getOperand(i));
Chris Lattner1b7e2352004-08-17 06:36:49 +0000776 }
777 return;
778 } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
779 // Print the fields in successive locations. Pad to align if needed!
Owen Andersona69571c2006-05-03 01:29:57 +0000780 const StructLayout *cvsLayout = TD->getStructLayout(CVS->getType());
Chris Lattnerdea18b62005-01-08 19:59:10 +0000781 uint64_t sizeSoFar = 0;
Chris Lattner1b7e2352004-08-17 06:36:49 +0000782 for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
783 const Constant* field = CVS->getOperand(i);
784
785 // Check if padding is needed and insert one or more 0s.
Owen Andersona69571c2006-05-03 01:29:57 +0000786 uint64_t fieldSize = TD->getTypeSize(field->getType());
Chris Lattnerb0c39a32007-02-10 19:59:22 +0000787 uint64_t padSize = ((i == e-1? cvsLayout->getSizeInBytes()
Chris Lattnerb1919e22007-02-10 19:55:17 +0000788 : cvsLayout->getElementOffset(i+1))
789 - cvsLayout->getElementOffset(i)) - fieldSize;
Chris Lattner1b7e2352004-08-17 06:36:49 +0000790 sizeSoFar += fieldSize + padSize;
791
792 // Now print the actual field value
Chris Lattner25045bd2005-11-21 07:51:36 +0000793 EmitGlobalConstant(field);
Chris Lattner1b7e2352004-08-17 06:36:49 +0000794
795 // Insert the field padding unless it's zero bytes...
Chris Lattner25045bd2005-11-21 07:51:36 +0000796 EmitZeros(padSize);
Chris Lattner1b7e2352004-08-17 06:36:49 +0000797 }
Chris Lattnerb0c39a32007-02-10 19:59:22 +0000798 assert(sizeSoFar == cvsLayout->getSizeInBytes() &&
Chris Lattner1b7e2352004-08-17 06:36:49 +0000799 "Layout of constant struct may be incorrect!");
800 return;
801 } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
802 // FP Constants are printed as integer constants to avoid losing
803 // precision...
804 double Val = CFP->getValue();
805 if (CFP->getType() == Type::DoubleTy) {
Jim Laskey563321a2006-09-06 18:34:40 +0000806 if (TAI->getData64bitsDirective())
807 O << TAI->getData64bitsDirective() << DoubleToBits(Val) << "\t"
808 << TAI->getCommentString() << " double value: " << Val << "\n";
Owen Andersona69571c2006-05-03 01:29:57 +0000809 else if (TD->isBigEndian()) {
Jim Laskey563321a2006-09-06 18:34:40 +0000810 O << TAI->getData32bitsDirective() << unsigned(DoubleToBits(Val) >> 32)
811 << "\t" << TAI->getCommentString()
812 << " double most significant word " << Val << "\n";
813 O << TAI->getData32bitsDirective() << unsigned(DoubleToBits(Val))
814 << "\t" << TAI->getCommentString()
815 << " double least significant word " << Val << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000816 } else {
Jim Laskey563321a2006-09-06 18:34:40 +0000817 O << TAI->getData32bitsDirective() << unsigned(DoubleToBits(Val))
818 << "\t" << TAI->getCommentString()
819 << " double least significant word " << Val << "\n";
820 O << TAI->getData32bitsDirective() << unsigned(DoubleToBits(Val) >> 32)
821 << "\t" << TAI->getCommentString()
822 << " double most significant word " << Val << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000823 }
824 return;
825 } else {
Jim Laskey563321a2006-09-06 18:34:40 +0000826 O << TAI->getData32bitsDirective() << FloatToBits(Val)
827 << "\t" << TAI->getCommentString() << " float " << Val << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000828 return;
829 }
Reid Spencer47857812006-12-31 05:55:36 +0000830 } else if (CV->getType() == Type::Int64Ty) {
Chris Lattner1b7e2352004-08-17 06:36:49 +0000831 if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
Reid Spencerb83eb642006-10-20 07:07:24 +0000832 uint64_t Val = CI->getZExtValue();
Misha Brukmanedf128a2005-04-21 22:36:52 +0000833
Jim Laskey563321a2006-09-06 18:34:40 +0000834 if (TAI->getData64bitsDirective())
835 O << TAI->getData64bitsDirective() << Val << "\n";
Owen Andersona69571c2006-05-03 01:29:57 +0000836 else if (TD->isBigEndian()) {
Jim Laskey563321a2006-09-06 18:34:40 +0000837 O << TAI->getData32bitsDirective() << unsigned(Val >> 32)
838 << "\t" << TAI->getCommentString()
839 << " Double-word most significant word " << Val << "\n";
840 O << TAI->getData32bitsDirective() << unsigned(Val)
841 << "\t" << TAI->getCommentString()
842 << " Double-word least significant word " << Val << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000843 } else {
Jim Laskey563321a2006-09-06 18:34:40 +0000844 O << TAI->getData32bitsDirective() << unsigned(Val)
845 << "\t" << TAI->getCommentString()
846 << " Double-word least significant word " << Val << "\n";
847 O << TAI->getData32bitsDirective() << unsigned(Val >> 32)
848 << "\t" << TAI->getCommentString()
849 << " Double-word most significant word " << Val << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000850 }
851 return;
852 }
Reid Spencer9d6565a2007-02-15 02:26:10 +0000853 } else if (const ConstantVector *CP = dyn_cast<ConstantVector>(CV)) {
854 const VectorType *PTy = CP->getType();
Nate Begeman8cfa57b2005-12-06 06:18:55 +0000855
856 for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I)
857 EmitGlobalConstant(CP->getOperand(I));
858
859 return;
Chris Lattner1b7e2352004-08-17 06:36:49 +0000860 }
861
862 const Type *type = CV->getType();
Evan Chengd6594ae2006-09-12 21:00:35 +0000863 printDataDirective(type);
Chris Lattner25045bd2005-11-21 07:51:36 +0000864 EmitConstantValueOnly(CV);
Chris Lattner1b7e2352004-08-17 06:36:49 +0000865 O << "\n";
866}
Chris Lattner0264d1a2006-01-27 02:10:10 +0000867
Evan Chengd6594ae2006-09-12 21:00:35 +0000868void
869AsmPrinter::EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
870 // Target doesn't support this yet!
871 abort();
872}
873
Chris Lattner3ce9b672006-09-26 23:59:50 +0000874/// PrintSpecial - Print information related to the specified machine instr
875/// that is independent of the operand, and may be independent of the instr
876/// itself. This can be useful for portably encoding the comment character
877/// or other bits of target-specific knowledge into the asmstrings. The
878/// syntax used is ${:comment}. Targets can override this to add support
879/// for their own strange codes.
880void AsmPrinter::PrintSpecial(const MachineInstr *MI, const char *Code) {
Chris Lattnerbae02cf2006-09-27 00:06:07 +0000881 if (!strcmp(Code, "private")) {
882 O << TAI->getPrivateGlobalPrefix();
883 } else if (!strcmp(Code, "comment")) {
Chris Lattner3ce9b672006-09-26 23:59:50 +0000884 O << TAI->getCommentString();
885 } else if (!strcmp(Code, "uid")) {
886 // Assign a unique ID to this machine instruction.
887 static const MachineInstr *LastMI = 0;
Chris Lattnerb6a24bf2007-02-05 21:23:52 +0000888 static const Function *F = 0;
Chris Lattner3ce9b672006-09-26 23:59:50 +0000889 static unsigned Counter = 0U-1;
Chris Lattnerb6a24bf2007-02-05 21:23:52 +0000890
891 // Comparing the address of MI isn't sufficient, because machineinstrs may
892 // be allocated to the same address across functions.
893 const Function *ThisF = MI->getParent()->getParent()->getFunction();
894
Chris Lattner3ce9b672006-09-26 23:59:50 +0000895 // If this is a new machine instruction, bump the counter.
Chris Lattnerb6a24bf2007-02-05 21:23:52 +0000896 if (LastMI != MI || F != ThisF) {
897 ++Counter;
898 LastMI = MI;
Chris Lattner4b092522007-02-06 01:56:31 +0000899 F = ThisF;
Chris Lattnerb6a24bf2007-02-05 21:23:52 +0000900 }
Chris Lattner3ce9b672006-09-26 23:59:50 +0000901 O << Counter;
902 } else {
Bill Wendlinge8156192006-12-07 01:30:32 +0000903 cerr << "Unknown special formatter '" << Code
904 << "' for machine instr: " << *MI;
Chris Lattner3ce9b672006-09-26 23:59:50 +0000905 exit(1);
906 }
907}
908
909
Chris Lattner0264d1a2006-01-27 02:10:10 +0000910/// printInlineAsm - This method formats and prints the specified machine
911/// instruction that is an inline asm.
912void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
Chris Lattnerf2b67cf2006-01-30 23:00:08 +0000913 unsigned NumOperands = MI->getNumOperands();
914
915 // Count the number of register definitions.
916 unsigned NumDefs = 0;
Chris Lattner67942f52006-09-05 20:02:51 +0000917 for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef();
918 ++NumDefs)
Chris Lattnerf2b67cf2006-01-30 23:00:08 +0000919 assert(NumDefs != NumOperands-1 && "No asm string?");
920
921 assert(MI->getOperand(NumDefs).isExternalSymbol() && "No asm string?");
Chris Lattner66099132006-02-01 22:41:11 +0000922
923 // Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
Chris Lattnerf2b67cf2006-01-30 23:00:08 +0000924 const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
Chris Lattner66099132006-02-01 22:41:11 +0000925
Chris Lattnerf26f5dd2006-07-28 00:17:20 +0000926 // If this asmstr is empty, don't bother printing the #APP/#NOAPP markers.
927 if (AsmStr[0] == 0) {
928 O << "\n"; // Tab already printed, avoid double indenting next instr.
929 return;
930 }
931
Jim Laskey563321a2006-09-06 18:34:40 +0000932 O << TAI->getInlineAsmStart() << "\n\t";
Chris Lattnerf26f5dd2006-07-28 00:17:20 +0000933
Bill Wendlingeb9a42c2007-01-16 03:42:04 +0000934 // The variant of the current asmprinter.
935 int AsmPrinterVariant = TAI->getAssemblerDialect();
936
Chris Lattner66099132006-02-01 22:41:11 +0000937 int CurVariant = -1; // The number of the {.|.|.} region we are in.
938 const char *LastEmitted = AsmStr; // One past the last character emitted.
Chris Lattner2cc2f662006-02-01 01:28:23 +0000939
Chris Lattner66099132006-02-01 22:41:11 +0000940 while (*LastEmitted) {
941 switch (*LastEmitted) {
942 default: {
943 // Not a special case, emit the string section literally.
944 const char *LiteralEnd = LastEmitted+1;
945 while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
Chris Lattner1c059972006-05-05 21:47:05 +0000946 *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
Chris Lattner66099132006-02-01 22:41:11 +0000947 ++LiteralEnd;
948 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
949 O.write(LastEmitted, LiteralEnd-LastEmitted);
950 LastEmitted = LiteralEnd;
951 break;
952 }
Chris Lattner1c059972006-05-05 21:47:05 +0000953 case '\n':
954 ++LastEmitted; // Consume newline character.
955 O << "\n\t"; // Indent code with newline.
956 break;
Chris Lattner66099132006-02-01 22:41:11 +0000957 case '$': {
958 ++LastEmitted; // Consume '$' character.
Chris Lattnerfaf1dae2006-10-03 23:27:09 +0000959 bool Done = true;
960
961 // Handle escapes.
962 switch (*LastEmitted) {
963 default: Done = false; break;
964 case '$': // $$ -> $
Chris Lattner66099132006-02-01 22:41:11 +0000965 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
966 O << '$';
967 ++LastEmitted; // Consume second '$' character.
968 break;
Chris Lattnerfaf1dae2006-10-03 23:27:09 +0000969 case '(': // $( -> same as GCC's { character.
970 ++LastEmitted; // Consume '(' character.
971 if (CurVariant != -1) {
Bill Wendlinge8156192006-12-07 01:30:32 +0000972 cerr << "Nested variants found in inline asm string: '"
973 << AsmStr << "'\n";
Chris Lattnerfaf1dae2006-10-03 23:27:09 +0000974 exit(1);
975 }
976 CurVariant = 0; // We're in the first variant now.
977 break;
978 case '|':
979 ++LastEmitted; // consume '|' character.
980 if (CurVariant == -1) {
Bill Wendlinge8156192006-12-07 01:30:32 +0000981 cerr << "Found '|' character outside of variant in inline asm "
982 << "string: '" << AsmStr << "'\n";
Chris Lattnerfaf1dae2006-10-03 23:27:09 +0000983 exit(1);
984 }
985 ++CurVariant; // We're in the next variant.
986 break;
987 case ')': // $) -> same as GCC's } char.
988 ++LastEmitted; // consume ')' character.
989 if (CurVariant == -1) {
Bill Wendlinge8156192006-12-07 01:30:32 +0000990 cerr << "Found '}' character outside of variant in inline asm "
991 << "string: '" << AsmStr << "'\n";
Chris Lattnerfaf1dae2006-10-03 23:27:09 +0000992 exit(1);
993 }
994 CurVariant = -1;
995 break;
Chris Lattner66099132006-02-01 22:41:11 +0000996 }
Chris Lattnerfaf1dae2006-10-03 23:27:09 +0000997 if (Done) break;
Chris Lattner66099132006-02-01 22:41:11 +0000998
999 bool HasCurlyBraces = false;
1000 if (*LastEmitted == '{') { // ${variable}
1001 ++LastEmitted; // Consume '{' character.
1002 HasCurlyBraces = true;
1003 }
1004
1005 const char *IDStart = LastEmitted;
1006 char *IDEnd;
Chris Lattnerfad29122007-01-23 00:36:17 +00001007 errno = 0;
Chris Lattner66099132006-02-01 22:41:11 +00001008 long Val = strtol(IDStart, &IDEnd, 10); // We only accept numbers for IDs.
1009 if (!isdigit(*IDStart) || (Val == 0 && errno == EINVAL)) {
Bill Wendlinge8156192006-12-07 01:30:32 +00001010 cerr << "Bad $ operand number in inline asm string: '"
1011 << AsmStr << "'\n";
Chris Lattner66099132006-02-01 22:41:11 +00001012 exit(1);
1013 }
1014 LastEmitted = IDEnd;
1015
Chris Lattnera36cb0a2006-02-06 22:17:23 +00001016 char Modifier[2] = { 0, 0 };
1017
Chris Lattner66099132006-02-01 22:41:11 +00001018 if (HasCurlyBraces) {
Chris Lattnera36cb0a2006-02-06 22:17:23 +00001019 // If we have curly braces, check for a modifier character. This
1020 // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
1021 if (*LastEmitted == ':') {
1022 ++LastEmitted; // Consume ':' character.
1023 if (*LastEmitted == 0) {
Bill Wendlinge8156192006-12-07 01:30:32 +00001024 cerr << "Bad ${:} expression in inline asm string: '"
1025 << AsmStr << "'\n";
Chris Lattnera36cb0a2006-02-06 22:17:23 +00001026 exit(1);
1027 }
1028
1029 Modifier[0] = *LastEmitted;
1030 ++LastEmitted; // Consume modifier character.
1031 }
1032
Chris Lattner66099132006-02-01 22:41:11 +00001033 if (*LastEmitted != '}') {
Bill Wendlinge8156192006-12-07 01:30:32 +00001034 cerr << "Bad ${} expression in inline asm string: '"
1035 << AsmStr << "'\n";
Chris Lattner66099132006-02-01 22:41:11 +00001036 exit(1);
1037 }
1038 ++LastEmitted; // Consume '}' character.
1039 }
1040
1041 if ((unsigned)Val >= NumOperands-1) {
Bill Wendlinge8156192006-12-07 01:30:32 +00001042 cerr << "Invalid $ operand number in inline asm string: '"
1043 << AsmStr << "'\n";
Chris Lattner66099132006-02-01 22:41:11 +00001044 exit(1);
1045 }
1046
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +00001047 // Okay, we finally have a value number. Ask the target to print this
Chris Lattner66099132006-02-01 22:41:11 +00001048 // operand!
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +00001049 if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
1050 unsigned OpNo = 1;
Chris Lattnerfd561cd2006-06-08 18:00:47 +00001051
1052 bool Error = false;
1053
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +00001054 // Scan to find the machine operand number for the operand.
Chris Lattnerdaf6bc62006-02-24 19:50:58 +00001055 for (; Val; --Val) {
Chris Lattnerfd561cd2006-06-08 18:00:47 +00001056 if (OpNo >= MI->getNumOperands()) break;
Chris Lattnerdaf6bc62006-02-24 19:50:58 +00001057 unsigned OpFlags = MI->getOperand(OpNo).getImmedValue();
1058 OpNo += (OpFlags >> 3) + 1;
1059 }
Chris Lattnerdd260332006-02-24 20:21:58 +00001060
Chris Lattnerfd561cd2006-06-08 18:00:47 +00001061 if (OpNo >= MI->getNumOperands()) {
1062 Error = true;
Chris Lattnerdd260332006-02-24 20:21:58 +00001063 } else {
Chris Lattnerfd561cd2006-06-08 18:00:47 +00001064 unsigned OpFlags = MI->getOperand(OpNo).getImmedValue();
1065 ++OpNo; // Skip over the ID number.
1066
1067 AsmPrinter *AP = const_cast<AsmPrinter*>(this);
1068 if ((OpFlags & 7) == 4 /*ADDR MODE*/) {
1069 Error = AP->PrintAsmMemoryOperand(MI, OpNo, AsmPrinterVariant,
1070 Modifier[0] ? Modifier : 0);
1071 } else {
1072 Error = AP->PrintAsmOperand(MI, OpNo, AsmPrinterVariant,
1073 Modifier[0] ? Modifier : 0);
1074 }
Chris Lattnerdd260332006-02-24 20:21:58 +00001075 }
1076 if (Error) {
Bill Wendlinge8156192006-12-07 01:30:32 +00001077 cerr << "Invalid operand found in inline asm: '"
1078 << AsmStr << "'\n";
Chris Lattner66099132006-02-01 22:41:11 +00001079 MI->dump();
1080 exit(1);
1081 }
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +00001082 }
Chris Lattner66099132006-02-01 22:41:11 +00001083 break;
1084 }
Chris Lattner66099132006-02-01 22:41:11 +00001085 }
1086 }
Jim Laskey563321a2006-09-06 18:34:40 +00001087 O << "\n\t" << TAI->getInlineAsmEnd() << "\n";
Chris Lattner66099132006-02-01 22:41:11 +00001088}
1089
Jim Laskey1ee29252007-01-26 14:34:52 +00001090/// printLabel - This method prints a local label used by debug and
1091/// exception handling tables.
1092void AsmPrinter::printLabel(const MachineInstr *MI) const {
Jim Laskeyb82313f2007-02-01 16:31:34 +00001093 O << "\n"
1094 << TAI->getPrivateGlobalPrefix()
Jim Laskeybacd3042007-02-21 22:48:45 +00001095 << "label"
Jim Laskey1ee29252007-01-26 14:34:52 +00001096 << MI->getOperand(0).getImmedValue()
1097 << ":\n";
1098}
1099
Chris Lattner66099132006-02-01 22:41:11 +00001100/// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
1101/// instruction, using the specified assembler variant. Targets should
1102/// overried this to format as appropriate.
1103bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
Chris Lattnera36cb0a2006-02-06 22:17:23 +00001104 unsigned AsmVariant, const char *ExtraCode) {
Chris Lattner66099132006-02-01 22:41:11 +00001105 // Target doesn't support this yet!
1106 return true;
Chris Lattner0264d1a2006-01-27 02:10:10 +00001107}
Chris Lattnerdd260332006-02-24 20:21:58 +00001108
1109bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
1110 unsigned AsmVariant,
1111 const char *ExtraCode) {
1112 // Target doesn't support this yet!
1113 return true;
1114}
Nate Begeman37efe672006-04-22 18:53:45 +00001115
1116/// printBasicBlockLabel - This method prints the label for the specified
1117/// MachineBasicBlock
Nate Begemancdf38c42006-05-02 05:37:32 +00001118void AsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB,
1119 bool printColon,
1120 bool printComment) const {
Jim Laskey563321a2006-09-06 18:34:40 +00001121 O << TAI->getPrivateGlobalPrefix() << "BB" << FunctionNumber << "_"
Nate Begeman9d51eeb2006-05-02 17:36:46 +00001122 << MBB->getNumber();
Nate Begemancdf38c42006-05-02 05:37:32 +00001123 if (printColon)
1124 O << ':';
Chris Lattner9c78ecb2006-10-05 21:40:14 +00001125 if (printComment && MBB->getBasicBlock())
Jim Laskey563321a2006-09-06 18:34:40 +00001126 O << '\t' << TAI->getCommentString() << MBB->getBasicBlock()->getName();
Nate Begeman37efe672006-04-22 18:53:45 +00001127}
Nate Begeman52a51e382006-08-12 21:29:52 +00001128
1129/// printSetLabel - This method prints a set label for the specified
1130/// MachineBasicBlock
1131void AsmPrinter::printSetLabel(unsigned uid,
1132 const MachineBasicBlock *MBB) const {
Jim Laskey563321a2006-09-06 18:34:40 +00001133 if (!TAI->getSetDirective())
Nate Begeman52a51e382006-08-12 21:29:52 +00001134 return;
1135
Jim Laskey563321a2006-09-06 18:34:40 +00001136 O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
1137 << getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',';
Nate Begeman52a51e382006-08-12 21:29:52 +00001138 printBasicBlockLabel(MBB, false, false);
Jim Laskey563321a2006-09-06 18:34:40 +00001139 O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
Nate Begeman52a51e382006-08-12 21:29:52 +00001140 << '_' << uid << '\n';
1141}
Evan Chengd6594ae2006-09-12 21:00:35 +00001142
Evan Cheng41349c12006-11-01 09:23:08 +00001143void AsmPrinter::printSetLabel(unsigned uid, unsigned uid2,
1144 const MachineBasicBlock *MBB) const {
1145 if (!TAI->getSetDirective())
1146 return;
1147
1148 O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
1149 << getFunctionNumber() << '_' << uid << '_' << uid2
1150 << "_set_" << MBB->getNumber() << ',';
1151 printBasicBlockLabel(MBB, false, false);
1152 O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
1153 << '_' << uid << '_' << uid2 << '\n';
1154}
1155
Evan Chengd6594ae2006-09-12 21:00:35 +00001156/// printDataDirective - This method prints the asm directive for the
1157/// specified type.
1158void AsmPrinter::printDataDirective(const Type *type) {
1159 const TargetData *TD = TM.getTargetData();
1160 switch (type->getTypeID()) {
Reid Spencera54b7cb2007-01-12 07:05:14 +00001161 case Type::IntegerTyID: {
1162 unsigned BitWidth = cast<IntegerType>(type)->getBitWidth();
1163 if (BitWidth <= 8)
1164 O << TAI->getData8bitsDirective();
1165 else if (BitWidth <= 16)
1166 O << TAI->getData16bitsDirective();
1167 else if (BitWidth <= 32)
1168 O << TAI->getData32bitsDirective();
1169 else if (BitWidth <= 64) {
1170 assert(TAI->getData64bitsDirective() &&
1171 "Target cannot handle 64-bit constant exprs!");
1172 O << TAI->getData64bitsDirective();
1173 }
Evan Chengd6594ae2006-09-12 21:00:35 +00001174 break;
Reid Spencera54b7cb2007-01-12 07:05:14 +00001175 }
Evan Chengd6594ae2006-09-12 21:00:35 +00001176 case Type::PointerTyID:
1177 if (TD->getPointerSize() == 8) {
1178 assert(TAI->getData64bitsDirective() &&
1179 "Target cannot handle 64-bit pointer exprs!");
1180 O << TAI->getData64bitsDirective();
Reid Spencera54b7cb2007-01-12 07:05:14 +00001181 } else {
1182 O << TAI->getData32bitsDirective();
Evan Chengd6594ae2006-09-12 21:00:35 +00001183 }
Evan Chengd6594ae2006-09-12 21:00:35 +00001184 break;
1185 case Type::FloatTyID: case Type::DoubleTyID:
1186 assert (0 && "Should have already output floating point constant.");
1187 default:
1188 assert (0 && "Can't handle printing this type of thing");
1189 break;
1190 }
1191}
Dale Johannesen4c3a5f82007-02-16 01:54:53 +00001192