2011-05-18 22:48:24 +00:00
|
|
|
//===- MCWin64EH.h - Machine Code Win64 EH support --------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2011-05-21 15:57:49 +00:00
|
|
|
// This file contains declarations to support the Win64 Exception Handling
|
|
|
|
// scheme in MC.
|
2011-05-18 22:48:24 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_MC_MCWIN64EH_H
|
|
|
|
#define LLVM_MC_MCWIN64EH_H
|
|
|
|
|
|
|
|
#include "llvm/Support/Win64EH.h"
|
2011-05-22 03:01:05 +00:00
|
|
|
#include <cassert>
|
2011-05-18 22:48:24 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace llvm {
|
2011-05-27 19:09:24 +00:00
|
|
|
class StringRef;
|
2011-05-18 22:48:24 +00:00
|
|
|
class MCStreamer;
|
|
|
|
class MCSymbol;
|
|
|
|
|
|
|
|
class MCWin64EHInstruction {
|
|
|
|
public:
|
|
|
|
typedef Win64EH::UnwindOpcodes OpType;
|
|
|
|
private:
|
|
|
|
OpType Operation;
|
2011-05-27 03:25:01 +00:00
|
|
|
MCSymbol *Label;
|
2011-05-18 22:48:24 +00:00
|
|
|
unsigned Offset;
|
2011-05-19 19:35:55 +00:00
|
|
|
unsigned Register;
|
2011-05-18 22:48:24 +00:00
|
|
|
public:
|
2011-05-27 03:25:01 +00:00
|
|
|
MCWin64EHInstruction(OpType Op, MCSymbol *L, unsigned Reg)
|
|
|
|
: Operation(Op), Label(L), Offset(0), Register(Reg) {
|
|
|
|
assert(Op == Win64EH::UOP_PushNonVol);
|
2011-05-18 22:48:24 +00:00
|
|
|
}
|
2011-05-27 03:25:01 +00:00
|
|
|
MCWin64EHInstruction(MCSymbol *L, unsigned Size)
|
2011-05-18 22:48:24 +00:00
|
|
|
: Operation(Size>128 ? Win64EH::UOP_AllocLarge : Win64EH::UOP_AllocSmall),
|
2011-05-27 03:25:01 +00:00
|
|
|
Label(L), Offset(Size) { }
|
|
|
|
MCWin64EHInstruction(OpType Op, MCSymbol *L, unsigned Reg, unsigned Off)
|
|
|
|
: Operation(Op), Label(L), Offset(Off), Register(Reg) {
|
2011-05-19 19:35:55 +00:00
|
|
|
assert(Op == Win64EH::UOP_SetFPReg ||
|
|
|
|
Op == Win64EH::UOP_SaveNonVol ||
|
2011-05-18 22:48:24 +00:00
|
|
|
Op == Win64EH::UOP_SaveNonVolBig ||
|
|
|
|
Op == Win64EH::UOP_SaveXMM128 ||
|
|
|
|
Op == Win64EH::UOP_SaveXMM128Big);
|
|
|
|
}
|
2011-05-27 03:25:01 +00:00
|
|
|
MCWin64EHInstruction(OpType Op, MCSymbol *L, bool Code)
|
|
|
|
: Operation(Op), Label(L), Offset(Code ? 1 : 0) {
|
2011-05-18 22:48:24 +00:00
|
|
|
assert(Op == Win64EH::UOP_PushMachFrame);
|
|
|
|
}
|
|
|
|
OpType getOperation() const { return Operation; }
|
2011-05-27 03:25:01 +00:00
|
|
|
MCSymbol *getLabel() const { return Label; }
|
2011-05-18 22:48:24 +00:00
|
|
|
unsigned getOffset() const { return Offset; }
|
|
|
|
unsigned getSize() const { return Offset; }
|
2011-05-19 19:35:55 +00:00
|
|
|
unsigned getRegister() const { return Register; }
|
2011-05-18 22:48:24 +00:00
|
|
|
bool isPushCodeFrame() const { return Offset == 1; }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MCWin64EHUnwindInfo {
|
2011-05-19 17:46:39 +00:00
|
|
|
MCWin64EHUnwindInfo() : Begin(0), End(0), ExceptionHandler(0),
|
2011-05-22 03:01:05 +00:00
|
|
|
Function(0), PrologEnd(0), Symbol(0),
|
|
|
|
HandlesUnwind(false), HandlesExceptions(false),
|
|
|
|
LastFrameInst(-1), ChainedParent(0),
|
|
|
|
Instructions() {}
|
2011-05-18 22:48:24 +00:00
|
|
|
MCSymbol *Begin;
|
|
|
|
MCSymbol *End;
|
|
|
|
const MCSymbol *ExceptionHandler;
|
|
|
|
const MCSymbol *Function;
|
2011-05-19 21:24:54 +00:00
|
|
|
MCSymbol *PrologEnd;
|
2011-05-22 03:01:05 +00:00
|
|
|
MCSymbol *Symbol;
|
2011-05-21 15:57:49 +00:00
|
|
|
bool HandlesUnwind;
|
|
|
|
bool HandlesExceptions;
|
2011-05-18 22:48:24 +00:00
|
|
|
int LastFrameInst;
|
2011-05-19 04:04:13 +00:00
|
|
|
MCWin64EHUnwindInfo *ChainedParent;
|
2011-05-18 22:48:24 +00:00
|
|
|
std::vector<MCWin64EHInstruction> Instructions;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MCWin64EHUnwindEmitter {
|
|
|
|
public:
|
2011-05-27 19:09:24 +00:00
|
|
|
static StringRef GetSectionSuffix(const MCSymbol *func);
|
2011-05-18 22:48:24 +00:00
|
|
|
//
|
2011-05-21 15:57:49 +00:00
|
|
|
// This emits the unwind info sections (.pdata and .xdata in PE/COFF).
|
2011-05-18 22:48:24 +00:00
|
|
|
//
|
|
|
|
static void Emit(MCStreamer &streamer);
|
2011-05-21 15:57:49 +00:00
|
|
|
static void EmitUnwindInfo(MCStreamer &streamer, MCWin64EHUnwindInfo *info);
|
2011-05-18 22:48:24 +00:00
|
|
|
};
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|