From d2af7853e377bce40cbf3e0632a4608484b6aba4 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 4 Apr 2010 20:20:50 +0000 Subject: [PATCH] move some more stuff to asmprinter. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100351 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/AsmPrinter.h | 9 ++++++ lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp | 32 ++++++++++++++++++++++ lib/CodeGen/AsmPrinter/DwarfException.cpp | 22 ++++++++------- lib/CodeGen/AsmPrinter/DwarfPrinter.cpp | 31 --------------------- lib/CodeGen/AsmPrinter/DwarfPrinter.h | 18 ------------ 5 files changed, 53 insertions(+), 59 deletions(-) diff --git a/include/llvm/CodeGen/AsmPrinter.h b/include/llvm/CodeGen/AsmPrinter.h index 4cdd1179da1..2ad1e1833a0 100644 --- a/include/llvm/CodeGen/AsmPrinter.h +++ b/include/llvm/CodeGen/AsmPrinter.h @@ -343,6 +343,15 @@ namespace llvm { /// specifying (e.g. "LSDA"). void EmitEncodingByte(unsigned Val, const char *Desc = 0); + /// GetSizeOfEncodedValue - Return the size of the encoding in bytes. + unsigned GetSizeOfEncodedValue(unsigned Encoding) const; + + /// EmitReference - Emit a reference to a label with a specified encoding. + /// + void EmitReference(const MCSymbol *Sym, unsigned Encoding) const; + void EmitReference(const GlobalValue *GV, unsigned Encoding) const; + + //===------------------------------------------------------------------===// // Inline Asm Support //===------------------------------------------------------------------===// diff --git a/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp b/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp index b6fb038d932..18f673b9564 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp @@ -15,6 +15,9 @@ #include "llvm/CodeGen/AsmPrinter.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCStreamer.h" +#include "llvm/Target/TargetData.h" +#include "llvm/Target/TargetLoweringObjectFile.h" +#include "llvm/Target/TargetMachine.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/Dwarf.h" using namespace llvm; @@ -126,3 +129,32 @@ void AsmPrinter::EmitEncodingByte(unsigned Val, const char *Desc) { OutStreamer.EmitIntValue(Val, 1, 0/*addrspace*/); } +/// GetSizeOfEncodedValue - Return the size of the encoding in bytes. +unsigned AsmPrinter::GetSizeOfEncodedValue(unsigned Encoding) const { + if (Encoding == dwarf::DW_EH_PE_omit) + return 0; + + switch (Encoding & 0x07) { + default: assert(0 && "Invalid encoded value."); + case dwarf::DW_EH_PE_absptr: return TM.getTargetData()->getPointerSize(); + case dwarf::DW_EH_PE_udata2: return 2; + case dwarf::DW_EH_PE_udata4: return 4; + case dwarf::DW_EH_PE_udata8: return 8; + } +} + +void AsmPrinter::EmitReference(const MCSymbol *Sym, unsigned Encoding) const { + const TargetLoweringObjectFile &TLOF = getObjFileLowering(); + + const MCExpr *Exp = + TLOF.getExprForDwarfReference(Sym, Mang, MMI, Encoding, OutStreamer); + OutStreamer.EmitValue(Exp, GetSizeOfEncodedValue(Encoding), /*addrspace*/0); +} + +void AsmPrinter::EmitReference(const GlobalValue *GV, unsigned Encoding)const{ + const TargetLoweringObjectFile &TLOF = getObjFileLowering(); + + const MCExpr *Exp = + TLOF.getExprForDwarfGlobalReference(GV, Mang, MMI, Encoding, OutStreamer); + OutStreamer.EmitValue(Exp, GetSizeOfEncodedValue(Encoding), /*addrspace*/0); +} diff --git a/lib/CodeGen/AsmPrinter/DwarfException.cpp b/lib/CodeGen/AsmPrinter/DwarfException.cpp index f8e656cd9e8..5c2bdb1678d 100644 --- a/lib/CodeGen/AsmPrinter/DwarfException.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfException.cpp @@ -106,7 +106,7 @@ void DwarfException::EmitCIE(const Function *PersonalityFn, unsigned Index) { if (PersonalityFn) { // There is a personality function. *APtr++ = 'P'; - AugmentationSize += 1 + SizeOfEncodedValue(PerEncoding); + AugmentationSize += 1 + Asm->GetSizeOfEncodedValue(PerEncoding); } if (UsesLSDA[Index]) { @@ -140,7 +140,7 @@ void DwarfException::EmitCIE(const Function *PersonalityFn, unsigned Index) { if (PersonalityFn) { Asm->EmitEncodingByte(PerEncoding, "Personality"); Asm->OutStreamer.AddComment("Personality"); - EmitReference(PersonalityFn, PerEncoding); + Asm->EmitReference(PersonalityFn, PerEncoding); } if (UsesLSDA[Index]) Asm->EmitEncodingByte(LSDAEncoding, "LSDA"); @@ -227,23 +227,24 @@ void DwarfException::EmitFDE(const FunctionEHFrameInfo &EHFrameInfo) { Asm->GetTempSymbol("eh_func_begin", EHFrameInfo.Number); Asm->OutStreamer.AddComment("FDE initial location"); - EmitReference(EHFuncBeginSym, FDEEncoding); + Asm->EmitReference(EHFuncBeginSym, FDEEncoding); Asm->OutStreamer.AddComment("FDE address range"); Asm->EmitLabelDifference(Asm->GetTempSymbol("eh_func_end", EHFrameInfo.Number), - EHFuncBeginSym, SizeOfEncodedValue(FDEEncoding)); + EHFuncBeginSym, + Asm->GetSizeOfEncodedValue(FDEEncoding)); // If there is a personality and landing pads then point to the language // specific data area in the exception table. if (MMI->getPersonalities()[0] != NULL) { - unsigned Size = SizeOfEncodedValue(LSDAEncoding); + unsigned Size = Asm->GetSizeOfEncodedValue(LSDAEncoding); Asm->EmitULEB128(Size, "Augmentation size"); Asm->OutStreamer.AddComment("Language Specific Data Area"); if (EHFrameInfo.hasLandingPads) - EmitReference(Asm->GetTempSymbol("exception", EHFrameInfo.Number), - LSDAEncoding); + Asm->EmitReference(Asm->GetTempSymbol("exception", EHFrameInfo.Number), + LSDAEncoding); else Asm->OutStreamer.EmitIntValue(0, Size/*size*/, 0/*addrspace*/); @@ -681,7 +682,7 @@ void DwarfException::EmitExceptionTable() { // in target-independent code. // TTypeEncoding = Asm->getObjFileLowering().getTTypeEncoding(); - TypeFormatSize = SizeOfEncodedValue(TTypeEncoding); + TypeFormatSize = Asm->GetSizeOfEncodedValue(TTypeEncoding); } // Begin the exception table. @@ -867,9 +868,10 @@ void DwarfException::EmitExceptionTable() { Asm->OutStreamer.AddComment("TypeInfo"); if (GV) - EmitReference(GV, TTypeEncoding); + Asm->EmitReference(GV, TTypeEncoding); else - Asm->OutStreamer.EmitIntValue(0, SizeOfEncodedValue(TTypeEncoding), 0); + Asm->OutStreamer.EmitIntValue(0,Asm->GetSizeOfEncodedValue(TTypeEncoding), + 0); } // Emit the Exception Specifications. diff --git a/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp b/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp index 10f302647bd..87224fa6682 100644 --- a/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp @@ -37,37 +37,6 @@ DwarfPrinter::DwarfPrinter(AsmPrinter *A) RI(Asm->TM.getRegisterInfo()), M(NULL), MF(NULL), MMI(NULL), SubprogramCount(0) {} -/// SizeOfEncodedValue - Return the size of the encoding in bytes. -unsigned DwarfPrinter::SizeOfEncodedValue(unsigned Encoding) const { - if (Encoding == dwarf::DW_EH_PE_omit) - return 0; - - switch (Encoding & 0x07) { - default: assert(0 && "Invalid encoded value."); - case dwarf::DW_EH_PE_absptr: return TD->getPointerSize(); - case dwarf::DW_EH_PE_udata2: return 2; - case dwarf::DW_EH_PE_udata4: return 4; - case dwarf::DW_EH_PE_udata8: return 8; - } -} - -void DwarfPrinter::EmitReference(const MCSymbol *Sym, unsigned Encoding) const { - const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); - - const MCExpr *Exp = TLOF.getExprForDwarfReference(Sym, Asm->Mang, - Asm->MMI, Encoding, - Asm->OutStreamer); - Asm->OutStreamer.EmitValue(Exp, SizeOfEncodedValue(Encoding), /*addrspace*/0); -} - -void DwarfPrinter::EmitReference(const GlobalValue *GV, unsigned Encoding)const{ - const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); - - const MCExpr *Exp = - TLOF.getExprForDwarfGlobalReference(GV, Asm->Mang, Asm->MMI, Encoding, - Asm->OutStreamer); - Asm->OutStreamer.EmitValue(Exp, SizeOfEncodedValue(Encoding), /*addrspace*/0); -} void DwarfPrinter::EmitSectionOffset(const MCSymbol *Label, const MCSymbol *Section, diff --git a/lib/CodeGen/AsmPrinter/DwarfPrinter.h b/lib/CodeGen/AsmPrinter/DwarfPrinter.h index e132cb6eaf7..1d4bc894ffa 100644 --- a/lib/CodeGen/AsmPrinter/DwarfPrinter.h +++ b/lib/CodeGen/AsmPrinter/DwarfPrinter.h @@ -74,24 +74,6 @@ public: const MCAsmInfo *getMCAsmInfo() const { return MAI; } const TargetData *getTargetData() const { return TD; } - /// SizeOfEncodedValue - Return the size of the encoding in bytes. - unsigned SizeOfEncodedValue(unsigned Encoding) 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 a string saying what the encoding is - /// specifying (e.g. "LSDA"). - void EmitEncodingByte(unsigned Val, const char *Desc); - - /// EmitCFAByte - Emit a .byte 42 directive for a DW_CFA_xxx value. - void EmitCFAByte(unsigned Val); - - - /// EmitReference - Emit a reference to a label. - /// - void EmitReference(const MCSymbol *Sym, unsigned Encoding) const; - void EmitReference(const GlobalValue *GV, unsigned Encoding) const; - /// EmitSectionOffset - Emit Label-Section or use a special purpose directive /// to emit a section offset if the target has one. void EmitSectionOffset(const MCSymbol *Label, const MCSymbol *Section,