Chris Lattner | a80ba71 | 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 | |
Nate Begeman | 8cfa57b | 2005-12-06 06:18:55 +0000 | [diff] [blame] | 14 | #include "llvm/DerivedTypes.h" |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/AsmPrinter.h" |
| 16 | #include "llvm/Constants.h" |
Chris Lattner | 450de39 | 2005-11-10 18:36:17 +0000 | [diff] [blame] | 17 | #include "llvm/Module.h" |
Chris Lattner | 3b4fd32 | 2005-11-21 08:25:09 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineConstantPool.h" |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Mangler.h" |
Jim Laskey | cb6682f | 2005-08-17 19:34:49 +0000 | [diff] [blame] | 20 | #include "llvm/Support/MathExtras.h" |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetMachine.h" |
Duraid Madina | 2e096c1 | 2005-12-28 06:29:02 +0000 | [diff] [blame] | 22 | #include <iostream> |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 23 | #include <cerrno> |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 24 | using namespace llvm; |
| 25 | |
Chris Lattner | ed13893 | 2005-12-13 06:32:10 +0000 | [diff] [blame] | 26 | AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm) |
| 27 | : FunctionNumber(0), O(o), TM(tm), |
| 28 | CommentString("#"), |
| 29 | GlobalPrefix(""), |
| 30 | PrivateGlobalPrefix("."), |
| 31 | GlobalVarAddrPrefix(""), |
| 32 | GlobalVarAddrSuffix(""), |
| 33 | FunctionAddrPrefix(""), |
| 34 | FunctionAddrSuffix(""), |
Chris Lattner | d6c65ea | 2006-02-08 23:41:56 +0000 | [diff] [blame] | 35 | InlineAsmStart("#APP\n"), |
| 36 | InlineAsmEnd("#NO_APP\n"), |
Chris Lattner | ed13893 | 2005-12-13 06:32:10 +0000 | [diff] [blame] | 37 | ZeroDirective("\t.zero\t"), |
| 38 | AsciiDirective("\t.ascii\t"), |
| 39 | AscizDirective("\t.asciz\t"), |
| 40 | Data8bitsDirective("\t.byte\t"), |
| 41 | Data16bitsDirective("\t.short\t"), |
| 42 | Data32bitsDirective("\t.long\t"), |
| 43 | Data64bitsDirective("\t.quad\t"), |
| 44 | AlignDirective("\t.align\t"), |
| 45 | AlignmentIsInBytes(true), |
| 46 | SwitchToSectionDirective("\t.section\t"), |
| 47 | ConstantPoolSection("\t.section .rodata\n"), |
| 48 | StaticCtorsSection("\t.section .ctors,\"aw\",@progbits"), |
| 49 | StaticDtorsSection("\t.section .dtors,\"aw\",@progbits"), |
| 50 | LCOMMDirective(0), |
| 51 | COMMDirective("\t.comm\t"), |
| 52 | COMMDirectiveTakesAlignment(true), |
| 53 | HasDotTypeDotSizeDirective(true) { |
| 54 | } |
| 55 | |
| 56 | |
Chris Lattner | ac28fbd | 2005-11-21 07:06:27 +0000 | [diff] [blame] | 57 | /// SwitchSection - Switch to the specified section of the executable if we |
| 58 | /// are not already in it! |
| 59 | /// |
| 60 | void AsmPrinter::SwitchSection(const char *NewSection, const GlobalValue *GV) { |
| 61 | std::string NS; |
| 62 | |
| 63 | if (GV && GV->hasSection()) |
Chris Lattner | 3b4fd32 | 2005-11-21 08:25:09 +0000 | [diff] [blame] | 64 | NS = SwitchToSectionDirective + GV->getSection(); |
Chris Lattner | ac28fbd | 2005-11-21 07:06:27 +0000 | [diff] [blame] | 65 | else |
Chris Lattner | 42a80fe | 2005-12-09 19:28:49 +0000 | [diff] [blame] | 66 | NS = std::string("\t")+NewSection; |
Chris Lattner | ac28fbd | 2005-11-21 07:06:27 +0000 | [diff] [blame] | 67 | |
| 68 | if (CurrentSection != NS) { |
| 69 | CurrentSection = NS; |
| 70 | if (!CurrentSection.empty()) |
Chris Lattner | 42a80fe | 2005-12-09 19:28:49 +0000 | [diff] [blame] | 71 | O << CurrentSection << '\n'; |
Chris Lattner | ac28fbd | 2005-11-21 07:06:27 +0000 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 75 | bool AsmPrinter::doInitialization(Module &M) { |
Chris Lattner | af2bf0a | 2004-08-17 06:06:19 +0000 | [diff] [blame] | 76 | Mang = new Mangler(M, GlobalPrefix); |
Chris Lattner | 2c1b159 | 2006-01-23 23:47:53 +0000 | [diff] [blame] | 77 | |
Chris Lattner | 3e2fa7a | 2006-01-24 04:16:34 +0000 | [diff] [blame] | 78 | if (!M.getModuleInlineAsm().empty()) |
| 79 | O << CommentString << " Start of file scope inline assembly\n" |
| 80 | << M.getModuleInlineAsm() |
| 81 | << "\n" << CommentString << " End of file scope inline assembly\n"; |
Chris Lattner | 2c1b159 | 2006-01-23 23:47:53 +0000 | [diff] [blame] | 82 | |
Chris Lattner | ac28fbd | 2005-11-21 07:06:27 +0000 | [diff] [blame] | 83 | SwitchSection("", 0); // Reset back to no section. |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 84 | |
| 85 | if (MachineDebugInfo *DebugInfo = getAnalysisToUpdate<MachineDebugInfo>()) { |
| 86 | DebugInfo->AnalyzeModule(M); |
| 87 | } |
| 88 | |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 89 | return false; |
| 90 | } |
| 91 | |
| 92 | bool AsmPrinter::doFinalization(Module &M) { |
| 93 | delete Mang; Mang = 0; |
| 94 | return false; |
| 95 | } |
| 96 | |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 97 | void AsmPrinter::SetupMachineFunction(MachineFunction &MF) { |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 98 | // What's my mangled name? |
Chris Lattner | 450de39 | 2005-11-10 18:36:17 +0000 | [diff] [blame] | 99 | CurrentFnName = Mang->getValueName(MF.getFunction()); |
Chris Lattner | 77bc228 | 2005-11-21 08:13:27 +0000 | [diff] [blame] | 100 | IncrementFunctionNumber(); |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Chris Lattner | 3b4fd32 | 2005-11-21 08:25:09 +0000 | [diff] [blame] | 103 | /// EmitConstantPool - Print to the current output stream assembly |
| 104 | /// representations of the constants in the constant pool MCP. This is |
| 105 | /// used to print out constants which have been "spilled to memory" by |
| 106 | /// the code generator. |
| 107 | /// |
| 108 | void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) { |
Chris Lattner | fa77d43 | 2006-02-09 04:22:52 +0000 | [diff] [blame] | 109 | const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants(); |
Chris Lattner | 3b4fd32 | 2005-11-21 08:25:09 +0000 | [diff] [blame] | 110 | if (CP.empty()) return; |
| 111 | const TargetData &TD = TM.getTargetData(); |
| 112 | |
| 113 | SwitchSection(ConstantPoolSection, 0); |
Chris Lattner | 3029f92 | 2006-02-09 04:46:04 +0000 | [diff] [blame] | 114 | EmitAlignment(MCP->getConstantPoolAlignment()); |
Chris Lattner | 3b4fd32 | 2005-11-21 08:25:09 +0000 | [diff] [blame] | 115 | for (unsigned i = 0, e = CP.size(); i != e; ++i) { |
Chris Lattner | 3b4fd32 | 2005-11-21 08:25:09 +0000 | [diff] [blame] | 116 | O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << '_' << i |
Chris Lattner | fa77d43 | 2006-02-09 04:22:52 +0000 | [diff] [blame] | 117 | << ":\t\t\t\t\t" << CommentString << *CP[i].Val << '\n'; |
| 118 | EmitGlobalConstant(CP[i].Val); |
Chris Lattner | 3029f92 | 2006-02-09 04:46:04 +0000 | [diff] [blame] | 119 | if (i != e-1) { |
| 120 | unsigned EntSize = TM.getTargetData().getTypeSize(CP[i].Val->getType()); |
| 121 | unsigned ValEnd = CP[i].Offset + EntSize; |
| 122 | // Emit inter-object padding for alignment. |
| 123 | EmitZeros(CP[i+1].Offset-ValEnd); |
| 124 | } |
Chris Lattner | 3b4fd32 | 2005-11-21 08:25:09 +0000 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
Chris Lattner | ed13893 | 2005-12-13 06:32:10 +0000 | [diff] [blame] | 128 | /// EmitSpecialLLVMGlobal - Check to see if the specified global is a |
| 129 | /// special global used by LLVM. If so, emit it and return true, otherwise |
| 130 | /// do nothing and return false. |
| 131 | bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) { |
| 132 | assert(GV->hasInitializer() && GV->hasAppendingLinkage() && |
| 133 | "Not a special LLVM global!"); |
| 134 | |
| 135 | if (GV->getName() == "llvm.used") |
| 136 | return true; // No need to emit this at all. |
| 137 | |
Chris Lattner | 5166b82 | 2006-01-12 19:17:23 +0000 | [diff] [blame] | 138 | if (GV->getName() == "llvm.global_ctors" && GV->use_empty()) { |
Chris Lattner | ed13893 | 2005-12-13 06:32:10 +0000 | [diff] [blame] | 139 | SwitchSection(StaticCtorsSection, 0); |
| 140 | EmitAlignment(2, 0); |
| 141 | EmitXXStructorList(GV->getInitializer()); |
| 142 | return true; |
| 143 | } |
| 144 | |
Chris Lattner | 5166b82 | 2006-01-12 19:17:23 +0000 | [diff] [blame] | 145 | if (GV->getName() == "llvm.global_dtors" && GV->use_empty()) { |
Chris Lattner | ed13893 | 2005-12-13 06:32:10 +0000 | [diff] [blame] | 146 | SwitchSection(StaticDtorsSection, 0); |
| 147 | EmitAlignment(2, 0); |
| 148 | EmitXXStructorList(GV->getInitializer()); |
| 149 | return true; |
| 150 | } |
| 151 | |
| 152 | return false; |
| 153 | } |
| 154 | |
| 155 | /// EmitXXStructorList - Emit the ctor or dtor list. This just prints out the |
| 156 | /// function pointers, ignoring the init priority. |
| 157 | void AsmPrinter::EmitXXStructorList(Constant *List) { |
| 158 | // Should be an array of '{ int, void ()* }' structs. The first value is the |
| 159 | // init priority, which we ignore. |
| 160 | if (!isa<ConstantArray>(List)) return; |
| 161 | ConstantArray *InitList = cast<ConstantArray>(List); |
| 162 | for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) |
| 163 | if (ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i))){ |
| 164 | if (CS->getNumOperands() != 2) return; // Not array of 2-element structs. |
Chris Lattner | 8de324b | 2005-12-21 01:17:37 +0000 | [diff] [blame] | 165 | |
| 166 | if (CS->getOperand(1)->isNullValue()) |
| 167 | return; // Found a null terminator, exit printing. |
| 168 | // Emit the function pointer. |
Chris Lattner | ed13893 | 2005-12-13 06:32:10 +0000 | [diff] [blame] | 169 | EmitGlobalConstant(CS->getOperand(1)); |
| 170 | } |
| 171 | } |
Chris Lattner | 3b4fd32 | 2005-11-21 08:25:09 +0000 | [diff] [blame] | 172 | |
Chris Lattner | 4d57e0c | 2006-02-05 01:29:18 +0000 | [diff] [blame] | 173 | /// getPreferredAlignmentLog - Return the preferred alignment of the |
| 174 | /// specified global, returned in log form. This includes an explicitly |
| 175 | /// requested alignment (if the global has one). |
| 176 | unsigned AsmPrinter::getPreferredAlignmentLog(const GlobalVariable *GV) const { |
| 177 | unsigned Alignment = TM.getTargetData().getTypeAlignmentShift(GV->getType()); |
| 178 | if (GV->getAlignment() > (1U << Alignment)) |
| 179 | Alignment = Log2_32(GV->getAlignment()); |
| 180 | |
Chris Lattner | 519ea2a | 2006-02-05 01:46:49 +0000 | [diff] [blame] | 181 | if (GV->hasInitializer()) { |
| 182 | // Always round up alignment of global doubles to 8 bytes. |
| 183 | if (GV->getType()->getElementType() == Type::DoubleTy && Alignment < 3) |
| 184 | Alignment = 3; |
| 185 | if (Alignment < 4) { |
| 186 | // If the global is not external, see if it is large. If so, give it a |
| 187 | // larger alignment. |
| 188 | if (TM.getTargetData().getTypeSize(GV->getType()->getElementType()) > 128) |
| 189 | Alignment = 4; // 16-byte alignment. |
| 190 | } |
Chris Lattner | 4d57e0c | 2006-02-05 01:29:18 +0000 | [diff] [blame] | 191 | } |
| 192 | return Alignment; |
| 193 | } |
Chris Lattner | 3b4fd32 | 2005-11-21 08:25:09 +0000 | [diff] [blame] | 194 | |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 195 | // EmitAlignment - Emit an alignment directive to the specified power of two. |
| 196 | void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV) const { |
Chris Lattner | a1ab72d | 2005-11-14 19:00:06 +0000 | [diff] [blame] | 197 | if (GV && GV->getAlignment()) |
| 198 | NumBits = Log2_32(GV->getAlignment()); |
Chris Lattner | 2a21c6e | 2005-11-10 18:09:27 +0000 | [diff] [blame] | 199 | if (NumBits == 0) return; // No need to emit alignment. |
Chris Lattner | bfddc20 | 2004-08-17 19:14:29 +0000 | [diff] [blame] | 200 | if (AlignmentIsInBytes) NumBits = 1 << NumBits; |
| 201 | O << AlignDirective << NumBits << "\n"; |
| 202 | } |
| 203 | |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 204 | /// EmitZeros - Emit a block of zeros. |
Chris Lattner | 7d057a3 | 2004-08-17 21:38:40 +0000 | [diff] [blame] | 205 | /// |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 206 | void AsmPrinter::EmitZeros(uint64_t NumZeros) const { |
Chris Lattner | 7d057a3 | 2004-08-17 21:38:40 +0000 | [diff] [blame] | 207 | if (NumZeros) { |
| 208 | if (ZeroDirective) |
| 209 | O << ZeroDirective << NumZeros << "\n"; |
| 210 | else { |
Chris Lattner | 7d057a3 | 2004-08-17 21:38:40 +0000 | [diff] [blame] | 211 | for (; NumZeros; --NumZeros) |
| 212 | O << Data8bitsDirective << "0\n"; |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 217 | // Print out the specified constant, without a storage class. Only the |
| 218 | // constants valid in constant expressions can occur here. |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 219 | void AsmPrinter::EmitConstantValueOnly(const Constant *CV) { |
Chris Lattner | bd1d382 | 2004-10-16 18:19:26 +0000 | [diff] [blame] | 220 | if (CV->isNullValue() || isa<UndefValue>(CV)) |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 221 | O << "0"; |
| 222 | else if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) { |
| 223 | assert(CB == ConstantBool::True); |
| 224 | O << "1"; |
| 225 | } else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV)) |
| 226 | if (((CI->getValue() << 32) >> 32) == CI->getValue()) |
| 227 | O << CI->getValue(); |
| 228 | else |
Duraid Madina | 4560657 | 2005-05-15 13:05:48 +0000 | [diff] [blame] | 229 | O << (uint64_t)CI->getValue(); |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 230 | else if (const ConstantUInt *CI = dyn_cast<ConstantUInt>(CV)) |
| 231 | O << CI->getValue(); |
Chris Lattner | 450de39 | 2005-11-10 18:36:17 +0000 | [diff] [blame] | 232 | else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) { |
Duraid Madina | 855a519 | 2005-04-02 12:21:51 +0000 | [diff] [blame] | 233 | // This is a constant address for a global variable or function. Use the |
| 234 | // name of the variable or function as the address value, possibly |
| 235 | // decorating it with GlobalVarAddrPrefix/Suffix or |
| 236 | // FunctionAddrPrefix/Suffix (these all default to "" ) |
Chris Lattner | 450de39 | 2005-11-10 18:36:17 +0000 | [diff] [blame] | 237 | if (isa<Function>(GV)) |
| 238 | O << FunctionAddrPrefix << Mang->getValueName(GV) << FunctionAddrSuffix; |
Duraid Madina | 855a519 | 2005-04-02 12:21:51 +0000 | [diff] [blame] | 239 | else |
Chris Lattner | 450de39 | 2005-11-10 18:36:17 +0000 | [diff] [blame] | 240 | O << GlobalVarAddrPrefix << Mang->getValueName(GV) << GlobalVarAddrSuffix; |
Duraid Madina | 855a519 | 2005-04-02 12:21:51 +0000 | [diff] [blame] | 241 | } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) { |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 242 | const TargetData &TD = TM.getTargetData(); |
| 243 | switch(CE->getOpcode()) { |
| 244 | case Instruction::GetElementPtr: { |
| 245 | // generate a symbolic expression for the byte address |
| 246 | const Constant *ptrVal = CE->getOperand(0); |
| 247 | std::vector<Value*> idxVec(CE->op_begin()+1, CE->op_end()); |
Chris Lattner | 27e1921 | 2005-02-14 21:40:26 +0000 | [diff] [blame] | 248 | if (int64_t Offset = TD.getIndexedOffset(ptrVal->getType(), idxVec)) { |
| 249 | if (Offset) |
| 250 | O << "("; |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 251 | EmitConstantValueOnly(ptrVal); |
Chris Lattner | 27e1921 | 2005-02-14 21:40:26 +0000 | [diff] [blame] | 252 | if (Offset > 0) |
| 253 | O << ") + " << Offset; |
| 254 | else if (Offset < 0) |
| 255 | O << ") - " << -Offset; |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 256 | } else { |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 257 | EmitConstantValueOnly(ptrVal); |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 258 | } |
| 259 | break; |
| 260 | } |
| 261 | case Instruction::Cast: { |
| 262 | // Support only non-converting or widening casts for now, that is, ones |
| 263 | // that do not involve a change in value. This assertion is really gross, |
| 264 | // and may not even be a complete check. |
| 265 | Constant *Op = CE->getOperand(0); |
| 266 | const Type *OpTy = Op->getType(), *Ty = CE->getType(); |
| 267 | |
| 268 | // Remember, kids, pointers can be losslessly converted back and forth |
| 269 | // into 32-bit or wider integers, regardless of signedness. :-P |
| 270 | assert(((isa<PointerType>(OpTy) |
| 271 | && (Ty == Type::LongTy || Ty == Type::ULongTy |
| 272 | || Ty == Type::IntTy || Ty == Type::UIntTy)) |
| 273 | || (isa<PointerType>(Ty) |
| 274 | && (OpTy == Type::LongTy || OpTy == Type::ULongTy |
| 275 | || OpTy == Type::IntTy || OpTy == Type::UIntTy)) |
| 276 | || (((TD.getTypeSize(Ty) >= TD.getTypeSize(OpTy)) |
| 277 | && OpTy->isLosslesslyConvertibleTo(Ty)))) |
| 278 | && "FIXME: Don't yet support this kind of constant cast expr"); |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 279 | EmitConstantValueOnly(Op); |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 280 | break; |
| 281 | } |
| 282 | case Instruction::Add: |
| 283 | O << "("; |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 284 | EmitConstantValueOnly(CE->getOperand(0)); |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 285 | O << ") + ("; |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 286 | EmitConstantValueOnly(CE->getOperand(1)); |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 287 | O << ")"; |
| 288 | break; |
| 289 | default: |
| 290 | assert(0 && "Unsupported operator!"); |
| 291 | } |
| 292 | } else { |
| 293 | assert(0 && "Unknown constant value!"); |
| 294 | } |
| 295 | } |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 296 | |
| 297 | /// toOctal - Convert the low order bits of X into an octal digit. |
| 298 | /// |
| 299 | static inline char toOctal(int X) { |
| 300 | return (X&7)+'0'; |
| 301 | } |
| 302 | |
Chris Lattner | 2980cef | 2005-11-10 18:06:33 +0000 | [diff] [blame] | 303 | /// printAsCString - Print the specified array as a C compatible string, only if |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 304 | /// the predicate isString is true. |
| 305 | /// |
Chris Lattner | 2980cef | 2005-11-10 18:06:33 +0000 | [diff] [blame] | 306 | static void printAsCString(std::ostream &O, const ConstantArray *CVA, |
| 307 | unsigned LastElt) { |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 308 | assert(CVA->isString() && "Array is not string compatible!"); |
| 309 | |
| 310 | O << "\""; |
Chris Lattner | 2980cef | 2005-11-10 18:06:33 +0000 | [diff] [blame] | 311 | for (unsigned i = 0; i != LastElt; ++i) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 312 | unsigned char C = |
Chris Lattner | dea18b6 | 2005-01-08 19:59:10 +0000 | [diff] [blame] | 313 | (unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getRawValue(); |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 314 | |
| 315 | if (C == '"') { |
| 316 | O << "\\\""; |
| 317 | } else if (C == '\\') { |
| 318 | O << "\\\\"; |
| 319 | } else if (isprint(C)) { |
| 320 | O << C; |
| 321 | } else { |
| 322 | switch(C) { |
| 323 | case '\b': O << "\\b"; break; |
| 324 | case '\f': O << "\\f"; break; |
| 325 | case '\n': O << "\\n"; break; |
| 326 | case '\r': O << "\\r"; break; |
| 327 | case '\t': O << "\\t"; break; |
| 328 | default: |
| 329 | O << '\\'; |
| 330 | O << toOctal(C >> 6); |
| 331 | O << toOctal(C >> 3); |
| 332 | O << toOctal(C >> 0); |
| 333 | break; |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | O << "\""; |
| 338 | } |
| 339 | |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 340 | /// EmitGlobalConstant - Print a general LLVM constant to the .s file. |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 341 | /// |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 342 | void AsmPrinter::EmitGlobalConstant(const Constant *CV) { |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 343 | const TargetData &TD = TM.getTargetData(); |
| 344 | |
Chris Lattner | bd1d382 | 2004-10-16 18:19:26 +0000 | [diff] [blame] | 345 | if (CV->isNullValue() || isa<UndefValue>(CV)) { |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 346 | EmitZeros(TD.getTypeSize(CV->getType())); |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 347 | return; |
| 348 | } else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) { |
| 349 | if (CVA->isString()) { |
Chris Lattner | 2980cef | 2005-11-10 18:06:33 +0000 | [diff] [blame] | 350 | unsigned NumElts = CVA->getNumOperands(); |
| 351 | if (AscizDirective && NumElts && |
| 352 | cast<ConstantInt>(CVA->getOperand(NumElts-1))->getRawValue() == 0) { |
| 353 | O << AscizDirective; |
| 354 | printAsCString(O, CVA, NumElts-1); |
| 355 | } else { |
| 356 | O << AsciiDirective; |
| 357 | printAsCString(O, CVA, NumElts); |
| 358 | } |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 359 | O << "\n"; |
| 360 | } else { // Not a string. Print the values in successive locations |
| 361 | for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i) |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 362 | EmitGlobalConstant(CVA->getOperand(i)); |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 363 | } |
| 364 | return; |
| 365 | } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) { |
| 366 | // Print the fields in successive locations. Pad to align if needed! |
| 367 | const StructLayout *cvsLayout = TD.getStructLayout(CVS->getType()); |
Chris Lattner | dea18b6 | 2005-01-08 19:59:10 +0000 | [diff] [blame] | 368 | uint64_t sizeSoFar = 0; |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 369 | for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) { |
| 370 | const Constant* field = CVS->getOperand(i); |
| 371 | |
| 372 | // Check if padding is needed and insert one or more 0s. |
Chris Lattner | dea18b6 | 2005-01-08 19:59:10 +0000 | [diff] [blame] | 373 | uint64_t fieldSize = TD.getTypeSize(field->getType()); |
| 374 | uint64_t padSize = ((i == e-1? cvsLayout->StructSize |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 375 | : cvsLayout->MemberOffsets[i+1]) |
| 376 | - cvsLayout->MemberOffsets[i]) - fieldSize; |
| 377 | sizeSoFar += fieldSize + padSize; |
| 378 | |
| 379 | // Now print the actual field value |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 380 | EmitGlobalConstant(field); |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 381 | |
| 382 | // Insert the field padding unless it's zero bytes... |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 383 | EmitZeros(padSize); |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 384 | } |
| 385 | assert(sizeSoFar == cvsLayout->StructSize && |
| 386 | "Layout of constant struct may be incorrect!"); |
| 387 | return; |
| 388 | } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) { |
| 389 | // FP Constants are printed as integer constants to avoid losing |
| 390 | // precision... |
| 391 | double Val = CFP->getValue(); |
| 392 | if (CFP->getType() == Type::DoubleTy) { |
Chris Lattner | e85a5a9 | 2004-08-17 06:48:16 +0000 | [diff] [blame] | 393 | if (Data64bitsDirective) |
Jim Laskey | cb6682f | 2005-08-17 19:34:49 +0000 | [diff] [blame] | 394 | O << Data64bitsDirective << DoubleToBits(Val) << "\t" << CommentString |
Chris Lattner | 7d057a3 | 2004-08-17 21:38:40 +0000 | [diff] [blame] | 395 | << " double value: " << Val << "\n"; |
Chris Lattner | e85a5a9 | 2004-08-17 06:48:16 +0000 | [diff] [blame] | 396 | else if (TD.isBigEndian()) { |
Jim Laskey | cb6682f | 2005-08-17 19:34:49 +0000 | [diff] [blame] | 397 | O << Data32bitsDirective << unsigned(DoubleToBits(Val) >> 32) |
Chris Lattner | f746a7d | 2004-08-18 02:22:55 +0000 | [diff] [blame] | 398 | << "\t" << CommentString << " double most significant word " |
Chris Lattner | 0554fb6 | 2004-08-17 16:27:05 +0000 | [diff] [blame] | 399 | << Val << "\n"; |
Jim Laskey | cb6682f | 2005-08-17 19:34:49 +0000 | [diff] [blame] | 400 | O << Data32bitsDirective << unsigned(DoubleToBits(Val)) |
Chris Lattner | f746a7d | 2004-08-18 02:22:55 +0000 | [diff] [blame] | 401 | << "\t" << CommentString << " double least significant word " |
Chris Lattner | 0554fb6 | 2004-08-17 16:27:05 +0000 | [diff] [blame] | 402 | << Val << "\n"; |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 403 | } else { |
Jim Laskey | cb6682f | 2005-08-17 19:34:49 +0000 | [diff] [blame] | 404 | O << Data32bitsDirective << unsigned(DoubleToBits(Val)) |
Chris Lattner | f746a7d | 2004-08-18 02:22:55 +0000 | [diff] [blame] | 405 | << "\t" << CommentString << " double least significant word " << Val |
Chris Lattner | 0554fb6 | 2004-08-17 16:27:05 +0000 | [diff] [blame] | 406 | << "\n"; |
Jim Laskey | cb6682f | 2005-08-17 19:34:49 +0000 | [diff] [blame] | 407 | O << Data32bitsDirective << unsigned(DoubleToBits(Val) >> 32) |
Chris Lattner | f746a7d | 2004-08-18 02:22:55 +0000 | [diff] [blame] | 408 | << "\t" << CommentString << " double most significant word " << Val |
Chris Lattner | 0554fb6 | 2004-08-17 16:27:05 +0000 | [diff] [blame] | 409 | << "\n"; |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 410 | } |
| 411 | return; |
| 412 | } else { |
Jim Laskey | cb6682f | 2005-08-17 19:34:49 +0000 | [diff] [blame] | 413 | O << Data32bitsDirective << FloatToBits(Val) << "\t" << CommentString |
Chris Lattner | 0554fb6 | 2004-08-17 16:27:05 +0000 | [diff] [blame] | 414 | << " float " << Val << "\n"; |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 415 | return; |
| 416 | } |
| 417 | } else if (CV->getType() == Type::ULongTy || CV->getType() == Type::LongTy) { |
| 418 | if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) { |
| 419 | uint64_t Val = CI->getRawValue(); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 420 | |
Chris Lattner | e85a5a9 | 2004-08-17 06:48:16 +0000 | [diff] [blame] | 421 | if (Data64bitsDirective) |
| 422 | O << Data64bitsDirective << Val << "\n"; |
| 423 | else if (TD.isBigEndian()) { |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 424 | O << Data32bitsDirective << unsigned(Val >> 32) |
Chris Lattner | f746a7d | 2004-08-18 02:22:55 +0000 | [diff] [blame] | 425 | << "\t" << CommentString << " Double-word most significant word " |
Chris Lattner | 0554fb6 | 2004-08-17 16:27:05 +0000 | [diff] [blame] | 426 | << Val << "\n"; |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 427 | O << Data32bitsDirective << unsigned(Val) |
Chris Lattner | f746a7d | 2004-08-18 02:22:55 +0000 | [diff] [blame] | 428 | << "\t" << CommentString << " Double-word least significant word " |
Chris Lattner | 0554fb6 | 2004-08-17 16:27:05 +0000 | [diff] [blame] | 429 | << Val << "\n"; |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 430 | } else { |
| 431 | O << Data32bitsDirective << unsigned(Val) |
Chris Lattner | f746a7d | 2004-08-18 02:22:55 +0000 | [diff] [blame] | 432 | << "\t" << CommentString << " Double-word least significant word " |
Chris Lattner | 0554fb6 | 2004-08-17 16:27:05 +0000 | [diff] [blame] | 433 | << Val << "\n"; |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 434 | O << Data32bitsDirective << unsigned(Val >> 32) |
Chris Lattner | f746a7d | 2004-08-18 02:22:55 +0000 | [diff] [blame] | 435 | << "\t" << CommentString << " Double-word most significant word " |
Chris Lattner | 0554fb6 | 2004-08-17 16:27:05 +0000 | [diff] [blame] | 436 | << Val << "\n"; |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 437 | } |
| 438 | return; |
| 439 | } |
Nate Begeman | 8cfa57b | 2005-12-06 06:18:55 +0000 | [diff] [blame] | 440 | } else if (const ConstantPacked *CP = dyn_cast<ConstantPacked>(CV)) { |
| 441 | const PackedType *PTy = CP->getType(); |
| 442 | |
| 443 | for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I) |
| 444 | EmitGlobalConstant(CP->getOperand(I)); |
| 445 | |
| 446 | return; |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | const Type *type = CV->getType(); |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 450 | switch (type->getTypeID()) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 451 | case Type::BoolTyID: |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 452 | case Type::UByteTyID: case Type::SByteTyID: |
| 453 | O << Data8bitsDirective; |
| 454 | break; |
| 455 | case Type::UShortTyID: case Type::ShortTyID: |
| 456 | O << Data16bitsDirective; |
| 457 | break; |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 458 | case Type::PointerTyID: |
Andrew Lenharth | 571c9c3 | 2005-02-04 13:47:16 +0000 | [diff] [blame] | 459 | if (TD.getPointerSize() == 8) { |
| 460 | O << Data64bitsDirective; |
| 461 | break; |
| 462 | } |
| 463 | //Fall through for pointer size == int size |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 464 | case Type::UIntTyID: case Type::IntTyID: |
| 465 | O << Data32bitsDirective; |
| 466 | break; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 467 | case Type::ULongTyID: case Type::LongTyID: |
Chris Lattner | 660538c | 2005-08-08 04:26:32 +0000 | [diff] [blame] | 468 | assert(Data64bitsDirective &&"Target cannot handle 64-bit constant exprs!"); |
| 469 | O << Data64bitsDirective; |
| 470 | break; |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 471 | case Type::FloatTyID: case Type::DoubleTyID: |
| 472 | assert (0 && "Should have already output floating point constant."); |
| 473 | default: |
| 474 | assert (0 && "Can't handle printing this type of thing"); |
| 475 | break; |
| 476 | } |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 477 | EmitConstantValueOnly(CV); |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 478 | O << "\n"; |
| 479 | } |
Chris Lattner | 0264d1a | 2006-01-27 02:10:10 +0000 | [diff] [blame] | 480 | |
| 481 | /// printInlineAsm - This method formats and prints the specified machine |
| 482 | /// instruction that is an inline asm. |
| 483 | void AsmPrinter::printInlineAsm(const MachineInstr *MI) const { |
Chris Lattner | d6c65ea | 2006-02-08 23:41:56 +0000 | [diff] [blame] | 484 | O << InlineAsmStart; |
Chris Lattner | f2b67cf | 2006-01-30 23:00:08 +0000 | [diff] [blame] | 485 | unsigned NumOperands = MI->getNumOperands(); |
| 486 | |
| 487 | // Count the number of register definitions. |
| 488 | unsigned NumDefs = 0; |
| 489 | for (; MI->getOperand(NumDefs).isDef(); ++NumDefs) |
| 490 | assert(NumDefs != NumOperands-1 && "No asm string?"); |
| 491 | |
| 492 | assert(MI->getOperand(NumDefs).isExternalSymbol() && "No asm string?"); |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 493 | |
| 494 | // Disassemble the AsmStr, printing out the literal pieces, the operands, etc. |
Chris Lattner | f2b67cf | 2006-01-30 23:00:08 +0000 | [diff] [blame] | 495 | const char *AsmStr = MI->getOperand(NumDefs).getSymbolName(); |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 496 | |
| 497 | // The variant of the current asmprinter: FIXME: change. |
| 498 | int AsmPrinterVariant = 0; |
Chris Lattner | f2b67cf | 2006-01-30 23:00:08 +0000 | [diff] [blame] | 499 | |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 500 | int CurVariant = -1; // The number of the {.|.|.} region we are in. |
| 501 | const char *LastEmitted = AsmStr; // One past the last character emitted. |
Chris Lattner | 2cc2f66 | 2006-02-01 01:28:23 +0000 | [diff] [blame] | 502 | |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 503 | while (*LastEmitted) { |
| 504 | switch (*LastEmitted) { |
| 505 | default: { |
| 506 | // Not a special case, emit the string section literally. |
| 507 | const char *LiteralEnd = LastEmitted+1; |
| 508 | while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' && |
| 509 | *LiteralEnd != '}' && *LiteralEnd != '$') |
| 510 | ++LiteralEnd; |
| 511 | if (CurVariant == -1 || CurVariant == AsmPrinterVariant) |
| 512 | O.write(LastEmitted, LiteralEnd-LastEmitted); |
| 513 | LastEmitted = LiteralEnd; |
| 514 | break; |
| 515 | } |
| 516 | case '$': { |
| 517 | ++LastEmitted; // Consume '$' character. |
| 518 | if (*LastEmitted == '$') { // $$ -> $ |
| 519 | if (CurVariant == -1 || CurVariant == AsmPrinterVariant) |
| 520 | O << '$'; |
| 521 | ++LastEmitted; // Consume second '$' character. |
| 522 | break; |
| 523 | } |
| 524 | |
| 525 | bool HasCurlyBraces = false; |
| 526 | if (*LastEmitted == '{') { // ${variable} |
| 527 | ++LastEmitted; // Consume '{' character. |
| 528 | HasCurlyBraces = true; |
| 529 | } |
| 530 | |
| 531 | const char *IDStart = LastEmitted; |
| 532 | char *IDEnd; |
| 533 | long Val = strtol(IDStart, &IDEnd, 10); // We only accept numbers for IDs. |
| 534 | if (!isdigit(*IDStart) || (Val == 0 && errno == EINVAL)) { |
| 535 | std::cerr << "Bad $ operand number in inline asm string: '" |
| 536 | << AsmStr << "'\n"; |
| 537 | exit(1); |
| 538 | } |
| 539 | LastEmitted = IDEnd; |
| 540 | |
Chris Lattner | a36cb0a | 2006-02-06 22:17:23 +0000 | [diff] [blame] | 541 | char Modifier[2] = { 0, 0 }; |
| 542 | |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 543 | if (HasCurlyBraces) { |
Chris Lattner | a36cb0a | 2006-02-06 22:17:23 +0000 | [diff] [blame] | 544 | // If we have curly braces, check for a modifier character. This |
| 545 | // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm. |
| 546 | if (*LastEmitted == ':') { |
| 547 | ++LastEmitted; // Consume ':' character. |
| 548 | if (*LastEmitted == 0) { |
| 549 | std::cerr << "Bad ${:} expression in inline asm string: '" |
| 550 | << AsmStr << "'\n"; |
| 551 | exit(1); |
| 552 | } |
| 553 | |
| 554 | Modifier[0] = *LastEmitted; |
| 555 | ++LastEmitted; // Consume modifier character. |
| 556 | } |
| 557 | |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 558 | if (*LastEmitted != '}') { |
| 559 | std::cerr << "Bad ${} expression in inline asm string: '" |
| 560 | << AsmStr << "'\n"; |
| 561 | exit(1); |
| 562 | } |
| 563 | ++LastEmitted; // Consume '}' character. |
| 564 | } |
| 565 | |
| 566 | if ((unsigned)Val >= NumOperands-1) { |
| 567 | std::cerr << "Invalid $ operand number in inline asm string: '" |
| 568 | << AsmStr << "'\n"; |
| 569 | exit(1); |
| 570 | } |
| 571 | |
Chris Lattner | c3a9f8d | 2006-02-23 19:21:04 +0000 | [diff] [blame] | 572 | // Okay, we finally have a value number. Ask the target to print this |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 573 | // operand! |
Chris Lattner | c3a9f8d | 2006-02-23 19:21:04 +0000 | [diff] [blame] | 574 | if (CurVariant == -1 || CurVariant == AsmPrinterVariant) { |
| 575 | unsigned OpNo = 1; |
| 576 | |
| 577 | // Scan to find the machine operand number for the operand. |
Chris Lattner | daf6bc6 | 2006-02-24 19:50:58 +0000 | [diff] [blame] | 578 | for (; Val; --Val) { |
| 579 | unsigned OpFlags = MI->getOperand(OpNo).getImmedValue(); |
| 580 | OpNo += (OpFlags >> 3) + 1; |
| 581 | } |
Chris Lattner | c3a9f8d | 2006-02-23 19:21:04 +0000 | [diff] [blame] | 582 | |
Chris Lattner | dd26033 | 2006-02-24 20:21:58 +0000 | [diff] [blame^] | 583 | unsigned OpFlags = MI->getOperand(OpNo).getImmedValue(); |
Chris Lattner | c3a9f8d | 2006-02-23 19:21:04 +0000 | [diff] [blame] | 584 | ++OpNo; // Skip over the ID number. |
Chris Lattner | dd26033 | 2006-02-24 20:21:58 +0000 | [diff] [blame^] | 585 | |
| 586 | bool Error; |
| 587 | AsmPrinter *AP = const_cast<AsmPrinter*>(this); |
| 588 | if ((OpFlags & 7) == 4 /*ADDR MODE*/) { |
| 589 | Error = AP->PrintAsmMemoryOperand(MI, OpNo, AsmPrinterVariant, |
| 590 | Modifier[0] ? Modifier : 0); |
| 591 | } else { |
| 592 | Error = AP->PrintAsmOperand(MI, OpNo, AsmPrinterVariant, |
| 593 | Modifier[0] ? Modifier : 0); |
| 594 | } |
| 595 | if (Error) { |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 596 | std::cerr << "Invalid operand found in inline asm: '" |
| 597 | << AsmStr << "'\n"; |
| 598 | MI->dump(); |
| 599 | exit(1); |
| 600 | } |
Chris Lattner | c3a9f8d | 2006-02-23 19:21:04 +0000 | [diff] [blame] | 601 | } |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 602 | break; |
| 603 | } |
| 604 | case '{': |
| 605 | ++LastEmitted; // Consume '{' character. |
| 606 | if (CurVariant != -1) { |
| 607 | std::cerr << "Nested variants found in inline asm string: '" |
| 608 | << AsmStr << "'\n"; |
| 609 | exit(1); |
| 610 | } |
| 611 | CurVariant = 0; // We're in the first variant now. |
| 612 | break; |
| 613 | case '|': |
| 614 | ++LastEmitted; // consume '|' character. |
| 615 | if (CurVariant == -1) { |
| 616 | std::cerr << "Found '|' character outside of variant in inline asm " |
| 617 | << "string: '" << AsmStr << "'\n"; |
| 618 | exit(1); |
| 619 | } |
| 620 | ++CurVariant; // We're in the next variant. |
| 621 | break; |
| 622 | case '}': |
| 623 | ++LastEmitted; // consume '}' character. |
| 624 | if (CurVariant == -1) { |
| 625 | std::cerr << "Found '}' character outside of variant in inline asm " |
| 626 | << "string: '" << AsmStr << "'\n"; |
| 627 | exit(1); |
| 628 | } |
| 629 | CurVariant = -1; |
| 630 | break; |
| 631 | } |
| 632 | } |
Chris Lattner | d6c65ea | 2006-02-08 23:41:56 +0000 | [diff] [blame] | 633 | O << "\n" << InlineAsmEnd; |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | /// PrintAsmOperand - Print the specified operand of MI, an INLINEASM |
| 637 | /// instruction, using the specified assembler variant. Targets should |
| 638 | /// overried this to format as appropriate. |
| 639 | bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, |
Chris Lattner | a36cb0a | 2006-02-06 22:17:23 +0000 | [diff] [blame] | 640 | unsigned AsmVariant, const char *ExtraCode) { |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 641 | // Target doesn't support this yet! |
| 642 | return true; |
Chris Lattner | 0264d1a | 2006-01-27 02:10:10 +0000 | [diff] [blame] | 643 | } |
Chris Lattner | dd26033 | 2006-02-24 20:21:58 +0000 | [diff] [blame^] | 644 | |
| 645 | bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, |
| 646 | unsigned AsmVariant, |
| 647 | const char *ExtraCode) { |
| 648 | // Target doesn't support this yet! |
| 649 | return true; |
| 650 | } |