Path: blob/main/contrib/llvm-project/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.h
213845 views
//===- SystemZHLASMAsmStreamer.h - HLASM Assembly Text Output ---*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file declares the SystemZHLASMAsmStreamer class.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMASMSTREAMER_H13#define LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMASMSTREAMER_H1415#include "llvm/ADT/SmallString.h"16#include "llvm/ADT/StringRef.h"17#include "llvm/MC/MCAsmBackend.h"18#include "llvm/MC/MCAsmInfo.h"19#include "llvm/MC/MCAssembler.h"20#include "llvm/MC/MCCodeEmitter.h"21#include "llvm/MC/MCContext.h"22#include "llvm/MC/MCInst.h"23#include "llvm/MC/MCInstPrinter.h"24#include "llvm/MC/MCObjectWriter.h"25#include "llvm/MC/MCStreamer.h"26#include "llvm/MC/MCTargetOptions.h"27#include "llvm/Support/FormattedStream.h"2829namespace llvm {3031class SystemZHLASMAsmStreamer final : public MCStreamer {32constexpr static size_t InstLimit = 80;33constexpr static size_t ContIndicatorColumn = 72;34constexpr static size_t ContStartColumn = 15;35constexpr static size_t ContLen = ContIndicatorColumn - ContStartColumn;36std::unique_ptr<formatted_raw_ostream> FOSOwner;37formatted_raw_ostream &FOS;38std::string Str;39raw_string_ostream OS;40const MCAsmInfo *MAI;41std::unique_ptr<MCInstPrinter> InstPrinter;42std::unique_ptr<MCAssembler> Assembler;43SmallString<128> CommentToEmit;44raw_svector_ostream CommentStream;45raw_null_ostream NullStream;46bool IsVerboseAsm = false;4748public:49SystemZHLASMAsmStreamer(MCContext &Context,50std::unique_ptr<formatted_raw_ostream> os,51std::unique_ptr<MCInstPrinter> printer,52std::unique_ptr<MCCodeEmitter> emitter,53std::unique_ptr<MCAsmBackend> asmbackend)54: MCStreamer(Context), FOSOwner(std::move(os)), FOS(*FOSOwner), OS(Str),55MAI(Context.getAsmInfo()), InstPrinter(std::move(printer)),56Assembler(std::make_unique<MCAssembler>(57Context, std::move(asmbackend), std::move(emitter),58(asmbackend) ? asmbackend->createObjectWriter(NullStream)59: nullptr)),60CommentStream(CommentToEmit) {61assert(InstPrinter);62if (Assembler->getBackendPtr())63setAllowAutoPadding(Assembler->getBackend().allowAutoPadding());6465Context.setUseNamesOnTempLabels(true);66auto *TO = Context.getTargetOptions();67if (!TO)68return;69IsVerboseAsm = TO->AsmVerbose;70if (IsVerboseAsm)71InstPrinter->setCommentStream(CommentStream);72}7374MCAssembler &getAssembler() { return *Assembler; }7576void EmitEOL();77void EmitComment();7879/// Add a comment that can be emitted to the generated .s file to make the80/// output of the compiler more readable. This only affects the MCAsmStreamer81/// and only when verbose assembly output is enabled.82void AddComment(const Twine &T, bool EOL = true) override;8384void emitBytes(StringRef Data) override;8586void emitAlignmentDS(uint64_t ByteAlignment, std::optional<int64_t> Value,87unsigned ValueSize, unsigned MaxBytesToEmit);88void emitValueToAlignment(Align Alignment, int64_t Fill, uint8_t FillLen,89unsigned MaxBytesToEmit) override;9091void emitCodeAlignment(Align Alignment, const MCSubtargetInfo *STI,92unsigned MaxBytesToEmit = 0) override;9394/// Return true if this streamer supports verbose assembly at all.95bool isVerboseAsm() const override { return IsVerboseAsm; }9697/// Do we support EmitRawText?98bool hasRawTextSupport() const override { return true; }99100/// @name MCStreamer Interface101/// @{102103void changeSection(MCSection *Section, uint32_t Subsection) override;104105void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;106void emitLabel(MCSymbol *Symbol, SMLoc Loc) override;107bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override {108return false;109}110111void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,112Align ByteAlignment) override {}113114void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,115uint64_t Size = 0, Align ByteAlignment = Align(1),116SMLoc Loc = SMLoc()) override {}117void emitRawTextImpl(StringRef String) override;118void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override;119120void emitHLASMValueImpl(const MCExpr *Value, unsigned Size,121bool Parens = false);122/// @}123124void emitEnd();125};126} // namespace llvm127128#endif // LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMASMSTREAMER_H129130131