/src/llvm-project/llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- RISCVTargetStreamer.cpp - RISC-V Target Streamer Methods ----------===// |
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 | | // This file provides RISC-V specific target streamer methods. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #include "RISCVTargetStreamer.h" |
14 | | #include "RISCVBaseInfo.h" |
15 | | #include "RISCVMCTargetDesc.h" |
16 | | #include "llvm/MC/MCSymbol.h" |
17 | | #include "llvm/Support/FormattedStream.h" |
18 | | #include "llvm/Support/RISCVAttributes.h" |
19 | | #include "llvm/Support/RISCVISAInfo.h" |
20 | | |
21 | | using namespace llvm; |
22 | | |
23 | 6.24k | RISCVTargetStreamer::RISCVTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {} |
24 | | |
25 | 6.24k | void RISCVTargetStreamer::finish() { finishAttributeSection(); } |
26 | 0 | void RISCVTargetStreamer::reset() {} |
27 | | |
28 | 0 | void RISCVTargetStreamer::emitDirectiveOptionPush() {} |
29 | 0 | void RISCVTargetStreamer::emitDirectiveOptionPop() {} |
30 | 0 | void RISCVTargetStreamer::emitDirectiveOptionPIC() {} |
31 | 0 | void RISCVTargetStreamer::emitDirectiveOptionNoPIC() {} |
32 | 0 | void RISCVTargetStreamer::emitDirectiveOptionRVC() {} |
33 | 0 | void RISCVTargetStreamer::emitDirectiveOptionNoRVC() {} |
34 | 0 | void RISCVTargetStreamer::emitDirectiveOptionRelax() {} |
35 | 0 | void RISCVTargetStreamer::emitDirectiveOptionNoRelax() {} |
36 | | void RISCVTargetStreamer::emitDirectiveOptionArch( |
37 | 0 | ArrayRef<RISCVOptionArchArg> Args) {} |
38 | 0 | void RISCVTargetStreamer::emitDirectiveVariantCC(MCSymbol &Symbol) {} |
39 | 6.24k | void RISCVTargetStreamer::emitAttribute(unsigned Attribute, unsigned Value) {} |
40 | 12.4k | void RISCVTargetStreamer::finishAttributeSection() {} |
41 | | void RISCVTargetStreamer::emitTextAttribute(unsigned Attribute, |
42 | 6.24k | StringRef String) {} |
43 | | void RISCVTargetStreamer::emitIntTextAttribute(unsigned Attribute, |
44 | | unsigned IntValue, |
45 | 0 | StringRef StringValue) {} |
46 | 0 | void RISCVTargetStreamer::setTargetABI(RISCVABI::ABI ABI) { |
47 | 0 | assert(ABI != RISCVABI::ABI_Unknown && "Improperly initialized target ABI"); |
48 | 0 | TargetABI = ABI; |
49 | 0 | } |
50 | | |
51 | | void RISCVTargetStreamer::emitTargetAttributes(const MCSubtargetInfo &STI, |
52 | 6.24k | bool EmitStackAlign) { |
53 | 6.24k | if (EmitStackAlign) { |
54 | 6.24k | if (TargetABI == RISCVABI::ABI_ILP32E) |
55 | 0 | emitAttribute(RISCVAttrs::STACK_ALIGN, RISCVAttrs::ALIGN_4); |
56 | 6.24k | else if (TargetABI == RISCVABI::ABI_LP64E) |
57 | 0 | emitAttribute(RISCVAttrs::STACK_ALIGN, RISCVAttrs::ALIGN_8); |
58 | 6.24k | else |
59 | 6.24k | emitAttribute(RISCVAttrs::STACK_ALIGN, RISCVAttrs::ALIGN_16); |
60 | 6.24k | } |
61 | | |
62 | 6.24k | auto ParseResult = RISCVFeatures::parseFeatureBits( |
63 | 6.24k | STI.hasFeature(RISCV::Feature64Bit), STI.getFeatureBits()); |
64 | 6.24k | if (!ParseResult) { |
65 | 0 | report_fatal_error(ParseResult.takeError()); |
66 | 6.24k | } else { |
67 | 6.24k | auto &ISAInfo = *ParseResult; |
68 | 6.24k | emitTextAttribute(RISCVAttrs::ARCH, ISAInfo->toString()); |
69 | 6.24k | } |
70 | 6.24k | } |
71 | | |
72 | | // This part is for ascii assembly output |
73 | | RISCVTargetAsmStreamer::RISCVTargetAsmStreamer(MCStreamer &S, |
74 | | formatted_raw_ostream &OS) |
75 | 0 | : RISCVTargetStreamer(S), OS(OS) {} |
76 | | |
77 | 0 | void RISCVTargetAsmStreamer::emitDirectiveOptionPush() { |
78 | 0 | OS << "\t.option\tpush\n"; |
79 | 0 | } |
80 | | |
81 | 0 | void RISCVTargetAsmStreamer::emitDirectiveOptionPop() { |
82 | 0 | OS << "\t.option\tpop\n"; |
83 | 0 | } |
84 | | |
85 | 0 | void RISCVTargetAsmStreamer::emitDirectiveOptionPIC() { |
86 | 0 | OS << "\t.option\tpic\n"; |
87 | 0 | } |
88 | | |
89 | 0 | void RISCVTargetAsmStreamer::emitDirectiveOptionNoPIC() { |
90 | 0 | OS << "\t.option\tnopic\n"; |
91 | 0 | } |
92 | | |
93 | 0 | void RISCVTargetAsmStreamer::emitDirectiveOptionRVC() { |
94 | 0 | OS << "\t.option\trvc\n"; |
95 | 0 | } |
96 | | |
97 | 0 | void RISCVTargetAsmStreamer::emitDirectiveOptionNoRVC() { |
98 | 0 | OS << "\t.option\tnorvc\n"; |
99 | 0 | } |
100 | | |
101 | 0 | void RISCVTargetAsmStreamer::emitDirectiveOptionRelax() { |
102 | 0 | OS << "\t.option\trelax\n"; |
103 | 0 | } |
104 | | |
105 | 0 | void RISCVTargetAsmStreamer::emitDirectiveOptionNoRelax() { |
106 | 0 | OS << "\t.option\tnorelax\n"; |
107 | 0 | } |
108 | | |
109 | | void RISCVTargetAsmStreamer::emitDirectiveOptionArch( |
110 | 0 | ArrayRef<RISCVOptionArchArg> Args) { |
111 | 0 | OS << "\t.option\tarch"; |
112 | 0 | for (const auto &Arg : Args) { |
113 | 0 | OS << ", "; |
114 | 0 | switch (Arg.Type) { |
115 | 0 | case RISCVOptionArchArgType::Full: |
116 | 0 | break; |
117 | 0 | case RISCVOptionArchArgType::Plus: |
118 | 0 | OS << "+"; |
119 | 0 | break; |
120 | 0 | case RISCVOptionArchArgType::Minus: |
121 | 0 | OS << "-"; |
122 | 0 | break; |
123 | 0 | } |
124 | 0 | OS << Arg.Value; |
125 | 0 | } |
126 | 0 | OS << "\n"; |
127 | 0 | } |
128 | | |
129 | 0 | void RISCVTargetAsmStreamer::emitDirectiveVariantCC(MCSymbol &Symbol) { |
130 | 0 | OS << "\t.variant_cc\t" << Symbol.getName() << "\n"; |
131 | 0 | } |
132 | | |
133 | 0 | void RISCVTargetAsmStreamer::emitAttribute(unsigned Attribute, unsigned Value) { |
134 | 0 | OS << "\t.attribute\t" << Attribute << ", " << Twine(Value) << "\n"; |
135 | 0 | } |
136 | | |
137 | | void RISCVTargetAsmStreamer::emitTextAttribute(unsigned Attribute, |
138 | 0 | StringRef String) { |
139 | 0 | OS << "\t.attribute\t" << Attribute << ", \"" << String << "\"\n"; |
140 | 0 | } |
141 | | |
142 | | void RISCVTargetAsmStreamer::emitIntTextAttribute(unsigned Attribute, |
143 | | unsigned IntValue, |
144 | 0 | StringRef StringValue) {} |
145 | | |
146 | 0 | void RISCVTargetAsmStreamer::finishAttributeSection() {} |