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/IR/DataLayout.h" 23 #include "llvm/IR/Mangler.h" 24 #include "llvm/IR/Module.h" 25 #include "llvm/MC/MCAsmInfo.h" 26 #include "llvm/MC/MCContext.h" 27 #include "llvm/MC/MCExpr.h" 28 #include "llvm/MC/MCSection.h" 29 #include "llvm/MC/MCStreamer.h" 30 #include "llvm/MC/MCSymbol.h" 31 #include "llvm/Support/CommandLine.h" 32 #include "llvm/Support/Dwarf.h" 33 #include "llvm/Support/FormattedStream.h" 34 #include "llvm/Target/TargetFrameLowering.h" 35 #include "llvm/Target/TargetOptions.h" 36 #include "llvm/Target/TargetRegisterInfo.h" 37 using namespace llvm; 38 39 ARMException::ARMException(AsmPrinter *A) 40 : DwarfException(A) {} 41 42 ARMException::~ARMException() {} 43 44 ARMTargetStreamer &ARMException::getTargetStreamer() { 45 MCTargetStreamer &TS = *Asm->OutStreamer.getTargetStreamer(); 46 return static_cast<ARMTargetStreamer &>(TS); 47 } 48 49 void ARMException::endModule() { 50 } 51 52 /// beginFunction - Gather pre-function exception information. Assumes it's 53 /// being emitted immediately after the function entry point. 54 void ARMException::beginFunction(const MachineFunction *MF) { 55 getTargetStreamer().emitFnStart(); 56 if (Asm->MF->getFunction()->needsUnwindTableEntry()) 57 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_begin", 58 Asm->getFunctionNumber())); 59 } 60 61 /// endFunction - Gather and emit post-function exception information. 62 /// 63 void ARMException::endFunction(const MachineFunction *) { 64 ARMTargetStreamer &ATS = getTargetStreamer(); 65 if (!Asm->MF->getFunction()->needsUnwindTableEntry()) 66 ATS.emitCantUnwind(); 67 else { 68 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_end", 69 Asm->getFunctionNumber())); 70 71 // Map all labels and get rid of any dead landing pads. 72 MMI->TidyLandingPads(); 73 74 if (!MMI->getLandingPads().empty()) { 75 // Emit references to personality. 76 if (const Function * Personality = 77 MMI->getPersonalities()[MMI->getPersonalityIndex()]) { 78 MCSymbol *PerSym = Asm->getSymbol(Personality); 79 Asm->OutStreamer.EmitSymbolAttribute(PerSym, MCSA_Global); 80 ATS.emitPersonality(PerSym); 81 } 82 83 // Emit .handlerdata directive. 84 ATS.emitHandlerData(); 85 86 // Emit actual exception table 87 EmitExceptionTable(); 88 } 89 } 90 91 ATS.emitFnEnd(); 92 } 93 94 void ARMException::EmitTypeInfos(unsigned TTypeEncoding) { 95 const std::vector<const GlobalVariable *> &TypeInfos = MMI->getTypeInfos(); 96 const std::vector<unsigned> &FilterIds = MMI->getFilterIds(); 97 98 bool VerboseAsm = Asm->OutStreamer.isVerboseAsm(); 99 100 int Entry = 0; 101 // Emit the Catch TypeInfos. 102 if (VerboseAsm && !TypeInfos.empty()) { 103 Asm->OutStreamer.AddComment(">> Catch TypeInfos <<"); 104 Asm->OutStreamer.AddBlankLine(); 105 Entry = TypeInfos.size(); 106 } 107 108 for (std::vector<const GlobalVariable *>::const_reverse_iterator 109 I = TypeInfos.rbegin(), E = TypeInfos.rend(); I != E; ++I) { 110 const GlobalVariable *GV = *I; 111 if (VerboseAsm) 112 Asm->OutStreamer.AddComment("TypeInfo " + Twine(Entry--)); 113 Asm->EmitTTypeReference(GV, TTypeEncoding); 114 } 115 116 // Emit the Exception Specifications. 117 if (VerboseAsm && !FilterIds.empty()) { 118 Asm->OutStreamer.AddComment(">> Filter TypeInfos <<"); 119 Asm->OutStreamer.AddBlankLine(); 120 Entry = 0; 121 } 122 for (std::vector<unsigned>::const_iterator 123 I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) { 124 unsigned TypeID = *I; 125 if (VerboseAsm) { 126 --Entry; 127 if (TypeID != 0) 128 Asm->OutStreamer.AddComment("FilterInfo " + Twine(Entry)); 129 } 130 131 Asm->EmitTTypeReference((TypeID == 0 ? 0 : TypeInfos[TypeID - 1]), 132 TTypeEncoding); 133 } 134 } 135