1//===-- X86WinCOFFStreamer.cpp - X86 Target WinCOFF Streamer ----*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "X86MCTargetDesc.h"
11#include "llvm/MC/MCWin64EH.h"
12#include "llvm/MC/MCWinCOFFStreamer.h"
13
14using namespace llvm;
15
16namespace {
17class X86WinCOFFStreamer : public MCWinCOFFStreamer {
18  Win64EH::UnwindEmitter EHStreamer;
19public:
20  X86WinCOFFStreamer(MCContext &C, MCAsmBackend &AB, MCCodeEmitter *CE,
21                     raw_pwrite_stream &OS)
22      : MCWinCOFFStreamer(C, AB, *CE, OS) {}
23
24  void EmitWinEHHandlerData() override;
25  void EmitWindowsUnwindTables() override;
26  void FinishImpl() override;
27};
28
29void X86WinCOFFStreamer::EmitWinEHHandlerData() {
30  MCStreamer::EmitWinEHHandlerData();
31
32  // We have to emit the unwind info now, because this directive
33  // actually switches to the .xdata section!
34  EHStreamer.EmitUnwindInfo(*this, getCurrentWinFrameInfo());
35}
36
37void X86WinCOFFStreamer::EmitWindowsUnwindTables() {
38  if (!getNumWinFrameInfos())
39    return;
40  EHStreamer.Emit(*this);
41}
42
43void X86WinCOFFStreamer::FinishImpl() {
44  EmitFrames(nullptr);
45  EmitWindowsUnwindTables();
46
47  MCWinCOFFStreamer::FinishImpl();
48}
49}
50
51MCStreamer *llvm::createX86WinCOFFStreamer(MCContext &C, MCAsmBackend &AB,
52                                           raw_pwrite_stream &OS,
53                                           MCCodeEmitter *CE, bool RelaxAll,
54                                           bool IncrementalLinkerCompatible) {
55  X86WinCOFFStreamer *S = new X86WinCOFFStreamer(C, AB, CE, OS);
56  S->getAssembler().setRelaxAll(RelaxAll);
57  S->getAssembler().setIncrementalLinkerCompatible(IncrementalLinkerCompatible);
58  return S;
59}
60
61