1 //===-- X86WinCOFFStreamer.cpp - X86 Target WinCOFF Streamer ----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "X86MCTargetDesc.h"
10 #include "X86TargetStreamer.h"
11 #include "llvm/MC/MCAsmBackend.h"
12 #include "llvm/MC/MCAssembler.h"
13 #include "llvm/MC/MCCodeEmitter.h"
14 #include "llvm/MC/MCObjectWriter.h"
15 #include "llvm/MC/MCWin64EH.h"
16 #include "llvm/MC/MCWinCOFFStreamer.h"
17
18 using namespace llvm;
19
20 namespace {
21 class X86WinCOFFStreamer : public MCWinCOFFStreamer {
22 Win64EH::UnwindEmitter EHStreamer;
23 public:
X86WinCOFFStreamer(MCContext & C,std::unique_ptr<MCAsmBackend> AB,std::unique_ptr<MCCodeEmitter> CE,std::unique_ptr<MCObjectWriter> OW)24 X86WinCOFFStreamer(MCContext &C, std::unique_ptr<MCAsmBackend> AB,
25 std::unique_ptr<MCCodeEmitter> CE,
26 std::unique_ptr<MCObjectWriter> OW)
27 : MCWinCOFFStreamer(C, std::move(AB), std::move(CE), std::move(OW)) {}
28
29 void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
30 void emitWinEHHandlerData(SMLoc Loc) override;
31 void emitWindowsUnwindTables(WinEH::FrameInfo *Frame) override;
32 void emitWindowsUnwindTables() override;
33 void emitCVFPOData(const MCSymbol *ProcSym, SMLoc Loc) override;
34 void finishImpl() override;
35 };
36
emitInstruction(const MCInst & Inst,const MCSubtargetInfo & STI)37 void X86WinCOFFStreamer::emitInstruction(const MCInst &Inst,
38 const MCSubtargetInfo &STI) {
39 X86_MC::emitInstruction(*this, Inst, STI);
40 }
41
emitWinEHHandlerData(SMLoc Loc)42 void X86WinCOFFStreamer::emitWinEHHandlerData(SMLoc Loc) {
43 MCStreamer::emitWinEHHandlerData(Loc);
44
45 // We have to emit the unwind info now, because this directive
46 // actually switches to the .xdata section.
47 if (WinEH::FrameInfo *CurFrame = getCurrentWinFrameInfo())
48 EHStreamer.EmitUnwindInfo(*this, CurFrame, /* HandlerData = */ true);
49 }
50
emitWindowsUnwindTables(WinEH::FrameInfo * Frame)51 void X86WinCOFFStreamer::emitWindowsUnwindTables(WinEH::FrameInfo *Frame) {
52 EHStreamer.EmitUnwindInfo(*this, Frame, /* HandlerData = */ false);
53 }
54
emitWindowsUnwindTables()55 void X86WinCOFFStreamer::emitWindowsUnwindTables() {
56 if (!getNumWinFrameInfos())
57 return;
58 EHStreamer.Emit(*this);
59 }
60
emitCVFPOData(const MCSymbol * ProcSym,SMLoc Loc)61 void X86WinCOFFStreamer::emitCVFPOData(const MCSymbol *ProcSym, SMLoc Loc) {
62 X86TargetStreamer *XTS =
63 static_cast<X86TargetStreamer *>(getTargetStreamer());
64 XTS->emitFPOData(ProcSym, Loc);
65 }
66
finishImpl()67 void X86WinCOFFStreamer::finishImpl() {
68 emitFrames(nullptr);
69 emitWindowsUnwindTables();
70
71 MCWinCOFFStreamer::finishImpl();
72 }
73 } // namespace
74
75 MCStreamer *
createX86WinCOFFStreamer(MCContext & C,std::unique_ptr<MCAsmBackend> && AB,std::unique_ptr<MCObjectWriter> && OW,std::unique_ptr<MCCodeEmitter> && CE)76 llvm::createX86WinCOFFStreamer(MCContext &C, std::unique_ptr<MCAsmBackend> &&AB,
77 std::unique_ptr<MCObjectWriter> &&OW,
78 std::unique_ptr<MCCodeEmitter> &&CE) {
79 return new X86WinCOFFStreamer(C, std::move(AB), std::move(CE), std::move(OW));
80 }
81