2014-07-17 05:08:50 +02:00
|
|
|
//===- MCWinEH.h - Windows Unwinding Support --------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-07-17 05:08:50 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_MC_MCWINEH_H
|
|
|
|
#define LLVM_MC_MCWINEH_H
|
|
|
|
|
2018-10-27 08:13:06 +02:00
|
|
|
#include "llvm/ADT/MapVector.h"
|
2014-08-03 20:51:17 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2014-07-17 05:08:50 +02:00
|
|
|
namespace llvm {
|
2014-08-07 04:59:41 +02:00
|
|
|
class MCSection;
|
|
|
|
class MCStreamer;
|
2014-07-17 05:08:50 +02:00
|
|
|
class MCSymbol;
|
|
|
|
|
|
|
|
namespace WinEH {
|
|
|
|
struct Instruction {
|
|
|
|
const MCSymbol *Label;
|
2018-10-27 08:13:06 +02:00
|
|
|
unsigned Offset;
|
|
|
|
unsigned Register;
|
|
|
|
unsigned Operation;
|
2014-07-17 05:08:50 +02:00
|
|
|
|
|
|
|
Instruction(unsigned Op, MCSymbol *L, unsigned Reg, unsigned Off)
|
|
|
|
: Label(L), Offset(Off), Register(Reg), Operation(Op) {}
|
2020-09-07 23:00:07 +02:00
|
|
|
|
|
|
|
bool operator==(const Instruction &I) const {
|
|
|
|
// Check whether two instructions refer to the same operation
|
|
|
|
// applied at a different spot (i.e. pointing at a different label).
|
|
|
|
return Offset == I.Offset && Register == I.Register &&
|
|
|
|
Operation == I.Operation;
|
|
|
|
}
|
|
|
|
bool operator!=(const Instruction &I) const { return !(*this == I); }
|
2014-07-17 05:08:50 +02:00
|
|
|
};
|
2014-08-03 20:51:17 +02:00
|
|
|
|
|
|
|
struct FrameInfo {
|
2016-05-03 01:22:18 +02:00
|
|
|
const MCSymbol *Begin = nullptr;
|
|
|
|
const MCSymbol *End = nullptr;
|
2018-10-27 08:13:06 +02:00
|
|
|
const MCSymbol *FuncletOrFuncEnd = nullptr;
|
2016-05-03 01:22:18 +02:00
|
|
|
const MCSymbol *ExceptionHandler = nullptr;
|
|
|
|
const MCSymbol *Function = nullptr;
|
|
|
|
const MCSymbol *PrologEnd = nullptr;
|
|
|
|
const MCSymbol *Symbol = nullptr;
|
2020-08-20 10:39:25 +02:00
|
|
|
MCSection *TextSection = nullptr;
|
2014-08-03 20:51:17 +02:00
|
|
|
|
2016-05-03 01:22:18 +02:00
|
|
|
bool HandlesUnwind = false;
|
|
|
|
bool HandlesExceptions = false;
|
2020-08-20 09:38:17 +02:00
|
|
|
bool EmitAttempted = false;
|
2014-08-03 20:51:17 +02:00
|
|
|
|
2016-05-03 01:22:18 +02:00
|
|
|
int LastFrameInst = -1;
|
|
|
|
const FrameInfo *ChainedParent = nullptr;
|
2014-08-03 20:51:17 +02:00
|
|
|
std::vector<Instruction> Instructions;
|
2018-10-27 08:13:06 +02:00
|
|
|
MapVector<MCSymbol*, std::vector<Instruction>> EpilogMap;
|
2014-08-03 20:51:17 +02:00
|
|
|
|
2016-05-03 01:22:18 +02:00
|
|
|
FrameInfo() = default;
|
2014-08-03 20:51:17 +02:00
|
|
|
FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel)
|
2016-05-03 01:22:18 +02:00
|
|
|
: Begin(BeginFuncEHLabel), Function(Function) {}
|
2014-08-03 20:51:17 +02:00
|
|
|
FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel,
|
|
|
|
const FrameInfo *ChainedParent)
|
2016-05-03 01:22:18 +02:00
|
|
|
: Begin(BeginFuncEHLabel), Function(Function),
|
|
|
|
ChainedParent(ChainedParent) {}
|
2020-08-20 09:38:17 +02:00
|
|
|
|
|
|
|
bool empty() const {
|
|
|
|
if (!Instructions.empty())
|
|
|
|
return false;
|
|
|
|
for (const auto &E : EpilogMap)
|
|
|
|
if (!E.second.empty())
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
2014-08-03 20:51:17 +02:00
|
|
|
};
|
2016-10-11 00:49:37 +02:00
|
|
|
|
|
|
|
class UnwindEmitter {
|
|
|
|
public:
|
|
|
|
virtual ~UnwindEmitter();
|
|
|
|
|
|
|
|
/// This emits the unwind info sections (.pdata and .xdata in PE/COFF).
|
|
|
|
virtual void Emit(MCStreamer &Streamer) const = 0;
|
|
|
|
virtual void EmitUnwindInfo(MCStreamer &Streamer, FrameInfo *FI) const = 0;
|
|
|
|
};
|
2015-06-23 11:49:53 +02:00
|
|
|
}
|
|
|
|
}
|
2014-07-17 05:08:50 +02:00
|
|
|
|
|
|
|
#endif
|