xref: /freebsd/contrib/llvm-project/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h (revision 357378bbdedf24ce2b90e9bd831af4a9db3ec70a)
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   int64_t MappingSymbolCounter = 0;
26   DenseMap<const MCSection *, ElfMappingSymbol> LastMappingSymbols;
27   ElfMappingSymbol LastEMS = EMS_None;
28 
29 public:
30   RISCVELFStreamer(MCContext &C, std::unique_ptr<MCAsmBackend> MAB,
31                    std::unique_ptr<MCObjectWriter> MOW,
32                    std::unique_ptr<MCCodeEmitter> MCE)
33       : MCELFStreamer(C, std::move(MAB), std::move(MOW), std::move(MCE)) {}
34 
35   void changeSection(MCSection *Section, const MCExpr *Subsection) override;
36   void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
37   void emitBytes(StringRef Data) override;
38   void emitFill(const MCExpr &NumBytes, uint64_t FillValue, SMLoc Loc) override;
39   void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override;
40 };
41 
42 namespace llvm {
43 
44 class RISCVTargetELFStreamer : public RISCVTargetStreamer {
45 private:
46   StringRef CurrentVendor;
47 
48   MCSection *AttributeSection = nullptr;
49 
50   void emitAttribute(unsigned Attribute, unsigned Value) override;
51   void emitTextAttribute(unsigned Attribute, StringRef String) override;
52   void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
53                             StringRef StringValue) override;
54   void finishAttributeSection() override;
55 
56   void reset() override;
57 
58 public:
59   RISCVELFStreamer &getStreamer();
60   RISCVTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI);
61 
62   void emitDirectiveOptionPush() override;
63   void emitDirectiveOptionPop() override;
64   void emitDirectiveOptionPIC() override;
65   void emitDirectiveOptionNoPIC() override;
66   void emitDirectiveOptionRVC() override;
67   void emitDirectiveOptionNoRVC() override;
68   void emitDirectiveOptionRelax() override;
69   void emitDirectiveOptionNoRelax() override;
70   void emitDirectiveVariantCC(MCSymbol &Symbol) override;
71 
72   void finish() override;
73 };
74 
75 MCELFStreamer *createRISCVELFStreamer(MCContext &C,
76                                       std::unique_ptr<MCAsmBackend> MAB,
77                                       std::unique_ptr<MCObjectWriter> MOW,
78                                       std::unique_ptr<MCCodeEmitter> MCE,
79                                       bool RelaxAll);
80 }
81 #endif
82