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