xref: /freebsd/contrib/llvm-project/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
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 using 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:
RISCVELFStreamer(MCContext & C,std::unique_ptr<MCAsmBackend> MAB,std::unique_ptr<MCObjectWriter> MOW,std::unique_ptr<MCCodeEmitter> MCE)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 namespace llvm {
42 
43 class RISCVTargetELFStreamer : public RISCVTargetStreamer {
44 private:
45   StringRef CurrentVendor;
46 
47   MCSection *AttributeSection = nullptr;
48 
49   void emitAttribute(unsigned Attribute, unsigned Value) override;
50   void emitTextAttribute(unsigned Attribute, StringRef String) override;
51   void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
52                             StringRef StringValue) override;
53   void finishAttributeSection() override;
54 
55   void reset() override;
56 
57 public:
58   RISCVELFStreamer &getStreamer();
59   RISCVTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI);
60 
61   void emitDirectiveOptionPush() override;
62   void emitDirectiveOptionPop() override;
63   void emitDirectiveOptionPIC() override;
64   void emitDirectiveOptionNoPIC() override;
65   void emitDirectiveOptionRVC() override;
66   void emitDirectiveOptionNoRVC() override;
67   void emitDirectiveOptionRelax() override;
68   void emitDirectiveOptionNoRelax() override;
69   void emitDirectiveVariantCC(MCSymbol &Symbol) override;
70 
71   void finish() override;
72 };
73 
74 MCELFStreamer *createRISCVELFStreamer(MCContext &C,
75                                       std::unique_ptr<MCAsmBackend> MAB,
76                                       std::unique_ptr<MCObjectWriter> MOW,
77                                       std::unique_ptr<MCCodeEmitter> MCE);
78 }
79 #endif
80