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
14 using namespace llvm;
15
16 namespace {
17 class X86WinCOFFStreamer : public MCWinCOFFStreamer {
18 Win64EH::UnwindEmitter EHStreamer;
19 public:
X86WinCOFFStreamer(MCContext & C,MCAsmBackend & AB,MCCodeEmitter * CE,raw_pwrite_stream & OS)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
EmitWinEHHandlerData()29 void 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
EmitWindowsUnwindTables()37 void X86WinCOFFStreamer::EmitWindowsUnwindTables() {
38 if (!getNumWinFrameInfos())
39 return;
40 EHStreamer.Emit(*this);
41 }
42
FinishImpl()43 void X86WinCOFFStreamer::FinishImpl() {
44 EmitFrames(nullptr);
45 EmitWindowsUnwindTables();
46
47 MCWinCOFFStreamer::FinishImpl();
48 }
49 }
50
createX86WinCOFFStreamer(MCContext & C,MCAsmBackend & AB,raw_pwrite_stream & OS,MCCodeEmitter * CE,bool RelaxAll)51 MCStreamer *llvm::createX86WinCOFFStreamer(MCContext &C, MCAsmBackend &AB,
52 raw_pwrite_stream &OS,
53 MCCodeEmitter *CE, bool RelaxAll) {
54 X86WinCOFFStreamer *S = new X86WinCOFFStreamer(C, AB, CE, OS);
55 S->getAssembler().setRelaxAll(RelaxAll);
56 return S;
57 }
58
59