X86WinCOFFStreamer.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #include "X86MCTargetDesc.h"
  9. #include "X86TargetStreamer.h"
  10. #include "llvm/MC/MCAsmBackend.h"
  11. #include "llvm/MC/MCAssembler.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. using namespace llvm;
  17. namespace {
  18. class X86WinCOFFStreamer : public MCWinCOFFStreamer {
  19. Win64EH::UnwindEmitter EHStreamer;
  20. public:
  21. X86WinCOFFStreamer(MCContext &C, std::unique_ptr<MCAsmBackend> AB,
  22. std::unique_ptr<MCCodeEmitter> CE,
  23. std::unique_ptr<MCObjectWriter> OW)
  24. : MCWinCOFFStreamer(C, std::move(AB), std::move(CE), std::move(OW)) {}
  25. void emitWinEHHandlerData(SMLoc Loc) override;
  26. void emitWindowsUnwindTables(WinEH::FrameInfo *Frame) override;
  27. void emitWindowsUnwindTables() override;
  28. void emitCVFPOData(const MCSymbol *ProcSym, SMLoc Loc) override;
  29. void finishImpl() override;
  30. };
  31. void X86WinCOFFStreamer::emitWinEHHandlerData(SMLoc Loc) {
  32. MCStreamer::emitWinEHHandlerData(Loc);
  33. // We have to emit the unwind info now, because this directive
  34. // actually switches to the .xdata section.
  35. if (WinEH::FrameInfo *CurFrame = getCurrentWinFrameInfo())
  36. EHStreamer.EmitUnwindInfo(*this, CurFrame, /* HandlerData = */ true);
  37. }
  38. void X86WinCOFFStreamer::emitWindowsUnwindTables(WinEH::FrameInfo *Frame) {
  39. EHStreamer.EmitUnwindInfo(*this, Frame, /* HandlerData = */ false);
  40. }
  41. void X86WinCOFFStreamer::emitWindowsUnwindTables() {
  42. if (!getNumWinFrameInfos())
  43. return;
  44. EHStreamer.Emit(*this);
  45. }
  46. void X86WinCOFFStreamer::emitCVFPOData(const MCSymbol *ProcSym, SMLoc Loc) {
  47. X86TargetStreamer *XTS =
  48. static_cast<X86TargetStreamer *>(getTargetStreamer());
  49. XTS->emitFPOData(ProcSym, Loc);
  50. }
  51. void X86WinCOFFStreamer::finishImpl() {
  52. emitFrames(nullptr);
  53. emitWindowsUnwindTables();
  54. MCWinCOFFStreamer::finishImpl();
  55. }
  56. } // namespace
  57. MCStreamer *llvm::createX86WinCOFFStreamer(MCContext &C,
  58. std::unique_ptr<MCAsmBackend> &&AB,
  59. std::unique_ptr<MCObjectWriter> &&OW,
  60. std::unique_ptr<MCCodeEmitter> &&CE,
  61. bool RelaxAll,
  62. bool IncrementalLinkerCompatible) {
  63. X86WinCOFFStreamer *S =
  64. new X86WinCOFFStreamer(C, std::move(AB), std::move(CE), std::move(OW));
  65. S->getAssembler().setRelaxAll(RelaxAll);
  66. S->getAssembler().setIncrementalLinkerCompatible(IncrementalLinkerCompatible);
  67. return S;
  68. }