LLVM API Documentation
00001 //===-- CodeGen/AsmPrinter/Win64Exception.cpp - Dwarf Exception Impl ------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file contains support for writing Win64 exception info into asm files. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "Win64Exception.h" 00015 #include "llvm/ADT/SmallString.h" 00016 #include "llvm/ADT/StringExtras.h" 00017 #include "llvm/ADT/Twine.h" 00018 #include "llvm/CodeGen/AsmPrinter.h" 00019 #include "llvm/CodeGen/MachineFrameInfo.h" 00020 #include "llvm/CodeGen/MachineFunction.h" 00021 #include "llvm/CodeGen/MachineModuleInfo.h" 00022 #include "llvm/IR/DataLayout.h" 00023 #include "llvm/IR/Mangler.h" 00024 #include "llvm/IR/Module.h" 00025 #include "llvm/MC/MCAsmInfo.h" 00026 #include "llvm/MC/MCContext.h" 00027 #include "llvm/MC/MCExpr.h" 00028 #include "llvm/MC/MCSection.h" 00029 #include "llvm/MC/MCStreamer.h" 00030 #include "llvm/MC/MCSymbol.h" 00031 #include "llvm/Support/Dwarf.h" 00032 #include "llvm/Support/ErrorHandling.h" 00033 #include "llvm/Support/FormattedStream.h" 00034 #include "llvm/Target/TargetFrameLowering.h" 00035 #include "llvm/Target/TargetLoweringObjectFile.h" 00036 #include "llvm/Target/TargetOptions.h" 00037 #include "llvm/Target/TargetRegisterInfo.h" 00038 using namespace llvm; 00039 00040 Win64Exception::Win64Exception(AsmPrinter *A) 00041 : EHStreamer(A), shouldEmitPersonality(false), shouldEmitLSDA(false), 00042 shouldEmitMoves(false) {} 00043 00044 Win64Exception::~Win64Exception() {} 00045 00046 /// endModule - Emit all exception information that should come after the 00047 /// content. 00048 void Win64Exception::endModule() { 00049 } 00050 00051 /// beginFunction - Gather pre-function exception information. Assumes it's 00052 /// being emitted immediately after the function entry point. 00053 void Win64Exception::beginFunction(const MachineFunction *MF) { 00054 shouldEmitMoves = shouldEmitPersonality = shouldEmitLSDA = false; 00055 00056 // If any landing pads survive, we need an EH table. 00057 bool hasLandingPads = !MMI->getLandingPads().empty(); 00058 00059 shouldEmitMoves = Asm->needsSEHMoves(); 00060 00061 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); 00062 unsigned PerEncoding = TLOF.getPersonalityEncoding(); 00063 const Function *Per = MMI->getPersonalities()[MMI->getPersonalityIndex()]; 00064 00065 shouldEmitPersonality = hasLandingPads && 00066 PerEncoding != dwarf::DW_EH_PE_omit && Per; 00067 00068 unsigned LSDAEncoding = TLOF.getLSDAEncoding(); 00069 shouldEmitLSDA = shouldEmitPersonality && 00070 LSDAEncoding != dwarf::DW_EH_PE_omit; 00071 00072 if (!shouldEmitPersonality && !shouldEmitMoves) 00073 return; 00074 00075 Asm->OutStreamer.EmitWinCFIStartProc(Asm->CurrentFnSym); 00076 00077 if (!shouldEmitPersonality) 00078 return; 00079 00080 const MCSymbol *PersHandlerSym = 00081 TLOF.getCFIPersonalitySymbol(Per, *Asm->Mang, Asm->TM, MMI); 00082 Asm->OutStreamer.EmitWinEHHandler(PersHandlerSym, true, true); 00083 00084 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_begin", 00085 Asm->getFunctionNumber())); 00086 } 00087 00088 /// endFunction - Gather and emit post-function exception information. 00089 /// 00090 void Win64Exception::endFunction(const MachineFunction *) { 00091 if (!shouldEmitPersonality && !shouldEmitMoves) 00092 return; 00093 00094 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_end", 00095 Asm->getFunctionNumber())); 00096 00097 // Map all labels and get rid of any dead landing pads. 00098 MMI->TidyLandingPads(); 00099 00100 if (shouldEmitPersonality) { 00101 Asm->OutStreamer.PushSection(); 00102 Asm->OutStreamer.EmitWinEHHandlerData(); 00103 emitExceptionTable(); 00104 Asm->OutStreamer.PopSection(); 00105 } 00106 Asm->OutStreamer.EmitWinCFIEndProc(); 00107 }