//
//===----------------------------------------------------------------------===//
//
-// This file contains the declaration of the MCDwarfFile to support the dwarf
-// .file directive and the .loc directive.
+// This file contains declarations to support the Win64 Exception Handling
+// scheme in MC.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_MC_MCWIN64EH_H
#define LLVM_MC_MCWIN64EH_H
-#include "llvm/CodeGen/MachineLocation.h" // FIXME
+#include "llvm/MC/MCWinEH.h"
#include "llvm/Support/Win64EH.h"
#include <vector>
namespace llvm {
- class MCStreamer;
- class MCSymbol;
+class MCStreamer;
+class MCSymbol;
- class MCWin64EHInstruction {
- public:
- typedef Win64EH::UnwindOpcodes OpType;
- private:
- OpType Operation;
- unsigned Offset;
- MachineLocation Destination;
- MachineLocation Source;
- public:
- MCWin64EHInstruction(OpType Op, unsigned Register)
- : Operation(Op), Offset(0), Destination(0), Source(Register) {
- assert(Op == Win64EH::UOP_PushNonVol);
- }
- MCWin64EHInstruction(unsigned Size)
- : Operation(Size>128 ? Win64EH::UOP_AllocLarge : Win64EH::UOP_AllocSmall),
- Offset(Size) { }
- MCWin64EHInstruction(unsigned Register, unsigned Off)
- : Operation(Win64EH::UOP_SetFPReg), Offset(Off), Destination(Register) { }
- MCWin64EHInstruction(OpType Op, const MachineLocation &D,
- unsigned S)
- : Operation(Op), Destination(D), Source(S) {
- assert(Op == Win64EH::UOP_SaveNonVol ||
- Op == Win64EH::UOP_SaveNonVolBig ||
- Op == Win64EH::UOP_SaveXMM128 ||
- Op == Win64EH::UOP_SaveXMM128Big);
- }
- MCWin64EHInstruction(OpType Op, bool Code)
- : Operation(Op), Offset(Code ? 1 : 0) {
- assert(Op == Win64EH::UOP_PushMachFrame);
- }
- OpType getOperation() const { return Operation; }
- unsigned getOffset() const { return Offset; }
- unsigned getSize() const { return Offset; }
- bool isPushCodeFrame() const { return Offset == 1; }
- const MachineLocation &getDestination() const { return Destination; }
- const MachineLocation &getSource() const { return Source; }
- };
+namespace Win64EH {
+struct Instruction {
+ static WinEH::Instruction PushNonVol(MCSymbol *L, unsigned Reg) {
+ return WinEH::Instruction(Win64EH::UOP_PushNonVol, L, Reg, -1);
+ }
+ static WinEH::Instruction Alloc(MCSymbol *L, unsigned Size) {
+ return WinEH::Instruction(Size > 128 ? UOP_AllocLarge : UOP_AllocSmall, L,
+ -1, Size);
+ }
+ static WinEH::Instruction PushMachFrame(MCSymbol *L, bool Code) {
+ return WinEH::Instruction(UOP_PushMachFrame, L, -1, Code ? 1 : 0);
+ }
+ static WinEH::Instruction SaveNonVol(MCSymbol *L, unsigned Reg,
+ unsigned Offset) {
+ return WinEH::Instruction(Offset > 512 * 1024 - 8 ? UOP_SaveNonVolBig
+ : UOP_SaveNonVol,
+ L, Reg, Offset);
+ }
+ static WinEH::Instruction SaveXMM(MCSymbol *L, unsigned Reg,
+ unsigned Offset) {
+ return WinEH::Instruction(Offset > 512 * 1024 - 8 ? UOP_SaveXMM128Big
+ : UOP_SaveXMM128,
+ L, Reg, Offset);
+ }
+ static WinEH::Instruction SetFPReg(MCSymbol *L, unsigned Reg, unsigned Off) {
+ return WinEH::Instruction(UOP_SetFPReg, L, Reg, Off);
+ }
+};
- struct MCWin64EHUnwindInfo {
- MCWin64EHUnwindInfo() : Begin(0), End(0), ExceptionHandler(0),
- Function(0), UnwindOnly(false),
- PrologSize(0), LastFrameInst(-1), ChainedParent(0),
- Instructions() {}
- MCSymbol *Begin;
- MCSymbol *End;
- const MCSymbol *ExceptionHandler;
- const MCSymbol *Function;
- bool UnwindOnly;
- unsigned PrologSize;
- int LastFrameInst;
- MCWin64EHUnwindInfo *ChainedParent;
- std::vector<MCWin64EHInstruction> Instructions;
- };
-
- class MCWin64EHUnwindEmitter {
- public:
- //
- // This emits the unwind info section (.xdata in PE/COFF).
- //
- static void Emit(MCStreamer &streamer);
- };
+class UnwindEmitter : public WinEH::UnwindEmitter {
+public:
+ void Emit(MCStreamer &Streamer) const override;
+ void EmitUnwindInfo(MCStreamer &Streamer, WinEH::FrameInfo *FI) const override;
+};
+}
} // end namespace llvm
#endif