44 : Context(Ctx), CurrentWinFrameInfo(nullptr) {
45 SectionStack.
push_back(std::pair<MCSectionSubPair, MCSectionSubPair>());
50 delete WinFrameInfos[i];
54 DwarfFrameInfos.clear();
56 delete WinFrameInfos[i];
57 WinFrameInfos.clear();
58 CurrentWinFrameInfo =
nullptr;
59 SymbolOrdering.
clear();
61 SectionStack.
push_back(std::pair<MCSectionSubPair, MCSectionSubPair>());
72 for (
auto &FI : DwarfFrameInfos)
73 FI.CompactUnwindEncoding =
80 assert(1 <= Size && Size <= 8 &&
"Invalid size");
81 assert((
isUIntN(8 * Size, Value) ||
isIntN(8 * Size, Value)) &&
85 for (
unsigned i = 0; i != Size; ++i) {
86 unsigned index = isLittleEndian ? i : (Size - i - 1);
87 buf[i] = uint8_t(Value >> (index * 8));
116 bool IsSectionRelative) {
117 assert((!IsSectionRelative || Size == 4) &&
118 "SectionRelative value requires 4-bytes");
120 if (!IsSectionRelative)
138 for (uint64_t i = 0, e = NumBytes; i != e; ++i)
154 unsigned Column,
unsigned Flags,
156 unsigned Discriminator,
173 if (DwarfFrameInfos.empty())
175 return &DwarfFrameInfos.back();
178 void MCStreamer::EnsureValidDwarfFrame() {
180 if (!CurFrame || CurFrame->
End)
200 SymbolOrdering[
Symbol] = 1 + SymbolOrdering.
size();
204 assert(!Symbol->
isVariable() &&
"Cannot emit a variable symbol!");
219 if (CurFrame && !CurFrame->
End)
236 DwarfFrameInfos.push_back(Frame);
243 EnsureValidDwarfFrame();
254 MCSymbol *MCStreamer::EmitCFICommon() {
255 EnsureValidDwarfFrame();
313 EnsureValidDwarfFrame();
320 EnsureValidDwarfFrame();
322 CurFrame->
Lsda = Sym;
365 EnsureValidDwarfFrame();
394 void MCStreamer::EnsureValidWinFrameInfo() {
398 if (!CurrentWinFrameInfo || CurrentWinFrameInfo->
End)
406 if (CurrentWinFrameInfo && !CurrentWinFrameInfo->
End)
413 CurrentWinFrameInfo = WinFrameInfos.back();
417 EnsureValidWinFrameInfo();
427 EnsureValidWinFrameInfo();
433 StartProc, CurrentWinFrameInfo));
434 CurrentWinFrameInfo = WinFrameInfos.back();
438 EnsureValidWinFrameInfo();
446 CurrentWinFrameInfo =
452 EnsureValidWinFrameInfo();
456 if (!Except && !Unwind)
465 EnsureValidWinFrameInfo();
471 EnsureValidWinFrameInfo();
481 EnsureValidWinFrameInfo();
499 EnsureValidWinFrameInfo();
513 EnsureValidWinFrameInfo();
526 EnsureValidWinFrameInfo();
539 EnsureValidWinFrameInfo();
551 EnsureValidWinFrameInfo();
572 errs() <<
"EmitRawText called on an MCStreamer that doesn't support it, "
573 " something must not be fully mc'ized\n";
586 if (!DwarfFrameInfos.empty() && !DwarfFrameInfos.back().End)
607 InstPrinter.
printInst(&Inst, OS,
"", STI);
690 unsigned MaxBytesToEmit) {}
692 unsigned MaxBytesToEmit) {}
702 assert(Section &&
"Cannot switch to a null section!");
704 SectionStack.
back().second = curSection;
708 assert(!Section->
hasEnded() &&
"Section already ended");
710 if (Sym && !Sym->isInSection())
virtual void EmitBundleUnlock()
Ends a bundle-locked group.
virtual void EmitAssemblerFlag(MCAssemblerFlag Flag)
Note in the output the specified Flag.
virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, unsigned Discriminator, StringRef FileName)
This implements the DWARF2 '.loc fileno lineno ...' assembler directive.
void AssignSection(MCSymbol *Symbol, MCSection *Section)
Sets the symbol's section.
virtual void EmitBundleAlignMode(unsigned AlignPow2)
Set the bundle alignment mode from now on in the section.
Instances of this class represent a uniqued identifier for a section in the current translation unit...
void push_back(const T &Elt)
virtual void EmitCFISameValue(int64_t Register)
const MCAsmInfo * getAsmInfo() const
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding)
virtual void EmitSLEB128Value(const MCExpr *Value)
void EmitRawText(const Twine &String)
If this file is backed by a assembly streamer, this dumps the specified string in the output ...
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
virtual void EmitWinCFIEndProlog()
void EmitSLEB128IntValue(int64_t Value)
Special case of EmitSLEB128Value that avoids the client having to pass in a MCExpr for constant integ...
void EmitSymbolValue(const MCSymbol *Sym, unsigned Size, bool IsSectionRelative=false)
Special case of EmitValue that avoids the client having to pass in a MCExpr for MCSymbols.
virtual void printInst(const MCInst *MI, raw_ostream &OS, StringRef Annot, const MCSubtargetInfo &STI)=0
Print the specified MCInst to the specified raw_ostream.
virtual void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment=0)
Emit a thread local bss (.tbss) symbol.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
virtual void EndCOFFSymbolDef()
Marks the end of the symbol definition.
virtual ~MCTargetStreamer()
virtual void EmitULEB128Value(const MCExpr *Value)
static MCCFIInstruction createRememberState(MCSymbol *L)
.cfi_remember_state Save all current rules for all registers.
virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol)
Emit an weak reference from Alias to Symbol.
static WinEH::Instruction SaveNonVol(MCSymbol *L, unsigned Reg, unsigned Offset)
virtual void EmitBytes(StringRef Data)
Emit the bytes in Data into the output.
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register, int Offset)
.cfi_offset Previous value of Register is saved at offset Offset from CFA.
MCSymbol * getLabel() const
Target specific streamer interface.
const char * getPrivateGlobalPrefix() const
virtual void reset()
State management.
unsigned CurrentCfaRegister
virtual void EmitWindowsUnwindTables()
void EmitCFIStartProc(bool IsSimple)
virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol)
Start emitting COFF symbol definition.
virtual unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory, StringRef Filename, unsigned CUID=0)
Associate a filename with a specified logical file number.
A raw_ostream that writes to an SmallVector or SmallString.
virtual void EmitCFIRegister(int64_t Register1, int64_t Register2)
virtual void EmitValueImpl(const MCExpr *Value, unsigned Size, const SMLoc &Loc=SMLoc())
Emit the expression Value into the output as a native integer of the given Size bytes.
virtual void EmitCFIDefCfaOffset(int64_t Offset)
virtual MCSymbol * getDwarfLineTableSymbol(unsigned CUID)
static MCCFIInstruction createDefCfaOffset(MCSymbol *L, int Offset)
.cfi_def_cfa_offset modifies a rule for computing CFA.
COFF::SymbolStorageClass StorageClass
virtual void EmitCOFFSymbolStorageClass(int StorageClass)
Emit the storage class of the symbol.
std::vector< Instruction > Instructions
static MCCFIInstruction createAdjustCfaOffset(MCSymbol *L, int Adjustment)
.cfi_adjust_cfa_offset Same as .cfi_def_cfa_offset, but Offset is a relative value that is added/subt...
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
virtual void emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value)
Emit an ELF .size directive.
virtual void EmitCFISections(bool EH, bool Debug)
virtual void EmitGPRel32Value(const MCExpr *Value)
Emit the expression Value into the output as a gprel32 (32-bit GP relative) value.
std::vector< MCCFIInstruction > Instructions
static MCCFIInstruction createUndefined(MCSymbol *L, unsigned Register)
.cfi_undefined From now on the previous value of Register can't be restored anymore.
virtual void EmitWinEHHandlerData()
virtual void EmitCFIRememberState()
virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding)
virtual void EmitGPRel64Value(const MCExpr *Value)
Emit the expression Value into the output as a gprel64 (64-bit GP relative) value.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
virtual void EmitCFIEscape(StringRef Values)
MCSectionSubPair getCurrentSection() const
Return the current section that the streamer is emitting code to.
virtual void EmitCOFFSymbolType(int Type)
Emit the type of the symbol.
Base class for the full range of assembler expressions which are needed for parsing.
const std::vector< MCCFIInstruction > & getInitialFrameState() const
bool doesSetDirectiveSuppressesReloc() const
virtual void emitLabel(MCSymbol *Symbol)
virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame)
unsigned getNumWinFrameInfos()
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
MCContext & getContext() const
MCSymbol * getEndSymbol(MCContext &Ctx)
bool isLittleEndian() const
True if the target is little endian.
void setSection(MCSection &S)
Mark the symbol as defined in the section S.
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
Context object for machine code objects.
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute)...
static WinEH::Instruction PushNonVol(MCSymbol *L, unsigned Reg)
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame)
std::pair< MCSection *, const MCExpr * > MCSectionSubPair
virtual bool EmitValueToOffset(const MCExpr *Offset, unsigned char Value=0)
Emit some number of copies of Value until the byte offset Offset is reached.
virtual void emitRawComment(const Twine &T, bool TabPrefix=true)
Print T and prefix it with the comment string (normally #) and optionally a tab.
virtual void EmitCFIRestoreState()
virtual void EmitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers...
Instances of this class represent a single low-level machine instruction.
virtual void EmitCFIRestore(int64_t Register)
Flag
These should be considered private to the implementation of the MCInstrDesc class.
This class is intended to be used as a base class for asm properties and features specific to the tar...
virtual void EmitBundleLock(bool AlignToEnd)
The following instructions are a bundle-locked group.
virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment)
Emit a local common (.lcomm) symbol.
const MCExpr * getExpr() const
static MCCFIInstruction createSameValue(MCSymbol *L, unsigned Register)
.cfi_same_value Current value of Register is the same as in the previous frame.
virtual raw_ostream & GetCommentOS()
Return a raw_ostream that comments can be written to.
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
virtual void EmitZeros(uint64_t NumBytes)
Emit NumBytes worth of zeros.
Streaming machine code generation interface.
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
const FrameInfo * ChainedParent
MCTargetStreamer * getTargetStreamer()
static MCCFIInstruction createDefCfa(MCSymbol *L, unsigned Register, int Offset)
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it...
The instances of the Type class are immutable: once they are created, they are never changed...
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register)
.cfi_def_cfa_register modifies a rule for computing CFA.
virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue)
Emit NumBytes bytes worth of the value specified by FillValue.
virtual void EmitWinCFIPushReg(unsigned Register)
static MCCFIInstruction createWindowSave(MCSymbol *L)
.cfi_window_save SPARC register window is saved.
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
static WinEH::Instruction PushMachFrame(MCSymbol *L, bool Code)
virtual void EmitCFIDefCfaRegister(int64_t Register)
virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0)
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
virtual void EmitCOFFSecRel32(MCSymbol const *Symbol)
Emits a COFF section relative relocation.
static MCCFIInstruction createRelOffset(MCSymbol *L, unsigned Register, int Offset)
.cfi_rel_offset Previous value of Register is saved at offset Offset from the current CFA register...
static MCCFIInstruction createRestore(MCSymbol *L, unsigned Register)
.cfi_restore says that the rule for Register is now the same as it was at the beginning of the functi...
virtual void EmitRawTextImpl(StringRef String)
EmitRawText - If this file is backed by an assembly streamer, this dumps the specified string in the ...
virtual void EmitWinCFIEndChained()
virtual void EmitWinCFIEndProc()
virtual void EmitCFIUndefined(int64_t Register)
unsigned PersonalityEncoding
static WinEH::Instruction SetFPReg(MCSymbol *L, unsigned Reg, unsigned Off)
void Finish()
Finish emission of machine code.
virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol)
bool isIntN(unsigned N, int64_t x)
isIntN - Checks if an signed integer fits into the given (dynamic) bit width.
static MCCFIInstruction createRestoreState(MCSymbol *L)
.cfi_restore_state Restore the previously saved state.
virtual void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except)
Binary assembler expressions.
virtual void EmitCOFFSafeSEH(MCSymbol const *Symbol)
void generateCompactUnwindEncodings(MCAsmBackend *MAB)
static WinEH::Instruction SaveXMM(MCSymbol *L, unsigned Reg, unsigned Offset)
const MCSymbol * PrologEnd
virtual void EmitWinCFIStartChained()
virtual void InitSections(bool NoExecStack)
Create the default sections and set the initial one.
virtual void EmitLabel(MCSymbol *Symbol)
Emit a label for Symbol into the current section.
virtual void EmitWinCFISaveXMM(unsigned Register, unsigned Offset)
virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size)
Emit the absolute difference between two symbols.
void setUndefined()
Mark the symbol as undefined.
virtual void EmitCFIOffset(int64_t Register, int64_t Offset)
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
static WinEH::Instruction Alloc(MCSymbol *L, unsigned Size)
virtual void EmitCodeAlignment(unsigned ByteAlignment, unsigned MaxBytesToEmit=0)
Emit nops until the byte alignment ByteAlignment is reached.
Promote Memory to Register
MCSymbol * getBeginSymbol()
virtual void prettyPrintAsm(MCInstPrinter &InstPrinter, raw_ostream &OS, const MCInst &Inst, const MCSubtargetInfo &STI)
virtual void EmitWinCFIAllocStack(unsigned Size)
virtual void ChangeSection(MCSection *, const MCExpr *)
Update streamer for a new active section.
void setVariableValue(const MCExpr *Value)
void encodeSLEB128(int64_t Value, raw_ostream &OS)
Utility function to encode a SLEB128 value to an output stream.
const MCSymbol * Function
void visitUsedExpr(const MCExpr &Expr)
MCTargetStreamer(MCStreamer &S)
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
StringRef str()
Flushes the stream contents to the target vector and return a StringRef for the vector contents...
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
virtual void EmitThumbFunc(MCSymbol *Func)
Note in the output that the specified Func is a Thumb mode function (ARM target only).
virtual void EmitCFISignalFrame()
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset)
const MCSymbol * Personality
unsigned getNumOperands() const
virtual void EmitFileDirective(StringRef Filename)
Switch to a new logical file.
MCSubtargetInfo - Generic base class for all target subtargets.
virtual uint32_t generateCompactUnwindEncoding(ArrayRef< MCCFIInstruction >) const
Generate the compact unwind encoding for the CFI instructions.
References to labels and assigned expressions.
virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset)
void EmitValue(const MCExpr *Value, unsigned Size, const SMLoc &Loc=SMLoc())
void EmitULEB128IntValue(uint64_t Value, unsigned Padding=0)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
MCSymbol * endSection(MCSection *Section)
bool isVariable() const
isVariable - Check if this is a variable symbol.
void setCurrentDwarfLoc(unsigned FileNum, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, unsigned Discriminator)
Saves the information from the currently parsed dwarf .loc directive and sets DwarfLocSeen.
virtual void FinishImpl()
Streamer specific finalization.
LLVM Value Representation.
Generic interface to target specific assembler backends.
unsigned getDwarfFile(StringRef Directory, StringRef FileName, unsigned FileNumber, unsigned CUID)
Creates an entry in the dwarf file and directory tables.
static cl::opt< bool, true > Debug("debug", cl::desc("Enable debug output"), cl::Hidden, cl::location(DebugFlag))
virtual void EmitWinCFIStartProc(const MCSymbol *Symbol)
raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
This class implements an extremely fast bulk output stream that can only output to a stream...
void encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned Padding=0)
Utility function to encode a ULEB128 value to an output stream.
virtual void EmitWinCFISaveReg(unsigned Register, unsigned Offset)
virtual void EmitWinCFIPushFrame(bool Code)
StringRef - Represent a constant reference to a string, i.e.
Target specific expression.
virtual void visitUsedSymbol(const MCSymbol &Sym)
Represents a location in source code.
static MCCFIInstruction createEscape(MCSymbol *L, StringRef Vals)
.cfi_escape Allows the user to add arbitrary bytes to the unwind info.
bool isUIntN(unsigned N, uint64_t x)
isUIntN - Checks if an unsigned integer fits into the given (dynamic) bit width.
const MCSymbol * ExceptionHandler
void setTargetStreamer(MCTargetStreamer *TS)
virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value)
virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol)
Emits a COFF section index.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment)
void setLabel(MCSymbol *Label)
const MCOperand & getOperand(unsigned i) const
static MCCFIInstruction createRegister(MCSymbol *L, unsigned Register1, unsigned Register2)
.cfi_register Previous value of Register1 is saved in register Register2.
virtual void EmitWinCFISetFrame(unsigned Register, unsigned Offset)
virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue)
Set the DescValue for the Symbol.
virtual void EmitCFIWindowSave()
bool usesWindowsCFI() const