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"
27 class MCWin64EHInstruction {
29 typedef Win64EH::UnwindOpcodes OpType;
36 MCWin64EHInstruction(OpType Op, MCSymbol *L, unsigned Reg)
37 : Operation(Op), Label(L), Offset(0), Register(Reg) {
38 assert(Op == Win64EH::UOP_PushNonVol);
40 MCWin64EHInstruction(MCSymbol *L, unsigned Size)
41 : Operation(Size>128 ? Win64EH::UOP_AllocLarge : Win64EH::UOP_AllocSmall),
42 Label(L), Offset(Size) { }
43 MCWin64EHInstruction(OpType Op, MCSymbol *L, unsigned Reg, unsigned Off)
44 : Operation(Op), Label(L), Offset(Off), Register(Reg) {
45 assert(Op == Win64EH::UOP_SetFPReg ||
46 Op == Win64EH::UOP_SaveNonVol ||
47 Op == Win64EH::UOP_SaveNonVolBig ||
48 Op == Win64EH::UOP_SaveXMM128 ||
49 Op == Win64EH::UOP_SaveXMM128Big);
51 MCWin64EHInstruction(OpType Op, MCSymbol *L, bool Code)
52 : Operation(Op), Label(L), Offset(Code ? 1 : 0) {
53 assert(Op == Win64EH::UOP_PushMachFrame);
55 OpType getOperation() const { return Operation; }
56 MCSymbol *getLabel() const { return Label; }
57 unsigned getOffset() const { return Offset; }
58 unsigned getSize() const { return Offset; }
59 unsigned getRegister() const { return Register; }
60 bool isPushCodeFrame() const { return Offset == 1; }
63 struct MCWin64EHUnwindInfo {
64 MCWin64EHUnwindInfo() : Begin(0), End(0), ExceptionHandler(0),
65 Function(0), PrologEnd(0), Symbol(0),
66 HandlesUnwind(false), HandlesExceptions(false),
67 LastFrameInst(-1), ChainedParent(0),
71 const MCSymbol *ExceptionHandler;
72 const MCSymbol *Function;
76 bool HandlesExceptions;
78 MCWin64EHUnwindInfo *ChainedParent;
79 std::vector<MCWin64EHInstruction> Instructions;
82 class MCWin64EHUnwindEmitter {
84 static StringRef GetSectionSuffix(const MCSymbol *func);
86 // This emits the unwind info sections (.pdata and .xdata in PE/COFF).
88 static void Emit(MCStreamer &streamer);
89 static void EmitUnwindInfo(MCStreamer &streamer, MCWin64EHUnwindInfo *info);
91 } // end namespace llvm