MCWin64EH.h revision 440596ffe5bb77a202acb36d5eadd158976ff39a
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
22namespace 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(Register) {
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),
66                            Function(0), UnwindOnly(false),
67                            PrologSize(0), LastFrameInst(-1), ChainedParent(0),
68                            Instructions() {}
69    MCSymbol *Begin;
70    MCSymbol *End;
71    const MCSymbol *ExceptionHandler;
72    const MCSymbol *Function;
73    bool UnwindOnly;
74    unsigned PrologSize;
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 section (.xdata in PE/COFF).
84    //
85    static void Emit(MCStreamer &streamer);
86  };
87} // end namespace llvm
88
89#endif
90