Start keeping track of where the various unwind instructions are in the prolog.
[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     MCSymbol *Label;
32     unsigned Offset;
33     unsigned Register;
34   public:
35     MCWin64EHInstruction(OpType Op, MCSymbol *L, unsigned Reg)
36       : Operation(Op), Label(L), Offset(0), Register(Reg) {
37      assert(Op == Win64EH::UOP_PushNonVol);
38     }
39     MCWin64EHInstruction(MCSymbol *L, unsigned Size)
40       : Operation(Size>128 ? Win64EH::UOP_AllocLarge : Win64EH::UOP_AllocSmall),
41         Label(L), Offset(Size) { }
42     MCWin64EHInstruction(OpType Op, MCSymbol *L, unsigned Reg, unsigned Off)
43       : Operation(Op), Label(L), 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, MCSymbol *L, bool Code)
51       : Operation(Op), Label(L), Offset(Code ? 1 : 0) {
52       assert(Op == Win64EH::UOP_PushMachFrame);
53     }
54     OpType getOperation() const { return Operation; }
55     MCSymbol *getLabel() const { return Label; }
56     unsigned getOffset() const { return Offset; }
57     unsigned getSize() const { return Offset; }
58     unsigned getRegister() const { return Register; }
59     bool isPushCodeFrame() const { return Offset == 1; }
60   };
61
62   struct MCWin64EHUnwindInfo {
63     MCWin64EHUnwindInfo() : Begin(0), End(0), ExceptionHandler(0),
64                             Function(0), PrologEnd(0), Symbol(0),
65                             HandlesUnwind(false), HandlesExceptions(false),
66                             LastFrameInst(-1), ChainedParent(0),
67                             Instructions() {}
68     MCSymbol *Begin;
69     MCSymbol *End;
70     const MCSymbol *ExceptionHandler;
71     const MCSymbol *Function;
72     MCSymbol *PrologEnd;
73     MCSymbol *Symbol;
74     bool HandlesUnwind;
75     bool HandlesExceptions;
76     int LastFrameInst;
77     MCWin64EHUnwindInfo *ChainedParent;
78     std::vector<MCWin64EHInstruction> Instructions;
79   };
80
81   class MCWin64EHUnwindEmitter {
82   public:
83     //
84     // This emits the unwind info sections (.pdata and .xdata in PE/COFF).
85     //
86     static void Emit(MCStreamer &streamer);
87     static void EmitUnwindInfo(MCStreamer &streamer, MCWin64EHUnwindInfo *info);
88   };
89 } // end namespace llvm
90
91 #endif