Implement the Win64 EH prolog instruction methods on the base MCStreamer.
[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 the declaration of the MCDwarfFile to support the dwarf
11 // .file directive and the .loc directive.
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
21 namespace 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), UnwindOnly(false),
63                             PrologSize(0), LastFrameInst(-1), ChainedParent(0),
64                             Instructions() {}
65     MCSymbol *Begin;
66     MCSymbol *End;
67     const MCSymbol *ExceptionHandler;
68     const MCSymbol *Function;
69     bool UnwindOnly;
70     unsigned PrologSize;
71     int LastFrameInst;
72     MCWin64EHUnwindInfo *ChainedParent;
73     std::vector<MCWin64EHInstruction> Instructions;
74   };
75
76   class MCWin64EHUnwindEmitter {
77   public:
78     //
79     // This emits the unwind info section (.xdata in PE/COFF).
80     //
81     static void Emit(MCStreamer &streamer);
82   };
83 } // end namespace llvm
84
85 #endif