blob: 26a3d39db5e44a58a7f86403bd0bbadfdd40ac9b [file] [log] [blame]
Chris Lattner6a8e0f52004-08-16 23:15:22 +00001//===-- AsmPrinter.cpp - Common AsmPrinter code ---------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the AsmPrinter class.
11//
12//===----------------------------------------------------------------------===//
13
Nate Begeman41b1cdc2005-12-06 06:18:55 +000014#include "llvm/DerivedTypes.h"
Chris Lattner6a8e0f52004-08-16 23:15:22 +000015#include "llvm/CodeGen/AsmPrinter.h"
16#include "llvm/Constants.h"
Chris Lattnerc0a1eba2005-11-10 18:36:17 +000017#include "llvm/Module.h"
Chris Lattnerf2991ce2005-11-21 08:25:09 +000018#include "llvm/CodeGen/MachineConstantPool.h"
Chris Lattner6a8e0f52004-08-16 23:15:22 +000019#include "llvm/Support/Mangler.h"
Jim Laskeyb74c6662005-08-17 19:34:49 +000020#include "llvm/Support/MathExtras.h"
Chris Lattner6a8e0f52004-08-16 23:15:22 +000021#include "llvm/Target/TargetMachine.h"
22using namespace llvm;
23
Chris Lattnerf0e9aef2005-12-13 06:32:10 +000024AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm)
25: FunctionNumber(0), O(o), TM(tm),
26 CommentString("#"),
27 GlobalPrefix(""),
28 PrivateGlobalPrefix("."),
29 GlobalVarAddrPrefix(""),
30 GlobalVarAddrSuffix(""),
31 FunctionAddrPrefix(""),
32 FunctionAddrSuffix(""),
33 ZeroDirective("\t.zero\t"),
34 AsciiDirective("\t.ascii\t"),
35 AscizDirective("\t.asciz\t"),
36 Data8bitsDirective("\t.byte\t"),
37 Data16bitsDirective("\t.short\t"),
38 Data32bitsDirective("\t.long\t"),
39 Data64bitsDirective("\t.quad\t"),
40 AlignDirective("\t.align\t"),
41 AlignmentIsInBytes(true),
42 SwitchToSectionDirective("\t.section\t"),
43 ConstantPoolSection("\t.section .rodata\n"),
44 StaticCtorsSection("\t.section .ctors,\"aw\",@progbits"),
45 StaticDtorsSection("\t.section .dtors,\"aw\",@progbits"),
46 LCOMMDirective(0),
47 COMMDirective("\t.comm\t"),
48 COMMDirectiveTakesAlignment(true),
49 HasDotTypeDotSizeDirective(true) {
50}
51
52
Chris Lattner2ea5c992005-11-21 07:06:27 +000053/// SwitchSection - Switch to the specified section of the executable if we
54/// are not already in it!
55///
56void AsmPrinter::SwitchSection(const char *NewSection, const GlobalValue *GV) {
57 std::string NS;
58
59 if (GV && GV->hasSection())
Chris Lattnerf2991ce2005-11-21 08:25:09 +000060 NS = SwitchToSectionDirective + GV->getSection();
Chris Lattner2ea5c992005-11-21 07:06:27 +000061 else
Chris Lattnera6f835f2005-12-09 19:28:49 +000062 NS = std::string("\t")+NewSection;
Chris Lattner2ea5c992005-11-21 07:06:27 +000063
64 if (CurrentSection != NS) {
65 CurrentSection = NS;
66 if (!CurrentSection.empty())
Chris Lattnera6f835f2005-12-09 19:28:49 +000067 O << CurrentSection << '\n';
Chris Lattner2ea5c992005-11-21 07:06:27 +000068 }
69}
70
Chris Lattner6a8e0f52004-08-16 23:15:22 +000071bool AsmPrinter::doInitialization(Module &M) {
Chris Lattner6d42cbd2004-08-17 06:06:19 +000072 Mang = new Mangler(M, GlobalPrefix);
Chris Lattner2ea5c992005-11-21 07:06:27 +000073 SwitchSection("", 0); // Reset back to no section.
Chris Lattner6a8e0f52004-08-16 23:15:22 +000074 return false;
75}
76
77bool AsmPrinter::doFinalization(Module &M) {
78 delete Mang; Mang = 0;
79 return false;
80}
81
Chris Lattnerbb644e32005-11-21 07:51:36 +000082void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
Chris Lattner6a8e0f52004-08-16 23:15:22 +000083 // What's my mangled name?
Chris Lattnerc0a1eba2005-11-10 18:36:17 +000084 CurrentFnName = Mang->getValueName(MF.getFunction());
Chris Lattner08adbd132005-11-21 08:13:27 +000085 IncrementFunctionNumber();
Chris Lattner6a8e0f52004-08-16 23:15:22 +000086}
87
Chris Lattnerf2991ce2005-11-21 08:25:09 +000088/// EmitConstantPool - Print to the current output stream assembly
89/// representations of the constants in the constant pool MCP. This is
90/// used to print out constants which have been "spilled to memory" by
91/// the code generator.
92///
93void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
94 const std::vector<Constant*> &CP = MCP->getConstants();
95 if (CP.empty()) return;
96 const TargetData &TD = TM.getTargetData();
97
98 SwitchSection(ConstantPoolSection, 0);
99 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
100 // FIXME: force doubles to be naturally aligned. We should handle this
101 // more correctly in the future.
102 unsigned Alignment = TD.getTypeAlignmentShift(CP[i]->getType());
103 if (CP[i]->getType() == Type::DoubleTy && Alignment < 3) Alignment = 3;
104
105 EmitAlignment(Alignment);
106 O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << '_' << i
107 << ":\t\t\t\t\t" << CommentString << *CP[i] << '\n';
108 EmitGlobalConstant(CP[i]);
109 }
110}
111
Chris Lattnerf0e9aef2005-12-13 06:32:10 +0000112/// EmitSpecialLLVMGlobal - Check to see if the specified global is a
113/// special global used by LLVM. If so, emit it and return true, otherwise
114/// do nothing and return false.
115bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
116 assert(GV->hasInitializer() && GV->hasAppendingLinkage() &&
117 "Not a special LLVM global!");
118
119 if (GV->getName() == "llvm.used")
120 return true; // No need to emit this at all.
121
122 if (GV->getName() == "llvm.global_ctors") {
123 SwitchSection(StaticCtorsSection, 0);
124 EmitAlignment(2, 0);
125 EmitXXStructorList(GV->getInitializer());
126 return true;
127 }
128
129 if (GV->getName() == "llvm.global_dtors") {
130 SwitchSection(StaticDtorsSection, 0);
131 EmitAlignment(2, 0);
132 EmitXXStructorList(GV->getInitializer());
133 return true;
134 }
135
136 return false;
137}
138
139/// EmitXXStructorList - Emit the ctor or dtor list. This just prints out the
140/// function pointers, ignoring the init priority.
141void AsmPrinter::EmitXXStructorList(Constant *List) {
142 // Should be an array of '{ int, void ()* }' structs. The first value is the
143 // init priority, which we ignore.
144 if (!isa<ConstantArray>(List)) return;
145 ConstantArray *InitList = cast<ConstantArray>(List);
146 for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
147 if (ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i))){
148 if (CS->getNumOperands() != 2) return; // Not array of 2-element structs.
Chris Lattner434ffe42005-12-21 01:17:37 +0000149
150 if (CS->getOperand(1)->isNullValue())
151 return; // Found a null terminator, exit printing.
152 // Emit the function pointer.
Chris Lattnerf0e9aef2005-12-13 06:32:10 +0000153 EmitGlobalConstant(CS->getOperand(1));
154 }
155}
Chris Lattnerf2991ce2005-11-21 08:25:09 +0000156
157
Chris Lattnerbb644e32005-11-21 07:51:36 +0000158// EmitAlignment - Emit an alignment directive to the specified power of two.
159void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV) const {
Chris Lattnerdd8eeed2005-11-14 19:00:06 +0000160 if (GV && GV->getAlignment())
161 NumBits = Log2_32(GV->getAlignment());
Chris Lattner747960d2005-11-10 18:09:27 +0000162 if (NumBits == 0) return; // No need to emit alignment.
Chris Lattner1d35c162004-08-17 19:14:29 +0000163 if (AlignmentIsInBytes) NumBits = 1 << NumBits;
164 O << AlignDirective << NumBits << "\n";
165}
166
Chris Lattnerbb644e32005-11-21 07:51:36 +0000167/// EmitZeros - Emit a block of zeros.
Chris Lattnerea751992004-08-17 21:38:40 +0000168///
Chris Lattnerbb644e32005-11-21 07:51:36 +0000169void AsmPrinter::EmitZeros(uint64_t NumZeros) const {
Chris Lattnerea751992004-08-17 21:38:40 +0000170 if (NumZeros) {
171 if (ZeroDirective)
172 O << ZeroDirective << NumZeros << "\n";
173 else {
Chris Lattnerea751992004-08-17 21:38:40 +0000174 for (; NumZeros; --NumZeros)
175 O << Data8bitsDirective << "0\n";
176 }
177 }
178}
179
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000180// Print out the specified constant, without a storage class. Only the
181// constants valid in constant expressions can occur here.
Chris Lattnerbb644e32005-11-21 07:51:36 +0000182void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
Chris Lattner61753bf2004-10-16 18:19:26 +0000183 if (CV->isNullValue() || isa<UndefValue>(CV))
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000184 O << "0";
185 else if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) {
186 assert(CB == ConstantBool::True);
187 O << "1";
188 } else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV))
189 if (((CI->getValue() << 32) >> 32) == CI->getValue())
190 O << CI->getValue();
191 else
Duraid Madina73c4dba2005-05-15 13:05:48 +0000192 O << (uint64_t)CI->getValue();
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000193 else if (const ConstantUInt *CI = dyn_cast<ConstantUInt>(CV))
194 O << CI->getValue();
Chris Lattnerc0a1eba2005-11-10 18:36:17 +0000195 else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
Duraid Madina73a316d2005-04-02 12:21:51 +0000196 // This is a constant address for a global variable or function. Use the
197 // name of the variable or function as the address value, possibly
198 // decorating it with GlobalVarAddrPrefix/Suffix or
199 // FunctionAddrPrefix/Suffix (these all default to "" )
Chris Lattnerc0a1eba2005-11-10 18:36:17 +0000200 if (isa<Function>(GV))
201 O << FunctionAddrPrefix << Mang->getValueName(GV) << FunctionAddrSuffix;
Duraid Madina73a316d2005-04-02 12:21:51 +0000202 else
Chris Lattnerc0a1eba2005-11-10 18:36:17 +0000203 O << GlobalVarAddrPrefix << Mang->getValueName(GV) << GlobalVarAddrSuffix;
Duraid Madina73a316d2005-04-02 12:21:51 +0000204 } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000205 const TargetData &TD = TM.getTargetData();
206 switch(CE->getOpcode()) {
207 case Instruction::GetElementPtr: {
208 // generate a symbolic expression for the byte address
209 const Constant *ptrVal = CE->getOperand(0);
210 std::vector<Value*> idxVec(CE->op_begin()+1, CE->op_end());
Chris Lattner145569b2005-02-14 21:40:26 +0000211 if (int64_t Offset = TD.getIndexedOffset(ptrVal->getType(), idxVec)) {
212 if (Offset)
213 O << "(";
Chris Lattnerbb644e32005-11-21 07:51:36 +0000214 EmitConstantValueOnly(ptrVal);
Chris Lattner145569b2005-02-14 21:40:26 +0000215 if (Offset > 0)
216 O << ") + " << Offset;
217 else if (Offset < 0)
218 O << ") - " << -Offset;
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000219 } else {
Chris Lattnerbb644e32005-11-21 07:51:36 +0000220 EmitConstantValueOnly(ptrVal);
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000221 }
222 break;
223 }
224 case Instruction::Cast: {
225 // Support only non-converting or widening casts for now, that is, ones
226 // that do not involve a change in value. This assertion is really gross,
227 // and may not even be a complete check.
228 Constant *Op = CE->getOperand(0);
229 const Type *OpTy = Op->getType(), *Ty = CE->getType();
230
231 // Remember, kids, pointers can be losslessly converted back and forth
232 // into 32-bit or wider integers, regardless of signedness. :-P
233 assert(((isa<PointerType>(OpTy)
234 && (Ty == Type::LongTy || Ty == Type::ULongTy
235 || Ty == Type::IntTy || Ty == Type::UIntTy))
236 || (isa<PointerType>(Ty)
237 && (OpTy == Type::LongTy || OpTy == Type::ULongTy
238 || OpTy == Type::IntTy || OpTy == Type::UIntTy))
239 || (((TD.getTypeSize(Ty) >= TD.getTypeSize(OpTy))
240 && OpTy->isLosslesslyConvertibleTo(Ty))))
241 && "FIXME: Don't yet support this kind of constant cast expr");
Chris Lattnerbb644e32005-11-21 07:51:36 +0000242 EmitConstantValueOnly(Op);
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000243 break;
244 }
245 case Instruction::Add:
246 O << "(";
Chris Lattnerbb644e32005-11-21 07:51:36 +0000247 EmitConstantValueOnly(CE->getOperand(0));
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000248 O << ") + (";
Chris Lattnerbb644e32005-11-21 07:51:36 +0000249 EmitConstantValueOnly(CE->getOperand(1));
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000250 O << ")";
251 break;
252 default:
253 assert(0 && "Unsupported operator!");
254 }
255 } else {
256 assert(0 && "Unknown constant value!");
257 }
258}
Chris Lattner8452a1f2004-08-17 06:36:49 +0000259
260/// toOctal - Convert the low order bits of X into an octal digit.
261///
262static inline char toOctal(int X) {
263 return (X&7)+'0';
264}
265
Chris Lattner55a6d902005-11-10 18:06:33 +0000266/// printAsCString - Print the specified array as a C compatible string, only if
Chris Lattner8452a1f2004-08-17 06:36:49 +0000267/// the predicate isString is true.
268///
Chris Lattner55a6d902005-11-10 18:06:33 +0000269static void printAsCString(std::ostream &O, const ConstantArray *CVA,
270 unsigned LastElt) {
Chris Lattner8452a1f2004-08-17 06:36:49 +0000271 assert(CVA->isString() && "Array is not string compatible!");
272
273 O << "\"";
Chris Lattner55a6d902005-11-10 18:06:33 +0000274 for (unsigned i = 0; i != LastElt; ++i) {
Misha Brukman835702a2005-04-21 22:36:52 +0000275 unsigned char C =
Chris Lattner0b955fd2005-01-08 19:59:10 +0000276 (unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getRawValue();
Chris Lattner8452a1f2004-08-17 06:36:49 +0000277
278 if (C == '"') {
279 O << "\\\"";
280 } else if (C == '\\') {
281 O << "\\\\";
282 } else if (isprint(C)) {
283 O << C;
284 } else {
285 switch(C) {
286 case '\b': O << "\\b"; break;
287 case '\f': O << "\\f"; break;
288 case '\n': O << "\\n"; break;
289 case '\r': O << "\\r"; break;
290 case '\t': O << "\\t"; break;
291 default:
292 O << '\\';
293 O << toOctal(C >> 6);
294 O << toOctal(C >> 3);
295 O << toOctal(C >> 0);
296 break;
297 }
298 }
299 }
300 O << "\"";
301}
302
Chris Lattnerbb644e32005-11-21 07:51:36 +0000303/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
Chris Lattner8452a1f2004-08-17 06:36:49 +0000304///
Chris Lattnerbb644e32005-11-21 07:51:36 +0000305void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
Chris Lattner8452a1f2004-08-17 06:36:49 +0000306 const TargetData &TD = TM.getTargetData();
307
Chris Lattner61753bf2004-10-16 18:19:26 +0000308 if (CV->isNullValue() || isa<UndefValue>(CV)) {
Chris Lattnerbb644e32005-11-21 07:51:36 +0000309 EmitZeros(TD.getTypeSize(CV->getType()));
Chris Lattner8452a1f2004-08-17 06:36:49 +0000310 return;
311 } else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
312 if (CVA->isString()) {
Chris Lattner55a6d902005-11-10 18:06:33 +0000313 unsigned NumElts = CVA->getNumOperands();
314 if (AscizDirective && NumElts &&
315 cast<ConstantInt>(CVA->getOperand(NumElts-1))->getRawValue() == 0) {
316 O << AscizDirective;
317 printAsCString(O, CVA, NumElts-1);
318 } else {
319 O << AsciiDirective;
320 printAsCString(O, CVA, NumElts);
321 }
Chris Lattner8452a1f2004-08-17 06:36:49 +0000322 O << "\n";
323 } else { // Not a string. Print the values in successive locations
324 for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
Chris Lattnerbb644e32005-11-21 07:51:36 +0000325 EmitGlobalConstant(CVA->getOperand(i));
Chris Lattner8452a1f2004-08-17 06:36:49 +0000326 }
327 return;
328 } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
329 // Print the fields in successive locations. Pad to align if needed!
330 const StructLayout *cvsLayout = TD.getStructLayout(CVS->getType());
Chris Lattner0b955fd2005-01-08 19:59:10 +0000331 uint64_t sizeSoFar = 0;
Chris Lattner8452a1f2004-08-17 06:36:49 +0000332 for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
333 const Constant* field = CVS->getOperand(i);
334
335 // Check if padding is needed and insert one or more 0s.
Chris Lattner0b955fd2005-01-08 19:59:10 +0000336 uint64_t fieldSize = TD.getTypeSize(field->getType());
337 uint64_t padSize = ((i == e-1? cvsLayout->StructSize
Chris Lattner8452a1f2004-08-17 06:36:49 +0000338 : cvsLayout->MemberOffsets[i+1])
339 - cvsLayout->MemberOffsets[i]) - fieldSize;
340 sizeSoFar += fieldSize + padSize;
341
342 // Now print the actual field value
Chris Lattnerbb644e32005-11-21 07:51:36 +0000343 EmitGlobalConstant(field);
Chris Lattner8452a1f2004-08-17 06:36:49 +0000344
345 // Insert the field padding unless it's zero bytes...
Chris Lattnerbb644e32005-11-21 07:51:36 +0000346 EmitZeros(padSize);
Chris Lattner8452a1f2004-08-17 06:36:49 +0000347 }
348 assert(sizeSoFar == cvsLayout->StructSize &&
349 "Layout of constant struct may be incorrect!");
350 return;
351 } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
352 // FP Constants are printed as integer constants to avoid losing
353 // precision...
354 double Val = CFP->getValue();
355 if (CFP->getType() == Type::DoubleTy) {
Chris Lattner9fa0fc42004-08-17 06:48:16 +0000356 if (Data64bitsDirective)
Jim Laskeyb74c6662005-08-17 19:34:49 +0000357 O << Data64bitsDirective << DoubleToBits(Val) << "\t" << CommentString
Chris Lattnerea751992004-08-17 21:38:40 +0000358 << " double value: " << Val << "\n";
Chris Lattner9fa0fc42004-08-17 06:48:16 +0000359 else if (TD.isBigEndian()) {
Jim Laskeyb74c6662005-08-17 19:34:49 +0000360 O << Data32bitsDirective << unsigned(DoubleToBits(Val) >> 32)
Chris Lattner10262ab2004-08-18 02:22:55 +0000361 << "\t" << CommentString << " double most significant word "
Chris Lattnerda6beac2004-08-17 16:27:05 +0000362 << Val << "\n";
Jim Laskeyb74c6662005-08-17 19:34:49 +0000363 O << Data32bitsDirective << unsigned(DoubleToBits(Val))
Chris Lattner10262ab2004-08-18 02:22:55 +0000364 << "\t" << CommentString << " double least significant word "
Chris Lattnerda6beac2004-08-17 16:27:05 +0000365 << Val << "\n";
Chris Lattner8452a1f2004-08-17 06:36:49 +0000366 } else {
Jim Laskeyb74c6662005-08-17 19:34:49 +0000367 O << Data32bitsDirective << unsigned(DoubleToBits(Val))
Chris Lattner10262ab2004-08-18 02:22:55 +0000368 << "\t" << CommentString << " double least significant word " << Val
Chris Lattnerda6beac2004-08-17 16:27:05 +0000369 << "\n";
Jim Laskeyb74c6662005-08-17 19:34:49 +0000370 O << Data32bitsDirective << unsigned(DoubleToBits(Val) >> 32)
Chris Lattner10262ab2004-08-18 02:22:55 +0000371 << "\t" << CommentString << " double most significant word " << Val
Chris Lattnerda6beac2004-08-17 16:27:05 +0000372 << "\n";
Chris Lattner8452a1f2004-08-17 06:36:49 +0000373 }
374 return;
375 } else {
Jim Laskeyb74c6662005-08-17 19:34:49 +0000376 O << Data32bitsDirective << FloatToBits(Val) << "\t" << CommentString
Chris Lattnerda6beac2004-08-17 16:27:05 +0000377 << " float " << Val << "\n";
Chris Lattner8452a1f2004-08-17 06:36:49 +0000378 return;
379 }
380 } else if (CV->getType() == Type::ULongTy || CV->getType() == Type::LongTy) {
381 if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
382 uint64_t Val = CI->getRawValue();
Misha Brukman835702a2005-04-21 22:36:52 +0000383
Chris Lattner9fa0fc42004-08-17 06:48:16 +0000384 if (Data64bitsDirective)
385 O << Data64bitsDirective << Val << "\n";
386 else if (TD.isBigEndian()) {
Chris Lattner8452a1f2004-08-17 06:36:49 +0000387 O << Data32bitsDirective << unsigned(Val >> 32)
Chris Lattner10262ab2004-08-18 02:22:55 +0000388 << "\t" << CommentString << " Double-word most significant word "
Chris Lattnerda6beac2004-08-17 16:27:05 +0000389 << Val << "\n";
Chris Lattner8452a1f2004-08-17 06:36:49 +0000390 O << Data32bitsDirective << unsigned(Val)
Chris Lattner10262ab2004-08-18 02:22:55 +0000391 << "\t" << CommentString << " Double-word least significant word "
Chris Lattnerda6beac2004-08-17 16:27:05 +0000392 << Val << "\n";
Chris Lattner8452a1f2004-08-17 06:36:49 +0000393 } else {
394 O << Data32bitsDirective << unsigned(Val)
Chris Lattner10262ab2004-08-18 02:22:55 +0000395 << "\t" << CommentString << " Double-word least significant word "
Chris Lattnerda6beac2004-08-17 16:27:05 +0000396 << Val << "\n";
Chris Lattner8452a1f2004-08-17 06:36:49 +0000397 O << Data32bitsDirective << unsigned(Val >> 32)
Chris Lattner10262ab2004-08-18 02:22:55 +0000398 << "\t" << CommentString << " Double-word most significant word "
Chris Lattnerda6beac2004-08-17 16:27:05 +0000399 << Val << "\n";
Chris Lattner8452a1f2004-08-17 06:36:49 +0000400 }
401 return;
402 }
Nate Begeman41b1cdc2005-12-06 06:18:55 +0000403 } else if (const ConstantPacked *CP = dyn_cast<ConstantPacked>(CV)) {
404 const PackedType *PTy = CP->getType();
405
406 for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I)
407 EmitGlobalConstant(CP->getOperand(I));
408
409 return;
Chris Lattner8452a1f2004-08-17 06:36:49 +0000410 }
411
412 const Type *type = CV->getType();
Chris Lattner8452a1f2004-08-17 06:36:49 +0000413 switch (type->getTypeID()) {
Misha Brukman835702a2005-04-21 22:36:52 +0000414 case Type::BoolTyID:
Chris Lattner8452a1f2004-08-17 06:36:49 +0000415 case Type::UByteTyID: case Type::SByteTyID:
416 O << Data8bitsDirective;
417 break;
418 case Type::UShortTyID: case Type::ShortTyID:
419 O << Data16bitsDirective;
420 break;
Chris Lattner8452a1f2004-08-17 06:36:49 +0000421 case Type::PointerTyID:
Andrew Lenharthc8770aa2005-02-04 13:47:16 +0000422 if (TD.getPointerSize() == 8) {
423 O << Data64bitsDirective;
424 break;
425 }
426 //Fall through for pointer size == int size
Chris Lattner8452a1f2004-08-17 06:36:49 +0000427 case Type::UIntTyID: case Type::IntTyID:
428 O << Data32bitsDirective;
429 break;
Misha Brukman835702a2005-04-21 22:36:52 +0000430 case Type::ULongTyID: case Type::LongTyID:
Chris Lattner88e2d2e2005-08-08 04:26:32 +0000431 assert(Data64bitsDirective &&"Target cannot handle 64-bit constant exprs!");
432 O << Data64bitsDirective;
433 break;
Chris Lattner8452a1f2004-08-17 06:36:49 +0000434 case Type::FloatTyID: case Type::DoubleTyID:
435 assert (0 && "Should have already output floating point constant.");
436 default:
437 assert (0 && "Can't handle printing this type of thing");
438 break;
439 }
Chris Lattnerbb644e32005-11-21 07:51:36 +0000440 EmitConstantValueOnly(CV);
Chris Lattner8452a1f2004-08-17 06:36:49 +0000441 O << "\n";
442}