Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 1 | //===--- lib/CodeGen/DwarfPrinter.cpp - Dwarf Printer ---------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Emit general DWARF directives. |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 11 | // |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "DwarfPrinter.h" |
| 15 | #include "llvm/Module.h" |
| 16 | #include "llvm/CodeGen/AsmPrinter.h" |
| 17 | #include "llvm/CodeGen/MachineFrameInfo.h" |
David Greene | eea1f4c | 2009-08-19 21:59:18 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineFunction.h" |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCAsmInfo.h" |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCContext.h" |
| 22 | #include "llvm/MC/MCExpr.h" |
Chris Lattner | f61ed8e | 2010-01-22 22:38:16 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCStreamer.h" |
Chris Lattner | 858431d | 2010-01-16 18:50:28 +0000 | [diff] [blame] | 24 | #include "llvm/MC/MCSymbol.h" |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 25 | #include "llvm/Target/TargetData.h" |
| 26 | #include "llvm/Target/TargetFrameInfo.h" |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 27 | #include "llvm/Target/TargetLoweringObjectFile.h" |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 28 | #include "llvm/Target/TargetRegisterInfo.h" |
Chris Lattner | 23132b1 | 2009-08-24 03:52:50 +0000 | [diff] [blame] | 29 | #include "llvm/Support/Dwarf.h" |
| 30 | #include "llvm/Support/ErrorHandling.h" |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/SmallString.h" |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 32 | using namespace llvm; |
| 33 | |
Chris Lattner | 066c9ac | 2010-01-22 22:23:57 +0000 | [diff] [blame] | 34 | DwarfPrinter::DwarfPrinter(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T, |
| 35 | const char *flavor) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 36 | : O(OS), Asm(A), MAI(T), TD(Asm->TM.getTargetData()), |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 37 | RI(Asm->TM.getRegisterInfo()), M(NULL), MF(NULL), MMI(NULL), |
| 38 | SubprogramCount(0), Flavor(flavor), SetCounter(1) {} |
| 39 | |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 40 | /// SizeOfEncodedValue - Return the size of the encoding in bytes. |
| 41 | unsigned DwarfPrinter::SizeOfEncodedValue(unsigned Encoding) const { |
| 42 | if (Encoding == dwarf::DW_EH_PE_omit) |
| 43 | return 0; |
| 44 | |
| 45 | switch (Encoding & 0x07) { |
| 46 | case dwarf::DW_EH_PE_absptr: |
| 47 | return TD->getPointerSize(); |
| 48 | case dwarf::DW_EH_PE_udata2: |
| 49 | return 2; |
| 50 | case dwarf::DW_EH_PE_udata4: |
| 51 | return 4; |
| 52 | case dwarf::DW_EH_PE_udata8: |
| 53 | return 8; |
| 54 | } |
| 55 | |
| 56 | assert(0 && "Invalid encoded value."); |
| 57 | return 0; |
| 58 | } |
| 59 | |
Chris Lattner | 066c9ac | 2010-01-22 22:23:57 +0000 | [diff] [blame] | 60 | void DwarfPrinter::PrintRelDirective(bool Force32Bit, bool isInSection) const { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 61 | if (isInSection && MAI->getDwarfSectionOffsetDirective()) |
| 62 | O << MAI->getDwarfSectionOffsetDirective(); |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 63 | else if (Force32Bit || TD->getPointerSize() == sizeof(int32_t)) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 64 | O << MAI->getData32bitsDirective(); |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 65 | else |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 66 | O << MAI->getData64bitsDirective(); |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 69 | void DwarfPrinter::PrintRelDirective(unsigned Encoding) const { |
| 70 | unsigned Size = SizeOfEncodedValue(Encoding); |
| 71 | assert((Size == 4 || Size == 8) && "Do not support other types or rels!"); |
| 72 | |
| 73 | O << (Size == 4 ? |
| 74 | MAI->getData32bitsDirective() : MAI->getData64bitsDirective()); |
| 75 | } |
| 76 | |
Chris Lattner | faca549 | 2010-01-22 23:47:11 +0000 | [diff] [blame] | 77 | /// EOL - Print a newline character to asm stream. If a comment is present |
| 78 | /// then it will be printed first. Comments should not contain '\n'. |
| 79 | void DwarfPrinter::EOL(const Twine &Comment) const { |
| 80 | if (Asm->VerboseAsm && !Comment.isTriviallyEmpty()) { |
| 81 | Asm->O.PadToColumn(MAI->getCommentColumn()); |
| 82 | Asm->O << Asm->MAI->getCommentString() << ' ' << Comment; |
| 83 | } |
| 84 | Asm->O << '\n'; |
| 85 | } |
| 86 | |
Chris Lattner | f61ed8e | 2010-01-22 22:38:16 +0000 | [diff] [blame] | 87 | static const char *DecodeDWARFEncoding(unsigned Encoding) { |
| 88 | switch (Encoding) { |
| 89 | case dwarf::DW_EH_PE_absptr: return "absptr"; |
| 90 | case dwarf::DW_EH_PE_omit: return "omit"; |
| 91 | case dwarf::DW_EH_PE_pcrel: return "pcrel"; |
| 92 | case dwarf::DW_EH_PE_udata4: return "udata4"; |
| 93 | case dwarf::DW_EH_PE_udata8: return "udata8"; |
| 94 | case dwarf::DW_EH_PE_sdata4: return "sdata4"; |
| 95 | case dwarf::DW_EH_PE_sdata8: return "sdata8"; |
| 96 | case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata4: return "pcrel udata4"; |
| 97 | case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4: return "pcrel sdata4"; |
| 98 | case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8: return "pcrel udata8"; |
| 99 | case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8: return "pcrel sdata8"; |
| 100 | case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata4: |
| 101 | return "indirect pcrel udata4"; |
| 102 | case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata4: |
| 103 | return "indirect pcrel sdata4"; |
| 104 | case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata8: |
| 105 | return "indirect pcrel udata8"; |
| 106 | case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata8: |
| 107 | return "indirect pcrel sdata8"; |
| 108 | } |
| 109 | |
| 110 | return "<unknown encoding>"; |
| 111 | } |
| 112 | |
| 113 | /// EmitEncodingByte - Emit a .byte 42 directive that corresponds to an |
| 114 | /// encoding. If verbose assembly output is enabled, we output comments |
| 115 | /// describing the encoding. Desc is an optional string saying what the |
| 116 | /// encoding is specifying (e.g. "LSDA"). |
| 117 | void DwarfPrinter::EmitEncodingByte(unsigned Val, const char *Desc) { |
| 118 | if (Asm->VerboseAsm) { |
| 119 | if (Desc != 0) |
| 120 | Asm->OutStreamer.AddComment(Twine(Desc)+" Encoding = " + |
| 121 | Twine(DecodeDWARFEncoding(Val))); |
| 122 | else |
| 123 | Asm->OutStreamer.AddComment(Twine("Encoding = ") + |
| 124 | DecodeDWARFEncoding(Val)); |
| 125 | } |
| 126 | |
| 127 | Asm->OutStreamer.EmitIntValue(Val, 1, 0/*addrspace*/); |
| 128 | } |
| 129 | |
Chris Lattner | 245834d | 2010-01-22 23:40:08 +0000 | [diff] [blame] | 130 | /// EmitCFAByte - Emit a .byte 42 directive for a DW_CFA_xxx value. |
| 131 | void DwarfPrinter::EmitCFAByte(unsigned Val) { |
| 132 | if (Asm->VerboseAsm) { |
| 133 | if (Val >= dwarf::DW_CFA_offset && Val < dwarf::DW_CFA_offset+64) |
| 134 | Asm->OutStreamer.AddComment("DW_CFA_offset + Reg (" + |
| 135 | Twine(Val-dwarf::DW_CFA_offset) + ")"); |
| 136 | else |
| 137 | Asm->OutStreamer.AddComment(dwarf::CallFrameString(Val)); |
| 138 | } |
| 139 | Asm->OutStreamer.EmitIntValue(Val, 1, 0/*addrspace*/); |
| 140 | } |
| 141 | |
Chris Lattner | 894d75a | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 142 | /// EmitSLEB128 - emit the specified signed leb128 value. |
| 143 | void DwarfPrinter::EmitSLEB128(int Value, const char *Desc) const { |
| 144 | if (Asm->VerboseAsm && Desc) |
| 145 | Asm->OutStreamer.AddComment(Desc); |
| 146 | |
| 147 | if (MAI->hasLEB128()) { |
| 148 | O << "\t.sleb128\t" << Value; |
| 149 | Asm->OutStreamer.AddBlankLine(); |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | // If we don't have .sleb128, emit as .bytes. |
Chris Lattner | bb9078a | 2010-01-22 22:56:55 +0000 | [diff] [blame] | 154 | int Sign = Value >> (8 * sizeof(Value) - 1); |
| 155 | bool IsMore; |
| 156 | |
| 157 | do { |
| 158 | unsigned char Byte = static_cast<unsigned char>(Value & 0x7f); |
| 159 | Value >>= 7; |
| 160 | IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0; |
| 161 | if (IsMore) Byte |= 0x80; |
Chris Lattner | 894d75a | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 162 | Asm->OutStreamer.EmitIntValue(Byte, 1, /*addrspace*/0); |
Chris Lattner | bb9078a | 2010-01-22 22:56:55 +0000 | [diff] [blame] | 163 | } while (IsMore); |
| 164 | } |
| 165 | |
Chris Lattner | 894d75a | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 166 | /// EmitULEB128 - emit the specified signed leb128 value. |
Bill Wendling | 3dc9b48 | 2010-02-24 23:34:35 +0000 | [diff] [blame^] | 167 | void DwarfPrinter::EmitULEB128(unsigned Value, const char *Desc, |
| 168 | unsigned PadTo) const { |
Chris Lattner | bb9078a | 2010-01-22 22:56:55 +0000 | [diff] [blame] | 169 | if (Asm->VerboseAsm && Desc) |
| 170 | Asm->OutStreamer.AddComment(Desc); |
Chris Lattner | 894d75a | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 171 | |
Bill Wendling | 3dc9b48 | 2010-02-24 23:34:35 +0000 | [diff] [blame^] | 172 | if (MAI->hasLEB128() && PadTo == 0) { |
Chris Lattner | 894d75a | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 173 | O << "\t.uleb128\t" << Value; |
Chris Lattner | bb9078a | 2010-01-22 22:56:55 +0000 | [diff] [blame] | 174 | Asm->OutStreamer.AddBlankLine(); |
Chris Lattner | 894d75a | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 175 | return; |
Chris Lattner | bb9078a | 2010-01-22 22:56:55 +0000 | [diff] [blame] | 176 | } |
Chris Lattner | 894d75a | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 177 | |
Bill Wendling | 3dc9b48 | 2010-02-24 23:34:35 +0000 | [diff] [blame^] | 178 | // If we don't have .uleb128 or we want to emit padding, emit as .bytes. |
Chris Lattner | 894d75a | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 179 | do { |
| 180 | unsigned char Byte = static_cast<unsigned char>(Value & 0x7f); |
| 181 | Value >>= 7; |
Bill Wendling | 3dc9b48 | 2010-02-24 23:34:35 +0000 | [diff] [blame^] | 182 | if (Value || PadTo != 0) Byte |= 0x80; |
Chris Lattner | 894d75a | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 183 | Asm->OutStreamer.EmitIntValue(Byte, 1, /*addrspace*/0); |
| 184 | } while (Value); |
Bill Wendling | 3dc9b48 | 2010-02-24 23:34:35 +0000 | [diff] [blame^] | 185 | |
| 186 | if (PadTo) |
| 187 | while (PadTo--) { |
| 188 | unsigned char Byte = (PadTo ? 0x80 : 0x00); |
| 189 | if (Asm->VerboseAsm) |
| 190 | Asm->OutStreamer.AddComment("Padding"); |
| 191 | Asm->OutStreamer.EmitIntValue(Byte, 1, /*addrspace*/0); |
| 192 | } |
Chris Lattner | bb9078a | 2010-01-22 22:56:55 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 196 | /// PrintLabelName - Print label name in form used by Dwarf writer. |
| 197 | /// |
Chris Lattner | 066c9ac | 2010-01-22 22:23:57 +0000 | [diff] [blame] | 198 | void DwarfPrinter::PrintLabelName(const char *Tag, unsigned Number) const { |
Jim Grosbach | a01d346 | 2009-09-01 16:43:35 +0000 | [diff] [blame] | 199 | O << MAI->getPrivateGlobalPrefix() << Tag; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 200 | if (Number) O << Number; |
| 201 | } |
Chris Lattner | 066c9ac | 2010-01-22 22:23:57 +0000 | [diff] [blame] | 202 | void DwarfPrinter::PrintLabelName(const char *Tag, unsigned Number, |
| 203 | const char *Suffix) const { |
Jim Grosbach | a01d346 | 2009-09-01 16:43:35 +0000 | [diff] [blame] | 204 | O << MAI->getPrivateGlobalPrefix() << Tag; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 205 | if (Number) O << Number; |
| 206 | O << Suffix; |
| 207 | } |
| 208 | |
| 209 | /// EmitLabel - Emit location label for internal use by Dwarf. |
| 210 | /// |
Chris Lattner | 066c9ac | 2010-01-22 22:23:57 +0000 | [diff] [blame] | 211 | void DwarfPrinter::EmitLabel(const char *Tag, unsigned Number) const { |
Jim Grosbach | a01d346 | 2009-09-01 16:43:35 +0000 | [diff] [blame] | 212 | PrintLabelName(Tag, Number); |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 213 | O << ":\n"; |
| 214 | } |
| 215 | |
| 216 | /// EmitReference - Emit a reference to a label. |
| 217 | /// |
Chris Lattner | 066c9ac | 2010-01-22 22:23:57 +0000 | [diff] [blame] | 218 | void DwarfPrinter::EmitReference(const char *Tag, unsigned Number, |
| 219 | bool IsPCRelative, bool Force32Bit) const { |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 220 | PrintRelDirective(Force32Bit); |
| 221 | PrintLabelName(Tag, Number); |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 222 | if (IsPCRelative) O << "-" << MAI->getPCSymbol(); |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 223 | } |
Chris Lattner | 066c9ac | 2010-01-22 22:23:57 +0000 | [diff] [blame] | 224 | void DwarfPrinter::EmitReference(const std::string &Name, bool IsPCRelative, |
| 225 | bool Force32Bit) const { |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 226 | PrintRelDirective(Force32Bit); |
| 227 | O << Name; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 228 | if (IsPCRelative) O << "-" << MAI->getPCSymbol(); |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Chris Lattner | 066c9ac | 2010-01-22 22:23:57 +0000 | [diff] [blame] | 231 | void DwarfPrinter::EmitReference(const MCSymbol *Sym, bool IsPCRelative, |
| 232 | bool Force32Bit) const { |
Chris Lattner | 858431d | 2010-01-16 18:50:28 +0000 | [diff] [blame] | 233 | PrintRelDirective(Force32Bit); |
Chris Lattner | 10b318b | 2010-01-17 21:43:43 +0000 | [diff] [blame] | 234 | O << *Sym; |
Chris Lattner | 858431d | 2010-01-16 18:50:28 +0000 | [diff] [blame] | 235 | if (IsPCRelative) O << "-" << MAI->getPCSymbol(); |
| 236 | } |
| 237 | |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 238 | void DwarfPrinter::EmitReference(const char *Tag, unsigned Number, |
| 239 | unsigned Encoding) const { |
| 240 | SmallString<64> Name; |
| 241 | raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() |
| 242 | << Tag << Number; |
| 243 | |
| 244 | MCSymbol *Sym = Asm->OutContext.GetOrCreateSymbol(Name.str()); |
| 245 | EmitReference(Sym, Encoding); |
| 246 | } |
| 247 | |
| 248 | void DwarfPrinter::EmitReference(const MCSymbol *Sym, unsigned Encoding) const { |
| 249 | const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); |
| 250 | |
| 251 | PrintRelDirective(Encoding); |
| 252 | O << *TLOF.getSymbolForDwarfReference(Sym, Asm->MMI, Encoding);; |
| 253 | } |
| 254 | |
| 255 | void DwarfPrinter::EmitReference(const GlobalValue *GV, unsigned Encoding)const { |
| 256 | const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); |
| 257 | |
| 258 | PrintRelDirective(Encoding); |
| 259 | O << *TLOF.getSymbolForDwarfGlobalReference(GV, Asm->Mang, |
| 260 | Asm->MMI, Encoding);; |
| 261 | } |
| 262 | |
Chris Lattner | 6a315c3 | 2010-01-26 20:20:43 +0000 | [diff] [blame] | 263 | /// EmitDifference - Emit the difference between two labels. If this assembler |
| 264 | /// supports .set, we emit a .set of a temporary and then use it in the .word. |
Chris Lattner | 066c9ac | 2010-01-22 22:23:57 +0000 | [diff] [blame] | 265 | void DwarfPrinter::EmitDifference(const char *TagHi, unsigned NumberHi, |
| 266 | const char *TagLo, unsigned NumberLo, |
| 267 | bool IsSmall) { |
Chris Lattner | cee6332 | 2010-01-26 20:40:54 +0000 | [diff] [blame] | 268 | if (MAI->hasSetDirective()) { |
Chris Lattner | c618c8a | 2010-01-26 21:53:08 +0000 | [diff] [blame] | 269 | // FIXME: switch to OutStreamer.EmitAssignment. |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 270 | O << "\t.set\t"; |
| 271 | PrintLabelName("set", SetCounter, Flavor); |
| 272 | O << ","; |
| 273 | PrintLabelName(TagHi, NumberHi); |
| 274 | O << "-"; |
| 275 | PrintLabelName(TagLo, NumberLo); |
| 276 | O << "\n"; |
| 277 | |
| 278 | PrintRelDirective(IsSmall); |
| 279 | PrintLabelName("set", SetCounter, Flavor); |
| 280 | ++SetCounter; |
| 281 | } else { |
| 282 | PrintRelDirective(IsSmall); |
| 283 | PrintLabelName(TagHi, NumberHi); |
| 284 | O << "-"; |
| 285 | PrintLabelName(TagLo, NumberLo); |
| 286 | } |
| 287 | } |
| 288 | |
Chris Lattner | 066c9ac | 2010-01-22 22:23:57 +0000 | [diff] [blame] | 289 | void DwarfPrinter::EmitSectionOffset(const char* Label, const char* Section, |
| 290 | unsigned LabelNumber, |
| 291 | unsigned SectionNumber, |
| 292 | bool IsSmall, bool isEH, |
| 293 | bool useSet) { |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 294 | bool printAbsolute = false; |
| 295 | if (isEH) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 296 | printAbsolute = MAI->isAbsoluteEHSectionOffsets(); |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 297 | else |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 298 | printAbsolute = MAI->isAbsoluteDebugSectionOffsets(); |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 299 | |
Chris Lattner | cee6332 | 2010-01-26 20:40:54 +0000 | [diff] [blame] | 300 | if (MAI->hasSetDirective() && useSet) { |
Chris Lattner | c618c8a | 2010-01-26 21:53:08 +0000 | [diff] [blame] | 301 | // FIXME: switch to OutStreamer.EmitAssignment. |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 302 | O << "\t.set\t"; |
| 303 | PrintLabelName("set", SetCounter, Flavor); |
| 304 | O << ","; |
| 305 | PrintLabelName(Label, LabelNumber); |
| 306 | |
| 307 | if (!printAbsolute) { |
| 308 | O << "-"; |
| 309 | PrintLabelName(Section, SectionNumber); |
| 310 | } |
| 311 | |
| 312 | O << "\n"; |
| 313 | PrintRelDirective(IsSmall); |
| 314 | PrintLabelName("set", SetCounter, Flavor); |
| 315 | ++SetCounter; |
| 316 | } else { |
| 317 | PrintRelDirective(IsSmall, true); |
| 318 | PrintLabelName(Label, LabelNumber); |
| 319 | |
| 320 | if (!printAbsolute) { |
| 321 | O << "-"; |
| 322 | PrintLabelName(Section, SectionNumber); |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | /// EmitFrameMoves - Emit frame instructions to describe the layout of the |
| 328 | /// frame. |
Chris Lattner | 066c9ac | 2010-01-22 22:23:57 +0000 | [diff] [blame] | 329 | void DwarfPrinter::EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID, |
| 330 | const std::vector<MachineMove> &Moves, |
| 331 | bool isEH) { |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 332 | int stackGrowth = |
| 333 | Asm->TM.getFrameInfo()->getStackGrowthDirection() == |
| 334 | TargetFrameInfo::StackGrowsUp ? |
| 335 | TD->getPointerSize() : -TD->getPointerSize(); |
| 336 | bool IsLocal = BaseLabel && strcmp(BaseLabel, "label") == 0; |
| 337 | |
| 338 | for (unsigned i = 0, N = Moves.size(); i < N; ++i) { |
| 339 | const MachineMove &Move = Moves[i]; |
| 340 | unsigned LabelID = Move.getLabelID(); |
| 341 | |
| 342 | if (LabelID) { |
| 343 | LabelID = MMI->MappedLabel(LabelID); |
| 344 | |
| 345 | // Throw out move if the label is invalid. |
| 346 | if (!LabelID) continue; |
| 347 | } |
| 348 | |
| 349 | const MachineLocation &Dst = Move.getDestination(); |
| 350 | const MachineLocation &Src = Move.getSource(); |
| 351 | |
| 352 | // Advance row if new location. |
| 353 | if (BaseLabel && LabelID && (BaseLabelID != LabelID || !IsLocal)) { |
Chris Lattner | 245834d | 2010-01-22 23:40:08 +0000 | [diff] [blame] | 354 | EmitCFAByte(dwarf::DW_CFA_advance_loc4); |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 355 | EmitDifference("label", LabelID, BaseLabel, BaseLabelID, true); |
Chris Lattner | 0ad9c91 | 2010-01-22 22:09:00 +0000 | [diff] [blame] | 356 | Asm->O << '\n'; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 357 | |
| 358 | BaseLabelID = LabelID; |
| 359 | BaseLabel = "label"; |
| 360 | IsLocal = true; |
| 361 | } |
| 362 | |
| 363 | // If advancing cfa. |
| 364 | if (Dst.isReg() && Dst.getReg() == MachineLocation::VirtualFP) { |
| 365 | if (!Src.isReg()) { |
| 366 | if (Src.getReg() == MachineLocation::VirtualFP) { |
Chris Lattner | 245834d | 2010-01-22 23:40:08 +0000 | [diff] [blame] | 367 | EmitCFAByte(dwarf::DW_CFA_def_cfa_offset); |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 368 | } else { |
Chris Lattner | 245834d | 2010-01-22 23:40:08 +0000 | [diff] [blame] | 369 | EmitCFAByte(dwarf::DW_CFA_def_cfa); |
Chris Lattner | 894d75a | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 370 | EmitULEB128(RI->getDwarfRegNum(Src.getReg(), isEH), "Register"); |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | int Offset = -Src.getOffset(); |
Chris Lattner | 894d75a | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 374 | EmitULEB128(Offset, "Offset"); |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 375 | } else { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 376 | llvm_unreachable("Machine move not supported yet."); |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 377 | } |
| 378 | } else if (Src.isReg() && |
| 379 | Src.getReg() == MachineLocation::VirtualFP) { |
| 380 | if (Dst.isReg()) { |
Chris Lattner | 245834d | 2010-01-22 23:40:08 +0000 | [diff] [blame] | 381 | EmitCFAByte(dwarf::DW_CFA_def_cfa_register); |
Chris Lattner | 894d75a | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 382 | EmitULEB128(RI->getDwarfRegNum(Dst.getReg(), isEH), "Register"); |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 383 | } else { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 384 | llvm_unreachable("Machine move not supported yet."); |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 385 | } |
| 386 | } else { |
| 387 | unsigned Reg = RI->getDwarfRegNum(Src.getReg(), isEH); |
| 388 | int Offset = Dst.getOffset() / stackGrowth; |
| 389 | |
| 390 | if (Offset < 0) { |
Chris Lattner | 245834d | 2010-01-22 23:40:08 +0000 | [diff] [blame] | 391 | EmitCFAByte(dwarf::DW_CFA_offset_extended_sf); |
Chris Lattner | 894d75a | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 392 | EmitULEB128(Reg, "Reg"); |
Chris Lattner | bb9078a | 2010-01-22 22:56:55 +0000 | [diff] [blame] | 393 | EmitSLEB128(Offset, "Offset"); |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 394 | } else if (Reg < 64) { |
Chris Lattner | 245834d | 2010-01-22 23:40:08 +0000 | [diff] [blame] | 395 | EmitCFAByte(dwarf::DW_CFA_offset + Reg); |
Chris Lattner | 894d75a | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 396 | EmitULEB128(Offset, "Offset"); |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 397 | } else { |
Chris Lattner | 245834d | 2010-01-22 23:40:08 +0000 | [diff] [blame] | 398 | EmitCFAByte(dwarf::DW_CFA_offset_extended); |
Chris Lattner | 894d75a | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 399 | EmitULEB128(Reg, "Reg"); |
| 400 | EmitULEB128(Offset, "Offset"); |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | } |
| 404 | } |