Add a header patterned after MCDwarf.h for supporting Win64 exception handling
[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/CodeGen/MachineLocation.h" // FIXME
19 #include "llvm/Support/Win64EH.h"
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     MachineLocation Destination;
33     MachineLocation Source;
34   public:
35     MCWin64EHInstruction(OpType Op, unsigned Register)
36       : Operation(Op), Offset(0), Destination(0), Source(S) {
37       assert(Op == Win64EH::UOP_PushNonVol);
38     }
39     MCWin64EHInstruction(unsigned Size)
40       : Operation(Size>128 ? Win64EH::UOP_AllocLarge : Win64EH::UOP_AllocSmall),
41         Offset(size) { }
42     MCWin64EHInstruction(unsigned Register, unsigned Off)
43       : Operation(Win64EH::UOP_SetFPReg), Offset(Off), Destination(Register) { }
44     MCWin64EHInstruction(OpType Op, const MachineLocation &D,
45                          unsigned S)
46       : Operation(Op), Destination(D), Source(S) {
47       assert(Op == Win64EH::UOP_SaveNonVol ||
48              Op == Win64EH::UOP_SaveNonVolBig ||
49              Op == Win64EH::UOP_SaveXMM128 ||
50              Op == Win64EH::UOP_SaveXMM128Big);
51     }
52     MCWin64EHInstruction(OpType Op, bool Code)
53       : Operation(Op), Offset(Code ? 1 : 0) {
54       assert(Op == Win64EH::UOP_PushMachFrame);
55     }
56     OpType getOperation() const { return Operation; }
57     unsigned getOffset() const { return Offset; }
58     unsigned getSize() const { return Offset; }
59     bool isPushCodeFrame() const { return Offset == 1; }
60     const MachineLocation &getDestination() const { return Destination; }
61     const MachineLocation &getSource() const { return Source; }
62   };
63
64   struct MCWin64EHUnwindInfo {
65     MCWin64EHUnwindInfo() : Begin(0), End(0), ExceptionHandler(0), Lsda(0),
66                             Function(0), UnwindOnly(false), LsdaSize(0),
67                             PrologSize(0), LastFrameInst(-1), Chained(false)
68                             Instructions() {}
69     MCSymbol *Begin;
70     MCSymbol *End;
71     const MCSymbol *ExceptionHandler;
72     const MCSymbol *Lsda;
73     const MCSymbol *Function;
74     bool UnwindOnly;
75     unsigned LsdaSize;
76     unsigned PrologSize;
77     int LastFrameInst;
78     bool Chained;
79     std::vector<MCWin64EHInstruction> Instructions;
80   };
81
82   class MCWin64EHUnwindEmitter {
83   public:
84     //
85     // This emits the unwind info section (.xdata in PE/COFF).
86     //
87     static void Emit(MCStreamer &streamer);
88   };
89 } // end namespace llvm
90
91 #endif