1 //===- MCWin64EH.h - Machine Code Win64 EH support --------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains declarations to support the Win64 Exception Handling
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_MC_MCWIN64EH_H
16 #define LLVM_MC_MCWIN64EH_H
18 #include "llvm/Support/Win64EH.h"
26 class MCWin64EHInstruction {
28 typedef Win64EH::UnwindOpcodes OpType;
35 MCWin64EHInstruction(OpType Op, MCSymbol *L, unsigned Reg)
36 : Operation(Op), Label(L), Offset(0), Register(Reg) {
37 assert(Op == Win64EH::UOP_PushNonVol);
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);
50 MCWin64EHInstruction(OpType Op, MCSymbol *L, bool Code)
51 : Operation(Op), Label(L), Offset(Code ? 1 : 0) {
52 assert(Op == Win64EH::UOP_PushMachFrame);
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; }
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),
70 const MCSymbol *ExceptionHandler;
71 const MCSymbol *Function;
75 bool HandlesExceptions;
77 MCWin64EHUnwindInfo *ChainedParent;
78 std::vector<MCWin64EHInstruction> Instructions;
81 class MCWin64EHUnwindEmitter {
84 // This emits the unwind info sections (.pdata and .xdata in PE/COFF).
86 static void Emit(MCStreamer &streamer);
87 static void EmitUnwindInfo(MCStreamer &streamer, MCWin64EHUnwindInfo *info);
89 } // end namespace llvm