Home | History | Annotate | Download | only in AsmPrinter
      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/Module.h"
     16 #include "llvm/CodeGen/AsmPrinter.h"
     17 #include "llvm/CodeGen/MachineModuleInfo.h"
     18 #include "llvm/CodeGen/MachineFrameInfo.h"
     19 #include "llvm/CodeGen/MachineFunction.h"
     20 #include "llvm/MC/MCAsmInfo.h"
     21 #include "llvm/MC/MCContext.h"
     22 #include "llvm/MC/MCExpr.h"
     23 #include "llvm/MC/MCSection.h"
     24 #include "llvm/MC/MCStreamer.h"
     25 #include "llvm/MC/MCSymbol.h"
     26 #include "llvm/Target/Mangler.h"
     27 #include "llvm/Target/TargetData.h"
     28 #include "llvm/Target/TargetFrameLowering.h"
     29 #include "llvm/Target/TargetMachine.h"
     30 #include "llvm/Target/TargetOptions.h"
     31 #include "llvm/Target/TargetRegisterInfo.h"
     32 #include "llvm/Support/CommandLine.h"
     33 #include "llvm/Support/Dwarf.h"
     34 #include "llvm/Support/FormattedStream.h"
     35 #include "llvm/ADT/SmallString.h"
     36 #include "llvm/ADT/StringExtras.h"
     37 #include "llvm/ADT/Twine.h"
     38 using namespace llvm;
     39 
     40 cl::opt<bool>
     41 EnableARMEHABIDescriptors("arm-enable-ehabi-descriptors", cl::Hidden,
     42   cl::desc("Generate ARM EHABI tables with unwinding descriptors"),
     43   cl::init(false));
     44 
     45 
     46 ARMException::ARMException(AsmPrinter *A)
     47   : DwarfException(A),
     48     shouldEmitTable(false), shouldEmitMoves(false), shouldEmitTableModule(false)
     49     {}
     50 
     51 ARMException::~ARMException() {}
     52 
     53 void ARMException::EndModule() {
     54 }
     55 
     56 /// BeginFunction - Gather pre-function exception information. Assumes it's
     57 /// being emitted immediately after the function entry point.
     58 void ARMException::BeginFunction(const MachineFunction *MF) {
     59   Asm->OutStreamer.EmitFnStart();
     60   if (Asm->MF->getFunction()->needsUnwindTableEntry())
     61     Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_begin",
     62                                                   Asm->getFunctionNumber()));
     63 }
     64 
     65 /// EndFunction - Gather and emit post-function exception information.
     66 ///
     67 void ARMException::EndFunction() {
     68   if (!Asm->MF->getFunction()->needsUnwindTableEntry())
     69     Asm->OutStreamer.EmitCantUnwind();
     70   else {
     71     Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_end",
     72                                                   Asm->getFunctionNumber()));
     73 
     74     // Emit references to personality.
     75     if (const Function * Personality =
     76         MMI->getPersonalities()[MMI->getPersonalityIndex()]) {
     77       MCSymbol *PerSym = Asm->Mang->getSymbol(Personality);
     78       Asm->OutStreamer.EmitSymbolAttribute(PerSym, MCSA_Global);
     79       Asm->OutStreamer.EmitPersonality(PerSym);
     80     }
     81 
     82     if (EnableARMEHABIDescriptors) {
     83       // Map all labels and get rid of any dead landing pads.
     84       MMI->TidyLandingPads();
     85 
     86       Asm->OutStreamer.EmitHandlerData();
     87 
     88       // Emit actual exception table
     89       EmitExceptionTable();
     90     }
     91   }
     92 
     93   Asm->OutStreamer.EmitFnEnd();
     94 }
     95