[llvm-branch-commits] [llvm] 6744490 - [debug-info] NFC - add isa<> support for MCStreamer
Chen Zheng via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Jan 25 04:17:37 PST 2021
Author: Chen Zheng
Date: 2021-01-25T02:55:35-05:00
New Revision: 67444901ed2ae692dcf9971708362df2463be975
URL: https://github.com/llvm/llvm-project/commit/67444901ed2ae692dcf9971708362df2463be975
DIFF: https://github.com/llvm/llvm-project/commit/67444901ed2ae692dcf9971708362df2463be975.diff
LOG: [debug-info] NFC - add isa<> support for MCStreamer
Added:
llvm/include/llvm/MC/MCAsmStreamer.h
Modified:
llvm/include/llvm/MC/MCObjectStreamer.h
llvm/include/llvm/MC/MCStreamer.h
llvm/lib/MC/MCAsmStreamer.cpp
llvm/lib/MC/MCNullStreamer.cpp
llvm/lib/Object/RecordStreamer.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCAsmStreamer.h b/llvm/include/llvm/MC/MCAsmStreamer.h
new file mode 100644
index 000000000000..5b2f407841e5
--- /dev/null
+++ b/llvm/include/llvm/MC/MCAsmStreamer.h
@@ -0,0 +1,374 @@
+//===- MCObjectStreamer.h - MCStreamer Object File Interface ----*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_MC_MCASMSTREAMER_H
+#define LLVM_MC_MCASMSTREAMER_H
+
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/MC/MCAsmBackend.h"
+#include "llvm/MC/MCAsmInfo.h"
+#include "llvm/MC/MCAssembler.h"
+#include "llvm/MC/MCCodeEmitter.h"
+#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCExpr.h"
+#include "llvm/MC/MCInst.h"
+#include "llvm/MC/MCInstPrinter.h"
+#include "llvm/MC/MCObjectFileInfo.h"
+#include "llvm/MC/MCObjectWriter.h"
+#include "llvm/MC/MCRegister.h"
+#include "llvm/MC/MCStreamer.h"
+#include "llvm/Support/Format.h"
+#include "llvm/Support/FormattedStream.h"
+
+using namespace llvm;
+
+namespace llvm {
+
+class MCAsmStreamer final : public MCStreamer {
+ std::unique_ptr<formatted_raw_ostream> OSOwner;
+ formatted_raw_ostream &OS;
+ const MCAsmInfo *MAI;
+ std::unique_ptr<MCInstPrinter> InstPrinter;
+ std::unique_ptr<MCAssembler> Assembler;
+
+ SmallString<128> ExplicitCommentToEmit;
+ SmallString<128> CommentToEmit;
+ raw_svector_ostream CommentStream;
+ raw_null_ostream NullStream;
+
+ unsigned IsVerboseAsm : 1;
+ unsigned ShowInst : 1;
+ unsigned UseDwarfDirectory : 1;
+
+ void EmitRegisterName(int64_t Register);
+ void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;
+ void emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override;
+
+public:
+ MCAsmStreamer(MCContext &Context, std::unique_ptr<formatted_raw_ostream> os,
+ bool isVerboseAsm, bool useDwarfDirectory,
+ MCInstPrinter *printer, std::unique_ptr<MCCodeEmitter> emitter,
+ std::unique_ptr<MCAsmBackend> asmbackend, bool showInst)
+ : MCStreamer(Context), OSOwner(std::move(os)), OS(*OSOwner),
+ MAI(Context.getAsmInfo()), InstPrinter(printer),
+ Assembler(std::make_unique<MCAssembler>(
+ Context, std::move(asmbackend), std::move(emitter),
+ (asmbackend) ? asmbackend->createObjectWriter(NullStream)
+ : nullptr)),
+ CommentStream(CommentToEmit), IsVerboseAsm(isVerboseAsm),
+ ShowInst(showInst), UseDwarfDirectory(useDwarfDirectory) {
+ assert(InstPrinter);
+ if (IsVerboseAsm)
+ InstPrinter->setCommentStream(CommentStream);
+ if (Assembler->getBackendPtr())
+ setAllowAutoPadding(Assembler->getBackend().allowAutoPadding());
+
+ Context.setUseNamesOnTempLabels(true);
+ }
+
+ MCAssembler &getAssembler() { return *Assembler; }
+ MCAssembler *getAssemblerPtr() override { return nullptr; }
+
+ inline void EmitEOL() {
+ // Dump Explicit Comments here.
+ emitExplicitComments();
+ // If we don't have any comments, just emit a \n.
+ if (!IsVerboseAsm) {
+ OS << '\n';
+ return;
+ }
+ EmitCommentsAndEOL();
+ }
+
+ uint32_t getStreamerKind() const override { return StreamerKindAsm; }
+ static bool classof(const MCStreamer *S) {
+ return S->getStreamerKind() == StreamerKindAsm;
+ }
+
+ void emitSyntaxDirective() override;
+
+ void EmitCommentsAndEOL();
+
+ /// Return true if this streamer supports verbose assembly at all.
+ bool isVerboseAsm() const override { return IsVerboseAsm; }
+
+ /// Do we support EmitRawText?
+ bool hasRawTextSupport() const override { return true; }
+
+ /// Add a comment that can be emitted to the generated .s file to make the
+ /// output of the compiler more readable. This only affects the MCAsmStreamer
+ /// and only when verbose assembly output is enabled.
+ void AddComment(const Twine &T, bool EOL = true) override;
+
+ /// Add a comment showing the encoding of an instruction.
+ void AddEncodingComment(const MCInst &Inst, const MCSubtargetInfo &);
+
+ /// Return a raw_ostream that comments can be written to.
+ /// Unlike AddComment, you are required to terminate comments with \n if you
+ /// use this method.
+ raw_ostream &GetCommentOS() override {
+ if (!IsVerboseAsm)
+ return nulls(); // Discard comments unless in verbose asm mode.
+ return CommentStream;
+ }
+
+ void emitRawComment(const Twine &T, bool TabPrefix = true) override;
+
+ void addExplicitComment(const Twine &T) override;
+ void emitExplicitComments() override;
+
+ /// Emit a blank line to a .s file to pretty it up.
+ void AddBlankLine() override {
+ EmitEOL();
+ }
+
+ /// @name MCStreamer Interface
+ /// @{
+
+ void changeSection(MCSection *Section, const MCExpr *Subsection) override;
+
+ void emitELFSymverDirective(StringRef AliasName,
+ const MCSymbol *Aliasee) override;
+
+ void emitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) override;
+
+ StringRef getMnemonic(MCInst &MI) override {
+ return InstPrinter->getMnemonic(&MI).first;
+ }
+
+ void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
+
+ void emitAssemblerFlag(MCAssemblerFlag Flag) override;
+ void emitLinkerOptions(ArrayRef<std::string> Options) override;
+ void emitDataRegion(MCDataRegionType Kind) override;
+ void emitVersionMin(MCVersionMinType Kind, unsigned Major, unsigned Minor,
+ unsigned Update, VersionTuple SDKVersion) override;
+ void emitBuildVersion(unsigned Platform, unsigned Major, unsigned Minor,
+ unsigned Update, VersionTuple SDKVersion) override;
+ void emitThumbFunc(MCSymbol *Func) override;
+
+ void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
+ void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
+ bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
+
+ void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
+ void BeginCOFFSymbolDef(const MCSymbol *Symbol) override;
+ void EmitCOFFSymbolStorageClass(int StorageClass) override;
+ void EmitCOFFSymbolType(int Type) override;
+ void EndCOFFSymbolDef() override;
+ void EmitCOFFSafeSEH(MCSymbol const *Symbol) override;
+ void EmitCOFFSymbolIndex(MCSymbol const *Symbol) override;
+ void EmitCOFFSectionIndex(MCSymbol const *Symbol) override;
+ void EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset) override;
+ void EmitCOFFImgRel32(MCSymbol const *Symbol, int64_t Offset) override;
+ void emitXCOFFLocalCommonSymbol(MCSymbol *LabelSym, uint64_t Size,
+ MCSymbol *CsectSym,
+ unsigned ByteAlign) override;
+ void emitXCOFFSymbolLinkageWithVisibility(MCSymbol *Symbol,
+ MCSymbolAttr Linakge,
+ MCSymbolAttr Visibility) override;
+ void emitXCOFFRenameDirective(const MCSymbol *Name,
+ StringRef Rename) override;
+
+ void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override;
+ void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
+ unsigned ByteAlignment) override;
+
+ /// Emit a local common (.lcomm) symbol.
+ ///
+ /// @param Symbol - The common symbol to emit.
+ /// @param Size - The size of the common symbol.
+ /// @param ByteAlignment - The alignment of the common symbol in bytes.
+ void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
+ unsigned ByteAlignment) override;
+
+ void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
+ uint64_t Size = 0, unsigned ByteAlignment = 0,
+ SMLoc Loc = SMLoc()) override;
+
+ void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
+ unsigned ByteAlignment = 0) override;
+
+ void emitBinaryData(StringRef Data) override;
+
+ void emitBytes(StringRef Data) override;
+
+ void emitValueImpl(const MCExpr *Value, unsigned Size,
+ SMLoc Loc = SMLoc()) override;
+ void emitIntValue(uint64_t Value, unsigned Size) override;
+ void emitIntValueInHex(uint64_t Value, unsigned Size) override;
+ void emitIntValueInHexWithPadding(uint64_t Value, unsigned Size) override;
+
+ void emitULEB128Value(const MCExpr *Value) override;
+
+ void emitSLEB128Value(const MCExpr *Value) override;
+
+ void emitDTPRel32Value(const MCExpr *Value) override;
+ void emitDTPRel64Value(const MCExpr *Value) override;
+ void emitTPRel32Value(const MCExpr *Value) override;
+ void emitTPRel64Value(const MCExpr *Value) override;
+
+ void emitGPRel64Value(const MCExpr *Value) override;
+
+ void emitGPRel32Value(const MCExpr *Value) override;
+
+ void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
+ SMLoc Loc = SMLoc()) override;
+
+ void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
+ SMLoc Loc = SMLoc()) override;
+
+ void emitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
+ unsigned ValueSize = 1,
+ unsigned MaxBytesToEmit = 0) override;
+
+ void emitCodeAlignment(unsigned ByteAlignment,
+ unsigned MaxBytesToEmit = 0) override;
+
+ void emitValueToOffset(const MCExpr *Offset,
+ unsigned char Value,
+ SMLoc Loc) override;
+
+ void emitFileDirective(StringRef Filename) override;
+ Expected<unsigned> tryEmitDwarfFileDirective(unsigned FileNo,
+ StringRef Directory,
+ StringRef Filename,
+ Optional<MD5::MD5Result> Checksum = None,
+ Optional<StringRef> Source = None,
+ unsigned CUID = 0) override;
+ void emitDwarfFile0Directive(StringRef Directory, StringRef Filename,
+ Optional<MD5::MD5Result> Checksum,
+ Optional<StringRef> Source,
+ unsigned CUID = 0) override;
+ void emitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column,
+ unsigned Flags, unsigned Isa,
+ unsigned Discriminator,
+ StringRef FileName) override;
+ MCSymbol *getDwarfLineTableSymbol(unsigned CUID) override;
+
+ bool EmitCVFileDirective(unsigned FileNo, StringRef Filename,
+ ArrayRef<uint8_t> Checksum,
+ unsigned ChecksumKind) override;
+ bool EmitCVFuncIdDirective(unsigned FuncId) override;
+ bool EmitCVInlineSiteIdDirective(unsigned FunctionId, unsigned IAFunc,
+ unsigned IAFile, unsigned IALine,
+ unsigned IACol, SMLoc Loc) override;
+ void emitCVLocDirective(unsigned FunctionId, unsigned FileNo, unsigned Line,
+ unsigned Column, bool PrologueEnd, bool IsStmt,
+ StringRef FileName, SMLoc Loc) override;
+ void emitCVLinetableDirective(unsigned FunctionId, const MCSymbol *FnStart,
+ const MCSymbol *FnEnd) override;
+ void emitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
+ unsigned SourceFileId,
+ unsigned SourceLineNum,
+ const MCSymbol *FnStartSym,
+ const MCSymbol *FnEndSym) override;
+
+ void PrintCVDefRangePrefix(
+ ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges);
+
+ void emitCVDefRangeDirective(
+ ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
+ codeview::DefRangeRegisterRelHeader DRHdr) override;
+
+ void emitCVDefRangeDirective(
+ ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
+ codeview::DefRangeSubfieldRegisterHeader DRHdr) override;
+
+ void emitCVDefRangeDirective(
+ ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
+ codeview::DefRangeRegisterHeader DRHdr) override;
+
+ void emitCVDefRangeDirective(
+ ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
+ codeview::DefRangeFramePointerRelHeader DRHdr) override;
+
+ void emitCVStringTableDirective() override;
+ void emitCVFileChecksumsDirective() override;
+ void emitCVFileChecksumOffsetDirective(unsigned FileNo) override;
+ void EmitCVFPOData(const MCSymbol *ProcSym, SMLoc L) override;
+
+ void emitIdent(StringRef IdentString) override;
+ void emitCFIBKeyFrame() override;
+ void emitCFISections(bool EH, bool Debug) override;
+ void emitCFIDefCfa(int64_t Register, int64_t Offset) override;
+ void emitCFIDefCfaOffset(int64_t Offset) override;
+ void emitCFIDefCfaRegister(int64_t Register) override;
+ void emitCFIOffset(int64_t Register, int64_t Offset) override;
+ void emitCFIPersonality(const MCSymbol *Sym, unsigned Encoding) override;
+ void emitCFILsda(const MCSymbol *Sym, unsigned Encoding) override;
+ void emitCFIRememberState() override;
+ void emitCFIRestoreState() override;
+ void emitCFIRestore(int64_t Register) override;
+ void emitCFISameValue(int64_t Register) override;
+ void emitCFIRelOffset(int64_t Register, int64_t Offset) override;
+ void emitCFIAdjustCfaOffset(int64_t Adjustment) override;
+ void emitCFIEscape(StringRef Values) override;
+ void emitCFIGnuArgsSize(int64_t Size) override;
+ void emitCFISignalFrame() override;
+ void emitCFIUndefined(int64_t Register) override;
+ void emitCFIRegister(int64_t Register1, int64_t Register2) override;
+ void emitCFIWindowSave() override;
+ void emitCFINegateRAState() override;
+ void emitCFIReturnColumn(int64_t Register) override;
+
+ void EmitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc) override;
+ void EmitWinCFIEndProc(SMLoc Loc) override;
+ void EmitWinCFIFuncletOrFuncEnd(SMLoc Loc) override;
+ void EmitWinCFIStartChained(SMLoc Loc) override;
+ void EmitWinCFIEndChained(SMLoc Loc) override;
+ void EmitWinCFIPushReg(MCRegister Register, SMLoc Loc) override;
+ void EmitWinCFISetFrame(MCRegister Register, unsigned Offset,
+ SMLoc Loc) override;
+ void EmitWinCFIAllocStack(unsigned Size, SMLoc Loc) override;
+ void EmitWinCFISaveReg(MCRegister Register, unsigned Offset,
+ SMLoc Loc) override;
+ void EmitWinCFISaveXMM(MCRegister Register, unsigned Offset,
+ SMLoc Loc) override;
+ void EmitWinCFIPushFrame(bool Code, SMLoc Loc) override;
+ void EmitWinCFIEndProlog(SMLoc Loc) override;
+
+ void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except,
+ SMLoc Loc) override;
+ void EmitWinEHHandlerData(SMLoc Loc) override;
+
+ void emitCGProfileEntry(const MCSymbolRefExpr *From,
+ const MCSymbolRefExpr *To, uint64_t Count) override;
+
+ void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
+
+ void emitPseudoProbe(uint64_t Guid, uint64_t Index, uint64_t Type,
+ uint64_t Attr,
+ const MCPseudoProbeInlineStack &InlineStack) override;
+
+ void emitBundleAlignMode(unsigned AlignPow2) override;
+ void emitBundleLock(bool AlignToEnd) override;
+ void emitBundleUnlock() override;
+
+ Optional<std::pair<bool, std::string>>
+ emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr,
+ SMLoc Loc, const MCSubtargetInfo &STI) override;
+
+ void emitAddrsig() override;
+ void emitAddrsigSym(const MCSymbol *Sym) override;
+
+ /// If this file is backed by an assembly streamer, this dumps the specified
+ /// string in the output .s file. This capability is indicated by the
+ /// hasRawTextSupport() predicate.
+ void emitRawTextImpl(StringRef String) override;
+
+ void finishImpl() override;
+};
+
+} // end anonymous namespace.
+
+#endif
diff --git a/llvm/include/llvm/MC/MCObjectStreamer.h b/llvm/include/llvm/MC/MCObjectStreamer.h
index a00000bc11b6..df428a727481 100644
--- a/llvm/include/llvm/MC/MCObjectStreamer.h
+++ b/llvm/include/llvm/MC/MCObjectStreamer.h
@@ -64,6 +64,11 @@ class MCObjectStreamer : public MCStreamer {
~MCObjectStreamer();
public:
+ uint32_t getStreamerKind() const override { return StreamerKindObject; }
+ static bool classof(const MCStreamer *S) {
+ return S->getStreamerKind() == StreamerKindObject;
+ }
+
/// state management
void reset() override;
diff --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h
index cdc728f73772..cf27c0e89f0c 100644
--- a/llvm/include/llvm/MC/MCStreamer.h
+++ b/llvm/include/llvm/MC/MCStreamer.h
@@ -256,10 +256,22 @@ class MCStreamer {
bool checkCVLocSection(unsigned FuncId, unsigned FileNo, SMLoc Loc);
public:
+
+ /// The kind of the streamer.
+ enum StreamerKind {
+ StreamerKindUnknown,
+ StreamerKindAsm,
+ StreamerKindObject,
+ StreamerKindNull,
+ StreamerKindRecord
+ };
+
MCStreamer(const MCStreamer &) = delete;
MCStreamer &operator=(const MCStreamer &) = delete;
virtual ~MCStreamer();
+ virtual uint32_t getStreamerKind() const { return StreamerKindUnknown; };
+
void visitUsedExpr(const MCExpr &Expr);
virtual void visitUsedSymbol(const MCSymbol &Sym);
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index 10d72553fe6d..77c5f409789a 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -6,33 +6,16 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/ADT/Optional.h"
-#include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallString.h"
-#include "llvm/ADT/StringExtras.h"
-#include "llvm/ADT/Twine.h"
+
#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
-#include "llvm/MC/MCAsmBackend.h"
-#include "llvm/MC/MCAsmInfo.h"
-#include "llvm/MC/MCAssembler.h"
-#include "llvm/MC/MCCodeEmitter.h"
+#include "llvm/MC/MCAsmStreamer.h"
#include "llvm/MC/MCCodeView.h"
-#include "llvm/MC/MCContext.h"
-#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCFixupKindInfo.h"
-#include "llvm/MC/MCInst.h"
-#include "llvm/MC/MCInstPrinter.h"
-#include "llvm/MC/MCObjectFileInfo.h"
-#include "llvm/MC/MCObjectWriter.h"
#include "llvm/MC/MCPseudoProbe.h"
-#include "llvm/MC/MCRegister.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCSectionMachO.h"
-#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbolXCOFF.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/Format.h"
-#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/LEB128.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Path.h"
@@ -41,341 +24,6 @@
using namespace llvm;
-namespace {
-
-class MCAsmStreamer final : public MCStreamer {
- std::unique_ptr<formatted_raw_ostream> OSOwner;
- formatted_raw_ostream &OS;
- const MCAsmInfo *MAI;
- std::unique_ptr<MCInstPrinter> InstPrinter;
- std::unique_ptr<MCAssembler> Assembler;
-
- SmallString<128> ExplicitCommentToEmit;
- SmallString<128> CommentToEmit;
- raw_svector_ostream CommentStream;
- raw_null_ostream NullStream;
-
- unsigned IsVerboseAsm : 1;
- unsigned ShowInst : 1;
- unsigned UseDwarfDirectory : 1;
-
- void EmitRegisterName(int64_t Register);
- void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;
- void emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override;
-
-public:
- MCAsmStreamer(MCContext &Context, std::unique_ptr<formatted_raw_ostream> os,
- bool isVerboseAsm, bool useDwarfDirectory,
- MCInstPrinter *printer, std::unique_ptr<MCCodeEmitter> emitter,
- std::unique_ptr<MCAsmBackend> asmbackend, bool showInst)
- : MCStreamer(Context), OSOwner(std::move(os)), OS(*OSOwner),
- MAI(Context.getAsmInfo()), InstPrinter(printer),
- Assembler(std::make_unique<MCAssembler>(
- Context, std::move(asmbackend), std::move(emitter),
- (asmbackend) ? asmbackend->createObjectWriter(NullStream)
- : nullptr)),
- CommentStream(CommentToEmit), IsVerboseAsm(isVerboseAsm),
- ShowInst(showInst), UseDwarfDirectory(useDwarfDirectory) {
- assert(InstPrinter);
- if (IsVerboseAsm)
- InstPrinter->setCommentStream(CommentStream);
- if (Assembler->getBackendPtr())
- setAllowAutoPadding(Assembler->getBackend().allowAutoPadding());
-
- Context.setUseNamesOnTempLabels(true);
- }
-
- MCAssembler &getAssembler() { return *Assembler; }
- MCAssembler *getAssemblerPtr() override { return nullptr; }
-
- inline void EmitEOL() {
- // Dump Explicit Comments here.
- emitExplicitComments();
- // If we don't have any comments, just emit a \n.
- if (!IsVerboseAsm) {
- OS << '\n';
- return;
- }
- EmitCommentsAndEOL();
- }
-
- void emitSyntaxDirective() override;
-
- void EmitCommentsAndEOL();
-
- /// Return true if this streamer supports verbose assembly at all.
- bool isVerboseAsm() const override { return IsVerboseAsm; }
-
- /// Do we support EmitRawText?
- bool hasRawTextSupport() const override { return true; }
-
- /// Add a comment that can be emitted to the generated .s file to make the
- /// output of the compiler more readable. This only affects the MCAsmStreamer
- /// and only when verbose assembly output is enabled.
- void AddComment(const Twine &T, bool EOL = true) override;
-
- /// Add a comment showing the encoding of an instruction.
- void AddEncodingComment(const MCInst &Inst, const MCSubtargetInfo &);
-
- /// Return a raw_ostream that comments can be written to.
- /// Unlike AddComment, you are required to terminate comments with \n if you
- /// use this method.
- raw_ostream &GetCommentOS() override {
- if (!IsVerboseAsm)
- return nulls(); // Discard comments unless in verbose asm mode.
- return CommentStream;
- }
-
- void emitRawComment(const Twine &T, bool TabPrefix = true) override;
-
- void addExplicitComment(const Twine &T) override;
- void emitExplicitComments() override;
-
- /// Emit a blank line to a .s file to pretty it up.
- void AddBlankLine() override {
- EmitEOL();
- }
-
- /// @name MCStreamer Interface
- /// @{
-
- void changeSection(MCSection *Section, const MCExpr *Subsection) override;
-
- void emitELFSymverDirective(StringRef AliasName,
- const MCSymbol *Aliasee) override;
-
- void emitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) override;
-
- StringRef getMnemonic(MCInst &MI) override {
- return InstPrinter->getMnemonic(&MI).first;
- }
-
- void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
-
- void emitAssemblerFlag(MCAssemblerFlag Flag) override;
- void emitLinkerOptions(ArrayRef<std::string> Options) override;
- void emitDataRegion(MCDataRegionType Kind) override;
- void emitVersionMin(MCVersionMinType Kind, unsigned Major, unsigned Minor,
- unsigned Update, VersionTuple SDKVersion) override;
- void emitBuildVersion(unsigned Platform, unsigned Major, unsigned Minor,
- unsigned Update, VersionTuple SDKVersion) override;
- void emitThumbFunc(MCSymbol *Func) override;
-
- void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
- void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
- bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
-
- void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
- void BeginCOFFSymbolDef(const MCSymbol *Symbol) override;
- void EmitCOFFSymbolStorageClass(int StorageClass) override;
- void EmitCOFFSymbolType(int Type) override;
- void EndCOFFSymbolDef() override;
- void EmitCOFFSafeSEH(MCSymbol const *Symbol) override;
- void EmitCOFFSymbolIndex(MCSymbol const *Symbol) override;
- void EmitCOFFSectionIndex(MCSymbol const *Symbol) override;
- void EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset) override;
- void EmitCOFFImgRel32(MCSymbol const *Symbol, int64_t Offset) override;
- void emitXCOFFLocalCommonSymbol(MCSymbol *LabelSym, uint64_t Size,
- MCSymbol *CsectSym,
- unsigned ByteAlign) override;
- void emitXCOFFSymbolLinkageWithVisibility(MCSymbol *Symbol,
- MCSymbolAttr Linakge,
- MCSymbolAttr Visibility) override;
- void emitXCOFFRenameDirective(const MCSymbol *Name,
- StringRef Rename) override;
-
- void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override;
- void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
- unsigned ByteAlignment) override;
-
- /// Emit a local common (.lcomm) symbol.
- ///
- /// @param Symbol - The common symbol to emit.
- /// @param Size - The size of the common symbol.
- /// @param ByteAlignment - The alignment of the common symbol in bytes.
- void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
- unsigned ByteAlignment) override;
-
- void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
- uint64_t Size = 0, unsigned ByteAlignment = 0,
- SMLoc Loc = SMLoc()) override;
-
- void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
- unsigned ByteAlignment = 0) override;
-
- void emitBinaryData(StringRef Data) override;
-
- void emitBytes(StringRef Data) override;
-
- void emitValueImpl(const MCExpr *Value, unsigned Size,
- SMLoc Loc = SMLoc()) override;
- void emitIntValue(uint64_t Value, unsigned Size) override;
- void emitIntValueInHex(uint64_t Value, unsigned Size) override;
- void emitIntValueInHexWithPadding(uint64_t Value, unsigned Size) override;
-
- void emitULEB128Value(const MCExpr *Value) override;
-
- void emitSLEB128Value(const MCExpr *Value) override;
-
- void emitDTPRel32Value(const MCExpr *Value) override;
- void emitDTPRel64Value(const MCExpr *Value) override;
- void emitTPRel32Value(const MCExpr *Value) override;
- void emitTPRel64Value(const MCExpr *Value) override;
-
- void emitGPRel64Value(const MCExpr *Value) override;
-
- void emitGPRel32Value(const MCExpr *Value) override;
-
- void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
- SMLoc Loc = SMLoc()) override;
-
- void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
- SMLoc Loc = SMLoc()) override;
-
- void emitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
- unsigned ValueSize = 1,
- unsigned MaxBytesToEmit = 0) override;
-
- void emitCodeAlignment(unsigned ByteAlignment,
- unsigned MaxBytesToEmit = 0) override;
-
- void emitValueToOffset(const MCExpr *Offset,
- unsigned char Value,
- SMLoc Loc) override;
-
- void emitFileDirective(StringRef Filename) override;
- Expected<unsigned> tryEmitDwarfFileDirective(unsigned FileNo,
- StringRef Directory,
- StringRef Filename,
- Optional<MD5::MD5Result> Checksum = None,
- Optional<StringRef> Source = None,
- unsigned CUID = 0) override;
- void emitDwarfFile0Directive(StringRef Directory, StringRef Filename,
- Optional<MD5::MD5Result> Checksum,
- Optional<StringRef> Source,
- unsigned CUID = 0) override;
- void emitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column,
- unsigned Flags, unsigned Isa,
- unsigned Discriminator,
- StringRef FileName) override;
- MCSymbol *getDwarfLineTableSymbol(unsigned CUID) override;
-
- bool EmitCVFileDirective(unsigned FileNo, StringRef Filename,
- ArrayRef<uint8_t> Checksum,
- unsigned ChecksumKind) override;
- bool EmitCVFuncIdDirective(unsigned FuncId) override;
- bool EmitCVInlineSiteIdDirective(unsigned FunctionId, unsigned IAFunc,
- unsigned IAFile, unsigned IALine,
- unsigned IACol, SMLoc Loc) override;
- void emitCVLocDirective(unsigned FunctionId, unsigned FileNo, unsigned Line,
- unsigned Column, bool PrologueEnd, bool IsStmt,
- StringRef FileName, SMLoc Loc) override;
- void emitCVLinetableDirective(unsigned FunctionId, const MCSymbol *FnStart,
- const MCSymbol *FnEnd) override;
- void emitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
- unsigned SourceFileId,
- unsigned SourceLineNum,
- const MCSymbol *FnStartSym,
- const MCSymbol *FnEndSym) override;
-
- void PrintCVDefRangePrefix(
- ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges);
-
- void emitCVDefRangeDirective(
- ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
- codeview::DefRangeRegisterRelHeader DRHdr) override;
-
- void emitCVDefRangeDirective(
- ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
- codeview::DefRangeSubfieldRegisterHeader DRHdr) override;
-
- void emitCVDefRangeDirective(
- ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
- codeview::DefRangeRegisterHeader DRHdr) override;
-
- void emitCVDefRangeDirective(
- ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
- codeview::DefRangeFramePointerRelHeader DRHdr) override;
-
- void emitCVStringTableDirective() override;
- void emitCVFileChecksumsDirective() override;
- void emitCVFileChecksumOffsetDirective(unsigned FileNo) override;
- void EmitCVFPOData(const MCSymbol *ProcSym, SMLoc L) override;
-
- void emitIdent(StringRef IdentString) override;
- void emitCFIBKeyFrame() override;
- void emitCFISections(bool EH, bool Debug) override;
- void emitCFIDefCfa(int64_t Register, int64_t Offset) override;
- void emitCFIDefCfaOffset(int64_t Offset) override;
- void emitCFIDefCfaRegister(int64_t Register) override;
- void emitCFIOffset(int64_t Register, int64_t Offset) override;
- void emitCFIPersonality(const MCSymbol *Sym, unsigned Encoding) override;
- void emitCFILsda(const MCSymbol *Sym, unsigned Encoding) override;
- void emitCFIRememberState() override;
- void emitCFIRestoreState() override;
- void emitCFIRestore(int64_t Register) override;
- void emitCFISameValue(int64_t Register) override;
- void emitCFIRelOffset(int64_t Register, int64_t Offset) override;
- void emitCFIAdjustCfaOffset(int64_t Adjustment) override;
- void emitCFIEscape(StringRef Values) override;
- void emitCFIGnuArgsSize(int64_t Size) override;
- void emitCFISignalFrame() override;
- void emitCFIUndefined(int64_t Register) override;
- void emitCFIRegister(int64_t Register1, int64_t Register2) override;
- void emitCFIWindowSave() override;
- void emitCFINegateRAState() override;
- void emitCFIReturnColumn(int64_t Register) override;
-
- void EmitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc) override;
- void EmitWinCFIEndProc(SMLoc Loc) override;
- void EmitWinCFIFuncletOrFuncEnd(SMLoc Loc) override;
- void EmitWinCFIStartChained(SMLoc Loc) override;
- void EmitWinCFIEndChained(SMLoc Loc) override;
- void EmitWinCFIPushReg(MCRegister Register, SMLoc Loc) override;
- void EmitWinCFISetFrame(MCRegister Register, unsigned Offset,
- SMLoc Loc) override;
- void EmitWinCFIAllocStack(unsigned Size, SMLoc Loc) override;
- void EmitWinCFISaveReg(MCRegister Register, unsigned Offset,
- SMLoc Loc) override;
- void EmitWinCFISaveXMM(MCRegister Register, unsigned Offset,
- SMLoc Loc) override;
- void EmitWinCFIPushFrame(bool Code, SMLoc Loc) override;
- void EmitWinCFIEndProlog(SMLoc Loc) override;
-
- void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except,
- SMLoc Loc) override;
- void EmitWinEHHandlerData(SMLoc Loc) override;
-
- void emitCGProfileEntry(const MCSymbolRefExpr *From,
- const MCSymbolRefExpr *To, uint64_t Count) override;
-
- void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
-
- void emitPseudoProbe(uint64_t Guid, uint64_t Index, uint64_t Type,
- uint64_t Attr,
- const MCPseudoProbeInlineStack &InlineStack) override;
-
- void emitBundleAlignMode(unsigned AlignPow2) override;
- void emitBundleLock(bool AlignToEnd) override;
- void emitBundleUnlock() override;
-
- Optional<std::pair<bool, std::string>>
- emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr,
- SMLoc Loc, const MCSubtargetInfo &STI) override;
-
- void emitAddrsig() override;
- void emitAddrsigSym(const MCSymbol *Sym) override;
-
- /// If this file is backed by an assembly streamer, this dumps the specified
- /// string in the output .s file. This capability is indicated by the
- /// hasRawTextSupport() predicate.
- void emitRawTextImpl(StringRef String) override;
-
- void finishImpl() override;
-};
-
-} // end anonymous namespace.
-
void MCAsmStreamer::AddComment(const Twine &T, bool EOL) {
if (!IsVerboseAsm) return;
diff --git a/llvm/lib/MC/MCNullStreamer.cpp b/llvm/lib/MC/MCNullStreamer.cpp
index 291d840b4f4b..01a2f3e0e0db 100644
--- a/llvm/lib/MC/MCNullStreamer.cpp
+++ b/llvm/lib/MC/MCNullStreamer.cpp
@@ -19,6 +19,11 @@ namespace {
public:
MCNullStreamer(MCContext &Context) : MCStreamer(Context) {}
+ uint32_t getStreamerKind() const override { return StreamerKindNull; }
+ static bool classof(const MCStreamer *S) {
+ return S->getStreamerKind() == StreamerKindNull;
+ }
+
/// @name MCStreamer Interface
/// @{
diff --git a/llvm/lib/Object/RecordStreamer.h b/llvm/lib/Object/RecordStreamer.h
index 99d15f790a15..34de42202afd 100644
--- a/llvm/lib/Object/RecordStreamer.h
+++ b/llvm/lib/Object/RecordStreamer.h
@@ -45,6 +45,11 @@ class RecordStreamer : public MCStreamer {
public:
RecordStreamer(MCContext &Context, const Module &M);
+ uint32_t getStreamerKind() const override { return StreamerKindRecord; }
+ static bool classof(const MCStreamer *S) {
+ return S->getStreamerKind() == StreamerKindRecord;
+ }
+
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
More information about the llvm-branch-commits
mailing list