| 1 | //===-- RISCVTargetStreamer.h - RISC-V 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_RISCVTARGETSTREAMER_H |
| 10 | #define LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVTARGETSTREAMER_H |
| 11 | |
| 12 | #include "RISCV.h" |
| 13 | #include "llvm/MC/MCStreamer.h" |
| 14 | #include "llvm/MC/MCSubtargetInfo.h" |
| 15 | |
| 16 | namespace llvm { |
| 17 | |
| 18 | class formatted_raw_ostream; |
| 19 | |
| 20 | enum class RISCVOptionArchArgType { |
| 21 | Full, |
| 22 | Plus, |
| 23 | Minus, |
| 24 | }; |
| 25 | |
| 26 | struct RISCVOptionArchArg { |
| 27 | RISCVOptionArchArgType Type; |
| 28 | std::string Value; |
| 29 | |
| 30 | RISCVOptionArchArg(RISCVOptionArchArgType Type, std::string Value) |
| 31 | : Type(Type), Value(Value) {} |
| 32 | }; |
| 33 | |
| 34 | class RISCVTargetStreamer : public MCTargetStreamer { |
| 35 | RISCVABI::ABI TargetABI = RISCVABI::ABI_Unknown; |
| 36 | bool HasRVC = false; |
| 37 | bool HasTSO = false; |
| 38 | |
| 39 | public: |
| 40 | RISCVTargetStreamer(MCStreamer &S); |
| 41 | void finish() override; |
| 42 | virtual void reset(); |
| 43 | |
| 44 | virtual void emitDirectiveOptionArch(ArrayRef<RISCVOptionArchArg> Args); |
| 45 | virtual void emitDirectiveOptionExact(); |
| 46 | virtual void emitDirectiveOptionNoExact(); |
| 47 | virtual void emitDirectiveOptionPIC(); |
| 48 | virtual void emitDirectiveOptionNoPIC(); |
| 49 | virtual void emitDirectiveOptionPop(); |
| 50 | virtual void emitDirectiveOptionPush(); |
| 51 | virtual void emitDirectiveOptionRelax(); |
| 52 | virtual void emitDirectiveOptionNoRelax(); |
| 53 | virtual void emitDirectiveOptionRVC(); |
| 54 | virtual void emitDirectiveOptionNoRVC(); |
| 55 | virtual void emitDirectiveVariantCC(MCSymbol &Symbol); |
| 56 | virtual void emitAttribute(unsigned Attribute, unsigned Value); |
| 57 | virtual void finishAttributeSection(); |
| 58 | virtual void emitTextAttribute(unsigned Attribute, StringRef String); |
| 59 | virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue, |
| 60 | StringRef StringValue); |
| 61 | void emitNoteGnuPropertySection(const uint32_t Feature1And); |
| 62 | |
| 63 | void emitTargetAttributes(const MCSubtargetInfo &STI, bool EmitStackAlign); |
| 64 | void setTargetABI(RISCVABI::ABI ABI); |
| 65 | RISCVABI::ABI getTargetABI() const { return TargetABI; } |
| 66 | void setFlagsFromFeatures(const MCSubtargetInfo &STI); |
| 67 | bool hasRVC() const { return HasRVC; } |
| 68 | bool hasTSO() const { return HasTSO; } |
| 69 | }; |
| 70 | |
| 71 | // This part is for ascii assembly output |
| 72 | class RISCVTargetAsmStreamer : public RISCVTargetStreamer { |
| 73 | formatted_raw_ostream &OS; |
| 74 | |
| 75 | void finishAttributeSection() override; |
| 76 | void emitAttribute(unsigned Attribute, unsigned Value) override; |
| 77 | void emitTextAttribute(unsigned Attribute, StringRef String) override; |
| 78 | void emitIntTextAttribute(unsigned Attribute, unsigned IntValue, |
| 79 | StringRef StringValue) override; |
| 80 | |
| 81 | public: |
| 82 | RISCVTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS); |
| 83 | |
| 84 | void emitDirectiveOptionArch(ArrayRef<RISCVOptionArchArg> Args) override; |
| 85 | void emitDirectiveOptionExact() override; |
| 86 | void emitDirectiveOptionNoExact() override; |
| 87 | void emitDirectiveOptionPIC() override; |
| 88 | void emitDirectiveOptionNoPIC() override; |
| 89 | void emitDirectiveOptionPop() override; |
| 90 | void emitDirectiveOptionPush() override; |
| 91 | void emitDirectiveOptionRelax() override; |
| 92 | void emitDirectiveOptionNoRelax() override; |
| 93 | void emitDirectiveOptionRVC() override; |
| 94 | void emitDirectiveOptionNoRVC() override; |
| 95 | void emitDirectiveVariantCC(MCSymbol &Symbol) override; |
| 96 | }; |
| 97 | |
| 98 | } |
| 99 | #endif |
| 100 | |