xref: /freebsd/contrib/llvm-project/llvm/lib/Target/X86/MCTargetDesc/X86WinCOFFStreamer.cpp (revision dc318a4ffabcbfa23bb56a33403aad36e6de30af)
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/MCCodeEmitter.h"
13 #include "llvm/MC/MCObjectWriter.h"
14 #include "llvm/MC/MCWin64EH.h"
15 #include "llvm/MC/MCWinCOFFStreamer.h"
16 
17 using namespace llvm;
18 
19 namespace {
20 class X86WinCOFFStreamer : public MCWinCOFFStreamer {
21   Win64EH::UnwindEmitter EHStreamer;
22 public:
23   X86WinCOFFStreamer(MCContext &C, std::unique_ptr<MCAsmBackend> AB,
24                      std::unique_ptr<MCCodeEmitter> CE,
25                      std::unique_ptr<MCObjectWriter> OW)
26       : MCWinCOFFStreamer(C, std::move(AB), std::move(CE), std::move(OW)) {}
27 
28   void EmitWinEHHandlerData(SMLoc Loc) override;
29   void EmitWindowsUnwindTables() override;
30   void EmitCVFPOData(const MCSymbol *ProcSym, SMLoc Loc) override;
31   void finishImpl() override;
32 };
33 
34 void X86WinCOFFStreamer::EmitWinEHHandlerData(SMLoc Loc) {
35   MCStreamer::EmitWinEHHandlerData(Loc);
36 
37   // We have to emit the unwind info now, because this directive
38   // actually switches to the .xdata section.
39   if (WinEH::FrameInfo *CurFrame = getCurrentWinFrameInfo())
40     EHStreamer.EmitUnwindInfo(*this, CurFrame);
41 }
42 
43 void X86WinCOFFStreamer::EmitWindowsUnwindTables() {
44   if (!getNumWinFrameInfos())
45     return;
46   EHStreamer.Emit(*this);
47 }
48 
49 void X86WinCOFFStreamer::EmitCVFPOData(const MCSymbol *ProcSym, SMLoc Loc) {
50   X86TargetStreamer *XTS =
51       static_cast<X86TargetStreamer *>(getTargetStreamer());
52   XTS->emitFPOData(ProcSym, Loc);
53 }
54 
55 void X86WinCOFFStreamer::finishImpl() {
56   emitFrames(nullptr);
57   EmitWindowsUnwindTables();
58 
59   MCWinCOFFStreamer::finishImpl();
60 }
61 }
62 
63 MCStreamer *llvm::createX86WinCOFFStreamer(MCContext &C,
64                                            std::unique_ptr<MCAsmBackend> &&AB,
65                                            std::unique_ptr<MCObjectWriter> &&OW,
66                                            std::unique_ptr<MCCodeEmitter> &&CE,
67                                            bool RelaxAll,
68                                            bool IncrementalLinkerCompatible) {
69   X86WinCOFFStreamer *S =
70       new X86WinCOFFStreamer(C, std::move(AB), std::move(CE), std::move(OW));
71   S->getAssembler().setRelaxAll(RelaxAll);
72   S->getAssembler().setIncrementalLinkerCompatible(IncrementalLinkerCompatible);
73   return S;
74 }
75 
76