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