blob: 377f0d82e3882090e2e013be06010a86601e00f6 [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
Nate Begeman8cfa57b2005-12-06 06:18:55 +000014#include "llvm/DerivedTypes.h"
Chris Lattnera80ba712004-08-16 23:15:22 +000015#include "llvm/CodeGen/AsmPrinter.h"
16#include "llvm/Constants.h"
Chris Lattner450de392005-11-10 18:36:17 +000017#include "llvm/Module.h"
Chris Lattner3b4fd322005-11-21 08:25:09 +000018#include "llvm/CodeGen/MachineConstantPool.h"
Chris Lattnera80ba712004-08-16 23:15:22 +000019#include "llvm/Support/Mangler.h"
Jim Laskeycb6682f2005-08-17 19:34:49 +000020#include "llvm/Support/MathExtras.h"
Chris Lattnera80ba712004-08-16 23:15:22 +000021#include "llvm/Target/TargetMachine.h"
Duraid Madina2e096c12005-12-28 06:29:02 +000022#include <iostream>
Chris Lattnera80ba712004-08-16 23:15:22 +000023using namespace llvm;
24
Chris Lattnered138932005-12-13 06:32:10 +000025AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm)
26: FunctionNumber(0), O(o), TM(tm),
27 CommentString("#"),
28 GlobalPrefix(""),
29 PrivateGlobalPrefix("."),
30 GlobalVarAddrPrefix(""),
31 GlobalVarAddrSuffix(""),
32 FunctionAddrPrefix(""),
33 FunctionAddrSuffix(""),
34 ZeroDirective("\t.zero\t"),
35 AsciiDirective("\t.ascii\t"),
36 AscizDirective("\t.asciz\t"),
37 Data8bitsDirective("\t.byte\t"),
38 Data16bitsDirective("\t.short\t"),
39 Data32bitsDirective("\t.long\t"),
40 Data64bitsDirective("\t.quad\t"),
41 AlignDirective("\t.align\t"),
42 AlignmentIsInBytes(true),
43 SwitchToSectionDirective("\t.section\t"),
44 ConstantPoolSection("\t.section .rodata\n"),
45 StaticCtorsSection("\t.section .ctors,\"aw\",@progbits"),
46 StaticDtorsSection("\t.section .dtors,\"aw\",@progbits"),
47 LCOMMDirective(0),
48 COMMDirective("\t.comm\t"),
49 COMMDirectiveTakesAlignment(true),
50 HasDotTypeDotSizeDirective(true) {
51}
52
53
Chris Lattnerac28fbd2005-11-21 07:06:27 +000054/// SwitchSection - Switch to the specified section of the executable if we
55/// are not already in it!
56///
57void AsmPrinter::SwitchSection(const char *NewSection, const GlobalValue *GV) {
58 std::string NS;
59
60 if (GV && GV->hasSection())
Chris Lattner3b4fd322005-11-21 08:25:09 +000061 NS = SwitchToSectionDirective + GV->getSection();
Chris Lattnerac28fbd2005-11-21 07:06:27 +000062 else
Chris Lattner42a80fe2005-12-09 19:28:49 +000063 NS = std::string("\t")+NewSection;
Chris Lattnerac28fbd2005-11-21 07:06:27 +000064
65 if (CurrentSection != NS) {
66 CurrentSection = NS;
67 if (!CurrentSection.empty())
Chris Lattner42a80fe2005-12-09 19:28:49 +000068 O << CurrentSection << '\n';
Chris Lattnerac28fbd2005-11-21 07:06:27 +000069 }
70}
71
Chris Lattnera80ba712004-08-16 23:15:22 +000072bool AsmPrinter::doInitialization(Module &M) {
Chris Lattneraf2bf0a2004-08-17 06:06:19 +000073 Mang = new Mangler(M, GlobalPrefix);
Chris Lattnerac28fbd2005-11-21 07:06:27 +000074 SwitchSection("", 0); // Reset back to no section.
Chris Lattnera80ba712004-08-16 23:15:22 +000075 return false;
76}
77
78bool AsmPrinter::doFinalization(Module &M) {
79 delete Mang; Mang = 0;
80 return false;
81}
82
Chris Lattner25045bd2005-11-21 07:51:36 +000083void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
Chris Lattnera80ba712004-08-16 23:15:22 +000084 // What's my mangled name?
Chris Lattner450de392005-11-10 18:36:17 +000085 CurrentFnName = Mang->getValueName(MF.getFunction());
Chris Lattner77bc2282005-11-21 08:13:27 +000086 IncrementFunctionNumber();
Chris Lattnera80ba712004-08-16 23:15:22 +000087}
88
Chris Lattner3b4fd322005-11-21 08:25:09 +000089/// EmitConstantPool - Print to the current output stream assembly
90/// representations of the constants in the constant pool MCP. This is
91/// used to print out constants which have been "spilled to memory" by
92/// the code generator.
93///
94void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
95 const std::vector<Constant*> &CP = MCP->getConstants();
96 if (CP.empty()) return;
97 const TargetData &TD = TM.getTargetData();
98
99 SwitchSection(ConstantPoolSection, 0);
100 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
101 // FIXME: force doubles to be naturally aligned. We should handle this
102 // more correctly in the future.
103 unsigned Alignment = TD.getTypeAlignmentShift(CP[i]->getType());
104 if (CP[i]->getType() == Type::DoubleTy && Alignment < 3) Alignment = 3;
105
106 EmitAlignment(Alignment);
107 O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << '_' << i
108 << ":\t\t\t\t\t" << CommentString << *CP[i] << '\n';
109 EmitGlobalConstant(CP[i]);
110 }
111}
112
Chris Lattnered138932005-12-13 06:32:10 +0000113/// EmitSpecialLLVMGlobal - Check to see if the specified global is a
114/// special global used by LLVM. If so, emit it and return true, otherwise
115/// do nothing and return false.
116bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
117 assert(GV->hasInitializer() && GV->hasAppendingLinkage() &&
118 "Not a special LLVM global!");
119
120 if (GV->getName() == "llvm.used")
121 return true; // No need to emit this at all.
122
Chris Lattner5166b822006-01-12 19:17:23 +0000123 if (GV->getName() == "llvm.global_ctors" && GV->use_empty()) {
Chris Lattnered138932005-12-13 06:32:10 +0000124 SwitchSection(StaticCtorsSection, 0);
125 EmitAlignment(2, 0);
126 EmitXXStructorList(GV->getInitializer());
127 return true;
128 }
129
Chris Lattner5166b822006-01-12 19:17:23 +0000130 if (GV->getName() == "llvm.global_dtors" && GV->use_empty()) {
Chris Lattnered138932005-12-13 06:32:10 +0000131 SwitchSection(StaticDtorsSection, 0);
132 EmitAlignment(2, 0);
133 EmitXXStructorList(GV->getInitializer());
134 return true;
135 }
136
137 return false;
138}
139
140/// EmitXXStructorList - Emit the ctor or dtor list. This just prints out the
141/// function pointers, ignoring the init priority.
142void AsmPrinter::EmitXXStructorList(Constant *List) {
143 // Should be an array of '{ int, void ()* }' structs. The first value is the
144 // init priority, which we ignore.
145 if (!isa<ConstantArray>(List)) return;
146 ConstantArray *InitList = cast<ConstantArray>(List);
147 for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
148 if (ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i))){
149 if (CS->getNumOperands() != 2) return; // Not array of 2-element structs.
Chris Lattner8de324b2005-12-21 01:17:37 +0000150
151 if (CS->getOperand(1)->isNullValue())
152 return; // Found a null terminator, exit printing.
153 // Emit the function pointer.
Chris Lattnered138932005-12-13 06:32:10 +0000154 EmitGlobalConstant(CS->getOperand(1));
155 }
156}
Chris Lattner3b4fd322005-11-21 08:25:09 +0000157
158
Chris Lattner25045bd2005-11-21 07:51:36 +0000159// EmitAlignment - Emit an alignment directive to the specified power of two.
160void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV) const {
Chris Lattnera1ab72d2005-11-14 19:00:06 +0000161 if (GV && GV->getAlignment())
162 NumBits = Log2_32(GV->getAlignment());
Chris Lattner2a21c6e2005-11-10 18:09:27 +0000163 if (NumBits == 0) return; // No need to emit alignment.
Chris Lattnerbfddc202004-08-17 19:14:29 +0000164 if (AlignmentIsInBytes) NumBits = 1 << NumBits;
165 O << AlignDirective << NumBits << "\n";
166}
167
Chris Lattner25045bd2005-11-21 07:51:36 +0000168/// EmitZeros - Emit a block of zeros.
Chris Lattner7d057a32004-08-17 21:38:40 +0000169///
Chris Lattner25045bd2005-11-21 07:51:36 +0000170void AsmPrinter::EmitZeros(uint64_t NumZeros) const {
Chris Lattner7d057a32004-08-17 21:38:40 +0000171 if (NumZeros) {
172 if (ZeroDirective)
173 O << ZeroDirective << NumZeros << "\n";
174 else {
Chris Lattner7d057a32004-08-17 21:38:40 +0000175 for (; NumZeros; --NumZeros)
176 O << Data8bitsDirective << "0\n";
177 }
178 }
179}
180
Chris Lattnera80ba712004-08-16 23:15:22 +0000181// Print out the specified constant, without a storage class. Only the
182// constants valid in constant expressions can occur here.
Chris Lattner25045bd2005-11-21 07:51:36 +0000183void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
Chris Lattnerbd1d3822004-10-16 18:19:26 +0000184 if (CV->isNullValue() || isa<UndefValue>(CV))
Chris Lattnera80ba712004-08-16 23:15:22 +0000185 O << "0";
186 else if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) {
187 assert(CB == ConstantBool::True);
188 O << "1";
189 } else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV))
190 if (((CI->getValue() << 32) >> 32) == CI->getValue())
191 O << CI->getValue();
192 else
Duraid Madina45606572005-05-15 13:05:48 +0000193 O << (uint64_t)CI->getValue();
Chris Lattnera80ba712004-08-16 23:15:22 +0000194 else if (const ConstantUInt *CI = dyn_cast<ConstantUInt>(CV))
195 O << CI->getValue();
Chris Lattner450de392005-11-10 18:36:17 +0000196 else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
Duraid Madina855a5192005-04-02 12:21:51 +0000197 // This is a constant address for a global variable or function. Use the
198 // name of the variable or function as the address value, possibly
199 // decorating it with GlobalVarAddrPrefix/Suffix or
200 // FunctionAddrPrefix/Suffix (these all default to "" )
Chris Lattner450de392005-11-10 18:36:17 +0000201 if (isa<Function>(GV))
202 O << FunctionAddrPrefix << Mang->getValueName(GV) << FunctionAddrSuffix;
Duraid Madina855a5192005-04-02 12:21:51 +0000203 else
Chris Lattner450de392005-11-10 18:36:17 +0000204 O << GlobalVarAddrPrefix << Mang->getValueName(GV) << GlobalVarAddrSuffix;
Duraid Madina855a5192005-04-02 12:21:51 +0000205 } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
Chris Lattnera80ba712004-08-16 23:15:22 +0000206 const TargetData &TD = TM.getTargetData();
207 switch(CE->getOpcode()) {
208 case Instruction::GetElementPtr: {
209 // generate a symbolic expression for the byte address
210 const Constant *ptrVal = CE->getOperand(0);
211 std::vector<Value*> idxVec(CE->op_begin()+1, CE->op_end());
Chris Lattner27e19212005-02-14 21:40:26 +0000212 if (int64_t Offset = TD.getIndexedOffset(ptrVal->getType(), idxVec)) {
213 if (Offset)
214 O << "(";
Chris Lattner25045bd2005-11-21 07:51:36 +0000215 EmitConstantValueOnly(ptrVal);
Chris Lattner27e19212005-02-14 21:40:26 +0000216 if (Offset > 0)
217 O << ") + " << Offset;
218 else if (Offset < 0)
219 O << ") - " << -Offset;
Chris Lattnera80ba712004-08-16 23:15:22 +0000220 } else {
Chris Lattner25045bd2005-11-21 07:51:36 +0000221 EmitConstantValueOnly(ptrVal);
Chris Lattnera80ba712004-08-16 23:15:22 +0000222 }
223 break;
224 }
225 case Instruction::Cast: {
226 // Support only non-converting or widening casts for now, that is, ones
227 // that do not involve a change in value. This assertion is really gross,
228 // and may not even be a complete check.
229 Constant *Op = CE->getOperand(0);
230 const Type *OpTy = Op->getType(), *Ty = CE->getType();
231
232 // Remember, kids, pointers can be losslessly converted back and forth
233 // into 32-bit or wider integers, regardless of signedness. :-P
234 assert(((isa<PointerType>(OpTy)
235 && (Ty == Type::LongTy || Ty == Type::ULongTy
236 || Ty == Type::IntTy || Ty == Type::UIntTy))
237 || (isa<PointerType>(Ty)
238 && (OpTy == Type::LongTy || OpTy == Type::ULongTy
239 || OpTy == Type::IntTy || OpTy == Type::UIntTy))
240 || (((TD.getTypeSize(Ty) >= TD.getTypeSize(OpTy))
241 && OpTy->isLosslesslyConvertibleTo(Ty))))
242 && "FIXME: Don't yet support this kind of constant cast expr");
Chris Lattner25045bd2005-11-21 07:51:36 +0000243 EmitConstantValueOnly(Op);
Chris Lattnera80ba712004-08-16 23:15:22 +0000244 break;
245 }
246 case Instruction::Add:
247 O << "(";
Chris Lattner25045bd2005-11-21 07:51:36 +0000248 EmitConstantValueOnly(CE->getOperand(0));
Chris Lattnera80ba712004-08-16 23:15:22 +0000249 O << ") + (";
Chris Lattner25045bd2005-11-21 07:51:36 +0000250 EmitConstantValueOnly(CE->getOperand(1));
Chris Lattnera80ba712004-08-16 23:15:22 +0000251 O << ")";
252 break;
253 default:
254 assert(0 && "Unsupported operator!");
255 }
256 } else {
257 assert(0 && "Unknown constant value!");
258 }
259}
Chris Lattner1b7e2352004-08-17 06:36:49 +0000260
261/// toOctal - Convert the low order bits of X into an octal digit.
262///
263static inline char toOctal(int X) {
264 return (X&7)+'0';
265}
266
Chris Lattner2980cef2005-11-10 18:06:33 +0000267/// printAsCString - Print the specified array as a C compatible string, only if
Chris Lattner1b7e2352004-08-17 06:36:49 +0000268/// the predicate isString is true.
269///
Chris Lattner2980cef2005-11-10 18:06:33 +0000270static void printAsCString(std::ostream &O, const ConstantArray *CVA,
271 unsigned LastElt) {
Chris Lattner1b7e2352004-08-17 06:36:49 +0000272 assert(CVA->isString() && "Array is not string compatible!");
273
274 O << "\"";
Chris Lattner2980cef2005-11-10 18:06:33 +0000275 for (unsigned i = 0; i != LastElt; ++i) {
Misha Brukmanedf128a2005-04-21 22:36:52 +0000276 unsigned char C =
Chris Lattnerdea18b62005-01-08 19:59:10 +0000277 (unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getRawValue();
Chris Lattner1b7e2352004-08-17 06:36:49 +0000278
279 if (C == '"') {
280 O << "\\\"";
281 } else if (C == '\\') {
282 O << "\\\\";
283 } else if (isprint(C)) {
284 O << C;
285 } else {
286 switch(C) {
287 case '\b': O << "\\b"; break;
288 case '\f': O << "\\f"; break;
289 case '\n': O << "\\n"; break;
290 case '\r': O << "\\r"; break;
291 case '\t': O << "\\t"; break;
292 default:
293 O << '\\';
294 O << toOctal(C >> 6);
295 O << toOctal(C >> 3);
296 O << toOctal(C >> 0);
297 break;
298 }
299 }
300 }
301 O << "\"";
302}
303
Chris Lattner25045bd2005-11-21 07:51:36 +0000304/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
Chris Lattner1b7e2352004-08-17 06:36:49 +0000305///
Chris Lattner25045bd2005-11-21 07:51:36 +0000306void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
Chris Lattner1b7e2352004-08-17 06:36:49 +0000307 const TargetData &TD = TM.getTargetData();
308
Chris Lattnerbd1d3822004-10-16 18:19:26 +0000309 if (CV->isNullValue() || isa<UndefValue>(CV)) {
Chris Lattner25045bd2005-11-21 07:51:36 +0000310 EmitZeros(TD.getTypeSize(CV->getType()));
Chris Lattner1b7e2352004-08-17 06:36:49 +0000311 return;
312 } else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
313 if (CVA->isString()) {
Chris Lattner2980cef2005-11-10 18:06:33 +0000314 unsigned NumElts = CVA->getNumOperands();
315 if (AscizDirective && NumElts &&
316 cast<ConstantInt>(CVA->getOperand(NumElts-1))->getRawValue() == 0) {
317 O << AscizDirective;
318 printAsCString(O, CVA, NumElts-1);
319 } else {
320 O << AsciiDirective;
321 printAsCString(O, CVA, NumElts);
322 }
Chris Lattner1b7e2352004-08-17 06:36:49 +0000323 O << "\n";
324 } else { // Not a string. Print the values in successive locations
325 for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
Chris Lattner25045bd2005-11-21 07:51:36 +0000326 EmitGlobalConstant(CVA->getOperand(i));
Chris Lattner1b7e2352004-08-17 06:36:49 +0000327 }
328 return;
329 } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
330 // Print the fields in successive locations. Pad to align if needed!
331 const StructLayout *cvsLayout = TD.getStructLayout(CVS->getType());
Chris Lattnerdea18b62005-01-08 19:59:10 +0000332 uint64_t sizeSoFar = 0;
Chris Lattner1b7e2352004-08-17 06:36:49 +0000333 for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
334 const Constant* field = CVS->getOperand(i);
335
336 // Check if padding is needed and insert one or more 0s.
Chris Lattnerdea18b62005-01-08 19:59:10 +0000337 uint64_t fieldSize = TD.getTypeSize(field->getType());
338 uint64_t padSize = ((i == e-1? cvsLayout->StructSize
Chris Lattner1b7e2352004-08-17 06:36:49 +0000339 : cvsLayout->MemberOffsets[i+1])
340 - cvsLayout->MemberOffsets[i]) - fieldSize;
341 sizeSoFar += fieldSize + padSize;
342
343 // Now print the actual field value
Chris Lattner25045bd2005-11-21 07:51:36 +0000344 EmitGlobalConstant(field);
Chris Lattner1b7e2352004-08-17 06:36:49 +0000345
346 // Insert the field padding unless it's zero bytes...
Chris Lattner25045bd2005-11-21 07:51:36 +0000347 EmitZeros(padSize);
Chris Lattner1b7e2352004-08-17 06:36:49 +0000348 }
349 assert(sizeSoFar == cvsLayout->StructSize &&
350 "Layout of constant struct may be incorrect!");
351 return;
352 } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
353 // FP Constants are printed as integer constants to avoid losing
354 // precision...
355 double Val = CFP->getValue();
356 if (CFP->getType() == Type::DoubleTy) {
Chris Lattnere85a5a92004-08-17 06:48:16 +0000357 if (Data64bitsDirective)
Jim Laskeycb6682f2005-08-17 19:34:49 +0000358 O << Data64bitsDirective << DoubleToBits(Val) << "\t" << CommentString
Chris Lattner7d057a32004-08-17 21:38:40 +0000359 << " double value: " << Val << "\n";
Chris Lattnere85a5a92004-08-17 06:48:16 +0000360 else if (TD.isBigEndian()) {
Jim Laskeycb6682f2005-08-17 19:34:49 +0000361 O << Data32bitsDirective << unsigned(DoubleToBits(Val) >> 32)
Chris Lattnerf746a7d2004-08-18 02:22:55 +0000362 << "\t" << CommentString << " double most significant word "
Chris Lattner0554fb62004-08-17 16:27:05 +0000363 << Val << "\n";
Jim Laskeycb6682f2005-08-17 19:34:49 +0000364 O << Data32bitsDirective << unsigned(DoubleToBits(Val))
Chris Lattnerf746a7d2004-08-18 02:22:55 +0000365 << "\t" << CommentString << " double least significant word "
Chris Lattner0554fb62004-08-17 16:27:05 +0000366 << Val << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000367 } else {
Jim Laskeycb6682f2005-08-17 19:34:49 +0000368 O << Data32bitsDirective << unsigned(DoubleToBits(Val))
Chris Lattnerf746a7d2004-08-18 02:22:55 +0000369 << "\t" << CommentString << " double least significant word " << Val
Chris Lattner0554fb62004-08-17 16:27:05 +0000370 << "\n";
Jim Laskeycb6682f2005-08-17 19:34:49 +0000371 O << Data32bitsDirective << unsigned(DoubleToBits(Val) >> 32)
Chris Lattnerf746a7d2004-08-18 02:22:55 +0000372 << "\t" << CommentString << " double most significant word " << Val
Chris Lattner0554fb62004-08-17 16:27:05 +0000373 << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000374 }
375 return;
376 } else {
Jim Laskeycb6682f2005-08-17 19:34:49 +0000377 O << Data32bitsDirective << FloatToBits(Val) << "\t" << CommentString
Chris Lattner0554fb62004-08-17 16:27:05 +0000378 << " float " << Val << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000379 return;
380 }
381 } else if (CV->getType() == Type::ULongTy || CV->getType() == Type::LongTy) {
382 if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
383 uint64_t Val = CI->getRawValue();
Misha Brukmanedf128a2005-04-21 22:36:52 +0000384
Chris Lattnere85a5a92004-08-17 06:48:16 +0000385 if (Data64bitsDirective)
386 O << Data64bitsDirective << Val << "\n";
387 else if (TD.isBigEndian()) {
Chris Lattner1b7e2352004-08-17 06:36:49 +0000388 O << Data32bitsDirective << unsigned(Val >> 32)
Chris Lattnerf746a7d2004-08-18 02:22:55 +0000389 << "\t" << CommentString << " Double-word most significant word "
Chris Lattner0554fb62004-08-17 16:27:05 +0000390 << Val << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000391 O << Data32bitsDirective << unsigned(Val)
Chris Lattnerf746a7d2004-08-18 02:22:55 +0000392 << "\t" << CommentString << " Double-word least significant word "
Chris Lattner0554fb62004-08-17 16:27:05 +0000393 << Val << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000394 } else {
395 O << Data32bitsDirective << unsigned(Val)
Chris Lattnerf746a7d2004-08-18 02:22:55 +0000396 << "\t" << CommentString << " Double-word least significant word "
Chris Lattner0554fb62004-08-17 16:27:05 +0000397 << Val << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000398 O << Data32bitsDirective << unsigned(Val >> 32)
Chris Lattnerf746a7d2004-08-18 02:22:55 +0000399 << "\t" << CommentString << " Double-word most significant word "
Chris Lattner0554fb62004-08-17 16:27:05 +0000400 << Val << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000401 }
402 return;
403 }
Nate Begeman8cfa57b2005-12-06 06:18:55 +0000404 } else if (const ConstantPacked *CP = dyn_cast<ConstantPacked>(CV)) {
405 const PackedType *PTy = CP->getType();
406
407 for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I)
408 EmitGlobalConstant(CP->getOperand(I));
409
410 return;
Chris Lattner1b7e2352004-08-17 06:36:49 +0000411 }
412
413 const Type *type = CV->getType();
Chris Lattner1b7e2352004-08-17 06:36:49 +0000414 switch (type->getTypeID()) {
Misha Brukmanedf128a2005-04-21 22:36:52 +0000415 case Type::BoolTyID:
Chris Lattner1b7e2352004-08-17 06:36:49 +0000416 case Type::UByteTyID: case Type::SByteTyID:
417 O << Data8bitsDirective;
418 break;
419 case Type::UShortTyID: case Type::ShortTyID:
420 O << Data16bitsDirective;
421 break;
Chris Lattner1b7e2352004-08-17 06:36:49 +0000422 case Type::PointerTyID:
Andrew Lenharth571c9c32005-02-04 13:47:16 +0000423 if (TD.getPointerSize() == 8) {
424 O << Data64bitsDirective;
425 break;
426 }
427 //Fall through for pointer size == int size
Chris Lattner1b7e2352004-08-17 06:36:49 +0000428 case Type::UIntTyID: case Type::IntTyID:
429 O << Data32bitsDirective;
430 break;
Misha Brukmanedf128a2005-04-21 22:36:52 +0000431 case Type::ULongTyID: case Type::LongTyID:
Chris Lattner660538c2005-08-08 04:26:32 +0000432 assert(Data64bitsDirective &&"Target cannot handle 64-bit constant exprs!");
433 O << Data64bitsDirective;
434 break;
Chris Lattner1b7e2352004-08-17 06:36:49 +0000435 case Type::FloatTyID: case Type::DoubleTyID:
436 assert (0 && "Should have already output floating point constant.");
437 default:
438 assert (0 && "Can't handle printing this type of thing");
439 break;
440 }
Chris Lattner25045bd2005-11-21 07:51:36 +0000441 EmitConstantValueOnly(CV);
Chris Lattner1b7e2352004-08-17 06:36:49 +0000442 O << "\n";
443}