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