MCWin64EH.h revision 321fe74b2d40d7762175fbd3054fda00b5e70833
1//===- MCWin64EH.h - Machine Code Win64 EH 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// This file contains declarations to support the Win64 Exception Handling
11// scheme in MC.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_MC_MCWIN64EH_H
16#define LLVM_MC_MCWIN64EH_H
17
18#include "llvm/Support/Win64EH.h"
19#include <vector>
20
21namespace llvm {
22  class MCStreamer;
23  class MCSymbol;
24
25  class MCWin64EHInstruction {
26  public:
27    typedef Win64EH::UnwindOpcodes OpType;
28  private:
29    OpType Operation;
30    unsigned Offset;
31    unsigned Register;
32  public:
33    MCWin64EHInstruction(OpType Op, unsigned Reg)
34      : Operation(Op), Offset(0), Register(Reg) {
35      assert(Op == Win64EH::UOP_PushNonVol);
36    }
37    MCWin64EHInstruction(unsigned Size)
38      : Operation(Size>128 ? Win64EH::UOP_AllocLarge : Win64EH::UOP_AllocSmall),
39        Offset(Size) { }
40    MCWin64EHInstruction(OpType Op, unsigned Reg,
41                         unsigned Off)
42      : Operation(Op), Offset(Off), Register(Reg) {
43      assert(Op == Win64EH::UOP_SetFPReg ||
44             Op == Win64EH::UOP_SaveNonVol ||
45             Op == Win64EH::UOP_SaveNonVolBig ||
46             Op == Win64EH::UOP_SaveXMM128 ||
47             Op == Win64EH::UOP_SaveXMM128Big);
48    }
49    MCWin64EHInstruction(OpType Op, bool Code)
50      : Operation(Op), Offset(Code ? 1 : 0) {
51      assert(Op == Win64EH::UOP_PushMachFrame);
52    }
53    OpType getOperation() const { return Operation; }
54    unsigned getOffset() const { return Offset; }
55    unsigned getSize() const { return Offset; }
56    unsigned getRegister() const { return Register; }
57    bool isPushCodeFrame() const { return Offset == 1; }
58  };
59
60  struct MCWin64EHUnwindInfo {
61    MCWin64EHUnwindInfo() : Begin(0), End(0), ExceptionHandler(0),
62                            Function(0), PrologEnd(0), HandlesUnwind(false),
63                            HandlesExceptions(false), LastFrameInst(-1),
64                            ChainedParent(0), Instructions(), Emitted(false) {}
65    MCSymbol *Begin;
66    MCSymbol *End;
67    const MCSymbol *ExceptionHandler;
68    const MCSymbol *Function;
69    MCSymbol *PrologEnd;
70    bool HandlesUnwind;
71    bool HandlesExceptions;
72    int LastFrameInst;
73    MCWin64EHUnwindInfo *ChainedParent;
74    std::vector<MCWin64EHInstruction> Instructions;
75    bool Emitted;
76  };
77
78  class MCWin64EHUnwindEmitter {
79  public:
80    //
81    // This emits the unwind info sections (.pdata and .xdata in PE/COFF).
82    //
83    static void Emit(MCStreamer &streamer);
84    static void EmitUnwindInfo(MCStreamer &streamer, MCWin64EHUnwindInfo *info);
85  };
86} // end namespace llvm
87
88#endif
89