ARMException.cpp revision d04a8d4b33ff316ca4cf961e06c9e312eff8e64f
1//===-- CodeGen/AsmPrinter/ARMException.cpp - ARM EHABI Exception Impl ----===// 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// This file contains support for writing DWARF exception info into asm files. 11// 12//===----------------------------------------------------------------------===// 13 14#include "DwarfException.h" 15#include "llvm/ADT/SmallString.h" 16#include "llvm/ADT/StringExtras.h" 17#include "llvm/ADT/Twine.h" 18#include "llvm/CodeGen/AsmPrinter.h" 19#include "llvm/CodeGen/MachineFrameInfo.h" 20#include "llvm/CodeGen/MachineFunction.h" 21#include "llvm/CodeGen/MachineModuleInfo.h" 22#include "llvm/DataLayout.h" 23#include "llvm/MC/MCAsmInfo.h" 24#include "llvm/MC/MCContext.h" 25#include "llvm/MC/MCExpr.h" 26#include "llvm/MC/MCSection.h" 27#include "llvm/MC/MCStreamer.h" 28#include "llvm/MC/MCSymbol.h" 29#include "llvm/Module.h" 30#include "llvm/Support/CommandLine.h" 31#include "llvm/Support/Dwarf.h" 32#include "llvm/Support/FormattedStream.h" 33#include "llvm/Target/Mangler.h" 34#include "llvm/Target/TargetFrameLowering.h" 35#include "llvm/Target/TargetMachine.h" 36#include "llvm/Target/TargetOptions.h" 37#include "llvm/Target/TargetRegisterInfo.h" 38using namespace llvm; 39 40cl::opt<bool> 41EnableARMEHABIDescriptors("arm-enable-ehabi-descriptors", cl::Hidden, 42 cl::desc("Generate ARM EHABI tables with unwinding descriptors"), 43 cl::init(false)); 44 45 46ARMException::ARMException(AsmPrinter *A) 47 : DwarfException(A) {} 48 49ARMException::~ARMException() {} 50 51void ARMException::EndModule() { 52} 53 54/// BeginFunction - Gather pre-function exception information. Assumes it's 55/// being emitted immediately after the function entry point. 56void ARMException::BeginFunction(const MachineFunction *MF) { 57 Asm->OutStreamer.EmitFnStart(); 58 if (Asm->MF->getFunction()->needsUnwindTableEntry()) 59 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_begin", 60 Asm->getFunctionNumber())); 61} 62 63/// EndFunction - Gather and emit post-function exception information. 64/// 65void ARMException::EndFunction() { 66 if (!Asm->MF->getFunction()->needsUnwindTableEntry()) 67 Asm->OutStreamer.EmitCantUnwind(); 68 else { 69 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_end", 70 Asm->getFunctionNumber())); 71 72 if (EnableARMEHABIDescriptors) { 73 // Map all labels and get rid of any dead landing pads. 74 MMI->TidyLandingPads(); 75 76 if (!MMI->getLandingPads().empty()) { 77 // Emit references to personality. 78 if (const Function * Personality = 79 MMI->getPersonalities()[MMI->getPersonalityIndex()]) { 80 MCSymbol *PerSym = Asm->Mang->getSymbol(Personality); 81 Asm->OutStreamer.EmitSymbolAttribute(PerSym, MCSA_Global); 82 Asm->OutStreamer.EmitPersonality(PerSym); 83 } 84 85 // Emit .handlerdata directive. 86 Asm->OutStreamer.EmitHandlerData(); 87 88 // Emit actual exception table 89 EmitExceptionTable(); 90 } 91 } 92 } 93 94 Asm->OutStreamer.EmitFnEnd(); 95} 96 97void ARMException::EmitTypeInfos(unsigned TTypeEncoding) { 98 const std::vector<const GlobalVariable *> &TypeInfos = MMI->getTypeInfos(); 99 const std::vector<unsigned> &FilterIds = MMI->getFilterIds(); 100 101 bool VerboseAsm = Asm->OutStreamer.isVerboseAsm(); 102 103 int Entry = 0; 104 // Emit the Catch TypeInfos. 105 if (VerboseAsm && !TypeInfos.empty()) { 106 Asm->OutStreamer.AddComment(">> Catch TypeInfos <<"); 107 Asm->OutStreamer.AddBlankLine(); 108 Entry = TypeInfos.size(); 109 } 110 111 for (std::vector<const GlobalVariable *>::const_reverse_iterator 112 I = TypeInfos.rbegin(), E = TypeInfos.rend(); I != E; ++I) { 113 const GlobalVariable *GV = *I; 114 if (VerboseAsm) 115 Asm->OutStreamer.AddComment("TypeInfo " + Twine(Entry--)); 116 Asm->EmitTTypeReference(GV, TTypeEncoding); 117 } 118 119 // Emit the Exception Specifications. 120 if (VerboseAsm && !FilterIds.empty()) { 121 Asm->OutStreamer.AddComment(">> Filter TypeInfos <<"); 122 Asm->OutStreamer.AddBlankLine(); 123 Entry = 0; 124 } 125 for (std::vector<unsigned>::const_iterator 126 I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) { 127 unsigned TypeID = *I; 128 if (VerboseAsm) { 129 --Entry; 130 if (TypeID != 0) 131 Asm->OutStreamer.AddComment("FilterInfo " + Twine(Entry)); 132 } 133 134 Asm->EmitTTypeReference((TypeID == 0 ? 0 : TypeInfos[TypeID - 1]), 135 TTypeEncoding); 136 } 137} 138