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