diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index ed2aac013bf1..87afee0cc3aa 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -703,56 +703,6 @@ void AsmPrinter::EOL(const Twine &Comment) const { O << '\n'; } -static const char *DecodeDWARFEncoding(unsigned Encoding) { - switch (Encoding) { - case dwarf::DW_EH_PE_absptr: - return "absptr"; - case dwarf::DW_EH_PE_omit: - return "omit"; - case dwarf::DW_EH_PE_pcrel: - return "pcrel"; - case dwarf::DW_EH_PE_udata4: - return "udata4"; - case dwarf::DW_EH_PE_udata8: - return "udata8"; - case dwarf::DW_EH_PE_sdata4: - return "sdata4"; - case dwarf::DW_EH_PE_sdata8: - return "sdata8"; - case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata4: - return "pcrel udata4"; - case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4: - return "pcrel sdata4"; - case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8: - return "pcrel udata8"; - case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8: - return "pcrel sdata8"; - case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata4: - return "indirect pcrel udata4"; - case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata4: - return "indirect pcrel sdata4"; - case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata8: - return "indirect pcrel udata8"; - case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata8: - return "indirect pcrel sdata8"; - } - - return 0; -} - -void AsmPrinter::EOL(const Twine &Comment, unsigned Encoding) const { - if (VerboseAsm && !Comment.isTriviallyEmpty()) { - O.PadToColumn(MAI->getCommentColumn()); - O << MAI->getCommentString() - << ' ' - << Comment; - - if (const char *EncStr = DecodeDWARFEncoding(Encoding)) - O << " (" << EncStr << ')'; - } - O << '\n'; -} - /// EmitULEB128Bytes - Emit an assembler byte data directive to compose an /// unsigned leb128 value. void AsmPrinter::EmitULEB128Bytes(unsigned Value) const { diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfException.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfException.cpp index 9f5311401f17..43b1abf05dac 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfException.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfException.cpp @@ -185,8 +185,7 @@ void DwarfException::EmitCIE(const Function *PersonalityFn, unsigned Index) { Asm->EmitULEB128Bytes(AugmentationSize); Asm->EOL("Augmentation Size"); - Asm->EmitInt8(PerEncoding); - Asm->EOL("Personality", PerEncoding); + EmitEncodingByte(PerEncoding, "Personality"); // If there is a personality, we need to indicate the function's location. if (PersonalityRef) { @@ -197,11 +196,8 @@ void DwarfException::EmitCIE(const Function *PersonalityFn, unsigned Index) { O << MAI->getData32bitsDirective() << *PersonalityRef; Asm->EOL("Personality"); - Asm->EmitInt8(LSDAEncoding); - Asm->EOL("LSDA Encoding", LSDAEncoding); - - Asm->EmitInt8(FDEEncoding); - Asm->EOL("FDE Encoding", FDEEncoding); + EmitEncodingByte(LSDAEncoding, "LSDA"); + EmitEncodingByte(FDEEncoding, "FDE"); } // Indicate locations of general callee saved registers in frame. @@ -784,11 +780,8 @@ void DwarfException::EmitExceptionTable() { } // Emit the header. - Asm->EmitInt8(dwarf::DW_EH_PE_omit); - Asm->EOL("@LPStart format", dwarf::DW_EH_PE_omit); - - Asm->EmitInt8(TTypeFormat); - Asm->EOL("@TType format", TTypeFormat); + EmitEncodingByte(dwarf::DW_EH_PE_omit, "@LPStart"); + EmitEncodingByte(TTypeFormat, "@TType"); if (HaveTTData) { Asm->EmitULEB128Bytes(TyOffset); @@ -797,8 +790,7 @@ void DwarfException::EmitExceptionTable() { // SjLj Exception handling if (IsSJLJ) { - Asm->EmitInt8(dwarf::DW_EH_PE_udata4); - Asm->EOL("Call site format", dwarf::DW_EH_PE_udata4); + EmitEncodingByte(dwarf::DW_EH_PE_udata4, "Call site"); Asm->EmitULEB128Bytes(SizeSites); Asm->EOL("Call site table length"); @@ -842,8 +834,7 @@ void DwarfException::EmitExceptionTable() { // supposed to throw. // Emit the landing pad call site table. - Asm->EmitInt8(dwarf::DW_EH_PE_udata4); - Asm->EOL("Call site format", dwarf::DW_EH_PE_udata4); + EmitEncodingByte(dwarf::DW_EH_PE_udata4, "Call site"); Asm->EmitULEB128Bytes(SizeSites); Asm->EOL("Call site table size"); diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp index f50c684e3522..99b46d61a0b1 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp @@ -18,6 +18,7 @@ #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/MC/MCAsmInfo.h" +#include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSymbol.h" #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetFrameInfo.h" @@ -41,6 +42,50 @@ void DwarfPrinter::PrintRelDirective(bool Force32Bit, bool isInSection) const { O << MAI->getData64bitsDirective(); } +static const char *DecodeDWARFEncoding(unsigned Encoding) { + switch (Encoding) { + case dwarf::DW_EH_PE_absptr: return "absptr"; + case dwarf::DW_EH_PE_omit: return "omit"; + case dwarf::DW_EH_PE_pcrel: return "pcrel"; + case dwarf::DW_EH_PE_udata4: return "udata4"; + case dwarf::DW_EH_PE_udata8: return "udata8"; + case dwarf::DW_EH_PE_sdata4: return "sdata4"; + case dwarf::DW_EH_PE_sdata8: return "sdata8"; + case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata4: return "pcrel udata4"; + case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4: return "pcrel sdata4"; + case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8: return "pcrel udata8"; + case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8: return "pcrel sdata8"; + case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata4: + return "indirect pcrel udata4"; + case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata4: + return "indirect pcrel sdata4"; + case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata8: + return "indirect pcrel udata8"; + case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata8: + return "indirect pcrel sdata8"; + } + + return ""; +} + +/// EmitEncodingByte - Emit a .byte 42 directive that corresponds to an +/// encoding. If verbose assembly output is enabled, we output comments +/// describing the encoding. Desc is an optional string saying what the +/// encoding is specifying (e.g. "LSDA"). +void DwarfPrinter::EmitEncodingByte(unsigned Val, const char *Desc) { + if (Asm->VerboseAsm) { + if (Desc != 0) + Asm->OutStreamer.AddComment(Twine(Desc)+" Encoding = " + + Twine(DecodeDWARFEncoding(Val))); + else + Asm->OutStreamer.AddComment(Twine("Encoding = ") + + DecodeDWARFEncoding(Val)); + } + + Asm->OutStreamer.EmitIntValue(Val, 1, 0/*addrspace*/); +} + + /// PrintLabelName - Print label name in form used by Dwarf writer. /// void DwarfPrinter::PrintLabelName(const char *Tag, unsigned Number) const { diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfPrinter.h b/llvm/lib/CodeGen/AsmPrinter/DwarfPrinter.h index 78b80d9a250a..d76caf9a4ee1 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfPrinter.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfPrinter.h @@ -73,6 +73,7 @@ protected: DwarfPrinter(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T, const char *flavor); public: + //===------------------------------------------------------------------===// // Accessors. // @@ -84,6 +85,12 @@ public: void PrintRelDirective(bool Force32Bit = false, bool isInSection = false) const; + /// EmitEncodingByte - Emit a .byte 42 directive that corresponds to an + /// encoding. If verbose assembly output is enabled, we output comments + /// describing the encoding. Desc is an optional string saying what the + /// encoding is specifying (e.g. "LSDA"). + void EmitEncodingByte(unsigned Val, const char *Desc = 0); + /// PrintLabelName - Print label name in form used by Dwarf writer. ///