LLVM 22.0.0git
SystemZHLASMAsmStreamer.h
Go to the documentation of this file.
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
17#include "llvm/ADT/StringRef.h"
19#include "llvm/MC/MCAsmInfo.h"
20#include "llvm/MC/MCAssembler.h"
22#include "llvm/MC/MCContext.h"
23#include "llvm/MC/MCInst.h"
26#include "llvm/MC/MCStreamer.h"
29
30namespace llvm {
31
32class 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;
39 std::string Str;
41 const MCAsmInfo *MAI;
42 std::unique_ptr<MCInstPrinter> InstPrinter;
43 std::unique_ptr<MCAssembler> Assembler;
44 SmallString<128> CommentToEmit;
45 raw_svector_ostream CommentStream;
46 raw_null_ostream NullStream;
47 bool IsVerboseAsm = false;
48
49public:
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 Context, std::move(asmbackend), std::move(emitter),
59 (asmbackend) ? asmbackend->createObjectWriter(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 EmitComment();
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 AddComment(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 Fill, uint8_t FillLen,
90 unsigned MaxBytesToEmit) override;
91
92 void emitCodeAlignment(Align Alignment, const MCSubtargetInfo *STI,
93 unsigned MaxBytesToEmit = 0) override;
94
95 /// Return true if this streamer supports verbose assembly at all.
96 bool isVerboseAsm() const override { return IsVerboseAsm; }
97
98 /// Do we support EmitRawText?
99 bool hasRawTextSupport() const override { return true; }
100
101 /// @name MCStreamer Interface
102 /// @{
103
104 void changeSection(MCSection *Section, uint32_t Subsection) override;
105
106 void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
107 void emitLabel(MCSymbol *Symbol, SMLoc Loc) override;
109 return false;
110 }
111
113 Align ByteAlignment) override {}
114
115 void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
116 uint64_t Size = 0, Align ByteAlignment = Align(1),
117 SMLoc Loc = SMLoc()) override {}
118 void emitRawTextImpl(StringRef String) override;
119 void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override;
120
121 void emitHLASMValueImpl(const MCExpr *Value, unsigned Size,
122 bool Parens = false);
123 /// @}
124
125 void emitEnd();
126};
127} // namespace llvm
128
129#endif // LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMASMSTREAMER_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
dxil pretty printer
uint64_t Size
raw_pwrite_stream & OS
This file defines the SmallString class.
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:64
Context object for machine code objects.
Definition: MCContext.h:83
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:188
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:496
Streaming machine code generation interface.
Definition: MCStreamer.h:220
void setAllowAutoPadding(bool v)
Definition: MCStreamer.h:328
Generic base class for all target subtargets.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
Represents a location in source code.
Definition: SMLoc.h:23
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
void emitCodeAlignment(Align Alignment, const MCSubtargetInfo *STI, unsigned MaxBytesToEmit=0) override
Emit nops until the byte alignment ByteAlignment is reached.
void emitHLASMValueImpl(const MCExpr *Value, unsigned Size, bool Parens=false)
void emitRawTextImpl(StringRef String) override
EmitRawText - If this file is backed by an assembly streamer, this dumps the specified string in the ...
void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, Align ByteAlignment) override
Emit a common symbol.
void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override
Emit the expression Value into the output as a native integer of the given Size bytes.
void emitBytes(StringRef Data) override
Emit the bytes in Data into the output.
void emitAlignmentDS(uint64_t ByteAlignment, std::optional< int64_t > Value, unsigned ValueSize, unsigned MaxBytesToEmit)
void emitZerofill(MCSection *Section, MCSymbol *Symbol=nullptr, uint64_t Size=0, Align ByteAlignment=Align(1), SMLoc Loc=SMLoc()) override
Emit the zerofill section and an optional symbol.
void AddComment(const Twine &T, bool EOL=true) override
Add a comment that can be emitted to the generated .s file to make the output of the compiler more re...
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
bool isVerboseAsm() const override
Return true if this streamer supports verbose assembly at all.
void emitValueToAlignment(Align Alignment, int64_t Fill, uint8_t FillLen, unsigned MaxBytesToEmit) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
SystemZHLASMAsmStreamer(MCContext &Context, std::unique_ptr< formatted_raw_ostream > os, std::unique_ptr< MCInstPrinter > printer, std::unique_ptr< MCCodeEmitter > emitter, std::unique_ptr< MCAsmBackend > asmbackend)
bool hasRawTextSupport() const override
Do we support EmitRawText?
void changeSection(MCSection *Section, uint32_t Subsection) override
This is called by popSection and switchSection, if the current section changes.
void emitLabel(MCSymbol *Symbol, SMLoc Loc) override
Emit a label for Symbol into the current section.
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:82
LLVM Value Representation.
Definition: Value.h:75
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
A raw_ostream that discards all output.
Definition: raw_ostream.h:732
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:662
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:692
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1886
MCSymbolAttr
Definition: MCDirectives.h:18
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:851
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39