#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/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/MC/TargetRegistry.h"
#include "llvm/Support/Casting.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"
#include <algorithm>
#include <optional>
usingnamespacellvm;
namespace {
class MCAsmStreamer final : public MCStreamer { … };
}
void MCAsmStreamer::AddComment(const Twine &T, bool EOL) { … }
void MCAsmStreamer::EmitCommentsAndEOL() { … }
static inline int64_t truncateToSize(int64_t Value, unsigned Bytes) { … }
void MCAsmStreamer::emitRawComment(const Twine &T, bool TabPrefix) { … }
void MCAsmStreamer::addExplicitComment(const Twine &T) { … }
void MCAsmStreamer::emitExplicitComments() { … }
void MCAsmStreamer::changeSection(MCSection *Section, uint32_t Subsection) { … }
void MCAsmStreamer::emitELFSymverDirective(const MCSymbol *OriginalSym,
StringRef Name,
bool KeepOriginalSym) { … }
void MCAsmStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) { … }
void MCAsmStreamer::emitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) { … }
void MCAsmStreamer::emitGNUAttribute(unsigned Tag, unsigned Value) { … }
void MCAsmStreamer::emitAssemblerFlag(MCAssemblerFlag Flag) { … }
void MCAsmStreamer::emitLinkerOptions(ArrayRef<std::string> Options) { … }
void MCAsmStreamer::emitDataRegion(MCDataRegionType Kind) { … }
static const char *getVersionMinDirective(MCVersionMinType Type) { … }
static void EmitSDKVersionSuffix(raw_ostream &OS,
const VersionTuple &SDKVersion) { … }
void MCAsmStreamer::emitVersionMin(MCVersionMinType Type, unsigned Major,
unsigned Minor, unsigned Update,
VersionTuple SDKVersion) { … }
static const char *getPlatformName(MachO::PlatformType Type) { … }
void MCAsmStreamer::emitBuildVersion(unsigned Platform, unsigned Major,
unsigned Minor, unsigned Update,
VersionTuple SDKVersion) { … }
void MCAsmStreamer::emitDarwinTargetVariantBuildVersion(
unsigned Platform, unsigned Major, unsigned Minor, unsigned Update,
VersionTuple SDKVersion) { … }
void MCAsmStreamer::emitThumbFunc(MCSymbol *Func) { … }
void MCAsmStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) { … }
void MCAsmStreamer::emitConditionalAssignment(MCSymbol *Symbol,
const MCExpr *Value) { … }
void MCAsmStreamer::emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) { … }
bool MCAsmStreamer::emitSymbolAttribute(MCSymbol *Symbol,
MCSymbolAttr Attribute) { … }
void MCAsmStreamer::emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) { … }
void MCAsmStreamer::emitSyntaxDirective() { … }
void MCAsmStreamer::beginCOFFSymbolDef(const MCSymbol *Symbol) { … }
void MCAsmStreamer::emitCOFFSymbolStorageClass(int StorageClass) { … }
void MCAsmStreamer::emitCOFFSymbolType(int Type) { … }
void MCAsmStreamer::endCOFFSymbolDef() { … }
void MCAsmStreamer::emitCOFFSafeSEH(MCSymbol const *Symbol) { … }
void MCAsmStreamer::emitCOFFSymbolIndex(MCSymbol const *Symbol) { … }
void MCAsmStreamer::emitCOFFSectionIndex(MCSymbol const *Symbol) { … }
void MCAsmStreamer::emitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset) { … }
void MCAsmStreamer::emitCOFFImgRel32(MCSymbol const *Symbol, int64_t Offset) { … }
void MCAsmStreamer::emitXCOFFLocalCommonSymbol(MCSymbol *LabelSym,
uint64_t Size,
MCSymbol *CsectSym,
Align Alignment) { … }
void MCAsmStreamer::emitXCOFFSymbolLinkageWithVisibility(
MCSymbol *Symbol, MCSymbolAttr Linkage, MCSymbolAttr Visibility) { … }
void MCAsmStreamer::emitXCOFFRenameDirective(const MCSymbol *Name,
StringRef Rename) { … }
void MCAsmStreamer::emitXCOFFRefDirective(const MCSymbol *Symbol) { … }
void MCAsmStreamer::emitXCOFFExceptDirective(const MCSymbol *Symbol,
const MCSymbol *Trap,
unsigned Lang,
unsigned Reason,
unsigned FunctionSize,
bool hasDebug) { … }
void MCAsmStreamer::emitXCOFFCInfoSym(StringRef Name, StringRef Metadata) { … }
void MCAsmStreamer::emitELFSize(MCSymbol *Symbol, const MCExpr *Value) { … }
void MCAsmStreamer::emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Align ByteAlignment) { … }
void MCAsmStreamer::emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Align ByteAlign) { … }
void MCAsmStreamer::emitZerofill(MCSection *Section, MCSymbol *Symbol,
uint64_t Size, Align ByteAlignment,
SMLoc Loc) { … }
void MCAsmStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
uint64_t Size, Align ByteAlignment) { … }
static inline bool isPrintableString(StringRef Data) { … }
static inline char toOctal(int X) { … }
static void PrintByteList(StringRef Data, raw_ostream &OS,
MCAsmInfo::AsmCharLiteralSyntax ACLS) { … }
void MCAsmStreamer::PrintQuotedString(StringRef Data, raw_ostream &OS) const { … }
void MCAsmStreamer::emitBytes(StringRef Data) { … }
void MCAsmStreamer::emitBinaryData(StringRef Data) { … }
void MCAsmStreamer::emitIntValue(uint64_t Value, unsigned Size) { … }
void MCAsmStreamer::emitIntValueInHex(uint64_t Value, unsigned Size) { … }
void MCAsmStreamer::emitIntValueInHexWithPadding(uint64_t Value,
unsigned Size) { … }
void MCAsmStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,
SMLoc Loc) { … }
void MCAsmStreamer::emitULEB128Value(const MCExpr *Value) { … }
void MCAsmStreamer::emitSLEB128Value(const MCExpr *Value) { … }
void MCAsmStreamer::emitDTPRel64Value(const MCExpr *Value) { … }
void MCAsmStreamer::emitDTPRel32Value(const MCExpr *Value) { … }
void MCAsmStreamer::emitTPRel64Value(const MCExpr *Value) { … }
void MCAsmStreamer::emitTPRel32Value(const MCExpr *Value) { … }
void MCAsmStreamer::emitGPRel64Value(const MCExpr *Value) { … }
void MCAsmStreamer::emitGPRel32Value(const MCExpr *Value) { … }
void MCAsmStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
SMLoc Loc) { … }
void MCAsmStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
int64_t Expr, SMLoc Loc) { … }
void MCAsmStreamer::emitAlignmentDirective(uint64_t ByteAlignment,
std::optional<int64_t> Value,
unsigned ValueSize,
unsigned MaxBytesToEmit) { … }
void MCAsmStreamer::emitValueToAlignment(Align Alignment, int64_t Value,
unsigned ValueSize,
unsigned MaxBytesToEmit) { … }
void MCAsmStreamer::emitCodeAlignment(Align Alignment,
const MCSubtargetInfo *STI,
unsigned MaxBytesToEmit) { … }
void MCAsmStreamer::emitValueToOffset(const MCExpr *Offset,
unsigned char Value,
SMLoc Loc) { … }
void MCAsmStreamer::emitFileDirective(StringRef Filename) { … }
void MCAsmStreamer::emitFileDirective(StringRef Filename,
StringRef CompilerVersion,
StringRef TimeStamp,
StringRef Description) { … }
void MCAsmStreamer::printDwarfFileDirective(
unsigned FileNo, StringRef Directory, StringRef Filename,
std::optional<MD5::MD5Result> Checksum, std::optional<StringRef> Source,
bool UseDwarfDirectory, raw_svector_ostream &OS) const { … }
Expected<unsigned> MCAsmStreamer::tryEmitDwarfFileDirective(
unsigned FileNo, StringRef Directory, StringRef Filename,
std::optional<MD5::MD5Result> Checksum, std::optional<StringRef> Source,
unsigned CUID) { … }
void MCAsmStreamer::emitDwarfFile0Directive(
StringRef Directory, StringRef Filename,
std::optional<MD5::MD5Result> Checksum, std::optional<StringRef> Source,
unsigned CUID) { … }
void MCAsmStreamer::emitDwarfLocDirective(unsigned FileNo, unsigned Line,
unsigned Column, unsigned Flags,
unsigned Isa, unsigned Discriminator,
StringRef FileName) { … }
MCSymbol *MCAsmStreamer::getDwarfLineTableSymbol(unsigned CUID) { … }
bool MCAsmStreamer::emitCVFileDirective(unsigned FileNo, StringRef Filename,
ArrayRef<uint8_t> Checksum,
unsigned ChecksumKind) { … }
bool MCAsmStreamer::emitCVFuncIdDirective(unsigned FuncId) { … }
bool MCAsmStreamer::emitCVInlineSiteIdDirective(unsigned FunctionId,
unsigned IAFunc,
unsigned IAFile,
unsigned IALine, unsigned IACol,
SMLoc Loc) { … }
void MCAsmStreamer::emitCVLocDirective(unsigned FunctionId, unsigned FileNo,
unsigned Line, unsigned Column,
bool PrologueEnd, bool IsStmt,
StringRef FileName, SMLoc Loc) { … }
void MCAsmStreamer::emitCVLinetableDirective(unsigned FunctionId,
const MCSymbol *FnStart,
const MCSymbol *FnEnd) { … }
void MCAsmStreamer::emitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
unsigned SourceFileId,
unsigned SourceLineNum,
const MCSymbol *FnStartSym,
const MCSymbol *FnEndSym) { … }
void MCAsmStreamer::PrintCVDefRangePrefix(
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges) { … }
void MCAsmStreamer::emitCVDefRangeDirective(
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
codeview::DefRangeRegisterRelHeader DRHdr) { … }
void MCAsmStreamer::emitCVDefRangeDirective(
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
codeview::DefRangeSubfieldRegisterHeader DRHdr) { … }
void MCAsmStreamer::emitCVDefRangeDirective(
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
codeview::DefRangeRegisterHeader DRHdr) { … }
void MCAsmStreamer::emitCVDefRangeDirective(
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
codeview::DefRangeFramePointerRelHeader DRHdr) { … }
void MCAsmStreamer::emitCVStringTableDirective() { … }
void MCAsmStreamer::emitCVFileChecksumsDirective() { … }
void MCAsmStreamer::emitCVFileChecksumOffsetDirective(unsigned FileNo) { … }
void MCAsmStreamer::emitCVFPOData(const MCSymbol *ProcSym, SMLoc L) { … }
void MCAsmStreamer::emitIdent(StringRef IdentString) { … }
void MCAsmStreamer::emitCFISections(bool EH, bool Debug) { … }
void MCAsmStreamer::emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) { … }
void MCAsmStreamer::emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) { … }
void MCAsmStreamer::EmitRegisterName(int64_t Register) { … }
void MCAsmStreamer::emitCFIDefCfa(int64_t Register, int64_t Offset, SMLoc Loc) { … }
void MCAsmStreamer::emitCFIDefCfaOffset(int64_t Offset, SMLoc Loc) { … }
void MCAsmStreamer::emitCFILLVMDefAspaceCfa(int64_t Register, int64_t Offset,
int64_t AddressSpace, SMLoc Loc) { … }
static void PrintCFIEscape(llvm::formatted_raw_ostream &OS, StringRef Values) { … }
void MCAsmStreamer::emitCFIEscape(StringRef Values, SMLoc Loc) { … }
void MCAsmStreamer::emitCFIGnuArgsSize(int64_t Size, SMLoc Loc) { … }
void MCAsmStreamer::emitCFIDefCfaRegister(int64_t Register, SMLoc Loc) { … }
void MCAsmStreamer::emitCFIOffset(int64_t Register, int64_t Offset, SMLoc Loc) { … }
void MCAsmStreamer::emitCFIPersonality(const MCSymbol *Sym,
unsigned Encoding) { … }
void MCAsmStreamer::emitCFILsda(const MCSymbol *Sym, unsigned Encoding) { … }
void MCAsmStreamer::emitCFIRememberState(SMLoc Loc) { … }
void MCAsmStreamer::emitCFIRestoreState(SMLoc Loc) { … }
void MCAsmStreamer::emitCFIRestore(int64_t Register, SMLoc Loc) { … }
void MCAsmStreamer::emitCFISameValue(int64_t Register, SMLoc Loc) { … }
void MCAsmStreamer::emitCFIRelOffset(int64_t Register, int64_t Offset,
SMLoc Loc) { … }
void MCAsmStreamer::emitCFIAdjustCfaOffset(int64_t Adjustment, SMLoc Loc) { … }
void MCAsmStreamer::emitCFISignalFrame() { … }
void MCAsmStreamer::emitCFIUndefined(int64_t Register, SMLoc Loc) { … }
void MCAsmStreamer::emitCFIRegister(int64_t Register1, int64_t Register2,
SMLoc Loc) { … }
void MCAsmStreamer::emitCFIWindowSave(SMLoc Loc) { … }
void MCAsmStreamer::emitCFINegateRAState(SMLoc Loc) { … }
void MCAsmStreamer::emitCFIReturnColumn(int64_t Register) { … }
void MCAsmStreamer::emitCFILabelDirective(SMLoc Loc, StringRef Name) { … }
void MCAsmStreamer::emitCFIBKeyFrame() { … }
void MCAsmStreamer::emitCFIMTETaggedFrame() { … }
void MCAsmStreamer::emitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc) { … }
void MCAsmStreamer::emitWinCFIEndProc(SMLoc Loc) { … }
void MCAsmStreamer::emitWinCFIFuncletOrFuncEnd(SMLoc Loc) { … }
void MCAsmStreamer::emitWinCFIStartChained(SMLoc Loc) { … }
void MCAsmStreamer::emitWinCFIEndChained(SMLoc Loc) { … }
void MCAsmStreamer::emitWinEHHandler(const MCSymbol *Sym, bool Unwind,
bool Except, SMLoc Loc) { … }
void MCAsmStreamer::emitWinEHHandlerData(SMLoc Loc) { … }
void MCAsmStreamer::emitWinCFIPushReg(MCRegister Register, SMLoc Loc) { … }
void MCAsmStreamer::emitWinCFISetFrame(MCRegister Register, unsigned Offset,
SMLoc Loc) { … }
void MCAsmStreamer::emitWinCFIAllocStack(unsigned Size, SMLoc Loc) { … }
void MCAsmStreamer::emitWinCFISaveReg(MCRegister Register, unsigned Offset,
SMLoc Loc) { … }
void MCAsmStreamer::emitWinCFISaveXMM(MCRegister Register, unsigned Offset,
SMLoc Loc) { … }
void MCAsmStreamer::emitWinCFIPushFrame(bool Code, SMLoc Loc) { … }
void MCAsmStreamer::emitWinCFIEndProlog(SMLoc Loc) { … }
void MCAsmStreamer::emitCGProfileEntry(const MCSymbolRefExpr *From,
const MCSymbolRefExpr *To,
uint64_t Count) { … }
void MCAsmStreamer::AddEncodingComment(const MCInst &Inst,
const MCSubtargetInfo &STI) { … }
void MCAsmStreamer::emitInstruction(const MCInst &Inst,
const MCSubtargetInfo &STI) { … }
void MCAsmStreamer::emitPseudoProbe(uint64_t Guid, uint64_t Index,
uint64_t Type, uint64_t Attr,
uint64_t Discriminator,
const MCPseudoProbeInlineStack &InlineStack,
MCSymbol *FnSym) { … }
void MCAsmStreamer::emitBundleAlignMode(Align Alignment) { … }
void MCAsmStreamer::emitBundleLock(bool AlignToEnd) { … }
void MCAsmStreamer::emitBundleUnlock() { … }
std::optional<std::pair<bool, std::string>>
MCAsmStreamer::emitRelocDirective(const MCExpr &Offset, StringRef Name,
const MCExpr *Expr, SMLoc,
const MCSubtargetInfo &STI) { … }
void MCAsmStreamer::emitAddrsig() { … }
void MCAsmStreamer::emitAddrsigSym(const MCSymbol *Sym) { … }
void MCAsmStreamer::emitRawTextImpl(StringRef String) { … }
void MCAsmStreamer::finishImpl() { … }
void MCAsmStreamer::emitDwarfUnitLength(uint64_t Length, const Twine &Comment) { … }
MCSymbol *MCAsmStreamer::emitDwarfUnitLength(const Twine &Prefix,
const Twine &Comment) { … }
void MCAsmStreamer::emitDwarfLineStartLabel(MCSymbol *StartSym) { … }
void MCAsmStreamer::emitDwarfLineEndEntry(MCSection *Section,
MCSymbol *LastLabel) { … }
void MCAsmStreamer::emitDwarfAdvanceLineAddr(int64_t LineDelta,
const MCSymbol *LastLabel,
const MCSymbol *Label,
unsigned PointerSize) { … }
void MCAsmStreamer::doFinalizationAtSectionEnd(MCSection *Section) { … }
MCStreamer *llvm::createAsmStreamer(MCContext &Context,
std::unique_ptr<formatted_raw_ostream> OS,
MCInstPrinter *IP,
std::unique_ptr<MCCodeEmitter> &&CE,
std::unique_ptr<MCAsmBackend> &&MAB) { … }