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/MCAsmStreamer.h"
21#include "llvm/MC/MCAssembler.h"
22#include "llvm/MC/MCCodeEmitter.h"
23#include "llvm/MC/MCContext.h"
24#include "llvm/MC/MCInst.h"
25#include "llvm/MC/MCInstPrinter.h"
26#include "llvm/MC/MCObjectWriter.h"
27#include "llvm/MC/MCStreamer.h"
28#include "llvm/MC/MCTargetOptions.h"
29#include "llvm/Support/FormattedStream.h"
30
31namespace llvm {
32class MCSymbolGOFF;
33
34class SystemZHLASMAsmStreamer final : public MCAsmBaseStreamer {
35 // The full length of a line.
36 constexpr static size_t InstLimit = 80;
37 // The column which contains the indicator that the line is continued.
38 constexpr static size_t ContIndicatorColumn = 72;
39 // The start column of a contined line.
40 constexpr static size_t ContStartColumn = 15;
41 constexpr static size_t ContLen = ContIndicatorColumn - ContStartColumn;
42 constexpr static size_t MaxXLLen = 256;
43 std::unique_ptr<formatted_raw_ostream> FOSOwner;
44 formatted_raw_ostream &FOS;
45 std::string Str;
46 raw_string_ostream OS;
47 const MCAsmInfo *MAI;
48 std::unique_ptr<MCInstPrinter> InstPrinter;
49 bool IsVerboseAsm = false;
50
51public:
52 SystemZHLASMAsmStreamer(MCContext &Context,
53 std::unique_ptr<formatted_raw_ostream> OS,
54 std::unique_ptr<MCInstPrinter> Printer,
55 std::unique_ptr<MCCodeEmitter> Emitter,
56 std::unique_ptr<MCAsmBackend> AsmBackend)
57 : MCAsmBaseStreamer(Context, std::move(Emitter), std::move(AsmBackend)),
58 FOSOwner(std::move(OS)), FOS(*FOSOwner), OS(Str),
59 MAI(&Context.getAsmInfo()), InstPrinter(std::move(Printer)) {
60 assert(InstPrinter);
61 if (Assembler->getBackendPtr())
62 setAllowAutoPadding(Assembler->getBackend().allowAutoPadding());
63
64 Context.setUseNamesOnTempLabels(true);
65 IsVerboseAsm = Context.getTargetOptions().AsmVerbose;
66 if (IsVerboseAsm)
67 InstPrinter->setCommentStream(CommentStream);
68 }
69
70 void EmitEOL();
71 void EmitComment();
72
73 /// Add a comment that can be emitted to the generated .s file to make the
74 /// output of the compiler more readable. This only affects the MCAsmStreamer
75 /// and only when verbose assembly output is enabled.
76 void AddComment(const Twine &T, bool EOL = true) override;
77
78 void emitBytes(StringRef Data) override;
79 void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
80 SMLoc Loc = SMLoc()) override;
81
82 void emitAlignmentDS(uint64_t ByteAlignment, std::optional<int64_t> Value,
83 unsigned ValueSize, unsigned MaxBytesToEmit);
84 void emitValueToAlignment(Align Alignment, int64_t Fill, uint8_t FillLen,
85 unsigned MaxBytesToEmit) override;
86
87 void emitCodeAlignment(Align Alignment, const MCSubtargetInfo &STI,
88 unsigned MaxBytesToEmit = 0) override;
89
90 void emitRawComment(const Twine &T, bool TabPrefix = false) override;
91 /// Return true if this streamer supports verbose assembly at all.
92 bool isVerboseAsm() const override { return IsVerboseAsm; }
93
94 /// Do we support EmitRawText?
95 bool hasRawTextSupport() const override { return true; }
96
97 void addEncodingComment(const MCInst &Inst, const MCSubtargetInfo &STI);
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