LLVM 24.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"
21#include "llvm/MC/MCAssembler.h"
23#include "llvm/MC/MCContext.h"
24#include "llvm/MC/MCInst.h"
27#include "llvm/MC/MCStreamer.h"
30
31namespace llvm {
32class MCSymbolGOFF;
33
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 // Number of leading blanks before the operation field of a statement without
40 // a name field. Must be at least 1, since column 1 is reserved for the name.
41 constexpr static size_t Indent = 10;
42 static_assert(Indent >= 1 && Indent < ContIndicatorColumn,
43 "Indent must leave the name field empty and fit the line");
44 // The start column of a continued line.
45 constexpr static size_t ContStartColumn = 15;
46 constexpr static size_t ContLen = ContIndicatorColumn - ContStartColumn;
47 constexpr static size_t MaxXLLen = 256;
48 std::unique_ptr<formatted_raw_ostream> FOSOwner;
50 std::string Str;
52 const MCAsmInfo *MAI;
53 std::unique_ptr<MCInstPrinter> InstPrinter;
54 bool IsVerboseAsm = false;
55
56public:
58 std::unique_ptr<formatted_raw_ostream> OS,
59 std::unique_ptr<MCInstPrinter> Printer,
60 std::unique_ptr<MCCodeEmitter> Emitter,
61 std::unique_ptr<MCAsmBackend> AsmBackend)
62 : MCAsmBaseStreamer(Context, std::move(Emitter), std::move(AsmBackend)),
63 FOSOwner(std::move(OS)), FOS(*FOSOwner), OS(Str),
64 MAI(&Context.getAsmInfo()), InstPrinter(std::move(Printer)) {
65 assert(InstPrinter);
66 if (Assembler->getBackendPtr())
67 setAllowAutoPadding(Assembler->getBackend().allowAutoPadding());
68
69 Context.setUseNamesOnTempLabels(true);
70 IsVerboseAsm = Context.getTargetOptions().AsmVerbose;
71 if (IsVerboseAsm)
72 InstPrinter->setCommentStream(CommentStream);
73 }
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 void emitBinaryData(StringRef Data) override;
85 void emitIntValue(uint64_t Value, unsigned Size) override;
86 void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
87 SMLoc Loc = SMLoc()) override;
88
89 void emitAlignmentDS(uint64_t ByteAlignment, std::optional<int64_t> Value,
90 unsigned ValueSize, unsigned MaxBytesToEmit);
91 void emitValueToAlignment(Align Alignment, int64_t Fill, uint8_t FillLen,
92 unsigned MaxBytesToEmit) override;
93
94 void emitCodeAlignment(Align Alignment, const MCSubtargetInfo &STI,
95 unsigned MaxBytesToEmit = 0) override;
96
97 void emitRawComment(const Twine &T, bool TabPrefix = false) override;
98 /// Return true if this streamer supports verbose assembly at all.
99 bool isVerboseAsm() const override { return IsVerboseAsm; }
100
101 /// Do we support EmitRawText?
102 bool hasRawTextSupport() const override { return true; }
103
104 void addEncodingComment(const MCInst &Inst, const MCSubtargetInfo &STI);
105
106 /// @name MCStreamer Interface
107 /// @{
108 void visitUsedSymbol(const MCSymbol &Sym) override;
109
110 void changeSection(MCSection *Section, uint32_t Subsection) override;
111
112 void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
113 void emitLabel(MCSymbol *Symbol, SMLoc Loc) override;
114 bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
115
117 Align ByteAlignment) override;
118
119 void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
120 uint64_t Size = 0, Align ByteAlignment = Align(1),
121 SMLoc Loc = SMLoc()) override {}
122 void emitRawTextImpl(StringRef String) override;
123 void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override;
124
125 void emitHLASMValueImpl(const MCExpr *Value, unsigned Size,
126 bool Parens = false);
127 /// @}
128
129 void finishImpl() override;
130
131protected:
132 void emitBytes(StringRef Data, bool MayBeString);
133};
134} // namespace llvm
135
136#endif // LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMASMSTREAMER_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
amdgpu next use AMDGPU Next Use Analysis Printer
dxil container DXContainer Global Emitter
#define T
This file defines the SmallString class.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:107
std::unique_ptr< MCAssembler > Assembler
LLVM_ABI MCAsmBaseStreamer(MCContext &Context, std::unique_ptr< MCCodeEmitter > Emitter, std::unique_ptr< MCAsmBackend > AsmBackend)
raw_svector_ostream CommentStream
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition MCAsmInfo.h:67
Context object for machine code objects.
Definition MCContext.h:84
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:580
void setAllowAutoPadding(bool v)
Definition MCStreamer.h:340
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:22
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
void emitHLASMValueImpl(const MCExpr *Value, unsigned Size, bool Parens=false)
void emitFill(const MCExpr &NumBytes, uint64_t FillValue, SMLoc Loc=SMLoc()) override
Emit Size bytes worth of the value specified by FillValue.
void emitRawTextImpl(StringRef String) override
EmitRawText - If this file is backed by an assembly streamer, this dumps the specified string in the ...
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)
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 addEncodingComment(const MCInst &Inst, const MCSubtargetInfo &STI)
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 emitIntValue(uint64_t Value, unsigned Size) override
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers.
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 finishImpl() override
Streamer specific finalization.
void visitUsedSymbol(const MCSymbol &Sym) override
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.
void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, Align ByteAlignment) override
Emit a common symbol.
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.
void emitRawComment(const Twine &T, bool TabPrefix=false) override
Print T and prefix it with the comment string (normally #) and optionally a tab.
void emitCodeAlignment(Align Alignment, const MCSubtargetInfo &STI, unsigned MaxBytesToEmit=0) override
Emit nops until the byte alignment ByteAlignment is reached.
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.
void emitBinaryData(StringRef Data) override
Functionally identical to EmitBytes.
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 writes to an std::string.
This is an optimization pass for GlobalISel generic memory operations.
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:1933
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:879
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39