xref: /llvm-project/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h (revision 1753008bbbc317511c07ed30eef21e0494d63de8)
1 //===-- RISCVELFStreamer.h - RISC-V ELF Target 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 #ifndef LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVELFSTREAMER_H
10 #define LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVELFSTREAMER_H
11 
12 #include "RISCVTargetStreamer.h"
13 #include "llvm/MC/MCELFStreamer.h"
14 
15 namespace llvm {
16 
17 class RISCVELFStreamer : public MCELFStreamer {
18   void reset() override;
19   void emitDataMappingSymbol();
20   void emitInstructionsMappingSymbol();
21   void emitMappingSymbol(StringRef Name);
22 
23   enum ElfMappingSymbol { EMS_None, EMS_Instructions, EMS_Data };
24 
25   DenseMap<const MCSection *, ElfMappingSymbol> LastMappingSymbols;
26   ElfMappingSymbol LastEMS = EMS_None;
27 
28 public:
29   RISCVELFStreamer(MCContext &C, std::unique_ptr<MCAsmBackend> MAB,
30                    std::unique_ptr<MCObjectWriter> MOW,
31                    std::unique_ptr<MCCodeEmitter> MCE)
32       : MCELFStreamer(C, std::move(MAB), std::move(MOW), std::move(MCE)) {}
33 
34   void changeSection(MCSection *Section, uint32_t Subsection) override;
35   void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
36   void emitBytes(StringRef Data) override;
37   void emitFill(const MCExpr &NumBytes, uint64_t FillValue, SMLoc Loc) override;
38   void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override;
39 };
40 
41 class RISCVTargetELFStreamer : public RISCVTargetStreamer {
42 private:
43   StringRef CurrentVendor;
44 
45   MCSection *AttributeSection = nullptr;
46 
47   void emitAttribute(unsigned Attribute, unsigned Value) override;
48   void emitTextAttribute(unsigned Attribute, StringRef String) override;
49   void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
50                             StringRef StringValue) override;
51   void finishAttributeSection() override;
52 
53   void reset() override;
54 
55 public:
56   RISCVELFStreamer &getStreamer();
57   RISCVTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI);
58 
59   void emitDirectiveOptionPush() override;
60   void emitDirectiveOptionPop() override;
61   void emitDirectiveOptionPIC() override;
62   void emitDirectiveOptionNoPIC() override;
63   void emitDirectiveOptionRVC() override;
64   void emitDirectiveOptionNoRVC() override;
65   void emitDirectiveOptionRelax() override;
66   void emitDirectiveOptionNoRelax() override;
67   void emitDirectiveVariantCC(MCSymbol &Symbol) override;
68 
69   void finish() override;
70 };
71 
72 MCELFStreamer *createRISCVELFStreamer(MCContext &C,
73                                       std::unique_ptr<MCAsmBackend> MAB,
74                                       std::unique_ptr<MCObjectWriter> MOW,
75                                       std::unique_ptr<MCCodeEmitter> MCE);
76 } // namespace llvm
77 
78 #endif // LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVELFSTREAMER_H
79