1 | //===- SystemZHLASMAsmStreamer.h - HLASM Assembly Text Output ---*- 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 | // This file declares the SystemZHLASMAsmStreamer class. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #ifndef LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMASMSTREAMER_H |
14 | #define LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMASMSTREAMER_H |
15 | |
16 | #include "llvm/ADT/SmallString.h" |
17 | #include "llvm/ADT/StringRef.h" |
18 | #include "llvm/MC/MCAsmBackend.h" |
19 | #include "llvm/MC/MCAsmInfo.h" |
20 | #include "llvm/MC/MCAssembler.h" |
21 | #include "llvm/MC/MCCodeEmitter.h" |
22 | #include "llvm/MC/MCContext.h" |
23 | #include "llvm/MC/MCInst.h" |
24 | #include "llvm/MC/MCInstPrinter.h" |
25 | #include "llvm/MC/MCObjectWriter.h" |
26 | #include "llvm/MC/MCStreamer.h" |
27 | #include "llvm/MC/MCTargetOptions.h" |
28 | #include "llvm/Support/FormattedStream.h" |
29 | |
30 | namespace llvm { |
31 | |
32 | class SystemZHLASMAsmStreamer final : public MCStreamer { |
33 | constexpr static size_t InstLimit = 80; |
34 | constexpr static size_t ContIndicatorColumn = 72; |
35 | constexpr static size_t ContStartColumn = 15; |
36 | constexpr static size_t ContLen = ContIndicatorColumn - ContStartColumn; |
37 | std::unique_ptr<formatted_raw_ostream> FOSOwner; |
38 | formatted_raw_ostream &FOS; |
39 | std::string Str; |
40 | raw_string_ostream OS; |
41 | const MCAsmInfo *MAI; |
42 | std::unique_ptr<MCInstPrinter> InstPrinter; |
43 | std::unique_ptr<MCAssembler> Assembler; |
44 | SmallString<128> ; |
45 | raw_svector_ostream ; |
46 | raw_null_ostream NullStream; |
47 | bool IsVerboseAsm = false; |
48 | |
49 | public: |
50 | SystemZHLASMAsmStreamer(MCContext &Context, |
51 | std::unique_ptr<formatted_raw_ostream> os, |
52 | std::unique_ptr<MCInstPrinter> printer, |
53 | std::unique_ptr<MCCodeEmitter> emitter, |
54 | std::unique_ptr<MCAsmBackend> asmbackend) |
55 | : MCStreamer(Context), FOSOwner(std::move(os)), FOS(*FOSOwner), OS(Str), |
56 | MAI(Context.getAsmInfo()), InstPrinter(std::move(printer)), |
57 | Assembler(std::make_unique<MCAssembler>( |
58 | args&: Context, args: std::move(asmbackend), args: std::move(emitter), |
59 | args: (asmbackend) ? asmbackend->createObjectWriter(OS&: NullStream) |
60 | : nullptr)), |
61 | CommentStream(CommentToEmit) { |
62 | assert(InstPrinter); |
63 | if (Assembler->getBackendPtr()) |
64 | setAllowAutoPadding(Assembler->getBackend().allowAutoPadding()); |
65 | |
66 | Context.setUseNamesOnTempLabels(true); |
67 | auto *TO = Context.getTargetOptions(); |
68 | if (!TO) |
69 | return; |
70 | IsVerboseAsm = TO->AsmVerbose; |
71 | if (IsVerboseAsm) |
72 | InstPrinter->setCommentStream(CommentStream); |
73 | } |
74 | |
75 | MCAssembler &getAssembler() { return *Assembler; } |
76 | |
77 | void EmitEOL(); |
78 | void (); |
79 | |
80 | /// Add a comment that can be emitted to the generated .s file to make the |
81 | /// output of the compiler more readable. This only affects the MCAsmStreamer |
82 | /// and only when verbose assembly output is enabled. |
83 | void (const Twine &T, bool EOL = true) override; |
84 | |
85 | void emitBytes(StringRef Data) override; |
86 | |
87 | void emitAlignmentDS(uint64_t ByteAlignment, std::optional<int64_t> Value, |
88 | unsigned ValueSize, unsigned MaxBytesToEmit); |
89 | void emitValueToAlignment(Align Alignment, int64_t Value = 0, |
90 | unsigned ValueSize = 1, |
91 | unsigned MaxBytesToEmit = 0) override; |
92 | |
93 | void emitCodeAlignment(Align Alignment, const MCSubtargetInfo *STI, |
94 | unsigned MaxBytesToEmit = 0) override; |
95 | |
96 | /// Return true if this streamer supports verbose assembly at all. |
97 | bool isVerboseAsm() const override { return IsVerboseAsm; } |
98 | |
99 | /// Do we support EmitRawText? |
100 | bool hasRawTextSupport() const override { return true; } |
101 | |
102 | /// @name MCStreamer Interface |
103 | /// @{ |
104 | |
105 | void changeSection(MCSection *Section, uint32_t Subsection) override; |
106 | |
107 | void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override; |
108 | void emitLabel(MCSymbol *Symbol, SMLoc Loc) override; |
109 | bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override { |
110 | return false; |
111 | } |
112 | |
113 | void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, |
114 | Align ByteAlignment) override {} |
115 | |
116 | void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr, |
117 | uint64_t Size = 0, Align ByteAlignment = Align(1), |
118 | SMLoc Loc = SMLoc()) override {} |
119 | void emitRawTextImpl(StringRef String) override; |
120 | void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override; |
121 | |
122 | void emitHLASMValueImpl(const MCExpr *Value, unsigned Size, |
123 | bool Parens = false); |
124 | /// @} |
125 | |
126 | void emitEnd(); |
127 | }; |
128 | } // namespace llvm |
129 | |
130 | #endif // LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMASMSTREAMER_H |
131 | |