MCWinEH.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- MCWinEH.h - Windows Unwinding Support --------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_MC_MCWINEH_H
  14. #define LLVM_MC_MCWINEH_H
  15. #include "llvm/ADT/MapVector.h"
  16. #include <vector>
  17. namespace llvm {
  18. class MCSection;
  19. class MCStreamer;
  20. class MCSymbol;
  21. namespace WinEH {
  22. struct Instruction {
  23. const MCSymbol *Label;
  24. unsigned Offset;
  25. unsigned Register;
  26. unsigned Operation;
  27. Instruction(unsigned Op, MCSymbol *L, unsigned Reg, unsigned Off)
  28. : Label(L), Offset(Off), Register(Reg), Operation(Op) {}
  29. bool operator==(const Instruction &I) const {
  30. // Check whether two instructions refer to the same operation
  31. // applied at a different spot (i.e. pointing at a different label).
  32. return Offset == I.Offset && Register == I.Register &&
  33. Operation == I.Operation;
  34. }
  35. bool operator!=(const Instruction &I) const { return !(*this == I); }
  36. };
  37. struct FrameInfo {
  38. const MCSymbol *Begin = nullptr;
  39. const MCSymbol *End = nullptr;
  40. const MCSymbol *FuncletOrFuncEnd = nullptr;
  41. const MCSymbol *ExceptionHandler = nullptr;
  42. const MCSymbol *Function = nullptr;
  43. const MCSymbol *PrologEnd = nullptr;
  44. const MCSymbol *Symbol = nullptr;
  45. MCSection *TextSection = nullptr;
  46. uint32_t PackedInfo = 0;
  47. bool HandlesUnwind = false;
  48. bool HandlesExceptions = false;
  49. bool EmitAttempted = false;
  50. int LastFrameInst = -1;
  51. const FrameInfo *ChainedParent = nullptr;
  52. std::vector<Instruction> Instructions;
  53. MapVector<MCSymbol*, std::vector<Instruction>> EpilogMap;
  54. FrameInfo() = default;
  55. FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel)
  56. : Begin(BeginFuncEHLabel), Function(Function) {}
  57. FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel,
  58. const FrameInfo *ChainedParent)
  59. : Begin(BeginFuncEHLabel), Function(Function),
  60. ChainedParent(ChainedParent) {}
  61. bool empty() const {
  62. if (!Instructions.empty())
  63. return false;
  64. for (const auto &E : EpilogMap)
  65. if (!E.second.empty())
  66. return false;
  67. return true;
  68. }
  69. };
  70. class UnwindEmitter {
  71. public:
  72. virtual ~UnwindEmitter();
  73. /// This emits the unwind info sections (.pdata and .xdata in PE/COFF).
  74. virtual void Emit(MCStreamer &Streamer) const = 0;
  75. virtual void EmitUnwindInfo(MCStreamer &Streamer, FrameInfo *FI,
  76. bool HandlerData) const = 0;
  77. };
  78. }
  79. }
  80. #endif
  81. #ifdef __GNUC__
  82. #pragma GCC diagnostic pop
  83. #endif