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