MCWinEH.h 2.6 KB

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