xref: /freebsd-src/contrib/llvm-project/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h (revision aa1a8ff2d6dbc51ef058f46f3db5a8bb77967145)
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   const MCSubtargetInfo &STI;
50 
51   void emitAttribute(unsigned Attribute, unsigned Value) override;
52   void emitTextAttribute(unsigned Attribute, StringRef String) override;
53   void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
54                             StringRef StringValue) override;
55   void finishAttributeSection() override;
56 
57   void reset() override;
58 
59 public:
60   RISCVELFStreamer &getStreamer();
61   RISCVTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI);
62 
63   void emitDirectiveOptionPush() override;
64   void emitDirectiveOptionPop() override;
65   void emitDirectiveOptionPIC() override;
66   void emitDirectiveOptionNoPIC() override;
67   void emitDirectiveOptionRVC() override;
68   void emitDirectiveOptionNoRVC() override;
69   void emitDirectiveOptionRelax() override;
70   void emitDirectiveOptionNoRelax() override;
71   void emitDirectiveVariantCC(MCSymbol &Symbol) override;
72 
73   void finish() override;
74 };
75 
76 MCELFStreamer *createRISCVELFStreamer(MCContext &C,
77                                       std::unique_ptr<MCAsmBackend> MAB,
78                                       std::unique_ptr<MCObjectWriter> MOW,
79                                       std::unique_ptr<MCCodeEmitter> MCE,
80                                       bool RelaxAll);
81 }
82 #endif
83