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