mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-07 12:28:24 +00:00
MC: rename Win64EHFrameInfo to WinEH::FrameInfo
The frame information stored in this structure is driven by the requirements for Windows NT unwinding rather than Windows 64 specifically. As a result, this type can be shared across multiple architectures (ARM, AXP, MIPS, PPC, SH). Rename this class in preparation for adding support for supporting unwinding information for Windows on ARM. Take the opportunity to constify the members as everything except the ChainedParent is read-only. This required some adjustment to the label handling. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214663 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -181,8 +181,8 @@ class MCStreamer {
|
|||||||
|
|
||||||
MCSymbol *EmitCFICommon();
|
MCSymbol *EmitCFICommon();
|
||||||
|
|
||||||
std::vector<MCWinFrameInfo *> WinFrameInfos;
|
std::vector<WinEH::FrameInfo *> WinFrameInfos;
|
||||||
MCWinFrameInfo *CurrentWinFrameInfo;
|
WinEH::FrameInfo *CurrentWinFrameInfo;
|
||||||
void EnsureValidWinFrameInfo();
|
void EnsureValidWinFrameInfo();
|
||||||
|
|
||||||
// SymbolOrdering - Tracks an index to represent the order
|
// SymbolOrdering - Tracks an index to represent the order
|
||||||
@@ -204,7 +204,7 @@ protected:
|
|||||||
virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
|
virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
|
||||||
virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
|
virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
|
||||||
|
|
||||||
MCWinFrameInfo *getCurrentWinFrameInfo() {
|
WinEH::FrameInfo *getCurrentWinFrameInfo() {
|
||||||
return CurrentWinFrameInfo;
|
return CurrentWinFrameInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,7 +238,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned getNumWinFrameInfos() { return WinFrameInfos.size(); }
|
unsigned getNumWinFrameInfos() { return WinFrameInfos.size(); }
|
||||||
ArrayRef<MCWinFrameInfo *> getWinFrameInfos() const {
|
ArrayRef<WinEH::FrameInfo *> getWinFrameInfos() const {
|
||||||
return WinFrameInfos;
|
return WinFrameInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -54,25 +54,6 @@ struct Instruction {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MCWinFrameInfo {
|
|
||||||
MCWinFrameInfo()
|
|
||||||
: Begin(nullptr), End(nullptr),ExceptionHandler(nullptr),
|
|
||||||
Function(nullptr), PrologEnd(nullptr), Symbol(nullptr),
|
|
||||||
HandlesUnwind(false), HandlesExceptions(false), LastFrameInst(-1),
|
|
||||||
ChainedParent(nullptr), Instructions() {}
|
|
||||||
MCSymbol *Begin;
|
|
||||||
MCSymbol *End;
|
|
||||||
const MCSymbol *ExceptionHandler;
|
|
||||||
const MCSymbol *Function;
|
|
||||||
MCSymbol *PrologEnd;
|
|
||||||
MCSymbol *Symbol;
|
|
||||||
bool HandlesUnwind;
|
|
||||||
bool HandlesExceptions;
|
|
||||||
int LastFrameInst;
|
|
||||||
MCWinFrameInfo *ChainedParent;
|
|
||||||
std::vector<WinEH::Instruction> Instructions;
|
|
||||||
};
|
|
||||||
|
|
||||||
class MCWin64EHUnwindEmitter {
|
class MCWin64EHUnwindEmitter {
|
||||||
public:
|
public:
|
||||||
static StringRef GetSectionSuffix(const MCSymbol *func);
|
static StringRef GetSectionSuffix(const MCSymbol *func);
|
||||||
@@ -80,7 +61,7 @@ struct Instruction {
|
|||||||
// This emits the unwind info sections (.pdata and .xdata in PE/COFF).
|
// This emits the unwind info sections (.pdata and .xdata in PE/COFF).
|
||||||
//
|
//
|
||||||
static void Emit(MCStreamer &streamer);
|
static void Emit(MCStreamer &streamer);
|
||||||
static void EmitUnwindInfo(MCStreamer &streamer, MCWinFrameInfo *info);
|
static void EmitUnwindInfo(MCStreamer &streamer, WinEH::FrameInfo *info);
|
||||||
};
|
};
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
|
||||||
|
@@ -10,6 +10,8 @@
|
|||||||
#ifndef LLVM_MC_MCWINEH_H
|
#ifndef LLVM_MC_MCWINEH_H
|
||||||
#define LLVM_MC_MCWINEH_H
|
#define LLVM_MC_MCWINEH_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class MCSymbol;
|
class MCSymbol;
|
||||||
|
|
||||||
@@ -23,6 +25,39 @@ struct Instruction {
|
|||||||
Instruction(unsigned Op, MCSymbol *L, unsigned Reg, unsigned Off)
|
Instruction(unsigned Op, MCSymbol *L, unsigned Reg, unsigned Off)
|
||||||
: Label(L), Offset(Off), Register(Reg), Operation(Op) {}
|
: Label(L), Offset(Off), Register(Reg), Operation(Op) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct FrameInfo {
|
||||||
|
const MCSymbol *Begin;
|
||||||
|
const MCSymbol *End;
|
||||||
|
const MCSymbol *ExceptionHandler;
|
||||||
|
const MCSymbol *Function;
|
||||||
|
const MCSymbol *PrologEnd;
|
||||||
|
const MCSymbol *Symbol;
|
||||||
|
|
||||||
|
bool HandlesUnwind;
|
||||||
|
bool HandlesExceptions;
|
||||||
|
|
||||||
|
int LastFrameInst;
|
||||||
|
const FrameInfo *ChainedParent;
|
||||||
|
std::vector<Instruction> Instructions;
|
||||||
|
|
||||||
|
FrameInfo()
|
||||||
|
: Begin(nullptr), End(nullptr), ExceptionHandler(nullptr),
|
||||||
|
Function(nullptr), PrologEnd(nullptr), Symbol(nullptr),
|
||||||
|
HandlesUnwind(false), HandlesExceptions(false), LastFrameInst(-1),
|
||||||
|
ChainedParent(nullptr), Instructions() {}
|
||||||
|
FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel)
|
||||||
|
: Begin(BeginFuncEHLabel), End(nullptr), ExceptionHandler(nullptr),
|
||||||
|
Function(Function), PrologEnd(nullptr), Symbol(nullptr),
|
||||||
|
HandlesUnwind(false), HandlesExceptions(false), LastFrameInst(-1),
|
||||||
|
ChainedParent(nullptr), Instructions() {}
|
||||||
|
FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel,
|
||||||
|
const FrameInfo *ChainedParent)
|
||||||
|
: Begin(BeginFuncEHLabel), End(nullptr), ExceptionHandler(nullptr),
|
||||||
|
Function(Function), PrologEnd(nullptr), Symbol(nullptr),
|
||||||
|
HandlesUnwind(false), HandlesExceptions(false), LastFrameInst(-1),
|
||||||
|
ChainedParent(ChainedParent), Instructions() {}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1109,7 +1109,7 @@ void MCAsmStreamer::EmitWinEHHandlerData() {
|
|||||||
// cause the section switch to be visible in the emitted assembly.
|
// cause the section switch to be visible in the emitted assembly.
|
||||||
// We only do this so the section switch that terminates the handler
|
// We only do this so the section switch that terminates the handler
|
||||||
// data block is visible.
|
// data block is visible.
|
||||||
MCWinFrameInfo *CurFrame = getCurrentWinFrameInfo();
|
WinEH::FrameInfo *CurFrame = getCurrentWinFrameInfo();
|
||||||
StringRef suffix=MCWin64EHUnwindEmitter::GetSectionSuffix(CurFrame->Function);
|
StringRef suffix=MCWin64EHUnwindEmitter::GetSectionSuffix(CurFrame->Function);
|
||||||
const MCSection *xdataSect = getWin64EHTableSection(suffix, getContext());
|
const MCSection *xdataSect = getWin64EHTableSection(suffix, getContext());
|
||||||
if (xdataSect)
|
if (xdataSect)
|
||||||
|
@@ -429,11 +429,11 @@ void MCStreamer::EnsureValidWinFrameInfo() {
|
|||||||
void MCStreamer::EmitWinCFIStartProc(const MCSymbol *Symbol) {
|
void MCStreamer::EmitWinCFIStartProc(const MCSymbol *Symbol) {
|
||||||
if (CurrentWinFrameInfo && !CurrentWinFrameInfo->End)
|
if (CurrentWinFrameInfo && !CurrentWinFrameInfo->End)
|
||||||
report_fatal_error("Starting a function before ending the previous one!");
|
report_fatal_error("Starting a function before ending the previous one!");
|
||||||
MCWinFrameInfo *Frame = new MCWinFrameInfo;
|
|
||||||
Frame->Begin = getContext().CreateTempSymbol();
|
MCSymbol *StartProc = getContext().CreateTempSymbol();
|
||||||
Frame->Function = Symbol;
|
EmitLabel(StartProc);
|
||||||
EmitLabel(Frame->Begin);
|
|
||||||
WinFrameInfos.push_back(Frame);
|
WinFrameInfos.push_back(new WinEH::FrameInfo(Symbol, StartProc));
|
||||||
CurrentWinFrameInfo = WinFrameInfos.back();
|
CurrentWinFrameInfo = WinFrameInfos.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -441,18 +441,20 @@ void MCStreamer::EmitWinCFIEndProc() {
|
|||||||
EnsureValidWinFrameInfo();
|
EnsureValidWinFrameInfo();
|
||||||
if (CurrentWinFrameInfo->ChainedParent)
|
if (CurrentWinFrameInfo->ChainedParent)
|
||||||
report_fatal_error("Not all chained regions terminated!");
|
report_fatal_error("Not all chained regions terminated!");
|
||||||
CurrentWinFrameInfo->End = getContext().CreateTempSymbol();
|
|
||||||
EmitLabel(CurrentWinFrameInfo->End);
|
MCSymbol *Label = getContext().CreateTempSymbol();
|
||||||
|
EmitLabel(Label);
|
||||||
|
CurrentWinFrameInfo->End = Label;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCStreamer::EmitWinCFIStartChained() {
|
void MCStreamer::EmitWinCFIStartChained() {
|
||||||
EnsureValidWinFrameInfo();
|
EnsureValidWinFrameInfo();
|
||||||
MCWinFrameInfo *Frame = new MCWinFrameInfo;
|
|
||||||
Frame->Begin = getContext().CreateTempSymbol();
|
MCSymbol *StartProc = getContext().CreateTempSymbol();
|
||||||
Frame->Function = CurrentWinFrameInfo->Function;
|
EmitLabel(StartProc);
|
||||||
Frame->ChainedParent = CurrentWinFrameInfo;
|
|
||||||
EmitLabel(Frame->Begin);
|
WinFrameInfos.push_back(new WinEH::FrameInfo(CurrentWinFrameInfo->Function,
|
||||||
WinFrameInfos.push_back(Frame);
|
StartProc, CurrentWinFrameInfo));
|
||||||
CurrentWinFrameInfo = WinFrameInfos.back();
|
CurrentWinFrameInfo = WinFrameInfos.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -460,9 +462,13 @@ void MCStreamer::EmitWinCFIEndChained() {
|
|||||||
EnsureValidWinFrameInfo();
|
EnsureValidWinFrameInfo();
|
||||||
if (!CurrentWinFrameInfo->ChainedParent)
|
if (!CurrentWinFrameInfo->ChainedParent)
|
||||||
report_fatal_error("End of a chained region outside a chained region!");
|
report_fatal_error("End of a chained region outside a chained region!");
|
||||||
CurrentWinFrameInfo->End = getContext().CreateTempSymbol();
|
|
||||||
EmitLabel(CurrentWinFrameInfo->End);
|
MCSymbol *Label = getContext().CreateTempSymbol();
|
||||||
CurrentWinFrameInfo = CurrentWinFrameInfo->ChainedParent;
|
EmitLabel(Label);
|
||||||
|
|
||||||
|
CurrentWinFrameInfo->End = Label;
|
||||||
|
CurrentWinFrameInfo =
|
||||||
|
const_cast<WinEH::FrameInfo *>(CurrentWinFrameInfo->ChainedParent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCStreamer::EmitWinEHHandler(const MCSymbol *Sym, bool Unwind,
|
void MCStreamer::EmitWinEHHandler(const MCSymbol *Sym, bool Unwind,
|
||||||
@@ -567,8 +573,11 @@ void MCStreamer::EmitWinCFIPushFrame(bool Code) {
|
|||||||
|
|
||||||
void MCStreamer::EmitWinCFIEndProlog() {
|
void MCStreamer::EmitWinCFIEndProlog() {
|
||||||
EnsureValidWinFrameInfo();
|
EnsureValidWinFrameInfo();
|
||||||
CurrentWinFrameInfo->PrologEnd = getContext().CreateTempSymbol();
|
|
||||||
EmitLabel(CurrentWinFrameInfo->PrologEnd);
|
MCSymbol *Label = getContext().CreateTempSymbol();
|
||||||
|
EmitLabel(Label);
|
||||||
|
|
||||||
|
CurrentWinFrameInfo->PrologEnd = Label;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol) {
|
void MCStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol) {
|
||||||
|
@@ -56,7 +56,7 @@ static void EmitAbsDifference(MCStreamer &Streamer, const MCSymbol *LHS,
|
|||||||
Streamer.EmitAbsValue(Diff, 1);
|
Streamer.EmitAbsValue(Diff, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EmitUnwindCode(MCStreamer &streamer, MCSymbol *begin,
|
static void EmitUnwindCode(MCStreamer &streamer, const MCSymbol *begin,
|
||||||
WinEH::Instruction &inst) {
|
WinEH::Instruction &inst) {
|
||||||
uint8_t b2;
|
uint8_t b2;
|
||||||
uint16_t w;
|
uint16_t w;
|
||||||
@@ -136,7 +136,7 @@ static void EmitSymbolRefWithOfs(MCStreamer &streamer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void EmitRuntimeFunction(MCStreamer &streamer,
|
static void EmitRuntimeFunction(MCStreamer &streamer,
|
||||||
const MCWinFrameInfo *info) {
|
const WinEH::FrameInfo *info) {
|
||||||
MCContext &context = streamer.getContext();
|
MCContext &context = streamer.getContext();
|
||||||
|
|
||||||
streamer.EmitValueToAlignment(4);
|
streamer.EmitValueToAlignment(4);
|
||||||
@@ -147,14 +147,17 @@ static void EmitRuntimeFunction(MCStreamer &streamer,
|
|||||||
context), 4);
|
context), 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EmitUnwindInfo(MCStreamer &streamer, MCWinFrameInfo *info) {
|
static void EmitUnwindInfo(MCStreamer &streamer, WinEH::FrameInfo *info) {
|
||||||
// If this UNWIND_INFO already has a symbol, it's already been emitted.
|
// If this UNWIND_INFO already has a symbol, it's already been emitted.
|
||||||
if (info->Symbol) return;
|
if (info->Symbol)
|
||||||
|
return;
|
||||||
|
|
||||||
MCContext &context = streamer.getContext();
|
MCContext &context = streamer.getContext();
|
||||||
|
MCSymbol *Label = context.CreateTempSymbol();
|
||||||
|
|
||||||
streamer.EmitValueToAlignment(4);
|
streamer.EmitValueToAlignment(4);
|
||||||
info->Symbol = context.CreateTempSymbol();
|
streamer.EmitLabel(Label);
|
||||||
streamer.EmitLabel(info->Symbol);
|
info->Symbol = Label;
|
||||||
|
|
||||||
// Upper 3 bits are the version number (currently 1).
|
// Upper 3 bits are the version number (currently 1).
|
||||||
uint8_t flags = 0x01;
|
uint8_t flags = 0x01;
|
||||||
@@ -256,7 +259,7 @@ static const MCSection *getWin64EHFuncTableSection(StringRef suffix,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MCWin64EHUnwindEmitter::EmitUnwindInfo(MCStreamer &streamer,
|
void MCWin64EHUnwindEmitter::EmitUnwindInfo(MCStreamer &streamer,
|
||||||
MCWinFrameInfo *info) {
|
WinEH::FrameInfo *info) {
|
||||||
// Switch sections (the static function above is meant to be called from
|
// Switch sections (the static function above is meant to be called from
|
||||||
// here and from Emit().
|
// here and from Emit().
|
||||||
MCContext &context = streamer.getContext();
|
MCContext &context = streamer.getContext();
|
||||||
|
Reference in New Issue
Block a user