Home | History | Annotate | Download | only in MC
      1 //===- MCWinEH.h - Windows Unwinding Support --------------------*- C++ -*-===//
      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 #ifndef LLVM_MC_MCWINEH_H
     11 #define LLVM_MC_MCWINEH_H
     12 
     13 #include <vector>
     14 
     15 namespace llvm {
     16 class MCContext;
     17 class MCSection;
     18 class MCStreamer;
     19 class MCSymbol;
     20 class StringRef;
     21 
     22 namespace WinEH {
     23 struct Instruction {
     24   const MCSymbol *Label;
     25   const unsigned Offset;
     26   const unsigned Register;
     27   const unsigned Operation;
     28 
     29   Instruction(unsigned Op, MCSymbol *L, unsigned Reg, unsigned Off)
     30     : Label(L), Offset(Off), Register(Reg), Operation(Op) {}
     31 };
     32 
     33 struct FrameInfo {
     34   const MCSymbol *Begin;
     35   const MCSymbol *End;
     36   const MCSymbol *ExceptionHandler;
     37   const MCSymbol *Function;
     38   const MCSymbol *PrologEnd;
     39   const MCSymbol *Symbol;
     40 
     41   bool HandlesUnwind;
     42   bool HandlesExceptions;
     43 
     44   int LastFrameInst;
     45   const FrameInfo *ChainedParent;
     46   std::vector<Instruction> Instructions;
     47 
     48   FrameInfo()
     49     : Begin(nullptr), End(nullptr), ExceptionHandler(nullptr),
     50       Function(nullptr), PrologEnd(nullptr), Symbol(nullptr),
     51       HandlesUnwind(false), HandlesExceptions(false), LastFrameInst(-1),
     52       ChainedParent(nullptr), Instructions() {}
     53   FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel)
     54     : Begin(BeginFuncEHLabel), End(nullptr), ExceptionHandler(nullptr),
     55       Function(Function), PrologEnd(nullptr), Symbol(nullptr),
     56       HandlesUnwind(false), HandlesExceptions(false), LastFrameInst(-1),
     57       ChainedParent(nullptr), Instructions() {}
     58   FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel,
     59             const FrameInfo *ChainedParent)
     60     : Begin(BeginFuncEHLabel), End(nullptr), ExceptionHandler(nullptr),
     61       Function(Function), PrologEnd(nullptr), Symbol(nullptr),
     62       HandlesUnwind(false), HandlesExceptions(false), LastFrameInst(-1),
     63       ChainedParent(ChainedParent), Instructions() {}
     64 };
     65 
     66 class UnwindEmitter {
     67 public:
     68   static MCSection *getPDataSection(const MCSymbol *Function,
     69                                     MCContext &Context);
     70   static MCSection *getXDataSection(const MCSymbol *Function,
     71                                     MCContext &Context);
     72 
     73   virtual ~UnwindEmitter() { }
     74 
     75   //
     76   // This emits the unwind info sections (.pdata and .xdata in PE/COFF).
     77   //
     78   virtual void Emit(MCStreamer &Streamer) const = 0;
     79   virtual void EmitUnwindInfo(MCStreamer &Streamer, FrameInfo *FI) const = 0;
     80 };
     81 }
     82 }
     83 
     84 #endif
     85