1 //===-- RISCVELFStreamer.h - RISC-V ELF Target Streamer ---------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVELFSTREAMER_H
10 #define LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVELFSTREAMER_H
12 #include "RISCVTargetStreamer.h"
13 #include "llvm/MC/MCELFStreamer.h"
17 class RISCVELFStreamer
: public MCELFStreamer
{
18 void reset() override
;
19 void emitDataMappingSymbol();
20 void emitInstructionsMappingSymbol();
21 void emitMappingSymbol(StringRef Name
);
23 enum ElfMappingSymbol
{ EMS_None
, EMS_Instructions
, EMS_Data
};
25 int64_t MappingSymbolCounter
= 0;
26 DenseMap
<const MCSection
*, ElfMappingSymbol
> LastMappingSymbols
;
27 ElfMappingSymbol LastEMS
= EMS_None
;
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
)) {}
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
;
44 class RISCVTargetELFStreamer
: public RISCVTargetStreamer
{
46 StringRef CurrentVendor
;
48 MCSection
*AttributeSection
= nullptr;
49 const MCSubtargetInfo
&STI
;
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
;
57 void reset() override
;
60 RISCVELFStreamer
&getStreamer();
61 RISCVTargetELFStreamer(MCStreamer
&S
, const MCSubtargetInfo
&STI
);
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
;
73 void finish() override
;
76 MCELFStreamer
*createRISCVELFStreamer(MCContext
&C
,
77 std::unique_ptr
<MCAsmBackend
> MAB
,
78 std::unique_ptr
<MCObjectWriter
> MOW
,
79 std::unique_ptr
<MCCodeEmitter
> MCE
,