LCOV - code coverage report
Current view: top level - include/llvm/MC - MCStreamer.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 43 51 84.3 %
Date: 2017-09-14 15:23:50 Functions: 13 20 65.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- MCStreamer.h - High-level Streaming Machine Code Output --*- C++ -*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file declares the MCStreamer class.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #ifndef LLVM_MC_MCSTREAMER_H
      15             : #define LLVM_MC_MCSTREAMER_H
      16             : 
      17             : #include "llvm/ADT/ArrayRef.h"
      18             : #include "llvm/ADT/DenseMap.h"
      19             : #include "llvm/ADT/SmallVector.h"
      20             : #include "llvm/ADT/StringRef.h"
      21             : #include "llvm/MC/MCDirectives.h"
      22             : #include "llvm/MC/MCDwarf.h"
      23             : #include "llvm/MC/MCLinkerOptimizationHint.h"
      24             : #include "llvm/MC/MCSymbol.h"
      25             : #include "llvm/MC/MCWinEH.h"
      26             : #include "llvm/Support/SMLoc.h"
      27             : #include "llvm/Support/TargetParser.h"
      28             : #include <cassert>
      29             : #include <cstdint>
      30             : #include <memory>
      31             : #include <string>
      32             : #include <utility>
      33             : #include <vector>
      34             : 
      35             : namespace llvm {
      36             : 
      37             : class AssemblerConstantPools;
      38             : class formatted_raw_ostream;
      39             : class MCAsmBackend;
      40             : class MCCodeEmitter;
      41             : class MCContext;
      42             : class MCExpr;
      43             : class MCInst;
      44             : class MCInstPrinter;
      45             : class MCSection;
      46             : class MCStreamer;
      47             : class MCSymbolRefExpr;
      48             : class MCSubtargetInfo;
      49             : class raw_ostream;
      50             : class Twine;
      51             : 
      52             : using MCSectionSubPair = std::pair<MCSection *, const MCExpr *>;
      53             : 
      54             : /// Target specific streamer interface. This is used so that targets can
      55             : /// implement support for target specific assembly directives.
      56             : ///
      57             : /// If target foo wants to use this, it should implement 3 classes:
      58             : /// * FooTargetStreamer : public MCTargetStreamer
      59             : /// * FooTargetAsmStreamer : public FooTargetStreamer
      60             : /// * FooTargetELFStreamer : public FooTargetStreamer
      61             : ///
      62             : /// FooTargetStreamer should have a pure virtual method for each directive. For
      63             : /// example, for a ".bar symbol_name" directive, it should have
      64             : /// virtual emitBar(const MCSymbol &Symbol) = 0;
      65             : ///
      66             : /// The FooTargetAsmStreamer and FooTargetELFStreamer classes implement the
      67             : /// method. The assembly streamer just prints ".bar symbol_name". The object
      68             : /// streamer does whatever is needed to implement .bar in the object file.
      69             : ///
      70             : /// In the assembly printer and parser the target streamer can be used by
      71             : /// calling getTargetStreamer and casting it to FooTargetStreamer:
      72             : ///
      73             : /// MCTargetStreamer &TS = OutStreamer.getTargetStreamer();
      74             : /// FooTargetStreamer &ATS = static_cast<FooTargetStreamer &>(TS);
      75             : ///
      76             : /// The base classes FooTargetAsmStreamer and FooTargetELFStreamer should
      77             : /// *never* be treated differently. Callers should always talk to a
      78             : /// FooTargetStreamer.
      79       11629 : class MCTargetStreamer {
      80             : protected:
      81             :   MCStreamer &Streamer;
      82             : 
      83             : public:
      84             :   MCTargetStreamer(MCStreamer &S);
      85             :   virtual ~MCTargetStreamer();
      86             : 
      87             :   MCStreamer &getStreamer() { return Streamer; }
      88             : 
      89             :   // Allow a target to add behavior to the EmitLabel of MCStreamer.
      90             :   virtual void emitLabel(MCSymbol *Symbol);
      91             :   // Allow a target to add behavior to the emitAssignment of MCStreamer.
      92             :   virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value);
      93             : 
      94             :   virtual void prettyPrintAsm(MCInstPrinter &InstPrinter, raw_ostream &OS,
      95             :                               const MCInst &Inst, const MCSubtargetInfo &STI);
      96             : 
      97             :   virtual void finish();
      98             : };
      99             : 
     100             : // FIXME: declared here because it is used from
     101             : // lib/CodeGen/AsmPrinter/ARMException.cpp.
     102        7252 : class ARMTargetStreamer : public MCTargetStreamer {
     103             : public:
     104             :   ARMTargetStreamer(MCStreamer &S);
     105             :   ~ARMTargetStreamer() override;
     106             : 
     107             :   virtual void emitFnStart();
     108             :   virtual void emitFnEnd();
     109             :   virtual void emitCantUnwind();
     110             :   virtual void emitPersonality(const MCSymbol *Personality);
     111             :   virtual void emitPersonalityIndex(unsigned Index);
     112             :   virtual void emitHandlerData();
     113             :   virtual void emitSetFP(unsigned FpReg, unsigned SpReg,
     114             :                          int64_t Offset = 0);
     115             :   virtual void emitMovSP(unsigned Reg, int64_t Offset = 0);
     116             :   virtual void emitPad(int64_t Offset);
     117             :   virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
     118             :                            bool isVector);
     119             :   virtual void emitUnwindRaw(int64_t StackOffset,
     120             :                              const SmallVectorImpl<uint8_t> &Opcodes);
     121             : 
     122             :   virtual void switchVendor(StringRef Vendor);
     123             :   virtual void emitAttribute(unsigned Attribute, unsigned Value);
     124             :   virtual void emitTextAttribute(unsigned Attribute, StringRef String);
     125             :   virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
     126             :                                     StringRef StringValue = "");
     127             :   virtual void emitFPU(unsigned FPU);
     128             :   virtual void emitArch(ARM::ArchKind Arch);
     129             :   virtual void emitArchExtension(unsigned ArchExt);
     130             :   virtual void emitObjectArch(ARM::ArchKind Arch);
     131             :   void emitTargetAttributes(const MCSubtargetInfo &STI);
     132             :   virtual void finishAttributeSection();
     133             :   virtual void emitInst(uint32_t Inst, char Suffix = '\0');
     134             : 
     135             :   virtual void AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
     136             : 
     137             :   virtual void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value);
     138             : 
     139             :   void finish() override;
     140             : 
     141             :   /// Reset any state between object emissions, i.e. the equivalent of
     142             :   /// MCStreamer's reset method.
     143             :   virtual void reset();
     144             : 
     145             :   /// Callback used to implement the ldr= pseudo.
     146             :   /// Add a new entry to the constant pool for the current section and return an
     147             :   /// MCExpr that can be used to refer to the constant pool location.
     148             :   const MCExpr *addConstantPoolEntry(const MCExpr *, SMLoc Loc);
     149             : 
     150             :   /// Callback used to implemnt the .ltorg directive.
     151             :   /// Emit contents of constant pool for the current section.
     152             :   void emitCurrentConstantPool();
     153             : 
     154             : private:
     155             :   std::unique_ptr<AssemblerConstantPools> ConstantPools;
     156             : };
     157             : 
     158             : /// \brief Streaming machine code generation interface.
     159             : ///
     160             : /// This interface is intended to provide a programatic interface that is very
     161             : /// similar to the level that an assembler .s file provides.  It has callbacks
     162             : /// to emit bytes, handle directives, etc.  The implementation of this interface
     163             : /// retains state to know what the current section is etc.
     164             : ///
     165             : /// There are multiple implementations of this interface: one for writing out
     166             : /// a .s file, and implementations that write out .o files of various formats.
     167             : ///
     168             : class MCStreamer {
     169             :   MCContext &Context;
     170             :   std::unique_ptr<MCTargetStreamer> TargetStreamer;
     171             : 
     172             :   std::vector<MCDwarfFrameInfo> DwarfFrameInfos;
     173             :   MCDwarfFrameInfo *getCurrentDwarfFrameInfo();
     174             :   void EnsureValidDwarfFrame();
     175             : 
     176             :   MCSymbol *EmitCFILabel();
     177             :   MCSymbol *EmitCFICommon();
     178             : 
     179             :   std::vector<WinEH::FrameInfo *> WinFrameInfos;
     180             :   WinEH::FrameInfo *CurrentWinFrameInfo;
     181             :   void EnsureValidWinFrameInfo();
     182             : 
     183             :   /// \brief Tracks an index to represent the order a symbol was emitted in.
     184             :   /// Zero means we did not emit that symbol.
     185             :   DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
     186             : 
     187             :   /// \brief This is stack of current and previous section values saved by
     188             :   /// PushSection.
     189             :   SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
     190             : 
     191             :   /// The next unique ID to use when creating a WinCFI-related section (.pdata
     192             :   /// or .xdata). This ID ensures that we have a one-to-one mapping from
     193             :   /// code section to unwind info section, which MSVC's incremental linker
     194             :   /// requires.
     195             :   unsigned NextWinCFIID = 0;
     196             : 
     197             : protected:
     198             :   MCStreamer(MCContext &Ctx);
     199             : 
     200             :   virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
     201             :   virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
     202             : 
     203             :   WinEH::FrameInfo *getCurrentWinFrameInfo() {
     204             :     return CurrentWinFrameInfo;
     205             :   }
     206             : 
     207             :   virtual void EmitWindowsUnwindTables();
     208             : 
     209             :   virtual void EmitRawTextImpl(StringRef String);
     210             : 
     211             : public:
     212             :   MCStreamer(const MCStreamer &) = delete;
     213             :   MCStreamer &operator=(const MCStreamer &) = delete;
     214             :   virtual ~MCStreamer();
     215             : 
     216             :   void visitUsedExpr(const MCExpr &Expr);
     217             :   virtual void visitUsedSymbol(const MCSymbol &Sym);
     218             : 
     219             :   void setTargetStreamer(MCTargetStreamer *TS) {
     220       23416 :     TargetStreamer.reset(TS);
     221             :   }
     222             : 
     223             :   /// State management
     224             :   ///
     225             :   virtual void reset();
     226             : 
     227             :   MCContext &getContext() const { return Context; }
     228             : 
     229             :   MCTargetStreamer *getTargetStreamer() {
     230     9195798 :     return TargetStreamer.get();
     231             :   }
     232             : 
     233       13756 :   unsigned getNumFrameInfos() { return DwarfFrameInfos.size(); }
     234             :   ArrayRef<MCDwarfFrameInfo> getDwarfFrameInfos() const {
     235        7176 :     return DwarfFrameInfos;
     236             :   }
     237             : 
     238             :   bool hasUnfinishedDwarfFrameInfo();
     239             : 
     240       78536 :   unsigned getNumWinFrameInfos() { return WinFrameInfos.size(); }
     241             :   ArrayRef<WinEH::FrameInfo *> getWinFrameInfos() const {
     242         156 :     return WinFrameInfos;
     243             :   }
     244             : 
     245             :   void generateCompactUnwindEncodings(MCAsmBackend *MAB);
     246             : 
     247             :   /// \name Assembly File Formatting.
     248             :   /// @{
     249             : 
     250             :   /// \brief Return true if this streamer supports verbose assembly and if it is
     251             :   /// enabled.
     252       72721 :   virtual bool isVerboseAsm() const { return false; }
     253             : 
     254             :   /// \brief Return true if this asm streamer supports emitting unformatted text
     255             :   /// to the .s file with EmitRawText.
     256      556932 :   virtual bool hasRawTextSupport() const { return false; }
     257             : 
     258             :   /// \brief Is the integrated assembler required for this streamer to function
     259             :   /// correctly?
     260        1687 :   virtual bool isIntegratedAssemblerRequired() const { return false; }
     261             : 
     262             :   /// \brief Add a textual comment.
     263             :   ///
     264             :   /// Typically for comments that can be emitted to the generated .s
     265             :   /// file if applicable as a QoI issue to make the output of the compiler
     266             :   /// more readable.  This only affects the MCAsmStreamer, and only when
     267             :   /// verbose assembly output is enabled.
     268             :   ///
     269             :   /// If the comment includes embedded \n's, they will each get the comment
     270             :   /// prefix as appropriate.  The added comment should not end with a \n.
     271             :   /// By default, each comment is terminated with an end of line, i.e. the
     272             :   /// EOL param is set to true by default. If one prefers not to end the 
     273             :   /// comment with a new line then the EOL param should be passed 
     274             :   /// with a false value.
     275      171767 :   virtual void AddComment(const Twine &T, bool EOL = true) {}
     276             : 
     277             :   /// \brief Return a raw_ostream that comments can be written to. Unlike
     278             :   /// AddComment, you are required to terminate comments with \n if you use this
     279             :   /// method.
     280             :   virtual raw_ostream &GetCommentOS();
     281             : 
     282             :   /// \brief Print T and prefix it with the comment string (normally #) and
     283             :   /// optionally a tab. This prints the comment immediately, not at the end of
     284             :   /// the current line. It is basically a safe version of EmitRawText: since it
     285             :   /// only prints comments, the object streamer ignores it instead of asserting.
     286             :   virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
     287             : 
     288             :   /// \brief Add explicit comment T. T is required to be a valid
     289             :   /// comment in the output and does not need to be escaped.
     290             :   virtual void addExplicitComment(const Twine &T);
     291             : 
     292             :   /// \brief Emit added explicit comments.
     293             :   virtual void emitExplicitComments();
     294             : 
     295             :   /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
     296      295112 :   virtual void AddBlankLine() {}
     297             : 
     298             :   /// @}
     299             : 
     300             :   /// \name Symbol & Section Management
     301             :   /// @{
     302             : 
     303             :   /// \brief Return the current section that the streamer is emitting code to.
     304             :   MCSectionSubPair getCurrentSection() const {
     305    25259754 :     if (!SectionStack.empty())
     306    50519504 :       return SectionStack.back().first;
     307             :     return MCSectionSubPair();
     308             :   }
     309    25252034 :   MCSection *getCurrentSectionOnly() const { return getCurrentSection().first; }
     310             : 
     311             :   /// \brief Return the previous section that the streamer is emitting code to.
     312             :   MCSectionSubPair getPreviousSection() const {
     313        2014 :     if (!SectionStack.empty())
     314        4028 :       return SectionStack.back().second;
     315             :     return MCSectionSubPair();
     316             :   }
     317             : 
     318             :   /// \brief Returns an index to represent the order a symbol was emitted in.
     319             :   /// (zero if we did not emit that symbol)
     320             :   unsigned GetSymbolOrder(const MCSymbol *Sym) const {
     321          56 :     return SymbolOrdering.lookup(Sym);
     322             :   }
     323             : 
     324             :   /// \brief Update streamer for a new active section.
     325             :   ///
     326             :   /// This is called by PopSection and SwitchSection, if the current
     327             :   /// section changes.
     328             :   virtual void ChangeSection(MCSection *, const MCExpr *);
     329             : 
     330             :   /// \brief Save the current and previous section on the section stack.
     331        1414 :   void PushSection() {
     332        2828 :     SectionStack.push_back(
     333        5656 :         std::make_pair(getCurrentSection(), getPreviousSection()));
     334        1414 :   }
     335             : 
     336             :   /// \brief Restore the current and previous section from the section stack.
     337             :   /// Calls ChangeSection as needed.
     338             :   ///
     339             :   /// Returns false if the stack was empty.
     340        1414 :   bool PopSection() {
     341        2828 :     if (SectionStack.size() <= 1)
     342             :       return false;
     343        1414 :     auto I = SectionStack.end();
     344        1414 :     --I;
     345        1414 :     MCSectionSubPair OldSection = I->first;
     346        1414 :     --I;
     347        1414 :     MCSectionSubPair NewSection = I->first;
     348             : 
     349        1196 :     if (OldSection != NewSection)
     350        1196 :       ChangeSection(NewSection.first, NewSection.second);
     351        2828 :     SectionStack.pop_back();
     352        1414 :     return true;
     353             :   }
     354             : 
     355             :   bool SubSection(const MCExpr *Subsection) {
     356           4 :     if (SectionStack.empty())
     357             :       return false;
     358             : 
     359           8 :     SwitchSection(SectionStack.back().first.first, Subsection);
     360             :     return true;
     361             :   }
     362             : 
     363             :   /// Set the current section where code is being emitted to \p Section.  This
     364             :   /// is required to update CurSection.
     365             :   ///
     366             :   /// This corresponds to assembler directives like .section, .text, etc.
     367             :   virtual void SwitchSection(MCSection *Section,
     368             :                              const MCExpr *Subsection = nullptr);
     369             : 
     370             :   /// \brief Set the current section where code is being emitted to \p Section.
     371             :   /// This is required to update CurSection. This version does not call
     372             :   /// ChangeSection.
     373             :   void SwitchSectionNoChange(MCSection *Section,
     374             :                              const MCExpr *Subsection = nullptr) {
     375             :     assert(Section && "Cannot switch to a null section!");
     376         646 :     MCSectionSubPair curSection = SectionStack.back().first;
     377         969 :     SectionStack.back().second = curSection;
     378         646 :     if (MCSectionSubPair(Section, Subsection) != curSection)
     379         969 :       SectionStack.back().first = MCSectionSubPair(Section, Subsection);
     380             :   }
     381             : 
     382             :   /// \brief Create the default sections and set the initial one.
     383             :   virtual void InitSections(bool NoExecStack);
     384             : 
     385             :   MCSymbol *endSection(MCSection *Section);
     386             : 
     387             :   /// \brief Sets the symbol's section.
     388             :   ///
     389             :   /// Each emitted symbol will be tracked in the ordering table,
     390             :   /// so we can sort on them later.
     391             :   void AssignFragment(MCSymbol *Symbol, MCFragment *Fragment);
     392             : 
     393             :   /// \brief Emit a label for \p Symbol into the current section.
     394             :   ///
     395             :   /// This corresponds to an assembler statement such as:
     396             :   ///   foo:
     397             :   ///
     398             :   /// \param Symbol - The symbol to emit. A given symbol should only be
     399             :   /// emitted as a label once, and symbols emitted as a label should never be
     400             :   /// used in an assignment.
     401             :   // FIXME: These emission are non-const because we mutate the symbol to
     402             :   // add the section we're emitting it to later.
     403             :   virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc());
     404             : 
     405             :   virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
     406             : 
     407             :   /// \brief Note in the output the specified \p Flag.
     408             :   virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
     409             : 
     410             :   /// \brief Emit the given list \p Options of strings as linker
     411             :   /// options into the output.
     412           0 :   virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
     413             : 
     414             :   /// \brief Note in the output the specified region \p Kind.
     415         132 :   virtual void EmitDataRegion(MCDataRegionType Kind) {}
     416             : 
     417             :   /// \brief Specify the MachO minimum deployment target version.
     418           0 :   virtual void EmitVersionMin(MCVersionMinType, unsigned Major, unsigned Minor,
     419           0 :                               unsigned Update) {}
     420             : 
     421             :   /// \brief Note in the output that the specified \p Func is a Thumb mode
     422             :   /// function (ARM target only).
     423             :   virtual void EmitThumbFunc(MCSymbol *Func);
     424             : 
     425             :   /// \brief Emit an assignment of \p Value to \p Symbol.
     426             :   ///
     427             :   /// This corresponds to an assembler statement such as:
     428             :   ///  symbol = value
     429             :   ///
     430             :   /// The assignment generates no code, but has the side effect of binding the
     431             :   /// value in the current context. For the assembly streamer, this prints the
     432             :   /// binding into the .s file.
     433             :   ///
     434             :   /// \param Symbol - The symbol being assigned to.
     435             :   /// \param Value - The value for the symbol.
     436             :   virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
     437             : 
     438             :   /// \brief Emit an weak reference from \p Alias to \p Symbol.
     439             :   ///
     440             :   /// This corresponds to an assembler statement such as:
     441             :   ///  .weakref alias, symbol
     442             :   ///
     443             :   /// \param Alias - The alias that is being created.
     444             :   /// \param Symbol - The symbol being aliased.
     445             :   virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
     446             : 
     447             :   /// \brief Add the given \p Attribute to \p Symbol.
     448             :   virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
     449             :                                    MCSymbolAttr Attribute) = 0;
     450             : 
     451             :   /// \brief Set the \p DescValue for the \p Symbol.
     452             :   ///
     453             :   /// \param Symbol - The symbol to have its n_desc field set.
     454             :   /// \param DescValue - The value to set into the n_desc field.
     455             :   virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
     456             : 
     457             :   /// \brief Start emitting COFF symbol definition
     458             :   ///
     459             :   /// \param Symbol - The symbol to have its External & Type fields set.
     460             :   virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol);
     461             : 
     462             :   /// \brief Emit the storage class of the symbol.
     463             :   ///
     464             :   /// \param StorageClass - The storage class the symbol should have.
     465             :   virtual void EmitCOFFSymbolStorageClass(int StorageClass);
     466             : 
     467             :   /// \brief Emit the type of the symbol.
     468             :   ///
     469             :   /// \param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
     470             :   virtual void EmitCOFFSymbolType(int Type);
     471             : 
     472             :   /// \brief Marks the end of the symbol definition.
     473             :   virtual void EndCOFFSymbolDef();
     474             : 
     475             :   virtual void EmitCOFFSafeSEH(MCSymbol const *Symbol);
     476             : 
     477             :   /// \brief Emits a COFF section index.
     478             :   ///
     479             :   /// \param Symbol - Symbol the section number relocation should point to.
     480             :   virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
     481             : 
     482             :   /// \brief Emits a COFF section relative relocation.
     483             :   ///
     484             :   /// \param Symbol - Symbol the section relative relocation should point to.
     485             :   virtual void EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset);
     486             : 
     487             :   /// \brief Emit an ELF .size directive.
     488             :   ///
     489             :   /// This corresponds to an assembler statement such as:
     490             :   ///  .size symbol, expression
     491             :   virtual void emitELFSize(MCSymbol *Symbol, const MCExpr *Value);
     492             : 
     493             :   /// \brief Emit an ELF .symver directive.
     494             :   ///
     495             :   /// This corresponds to an assembler statement such as:
     496             :   ///  .symver _start, foo@@SOME_VERSION
     497             :   /// \param Alias - The versioned alias (i.e. "foo@@SOME_VERSION")
     498             :   /// \param Aliasee - The aliased symbol (i.e. "_start")
     499             :   virtual void emitELFSymverDirective(MCSymbol *Alias, const MCSymbol *Aliasee);
     500             : 
     501             :   /// \brief Emit a Linker Optimization Hint (LOH) directive.
     502             :   /// \param Args - Arguments of the LOH.
     503           0 :   virtual void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {}
     504             : 
     505             :   /// \brief Emit a common symbol.
     506             :   ///
     507             :   /// \param Symbol - The common symbol to emit.
     508             :   /// \param Size - The size of the common symbol.
     509             :   /// \param ByteAlignment - The alignment of the symbol if
     510             :   /// non-zero. This must be a power of 2.
     511             :   virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
     512             :                                 unsigned ByteAlignment) = 0;
     513             : 
     514             :   /// \brief Emit a local common (.lcomm) symbol.
     515             :   ///
     516             :   /// \param Symbol - The common symbol to emit.
     517             :   /// \param Size - The size of the common symbol.
     518             :   /// \param ByteAlignment - The alignment of the common symbol in bytes.
     519             :   virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
     520             :                                      unsigned ByteAlignment);
     521             : 
     522             :   /// \brief Emit the zerofill section and an optional symbol.
     523             :   ///
     524             :   /// \param Section - The zerofill section to create and or to put the symbol
     525             :   /// \param Symbol - The zerofill symbol to emit, if non-NULL.
     526             :   /// \param Size - The size of the zerofill symbol.
     527             :   /// \param ByteAlignment - The alignment of the zerofill symbol if
     528             :   /// non-zero. This must be a power of 2 on some targets.
     529             :   virtual void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
     530             :                             uint64_t Size = 0, unsigned ByteAlignment = 0) = 0;
     531             : 
     532             :   /// \brief Emit a thread local bss (.tbss) symbol.
     533             :   ///
     534             :   /// \param Section - The thread local common section.
     535             :   /// \param Symbol - The thread local common symbol to emit.
     536             :   /// \param Size - The size of the symbol.
     537             :   /// \param ByteAlignment - The alignment of the thread local common symbol
     538             :   /// if non-zero.  This must be a power of 2 on some targets.
     539             :   virtual void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
     540             :                               uint64_t Size, unsigned ByteAlignment = 0);
     541             : 
     542             :   /// @}
     543             :   /// \name Generating Data
     544             :   /// @{
     545             : 
     546             :   /// \brief Emit the bytes in \p Data into the output.
     547             :   ///
     548             :   /// This is used to implement assembler directives such as .byte, .ascii,
     549             :   /// etc.
     550             :   virtual void EmitBytes(StringRef Data);
     551             : 
     552             :   /// Functionally identical to EmitBytes. When emitting textual assembly, this
     553             :   /// method uses .byte directives instead of .ascii or .asciz for readability.
     554             :   virtual void EmitBinaryData(StringRef Data);
     555             : 
     556             :   /// \brief Emit the expression \p Value into the output as a native
     557             :   /// integer of the given \p Size bytes.
     558             :   ///
     559             :   /// This is used to implement assembler directives such as .word, .quad,
     560             :   /// etc.
     561             :   ///
     562             :   /// \param Value - The value to emit.
     563             :   /// \param Size - The size of the integer (in bytes) to emit. This must
     564             :   /// match a native machine width.
     565             :   /// \param Loc - The location of the expression for error reporting.
     566             :   virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
     567             :                              SMLoc Loc = SMLoc());
     568             : 
     569             :   void EmitValue(const MCExpr *Value, unsigned Size, SMLoc Loc = SMLoc());
     570             : 
     571             :   /// \brief Special case of EmitValue that avoids the client having
     572             :   /// to pass in a MCExpr for constant integers.
     573             :   virtual void EmitIntValue(uint64_t Value, unsigned Size);
     574             : 
     575             :   virtual void EmitULEB128Value(const MCExpr *Value);
     576             : 
     577             :   virtual void EmitSLEB128Value(const MCExpr *Value);
     578             : 
     579             :   /// \brief Special case of EmitULEB128Value that avoids the client having to
     580             :   /// pass in a MCExpr for constant integers.
     581             :   void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
     582             : 
     583             :   /// \brief Special case of EmitSLEB128Value that avoids the client having to
     584             :   /// pass in a MCExpr for constant integers.
     585             :   void EmitSLEB128IntValue(int64_t Value);
     586             : 
     587             :   /// \brief Special case of EmitValue that avoids the client having to pass in
     588             :   /// a MCExpr for MCSymbols.
     589             :   void EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
     590             :                        bool IsSectionRelative = false);
     591             : 
     592             :   /// \brief Emit the expression \p Value into the output as a dtprel
     593             :   /// (64-bit DTP relative) value.
     594             :   ///
     595             :   /// This is used to implement assembler directives such as .dtpreldword on
     596             :   /// targets that support them.
     597             :   virtual void EmitDTPRel64Value(const MCExpr *Value);
     598             : 
     599             :   /// \brief Emit the expression \p Value into the output as a dtprel
     600             :   /// (32-bit DTP relative) value.
     601             :   ///
     602             :   /// This is used to implement assembler directives such as .dtprelword on
     603             :   /// targets that support them.
     604             :   virtual void EmitDTPRel32Value(const MCExpr *Value);
     605             : 
     606             :   /// \brief Emit the expression \p Value into the output as a tprel
     607             :   /// (64-bit TP relative) value.
     608             :   ///
     609             :   /// This is used to implement assembler directives such as .tpreldword on
     610             :   /// targets that support them.
     611             :   virtual void EmitTPRel64Value(const MCExpr *Value);
     612             : 
     613             :   /// \brief Emit the expression \p Value into the output as a tprel
     614             :   /// (32-bit TP relative) value.
     615             :   ///
     616             :   /// This is used to implement assembler directives such as .tprelword on
     617             :   /// targets that support them.
     618             :   virtual void EmitTPRel32Value(const MCExpr *Value);
     619             : 
     620             :   /// \brief Emit the expression \p Value into the output as a gprel64 (64-bit
     621             :   /// GP relative) value.
     622             :   ///
     623             :   /// This is used to implement assembler directives such as .gpdword on
     624             :   /// targets that support them.
     625             :   virtual void EmitGPRel64Value(const MCExpr *Value);
     626             : 
     627             :   /// \brief Emit the expression \p Value into the output as a gprel32 (32-bit
     628             :   /// GP relative) value.
     629             :   ///
     630             :   /// This is used to implement assembler directives such as .gprel32 on
     631             :   /// targets that support them.
     632             :   virtual void EmitGPRel32Value(const MCExpr *Value);
     633             : 
     634             :   /// \brief Emit NumBytes bytes worth of the value specified by FillValue.
     635             :   /// This implements directives such as '.space'.
     636             :   virtual void emitFill(uint64_t NumBytes, uint8_t FillValue);
     637             : 
     638             :   /// \brief Emit \p Size bytes worth of the value specified by \p FillValue.
     639             :   ///
     640             :   /// This is used to implement assembler directives such as .space or .skip.
     641             :   ///
     642             :   /// \param NumBytes - The number of bytes to emit.
     643             :   /// \param FillValue - The value to use when filling bytes.
     644             :   /// \param Loc - The location of the expression for error reporting.
     645             :   virtual void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
     646             :                         SMLoc Loc = SMLoc());
     647             : 
     648             :   /// \brief Emit \p NumValues copies of \p Size bytes. Each \p Size bytes is
     649             :   /// taken from the lowest order 4 bytes of \p Expr expression.
     650             :   ///
     651             :   /// This is used to implement assembler directives such as .fill.
     652             :   ///
     653             :   /// \param NumValues - The number of copies of \p Size bytes to emit.
     654             :   /// \param Size - The size (in bytes) of each repeated value.
     655             :   /// \param Expr - The expression from which \p Size bytes are used.
     656             :   virtual void emitFill(uint64_t NumValues, int64_t Size, int64_t Expr);
     657             :   virtual void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
     658             :                         SMLoc Loc = SMLoc());
     659             : 
     660             :   /// \brief Emit NumBytes worth of zeros.
     661             :   /// This function properly handles data in virtual sections.
     662             :   void EmitZeros(uint64_t NumBytes);
     663             : 
     664             :   /// \brief Emit some number of copies of \p Value until the byte alignment \p
     665             :   /// ByteAlignment is reached.
     666             :   ///
     667             :   /// If the number of bytes need to emit for the alignment is not a multiple
     668             :   /// of \p ValueSize, then the contents of the emitted fill bytes is
     669             :   /// undefined.
     670             :   ///
     671             :   /// This used to implement the .align assembler directive.
     672             :   ///
     673             :   /// \param ByteAlignment - The alignment to reach. This must be a power of
     674             :   /// two on some targets.
     675             :   /// \param Value - The value to use when filling bytes.
     676             :   /// \param ValueSize - The size of the integer (in bytes) to emit for
     677             :   /// \p Value. This must match a native machine width.
     678             :   /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
     679             :   /// the alignment cannot be reached in this many bytes, no bytes are
     680             :   /// emitted.
     681             :   virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
     682             :                                     unsigned ValueSize = 1,
     683             :                                     unsigned MaxBytesToEmit = 0);
     684             : 
     685             :   /// \brief Emit nops until the byte alignment \p ByteAlignment is reached.
     686             :   ///
     687             :   /// This used to align code where the alignment bytes may be executed.  This
     688             :   /// can emit different bytes for different sizes to optimize execution.
     689             :   ///
     690             :   /// \param ByteAlignment - The alignment to reach. This must be a power of
     691             :   /// two on some targets.
     692             :   /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
     693             :   /// the alignment cannot be reached in this many bytes, no bytes are
     694             :   /// emitted.
     695             :   virtual void EmitCodeAlignment(unsigned ByteAlignment,
     696             :                                  unsigned MaxBytesToEmit = 0);
     697             : 
     698             :   /// \brief Emit some number of copies of \p Value until the byte offset \p
     699             :   /// Offset is reached.
     700             :   ///
     701             :   /// This is used to implement assembler directives such as .org.
     702             :   ///
     703             :   /// \param Offset - The offset to reach. This may be an expression, but the
     704             :   /// expression must be associated with the current section.
     705             :   /// \param Value - The value to use when filling bytes.
     706             :   virtual void emitValueToOffset(const MCExpr *Offset, unsigned char Value,
     707             :                                  SMLoc Loc);
     708             : 
     709             :   /// @}
     710             : 
     711             :   /// \brief Switch to a new logical file.  This is used to implement the '.file
     712             :   /// "foo.c"' assembler directive.
     713             :   virtual void EmitFileDirective(StringRef Filename);
     714             : 
     715             :   /// \brief Emit the "identifiers" directive.  This implements the
     716             :   /// '.ident "version foo"' assembler directive.
     717           3 :   virtual void EmitIdent(StringRef IdentString) {}
     718             : 
     719             :   /// \brief Associate a filename with a specified logical file number.  This
     720             :   /// implements the DWARF2 '.file 4 "foo.c"' assembler directive.
     721             :   virtual unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
     722             :                                           StringRef Filename,
     723             :                                           unsigned CUID = 0);
     724             : 
     725             :   /// \brief This implements the DWARF2 '.loc fileno lineno ...' assembler
     726             :   /// directive.
     727             :   virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
     728             :                                      unsigned Column, unsigned Flags,
     729             :                                      unsigned Isa, unsigned Discriminator,
     730             :                                      StringRef FileName);
     731             : 
     732             :   /// \brief Associate a filename with a specified logical file number.  This
     733             :   /// implements the '.cv_file 4 "foo.c"' assembler directive. Returns true on
     734             :   /// success.
     735             :   virtual bool EmitCVFileDirective(unsigned FileNo, StringRef Filename);
     736             : 
     737             :   /// \brief Introduces a function id for use with .cv_loc.
     738             :   virtual bool EmitCVFuncIdDirective(unsigned FunctionId);
     739             : 
     740             :   /// \brief Introduces an inline call site id for use with .cv_loc. Includes
     741             :   /// extra information for inline line table generation.
     742             :   virtual bool EmitCVInlineSiteIdDirective(unsigned FunctionId, unsigned IAFunc,
     743             :                                            unsigned IAFile, unsigned IALine,
     744             :                                            unsigned IACol, SMLoc Loc);
     745             : 
     746             :   /// \brief This implements the CodeView '.cv_loc' assembler directive.
     747             :   virtual void EmitCVLocDirective(unsigned FunctionId, unsigned FileNo,
     748             :                                   unsigned Line, unsigned Column,
     749             :                                   bool PrologueEnd, bool IsStmt,
     750             :                                   StringRef FileName, SMLoc Loc);
     751             : 
     752             :   /// \brief This implements the CodeView '.cv_linetable' assembler directive.
     753             :   virtual void EmitCVLinetableDirective(unsigned FunctionId,
     754             :                                         const MCSymbol *FnStart,
     755             :                                         const MCSymbol *FnEnd);
     756             : 
     757             :   /// \brief This implements the CodeView '.cv_inline_linetable' assembler
     758             :   /// directive.
     759             :   virtual void EmitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
     760             :                                               unsigned SourceFileId,
     761             :                                               unsigned SourceLineNum,
     762             :                                               const MCSymbol *FnStartSym,
     763             :                                               const MCSymbol *FnEndSym);
     764             : 
     765             :   /// \brief This implements the CodeView '.cv_def_range' assembler
     766             :   /// directive.
     767             :   virtual void EmitCVDefRangeDirective(
     768             :       ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
     769             :       StringRef FixedSizePortion);
     770             : 
     771             :   /// \brief This implements the CodeView '.cv_stringtable' assembler directive.
     772           0 :   virtual void EmitCVStringTableDirective() {}
     773             : 
     774             :   /// \brief This implements the CodeView '.cv_filechecksums' assembler directive.
     775           0 :   virtual void EmitCVFileChecksumsDirective() {}
     776             : 
     777             :   /// Emit the absolute difference between two symbols.
     778             :   ///
     779             :   /// \pre Offset of \c Hi is greater than the offset \c Lo.
     780             :   virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo,
     781             :                                       unsigned Size);
     782             : 
     783             :   virtual MCSymbol *getDwarfLineTableSymbol(unsigned CUID);
     784             :   virtual void EmitCFISections(bool EH, bool Debug);
     785             :   void EmitCFIStartProc(bool IsSimple);
     786             :   void EmitCFIEndProc();
     787             :   virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
     788             :   virtual void EmitCFIDefCfaOffset(int64_t Offset);
     789             :   virtual void EmitCFIDefCfaRegister(int64_t Register);
     790             :   virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
     791             :   virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
     792             :   virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
     793             :   virtual void EmitCFIRememberState();
     794             :   virtual void EmitCFIRestoreState();
     795             :   virtual void EmitCFISameValue(int64_t Register);
     796             :   virtual void EmitCFIRestore(int64_t Register);
     797             :   virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
     798             :   virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
     799             :   virtual void EmitCFIEscape(StringRef Values);
     800             :   virtual void EmitCFIReturnColumn(int64_t Register);
     801             :   virtual void EmitCFIGnuArgsSize(int64_t Size);
     802             :   virtual void EmitCFISignalFrame();
     803             :   virtual void EmitCFIUndefined(int64_t Register);
     804             :   virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
     805             :   virtual void EmitCFIWindowSave();
     806             : 
     807             :   virtual void EmitWinCFIStartProc(const MCSymbol *Symbol);
     808             :   virtual void EmitWinCFIEndProc();
     809             :   virtual void EmitWinCFIStartChained();
     810             :   virtual void EmitWinCFIEndChained();
     811             :   virtual void EmitWinCFIPushReg(unsigned Register);
     812             :   virtual void EmitWinCFISetFrame(unsigned Register, unsigned Offset);
     813             :   virtual void EmitWinCFIAllocStack(unsigned Size);
     814             :   virtual void EmitWinCFISaveReg(unsigned Register, unsigned Offset);
     815             :   virtual void EmitWinCFISaveXMM(unsigned Register, unsigned Offset);
     816             :   virtual void EmitWinCFIPushFrame(bool Code);
     817             :   virtual void EmitWinCFIEndProlog();
     818             : 
     819             :   virtual void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except);
     820             :   virtual void EmitWinEHHandlerData();
     821             : 
     822             :   /// Get the .pdata section used for the given section. Typically the given
     823             :   /// section is either the main .text section or some other COMDAT .text
     824             :   /// section, but it may be any section containing code.
     825             :   MCSection *getAssociatedPDataSection(const MCSection *TextSec);
     826             : 
     827             :   /// Get the .xdata section used for the given section.
     828             :   MCSection *getAssociatedXDataSection(const MCSection *TextSec);
     829             : 
     830             :   virtual void EmitSyntaxDirective();
     831             : 
     832             :   /// \brief Emit a .reloc directive.
     833             :   /// Returns true if the relocation could not be emitted because Name is not
     834             :   /// known.
     835           0 :   virtual bool EmitRelocDirective(const MCExpr &Offset, StringRef Name,
     836             :                                   const MCExpr *Expr, SMLoc Loc) {
     837           0 :     return true;
     838             :   }
     839             : 
     840             :   /// \brief Emit the given \p Instruction into the current section.
     841             :   /// PrintSchedInfo == true then schedul comment should be added to output
     842             :   virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
     843             :                                bool PrintSchedInfo = false);
     844             : 
     845             :   /// \brief Set the bundle alignment mode from now on in the section.
     846             :   /// The argument is the power of 2 to which the alignment is set. The
     847             :   /// value 0 means turn the bundle alignment off.
     848             :   virtual void EmitBundleAlignMode(unsigned AlignPow2);
     849             : 
     850             :   /// \brief The following instructions are a bundle-locked group.
     851             :   ///
     852             :   /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
     853             :   ///                     the end of a bundle.
     854             :   virtual void EmitBundleLock(bool AlignToEnd);
     855             : 
     856             :   /// \brief Ends a bundle-locked group.
     857             :   virtual void EmitBundleUnlock();
     858             : 
     859             :   /// \brief If this file is backed by a assembly streamer, this dumps the
     860             :   /// specified string in the output .s file.  This capability is indicated by
     861             :   /// the hasRawTextSupport() predicate.  By default this aborts.
     862             :   void EmitRawText(const Twine &String);
     863             : 
     864             :   /// \brief Streamer specific finalization.
     865             :   virtual void FinishImpl();
     866             :   /// \brief Finish emission of machine code.
     867             :   void Finish();
     868             : 
     869           5 :   virtual bool mayHaveInstructions(MCSection &Sec) const { return true; }
     870             : };
     871             : 
     872             : /// Create a dummy machine code streamer, which does nothing. This is useful for
     873             : /// timing the assembler front end.
     874             : MCStreamer *createNullStreamer(MCContext &Ctx);
     875             : 
     876             : /// Create a machine code streamer which will print out assembly for the native
     877             : /// target, suitable for compiling with a native assembler.
     878             : ///
     879             : /// \param InstPrint - If given, the instruction printer to use. If not given
     880             : /// the MCInst representation will be printed.  This method takes ownership of
     881             : /// InstPrint.
     882             : ///
     883             : /// \param CE - If given, a code emitter to use to show the instruction
     884             : /// encoding inline with the assembly. This method takes ownership of \p CE.
     885             : ///
     886             : /// \param TAB - If given, a target asm backend to use to show the fixup
     887             : /// information in conjunction with encoding information. This method takes
     888             : /// ownership of \p TAB.
     889             : ///
     890             : /// \param ShowInst - Whether to show the MCInst representation inline with
     891             : /// the assembly.
     892             : MCStreamer *createAsmStreamer(MCContext &Ctx,
     893             :                               std::unique_ptr<formatted_raw_ostream> OS,
     894             :                               bool isVerboseAsm, bool useDwarfDirectory,
     895             :                               MCInstPrinter *InstPrint, MCCodeEmitter *CE,
     896             :                               MCAsmBackend *TAB, bool ShowInst);
     897             : 
     898             : } // end namespace llvm
     899             : 
     900             : #endif // LLVM_MC_MCSTREAMER_H

Generated by: LCOV version 1.13