Chris Lattner | 6a8e0f5 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 1 | //===-- 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 | |
| 14 | #include "llvm/CodeGen/AsmPrinter.h" |
| 15 | #include "llvm/Constants.h" |
Chris Lattner | c0a1eba | 2005-11-10 18:36:17 +0000 | [diff] [blame] | 16 | #include "llvm/Module.h" |
Chris Lattner | 6a8e0f5 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 17 | #include "llvm/Support/Mangler.h" |
Jim Laskey | b74c666 | 2005-08-17 19:34:49 +0000 | [diff] [blame] | 18 | #include "llvm/Support/MathExtras.h" |
Chris Lattner | 6a8e0f5 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 19 | #include "llvm/Target/TargetMachine.h" |
| 20 | using namespace llvm; |
| 21 | |
Chris Lattner | 2ea5c99 | 2005-11-21 07:06:27 +0000 | [diff] [blame] | 22 | /// SwitchSection - Switch to the specified section of the executable if we |
| 23 | /// are not already in it! |
| 24 | /// |
| 25 | void AsmPrinter::SwitchSection(const char *NewSection, const GlobalValue *GV) { |
| 26 | std::string NS; |
| 27 | |
| 28 | if (GV && GV->hasSection()) |
| 29 | NS = ".section " + GV->getSection(); |
| 30 | else |
| 31 | NS = NewSection; |
| 32 | |
| 33 | if (CurrentSection != NS) { |
| 34 | CurrentSection = NS; |
| 35 | if (!CurrentSection.empty()) |
| 36 | O << "\t" << CurrentSection << "\n"; |
| 37 | } |
| 38 | } |
| 39 | |
Chris Lattner | 6a8e0f5 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 40 | bool AsmPrinter::doInitialization(Module &M) { |
Chris Lattner | 6d42cbd | 2004-08-17 06:06:19 +0000 | [diff] [blame] | 41 | Mang = new Mangler(M, GlobalPrefix); |
Chris Lattner | 2ea5c99 | 2005-11-21 07:06:27 +0000 | [diff] [blame] | 42 | SwitchSection("", 0); // Reset back to no section. |
Chris Lattner | 6a8e0f5 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 43 | return false; |
| 44 | } |
| 45 | |
| 46 | bool AsmPrinter::doFinalization(Module &M) { |
| 47 | delete Mang; Mang = 0; |
| 48 | return false; |
| 49 | } |
| 50 | |
Chris Lattner | bb644e3 | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 51 | void AsmPrinter::SetupMachineFunction(MachineFunction &MF) { |
Chris Lattner | 6a8e0f5 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 52 | // What's my mangled name? |
Chris Lattner | c0a1eba | 2005-11-10 18:36:17 +0000 | [diff] [blame] | 53 | CurrentFnName = Mang->getValueName(MF.getFunction()); |
Chris Lattner | 08adbd13 | 2005-11-21 08:13:27 +0000 | [diff] [blame^] | 54 | IncrementFunctionNumber(); |
Chris Lattner | 6a8e0f5 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Chris Lattner | bb644e3 | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 57 | // EmitAlignment - Emit an alignment directive to the specified power of two. |
| 58 | void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV) const { |
Chris Lattner | dd8eeed | 2005-11-14 19:00:06 +0000 | [diff] [blame] | 59 | if (GV && GV->getAlignment()) |
| 60 | NumBits = Log2_32(GV->getAlignment()); |
Chris Lattner | 747960d | 2005-11-10 18:09:27 +0000 | [diff] [blame] | 61 | if (NumBits == 0) return; // No need to emit alignment. |
Chris Lattner | 1d35c16 | 2004-08-17 19:14:29 +0000 | [diff] [blame] | 62 | if (AlignmentIsInBytes) NumBits = 1 << NumBits; |
| 63 | O << AlignDirective << NumBits << "\n"; |
| 64 | } |
| 65 | |
Chris Lattner | bb644e3 | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 66 | /// EmitZeros - Emit a block of zeros. |
Chris Lattner | ea75199 | 2004-08-17 21:38:40 +0000 | [diff] [blame] | 67 | /// |
Chris Lattner | bb644e3 | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 68 | void AsmPrinter::EmitZeros(uint64_t NumZeros) const { |
Chris Lattner | ea75199 | 2004-08-17 21:38:40 +0000 | [diff] [blame] | 69 | if (NumZeros) { |
| 70 | if (ZeroDirective) |
| 71 | O << ZeroDirective << NumZeros << "\n"; |
| 72 | else { |
Chris Lattner | ea75199 | 2004-08-17 21:38:40 +0000 | [diff] [blame] | 73 | for (; NumZeros; --NumZeros) |
| 74 | O << Data8bitsDirective << "0\n"; |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
Chris Lattner | 6a8e0f5 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 79 | // Print out the specified constant, without a storage class. Only the |
| 80 | // constants valid in constant expressions can occur here. |
Chris Lattner | bb644e3 | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 81 | void AsmPrinter::EmitConstantValueOnly(const Constant *CV) { |
Chris Lattner | 61753bf | 2004-10-16 18:19:26 +0000 | [diff] [blame] | 82 | if (CV->isNullValue() || isa<UndefValue>(CV)) |
Chris Lattner | 6a8e0f5 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 83 | O << "0"; |
| 84 | else if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) { |
| 85 | assert(CB == ConstantBool::True); |
| 86 | O << "1"; |
| 87 | } else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV)) |
| 88 | if (((CI->getValue() << 32) >> 32) == CI->getValue()) |
| 89 | O << CI->getValue(); |
| 90 | else |
Duraid Madina | 73c4dba | 2005-05-15 13:05:48 +0000 | [diff] [blame] | 91 | O << (uint64_t)CI->getValue(); |
Chris Lattner | 6a8e0f5 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 92 | else if (const ConstantUInt *CI = dyn_cast<ConstantUInt>(CV)) |
| 93 | O << CI->getValue(); |
Chris Lattner | c0a1eba | 2005-11-10 18:36:17 +0000 | [diff] [blame] | 94 | else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) { |
Duraid Madina | 73a316d | 2005-04-02 12:21:51 +0000 | [diff] [blame] | 95 | // This is a constant address for a global variable or function. Use the |
| 96 | // name of the variable or function as the address value, possibly |
| 97 | // decorating it with GlobalVarAddrPrefix/Suffix or |
| 98 | // FunctionAddrPrefix/Suffix (these all default to "" ) |
Chris Lattner | c0a1eba | 2005-11-10 18:36:17 +0000 | [diff] [blame] | 99 | if (isa<Function>(GV)) |
| 100 | O << FunctionAddrPrefix << Mang->getValueName(GV) << FunctionAddrSuffix; |
Duraid Madina | 73a316d | 2005-04-02 12:21:51 +0000 | [diff] [blame] | 101 | else |
Chris Lattner | c0a1eba | 2005-11-10 18:36:17 +0000 | [diff] [blame] | 102 | O << GlobalVarAddrPrefix << Mang->getValueName(GV) << GlobalVarAddrSuffix; |
Duraid Madina | 73a316d | 2005-04-02 12:21:51 +0000 | [diff] [blame] | 103 | } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) { |
Chris Lattner | 6a8e0f5 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 104 | const TargetData &TD = TM.getTargetData(); |
| 105 | switch(CE->getOpcode()) { |
| 106 | case Instruction::GetElementPtr: { |
| 107 | // generate a symbolic expression for the byte address |
| 108 | const Constant *ptrVal = CE->getOperand(0); |
| 109 | std::vector<Value*> idxVec(CE->op_begin()+1, CE->op_end()); |
Chris Lattner | 145569b | 2005-02-14 21:40:26 +0000 | [diff] [blame] | 110 | if (int64_t Offset = TD.getIndexedOffset(ptrVal->getType(), idxVec)) { |
| 111 | if (Offset) |
| 112 | O << "("; |
Chris Lattner | bb644e3 | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 113 | EmitConstantValueOnly(ptrVal); |
Chris Lattner | 145569b | 2005-02-14 21:40:26 +0000 | [diff] [blame] | 114 | if (Offset > 0) |
| 115 | O << ") + " << Offset; |
| 116 | else if (Offset < 0) |
| 117 | O << ") - " << -Offset; |
Chris Lattner | 6a8e0f5 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 118 | } else { |
Chris Lattner | bb644e3 | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 119 | EmitConstantValueOnly(ptrVal); |
Chris Lattner | 6a8e0f5 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 120 | } |
| 121 | break; |
| 122 | } |
| 123 | case Instruction::Cast: { |
| 124 | // Support only non-converting or widening casts for now, that is, ones |
| 125 | // that do not involve a change in value. This assertion is really gross, |
| 126 | // and may not even be a complete check. |
| 127 | Constant *Op = CE->getOperand(0); |
| 128 | const Type *OpTy = Op->getType(), *Ty = CE->getType(); |
| 129 | |
| 130 | // Remember, kids, pointers can be losslessly converted back and forth |
| 131 | // into 32-bit or wider integers, regardless of signedness. :-P |
| 132 | assert(((isa<PointerType>(OpTy) |
| 133 | && (Ty == Type::LongTy || Ty == Type::ULongTy |
| 134 | || Ty == Type::IntTy || Ty == Type::UIntTy)) |
| 135 | || (isa<PointerType>(Ty) |
| 136 | && (OpTy == Type::LongTy || OpTy == Type::ULongTy |
| 137 | || OpTy == Type::IntTy || OpTy == Type::UIntTy)) |
| 138 | || (((TD.getTypeSize(Ty) >= TD.getTypeSize(OpTy)) |
| 139 | && OpTy->isLosslesslyConvertibleTo(Ty)))) |
| 140 | && "FIXME: Don't yet support this kind of constant cast expr"); |
Chris Lattner | bb644e3 | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 141 | EmitConstantValueOnly(Op); |
Chris Lattner | 6a8e0f5 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 142 | break; |
| 143 | } |
| 144 | case Instruction::Add: |
| 145 | O << "("; |
Chris Lattner | bb644e3 | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 146 | EmitConstantValueOnly(CE->getOperand(0)); |
Chris Lattner | 6a8e0f5 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 147 | O << ") + ("; |
Chris Lattner | bb644e3 | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 148 | EmitConstantValueOnly(CE->getOperand(1)); |
Chris Lattner | 6a8e0f5 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 149 | O << ")"; |
| 150 | break; |
| 151 | default: |
| 152 | assert(0 && "Unsupported operator!"); |
| 153 | } |
| 154 | } else { |
| 155 | assert(0 && "Unknown constant value!"); |
| 156 | } |
| 157 | } |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 158 | |
| 159 | /// toOctal - Convert the low order bits of X into an octal digit. |
| 160 | /// |
| 161 | static inline char toOctal(int X) { |
| 162 | return (X&7)+'0'; |
| 163 | } |
| 164 | |
Chris Lattner | 55a6d90 | 2005-11-10 18:06:33 +0000 | [diff] [blame] | 165 | /// printAsCString - Print the specified array as a C compatible string, only if |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 166 | /// the predicate isString is true. |
| 167 | /// |
Chris Lattner | 55a6d90 | 2005-11-10 18:06:33 +0000 | [diff] [blame] | 168 | static void printAsCString(std::ostream &O, const ConstantArray *CVA, |
| 169 | unsigned LastElt) { |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 170 | assert(CVA->isString() && "Array is not string compatible!"); |
| 171 | |
| 172 | O << "\""; |
Chris Lattner | 55a6d90 | 2005-11-10 18:06:33 +0000 | [diff] [blame] | 173 | for (unsigned i = 0; i != LastElt; ++i) { |
Misha Brukman | 835702a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 174 | unsigned char C = |
Chris Lattner | 0b955fd | 2005-01-08 19:59:10 +0000 | [diff] [blame] | 175 | (unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getRawValue(); |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 176 | |
| 177 | if (C == '"') { |
| 178 | O << "\\\""; |
| 179 | } else if (C == '\\') { |
| 180 | O << "\\\\"; |
| 181 | } else if (isprint(C)) { |
| 182 | O << C; |
| 183 | } else { |
| 184 | switch(C) { |
| 185 | case '\b': O << "\\b"; break; |
| 186 | case '\f': O << "\\f"; break; |
| 187 | case '\n': O << "\\n"; break; |
| 188 | case '\r': O << "\\r"; break; |
| 189 | case '\t': O << "\\t"; break; |
| 190 | default: |
| 191 | O << '\\'; |
| 192 | O << toOctal(C >> 6); |
| 193 | O << toOctal(C >> 3); |
| 194 | O << toOctal(C >> 0); |
| 195 | break; |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | O << "\""; |
| 200 | } |
| 201 | |
Chris Lattner | bb644e3 | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 202 | /// EmitGlobalConstant - Print a general LLVM constant to the .s file. |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 203 | /// |
Chris Lattner | bb644e3 | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 204 | void AsmPrinter::EmitGlobalConstant(const Constant *CV) { |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 205 | const TargetData &TD = TM.getTargetData(); |
| 206 | |
Chris Lattner | 61753bf | 2004-10-16 18:19:26 +0000 | [diff] [blame] | 207 | if (CV->isNullValue() || isa<UndefValue>(CV)) { |
Chris Lattner | bb644e3 | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 208 | EmitZeros(TD.getTypeSize(CV->getType())); |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 209 | return; |
| 210 | } else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) { |
| 211 | if (CVA->isString()) { |
Chris Lattner | 55a6d90 | 2005-11-10 18:06:33 +0000 | [diff] [blame] | 212 | unsigned NumElts = CVA->getNumOperands(); |
| 213 | if (AscizDirective && NumElts && |
| 214 | cast<ConstantInt>(CVA->getOperand(NumElts-1))->getRawValue() == 0) { |
| 215 | O << AscizDirective; |
| 216 | printAsCString(O, CVA, NumElts-1); |
| 217 | } else { |
| 218 | O << AsciiDirective; |
| 219 | printAsCString(O, CVA, NumElts); |
| 220 | } |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 221 | O << "\n"; |
| 222 | } else { // Not a string. Print the values in successive locations |
| 223 | for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i) |
Chris Lattner | bb644e3 | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 224 | EmitGlobalConstant(CVA->getOperand(i)); |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 225 | } |
| 226 | return; |
| 227 | } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) { |
| 228 | // Print the fields in successive locations. Pad to align if needed! |
| 229 | const StructLayout *cvsLayout = TD.getStructLayout(CVS->getType()); |
Chris Lattner | 0b955fd | 2005-01-08 19:59:10 +0000 | [diff] [blame] | 230 | uint64_t sizeSoFar = 0; |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 231 | for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) { |
| 232 | const Constant* field = CVS->getOperand(i); |
| 233 | |
| 234 | // Check if padding is needed and insert one or more 0s. |
Chris Lattner | 0b955fd | 2005-01-08 19:59:10 +0000 | [diff] [blame] | 235 | uint64_t fieldSize = TD.getTypeSize(field->getType()); |
| 236 | uint64_t padSize = ((i == e-1? cvsLayout->StructSize |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 237 | : cvsLayout->MemberOffsets[i+1]) |
| 238 | - cvsLayout->MemberOffsets[i]) - fieldSize; |
| 239 | sizeSoFar += fieldSize + padSize; |
| 240 | |
| 241 | // Now print the actual field value |
Chris Lattner | bb644e3 | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 242 | EmitGlobalConstant(field); |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 243 | |
| 244 | // Insert the field padding unless it's zero bytes... |
Chris Lattner | bb644e3 | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 245 | EmitZeros(padSize); |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 246 | } |
| 247 | assert(sizeSoFar == cvsLayout->StructSize && |
| 248 | "Layout of constant struct may be incorrect!"); |
| 249 | return; |
| 250 | } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) { |
| 251 | // FP Constants are printed as integer constants to avoid losing |
| 252 | // precision... |
| 253 | double Val = CFP->getValue(); |
| 254 | if (CFP->getType() == Type::DoubleTy) { |
Chris Lattner | 9fa0fc4 | 2004-08-17 06:48:16 +0000 | [diff] [blame] | 255 | if (Data64bitsDirective) |
Jim Laskey | b74c666 | 2005-08-17 19:34:49 +0000 | [diff] [blame] | 256 | O << Data64bitsDirective << DoubleToBits(Val) << "\t" << CommentString |
Chris Lattner | ea75199 | 2004-08-17 21:38:40 +0000 | [diff] [blame] | 257 | << " double value: " << Val << "\n"; |
Chris Lattner | 9fa0fc4 | 2004-08-17 06:48:16 +0000 | [diff] [blame] | 258 | else if (TD.isBigEndian()) { |
Jim Laskey | b74c666 | 2005-08-17 19:34:49 +0000 | [diff] [blame] | 259 | O << Data32bitsDirective << unsigned(DoubleToBits(Val) >> 32) |
Chris Lattner | 10262ab | 2004-08-18 02:22:55 +0000 | [diff] [blame] | 260 | << "\t" << CommentString << " double most significant word " |
Chris Lattner | da6beac | 2004-08-17 16:27:05 +0000 | [diff] [blame] | 261 | << Val << "\n"; |
Jim Laskey | b74c666 | 2005-08-17 19:34:49 +0000 | [diff] [blame] | 262 | O << Data32bitsDirective << unsigned(DoubleToBits(Val)) |
Chris Lattner | 10262ab | 2004-08-18 02:22:55 +0000 | [diff] [blame] | 263 | << "\t" << CommentString << " double least significant word " |
Chris Lattner | da6beac | 2004-08-17 16:27:05 +0000 | [diff] [blame] | 264 | << Val << "\n"; |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 265 | } else { |
Jim Laskey | b74c666 | 2005-08-17 19:34:49 +0000 | [diff] [blame] | 266 | O << Data32bitsDirective << unsigned(DoubleToBits(Val)) |
Chris Lattner | 10262ab | 2004-08-18 02:22:55 +0000 | [diff] [blame] | 267 | << "\t" << CommentString << " double least significant word " << Val |
Chris Lattner | da6beac | 2004-08-17 16:27:05 +0000 | [diff] [blame] | 268 | << "\n"; |
Jim Laskey | b74c666 | 2005-08-17 19:34:49 +0000 | [diff] [blame] | 269 | O << Data32bitsDirective << unsigned(DoubleToBits(Val) >> 32) |
Chris Lattner | 10262ab | 2004-08-18 02:22:55 +0000 | [diff] [blame] | 270 | << "\t" << CommentString << " double most significant word " << Val |
Chris Lattner | da6beac | 2004-08-17 16:27:05 +0000 | [diff] [blame] | 271 | << "\n"; |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 272 | } |
| 273 | return; |
| 274 | } else { |
Jim Laskey | b74c666 | 2005-08-17 19:34:49 +0000 | [diff] [blame] | 275 | O << Data32bitsDirective << FloatToBits(Val) << "\t" << CommentString |
Chris Lattner | da6beac | 2004-08-17 16:27:05 +0000 | [diff] [blame] | 276 | << " float " << Val << "\n"; |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 277 | return; |
| 278 | } |
| 279 | } else if (CV->getType() == Type::ULongTy || CV->getType() == Type::LongTy) { |
| 280 | if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) { |
| 281 | uint64_t Val = CI->getRawValue(); |
Misha Brukman | 835702a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 282 | |
Chris Lattner | 9fa0fc4 | 2004-08-17 06:48:16 +0000 | [diff] [blame] | 283 | if (Data64bitsDirective) |
| 284 | O << Data64bitsDirective << Val << "\n"; |
| 285 | else if (TD.isBigEndian()) { |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 286 | O << Data32bitsDirective << unsigned(Val >> 32) |
Chris Lattner | 10262ab | 2004-08-18 02:22:55 +0000 | [diff] [blame] | 287 | << "\t" << CommentString << " Double-word most significant word " |
Chris Lattner | da6beac | 2004-08-17 16:27:05 +0000 | [diff] [blame] | 288 | << Val << "\n"; |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 289 | O << Data32bitsDirective << unsigned(Val) |
Chris Lattner | 10262ab | 2004-08-18 02:22:55 +0000 | [diff] [blame] | 290 | << "\t" << CommentString << " Double-word least significant word " |
Chris Lattner | da6beac | 2004-08-17 16:27:05 +0000 | [diff] [blame] | 291 | << Val << "\n"; |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 292 | } else { |
| 293 | O << Data32bitsDirective << unsigned(Val) |
Chris Lattner | 10262ab | 2004-08-18 02:22:55 +0000 | [diff] [blame] | 294 | << "\t" << CommentString << " Double-word least significant word " |
Chris Lattner | da6beac | 2004-08-17 16:27:05 +0000 | [diff] [blame] | 295 | << Val << "\n"; |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 296 | O << Data32bitsDirective << unsigned(Val >> 32) |
Chris Lattner | 10262ab | 2004-08-18 02:22:55 +0000 | [diff] [blame] | 297 | << "\t" << CommentString << " Double-word most significant word " |
Chris Lattner | da6beac | 2004-08-17 16:27:05 +0000 | [diff] [blame] | 298 | << Val << "\n"; |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 299 | } |
| 300 | return; |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | const Type *type = CV->getType(); |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 305 | switch (type->getTypeID()) { |
Misha Brukman | 835702a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 306 | case Type::BoolTyID: |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 307 | case Type::UByteTyID: case Type::SByteTyID: |
| 308 | O << Data8bitsDirective; |
| 309 | break; |
| 310 | case Type::UShortTyID: case Type::ShortTyID: |
| 311 | O << Data16bitsDirective; |
| 312 | break; |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 313 | case Type::PointerTyID: |
Andrew Lenharth | c8770aa | 2005-02-04 13:47:16 +0000 | [diff] [blame] | 314 | if (TD.getPointerSize() == 8) { |
| 315 | O << Data64bitsDirective; |
| 316 | break; |
| 317 | } |
| 318 | //Fall through for pointer size == int size |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 319 | case Type::UIntTyID: case Type::IntTyID: |
| 320 | O << Data32bitsDirective; |
| 321 | break; |
Misha Brukman | 835702a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 322 | case Type::ULongTyID: case Type::LongTyID: |
Chris Lattner | 88e2d2e | 2005-08-08 04:26:32 +0000 | [diff] [blame] | 323 | assert(Data64bitsDirective &&"Target cannot handle 64-bit constant exprs!"); |
| 324 | O << Data64bitsDirective; |
| 325 | break; |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 326 | case Type::FloatTyID: case Type::DoubleTyID: |
| 327 | assert (0 && "Should have already output floating point constant."); |
| 328 | default: |
| 329 | assert (0 && "Can't handle printing this type of thing"); |
| 330 | break; |
| 331 | } |
Chris Lattner | bb644e3 | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 332 | EmitConstantValueOnly(CV); |
Chris Lattner | 8452a1f | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 333 | O << "\n"; |
| 334 | } |