LLVM API Documentation

MCStreamer.h
Go to the documentation of this file.
00001 //===- MCStreamer.h - High-level Streaming Machine Code Output --*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file declares the MCStreamer class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_MC_MCSTREAMER_H
00015 #define LLVM_MC_MCSTREAMER_H
00016 
00017 #include "llvm/ADT/ArrayRef.h"
00018 #include "llvm/ADT/SmallVector.h"
00019 #include "llvm/MC/MCAssembler.h"
00020 #include "llvm/MC/MCDirectives.h"
00021 #include "llvm/MC/MCDwarf.h"
00022 #include "llvm/MC/MCLinkerOptimizationHint.h"
00023 #include "llvm/MC/MCWinEH.h"
00024 #include "llvm/Support/DataTypes.h"
00025 #include <string>
00026 
00027 namespace llvm {
00028 class MCAsmBackend;
00029 class MCCodeEmitter;
00030 class MCContext;
00031 class MCExpr;
00032 class MCInst;
00033 class MCInstPrinter;
00034 class MCSection;
00035 class MCStreamer;
00036 class MCSymbol;
00037 class MCSymbolRefExpr;
00038 class MCSubtargetInfo;
00039 class StringRef;
00040 class Twine;
00041 class raw_ostream;
00042 class formatted_raw_ostream;
00043 class AssemblerConstantPools;
00044 
00045 typedef std::pair<const MCSection *, const MCExpr *> MCSectionSubPair;
00046 
00047 /// Target specific streamer interface. This is used so that targets can
00048 /// implement support for target specific assembly directives.
00049 ///
00050 /// If target foo wants to use this, it should implement 3 classes:
00051 /// * FooTargetStreamer : public MCTargetStreamer
00052 /// * FooTargetAsmSreamer : public FooTargetStreamer
00053 /// * FooTargetELFStreamer : public FooTargetStreamer
00054 ///
00055 /// FooTargetStreamer should have a pure virtual method for each directive. For
00056 /// example, for a ".bar symbol_name" directive, it should have
00057 /// virtual emitBar(const MCSymbol &Symbol) = 0;
00058 ///
00059 /// The FooTargetAsmSreamer and FooTargetELFStreamer classes implement the
00060 /// method. The assembly streamer just prints ".bar symbol_name". The object
00061 /// streamer does whatever is needed to implement .bar in the object file.
00062 ///
00063 /// In the assembly printer and parser the target streamer can be used by
00064 /// calling getTargetStreamer and casting it to FooTargetStreamer:
00065 ///
00066 /// MCTargetStreamer &TS = OutStreamer.getTargetStreamer();
00067 /// FooTargetStreamer &ATS = static_cast<FooTargetStreamer &>(TS);
00068 ///
00069 /// The base classes FooTargetAsmSreamer and FooTargetELFStreamer should *never*
00070 /// be treated differently. Callers should always talk to a FooTargetStreamer.
00071 class MCTargetStreamer {
00072 protected:
00073   MCStreamer &Streamer;
00074 
00075 public:
00076   MCTargetStreamer(MCStreamer &S);
00077   virtual ~MCTargetStreamer();
00078 
00079   const MCStreamer &getStreamer() { return Streamer; }
00080 
00081   // Allow a target to add behavior to the EmitLabel of MCStreamer.
00082   virtual void emitLabel(MCSymbol *Symbol);
00083   // Allow a target to add behavior to the emitAssignment of MCStreamer.
00084   virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value);
00085 
00086   virtual void finish();
00087 };
00088 
00089 class AArch64TargetStreamer : public MCTargetStreamer {
00090 public:
00091   AArch64TargetStreamer(MCStreamer &S);
00092   ~AArch64TargetStreamer();
00093 
00094 
00095   void finish() override;
00096 
00097   /// Callback used to implement the ldr= pseudo.
00098   /// Add a new entry to the constant pool for the current section and return an
00099   /// MCExpr that can be used to refer to the constant pool location.
00100   const MCExpr *addConstantPoolEntry(const MCExpr *, unsigned Size);
00101 
00102   /// Callback used to implemnt the .ltorg directive.
00103   /// Emit contents of constant pool for the current section.
00104   void emitCurrentConstantPool();
00105 
00106 private:
00107   std::unique_ptr<AssemblerConstantPools> ConstantPools;
00108 };
00109 
00110 // FIXME: declared here because it is used from
00111 // lib/CodeGen/AsmPrinter/ARMException.cpp.
00112 class ARMTargetStreamer : public MCTargetStreamer {
00113 public:
00114   ARMTargetStreamer(MCStreamer &S);
00115   ~ARMTargetStreamer();
00116 
00117   virtual void emitFnStart();
00118   virtual void emitFnEnd();
00119   virtual void emitCantUnwind();
00120   virtual void emitPersonality(const MCSymbol *Personality);
00121   virtual void emitPersonalityIndex(unsigned Index);
00122   virtual void emitHandlerData();
00123   virtual void emitSetFP(unsigned FpReg, unsigned SpReg,
00124                          int64_t Offset = 0);
00125   virtual void emitMovSP(unsigned Reg, int64_t Offset = 0);
00126   virtual void emitPad(int64_t Offset);
00127   virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
00128                            bool isVector);
00129   virtual void emitUnwindRaw(int64_t StackOffset,
00130                              const SmallVectorImpl<uint8_t> &Opcodes);
00131 
00132   virtual void switchVendor(StringRef Vendor);
00133   virtual void emitAttribute(unsigned Attribute, unsigned Value);
00134   virtual void emitTextAttribute(unsigned Attribute, StringRef String);
00135   virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
00136                                     StringRef StringValue = "");
00137   virtual void emitFPU(unsigned FPU);
00138   virtual void emitArch(unsigned Arch);
00139   virtual void emitObjectArch(unsigned Arch);
00140   virtual void finishAttributeSection();
00141   virtual void emitInst(uint32_t Inst, char Suffix = '\0');
00142 
00143   virtual void AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
00144 
00145   virtual void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value);
00146 
00147   void finish() override;
00148 
00149   /// Callback used to implement the ldr= pseudo.
00150   /// Add a new entry to the constant pool for the current section and return an
00151   /// MCExpr that can be used to refer to the constant pool location.
00152   const MCExpr *addConstantPoolEntry(const MCExpr *);
00153 
00154   /// Callback used to implemnt the .ltorg directive.
00155   /// Emit contents of constant pool for the current section.
00156   void emitCurrentConstantPool();
00157 
00158 private:
00159   std::unique_ptr<AssemblerConstantPools> ConstantPools;
00160 };
00161 
00162 /// MCStreamer - Streaming machine code generation interface.  This interface
00163 /// is intended to provide a programatic interface that is very similar to the
00164 /// level that an assembler .s file provides.  It has callbacks to emit bytes,
00165 /// handle directives, etc.  The implementation of this interface retains
00166 /// state to know what the current section is etc.
00167 ///
00168 /// There are multiple implementations of this interface: one for writing out
00169 /// a .s file, and implementations that write out .o files of various formats.
00170 ///
00171 class MCStreamer {
00172   MCContext &Context;
00173   std::unique_ptr<MCTargetStreamer> TargetStreamer;
00174 
00175   MCStreamer(const MCStreamer &) LLVM_DELETED_FUNCTION;
00176   MCStreamer &operator=(const MCStreamer &) LLVM_DELETED_FUNCTION;
00177 
00178   std::vector<MCDwarfFrameInfo> DwarfFrameInfos;
00179   MCDwarfFrameInfo *getCurrentDwarfFrameInfo();
00180   void EnsureValidDwarfFrame();
00181 
00182   MCSymbol *EmitCFICommon();
00183 
00184   std::vector<WinEH::FrameInfo *> WinFrameInfos;
00185   WinEH::FrameInfo *CurrentWinFrameInfo;
00186   void EnsureValidWinFrameInfo();
00187 
00188   // SymbolOrdering - Tracks an index to represent the order
00189   // a symbol was emitted in. Zero means we did not emit that symbol.
00190   DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
00191 
00192   /// SectionStack - This is stack of current and previous section
00193   /// values saved by PushSection.
00194   SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
00195 
00196 protected:
00197   MCStreamer(MCContext &Ctx);
00198 
00199   virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
00200   virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
00201 
00202   WinEH::FrameInfo *getCurrentWinFrameInfo() {
00203     return CurrentWinFrameInfo;
00204   }
00205 
00206   virtual void EmitWindowsUnwindTables();
00207 
00208   virtual void EmitRawTextImpl(StringRef String);
00209 
00210 public:
00211   virtual ~MCStreamer();
00212 
00213   void visitUsedExpr(const MCExpr &Expr);
00214   virtual void visitUsedSymbol(const MCSymbol &Sym);
00215 
00216   void setTargetStreamer(MCTargetStreamer *TS) {
00217     TargetStreamer.reset(TS);
00218   }
00219 
00220   /// State management
00221   ///
00222   virtual void reset();
00223 
00224   MCContext &getContext() const { return Context; }
00225 
00226   MCTargetStreamer *getTargetStreamer() {
00227     return TargetStreamer.get();
00228   }
00229 
00230   unsigned getNumFrameInfos() { return DwarfFrameInfos.size(); }
00231   ArrayRef<MCDwarfFrameInfo> getDwarfFrameInfos() const {
00232     return DwarfFrameInfos;
00233   }
00234 
00235   unsigned getNumWinFrameInfos() { return WinFrameInfos.size(); }
00236   ArrayRef<WinEH::FrameInfo *> getWinFrameInfos() const {
00237     return WinFrameInfos;
00238   }
00239 
00240   void generateCompactUnwindEncodings(MCAsmBackend *MAB);
00241 
00242   /// @name Assembly File Formatting.
00243   /// @{
00244 
00245   /// isVerboseAsm - Return true if this streamer supports verbose assembly
00246   /// and if it is enabled.
00247   virtual bool isVerboseAsm() const { return false; }
00248 
00249   /// hasRawTextSupport - Return true if this asm streamer supports emitting
00250   /// unformatted text to the .s file with EmitRawText.
00251   virtual bool hasRawTextSupport() const { return false; }
00252 
00253   /// Is the integrated assembler required for this streamer to function
00254   /// correctly?
00255   virtual bool isIntegratedAssemblerRequired() const { return false; }
00256 
00257   /// AddComment - Add a comment that can be emitted to the generated .s
00258   /// file if applicable as a QoI issue to make the output of the compiler
00259   /// more readable.  This only affects the MCAsmStreamer, and only when
00260   /// verbose assembly output is enabled.
00261   ///
00262   /// If the comment includes embedded \n's, they will each get the comment
00263   /// prefix as appropriate.  The added comment should not end with a \n.
00264   virtual void AddComment(const Twine &T) {}
00265 
00266   /// GetCommentOS - Return a raw_ostream that comments can be written to.
00267   /// Unlike AddComment, you are required to terminate comments with \n if you
00268   /// use this method.
00269   virtual raw_ostream &GetCommentOS();
00270 
00271   /// Print T and prefix it with the comment string (normally #) and optionally
00272   /// a tab. This prints the comment immediately, not at the end of the
00273   /// current line. It is basically a safe version of EmitRawText: since it
00274   /// only prints comments, the object streamer ignores it instead of asserting.
00275   virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
00276 
00277   /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
00278   virtual void AddBlankLine() {}
00279 
00280   /// @}
00281 
00282   /// @name Symbol & Section Management
00283   /// @{
00284 
00285   /// getCurrentSection - Return the current section that the streamer is
00286   /// emitting code to.
00287   MCSectionSubPair getCurrentSection() const {
00288     if (!SectionStack.empty())
00289       return SectionStack.back().first;
00290     return MCSectionSubPair();
00291   }
00292 
00293   /// getPreviousSection - Return the previous section that the streamer is
00294   /// emitting code to.
00295   MCSectionSubPair getPreviousSection() const {
00296     if (!SectionStack.empty())
00297       return SectionStack.back().second;
00298     return MCSectionSubPair();
00299   }
00300 
00301   /// GetSymbolOrder - Returns an index to represent the order
00302   /// a symbol was emitted in. (zero if we did not emit that symbol)
00303   unsigned GetSymbolOrder(const MCSymbol *Sym) const {
00304     return SymbolOrdering.lookup(Sym);
00305   }
00306 
00307   /// ChangeSection - Update streamer for a new active section.
00308   ///
00309   /// This is called by PopSection and SwitchSection, if the current
00310   /// section changes.
00311   virtual void ChangeSection(const MCSection *, const MCExpr *);
00312 
00313   /// pushSection - Save the current and previous section on the
00314   /// section stack.
00315   void PushSection() {
00316     SectionStack.push_back(
00317         std::make_pair(getCurrentSection(), getPreviousSection()));
00318   }
00319 
00320   /// popSection - Restore the current and previous section from
00321   /// the section stack.  Calls ChangeSection as needed.
00322   ///
00323   /// Returns false if the stack was empty.
00324   bool PopSection() {
00325     if (SectionStack.size() <= 1)
00326       return false;
00327     MCSectionSubPair oldSection = SectionStack.pop_back_val().first;
00328     MCSectionSubPair curSection = SectionStack.back().first;
00329 
00330     if (oldSection != curSection)
00331       ChangeSection(curSection.first, curSection.second);
00332     return true;
00333   }
00334 
00335   bool SubSection(const MCExpr *Subsection) {
00336     if (SectionStack.empty())
00337       return false;
00338 
00339     SwitchSection(SectionStack.back().first.first, Subsection);
00340     return true;
00341   }
00342 
00343   /// SwitchSection - Set the current section where code is being emitted to
00344   /// @p Section.  This is required to update CurSection.
00345   ///
00346   /// This corresponds to assembler directives like .section, .text, etc.
00347   void SwitchSection(const MCSection *Section,
00348                      const MCExpr *Subsection = nullptr) {
00349     assert(Section && "Cannot switch to a null section!");
00350     MCSectionSubPair curSection = SectionStack.back().first;
00351     SectionStack.back().second = curSection;
00352     if (MCSectionSubPair(Section, Subsection) != curSection) {
00353       SectionStack.back().first = MCSectionSubPair(Section, Subsection);
00354       ChangeSection(Section, Subsection);
00355     }
00356   }
00357 
00358   /// SwitchSectionNoChange - Set the current section where code is being
00359   /// emitted to @p Section.  This is required to update CurSection. This
00360   /// version does not call ChangeSection.
00361   void SwitchSectionNoChange(const MCSection *Section,
00362                              const MCExpr *Subsection = nullptr) {
00363     assert(Section && "Cannot switch to a null section!");
00364     MCSectionSubPair curSection = SectionStack.back().first;
00365     SectionStack.back().second = curSection;
00366     if (MCSectionSubPair(Section, Subsection) != curSection)
00367       SectionStack.back().first = MCSectionSubPair(Section, Subsection);
00368   }
00369 
00370   /// Create the default sections and set the initial one.
00371   virtual void InitSections();
00372 
00373   /// AssignSection - Sets the symbol's section.
00374   ///
00375   /// Each emitted symbol will be tracked in the ordering table,
00376   /// so we can sort on them later.
00377   void AssignSection(MCSymbol *Symbol, const MCSection *Section);
00378 
00379   /// EmitLabel - Emit a label for @p Symbol into the current section.
00380   ///
00381   /// This corresponds to an assembler statement such as:
00382   ///   foo:
00383   ///
00384   /// @param Symbol - The symbol to emit. A given symbol should only be
00385   /// emitted as a label once, and symbols emitted as a label should never be
00386   /// used in an assignment.
00387   // FIXME: These emission are non-const because we mutate the symbol to
00388   // add the section we're emitting it to later.
00389   virtual void EmitLabel(MCSymbol *Symbol);
00390 
00391   virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
00392 
00393   /// EmitAssemblerFlag - Note in the output the specified @p Flag.
00394   virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
00395 
00396   /// EmitLinkerOptions - Emit the given list @p Options of strings as linker
00397   /// options into the output.
00398   virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
00399 
00400   /// EmitDataRegion - Note in the output the specified region @p Kind.
00401   virtual void EmitDataRegion(MCDataRegionType Kind) {}
00402 
00403   /// EmitVersionMin - Specify the MachO minimum deployment target version.
00404   virtual void EmitVersionMin(MCVersionMinType, unsigned Major, unsigned Minor,
00405                               unsigned Update) {}
00406 
00407   /// EmitThumbFunc - Note in the output that the specified @p Func is
00408   /// a Thumb mode function (ARM target only).
00409   virtual void EmitThumbFunc(MCSymbol *Func);
00410 
00411   /// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
00412   ///
00413   /// This corresponds to an assembler statement such as:
00414   ///  symbol = value
00415   ///
00416   /// The assignment generates no code, but has the side effect of binding the
00417   /// value in the current context. For the assembly streamer, this prints the
00418   /// binding into the .s file.
00419   ///
00420   /// @param Symbol - The symbol being assigned to.
00421   /// @param Value - The value for the symbol.
00422   virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
00423 
00424   /// EmitWeakReference - Emit an weak reference from @p Alias to @p Symbol.
00425   ///
00426   /// This corresponds to an assembler statement such as:
00427   ///  .weakref alias, symbol
00428   ///
00429   /// @param Alias - The alias that is being created.
00430   /// @param Symbol - The symbol being aliased.
00431   virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
00432 
00433   /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
00434   virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
00435                                    MCSymbolAttr Attribute) = 0;
00436 
00437   /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
00438   ///
00439   /// @param Symbol - The symbol to have its n_desc field set.
00440   /// @param DescValue - The value to set into the n_desc field.
00441   virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
00442 
00443   /// BeginCOFFSymbolDef - Start emitting COFF symbol definition
00444   ///
00445   /// @param Symbol - The symbol to have its External & Type fields set.
00446   virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol);
00447 
00448   /// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
00449   ///
00450   /// @param StorageClass - The storage class the symbol should have.
00451   virtual void EmitCOFFSymbolStorageClass(int StorageClass);
00452 
00453   /// EmitCOFFSymbolType - Emit the type of the symbol.
00454   ///
00455   /// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
00456   virtual void EmitCOFFSymbolType(int Type);
00457 
00458   /// EndCOFFSymbolDef - Marks the end of the symbol definition.
00459   virtual void EndCOFFSymbolDef();
00460 
00461   /// EmitCOFFSectionIndex - Emits a COFF section index.
00462   ///
00463   /// @param Symbol - Symbol the section number relocation should point to.
00464   virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
00465 
00466   /// EmitCOFFSecRel32 - Emits a COFF section relative relocation.
00467   ///
00468   /// @param Symbol - Symbol the section relative relocation should point to.
00469   virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
00470 
00471   /// EmitELFSize - Emit an ELF .size directive.
00472   ///
00473   /// This corresponds to an assembler statement such as:
00474   ///  .size symbol, expression
00475   ///
00476   virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
00477 
00478   /// \brief Emit a Linker Optimization Hint (LOH) directive.
00479   /// \param Args - Arguments of the LOH.
00480   virtual void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {}
00481 
00482   /// EmitCommonSymbol - Emit a common symbol.
00483   ///
00484   /// @param Symbol - The common symbol to emit.
00485   /// @param Size - The size of the common symbol.
00486   /// @param ByteAlignment - The alignment of the symbol if
00487   /// non-zero. This must be a power of 2.
00488   virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
00489                                 unsigned ByteAlignment) = 0;
00490 
00491   /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
00492   ///
00493   /// @param Symbol - The common symbol to emit.
00494   /// @param Size - The size of the common symbol.
00495   /// @param ByteAlignment - The alignment of the common symbol in bytes.
00496   virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
00497                                      unsigned ByteAlignment);
00498 
00499   /// EmitZerofill - Emit the zerofill section and an optional symbol.
00500   ///
00501   /// @param Section - The zerofill section to create and or to put the symbol
00502   /// @param Symbol - The zerofill symbol to emit, if non-NULL.
00503   /// @param Size - The size of the zerofill symbol.
00504   /// @param ByteAlignment - The alignment of the zerofill symbol if
00505   /// non-zero. This must be a power of 2 on some targets.
00506   virtual void EmitZerofill(const MCSection *Section,
00507                             MCSymbol *Symbol = nullptr, uint64_t Size = 0,
00508                             unsigned ByteAlignment = 0) = 0;
00509 
00510   /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
00511   ///
00512   /// @param Section - The thread local common section.
00513   /// @param Symbol - The thread local common symbol to emit.
00514   /// @param Size - The size of the symbol.
00515   /// @param ByteAlignment - The alignment of the thread local common symbol
00516   /// if non-zero.  This must be a power of 2 on some targets.
00517   virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
00518                               uint64_t Size, unsigned ByteAlignment = 0);
00519 
00520   /// @}
00521   /// @name Generating Data
00522   /// @{
00523 
00524   /// EmitBytes - Emit the bytes in \p Data into the output.
00525   ///
00526   /// This is used to implement assembler directives such as .byte, .ascii,
00527   /// etc.
00528   virtual void EmitBytes(StringRef Data);
00529 
00530   /// EmitValue - Emit the expression @p Value into the output as a native
00531   /// integer of the given @p Size bytes.
00532   ///
00533   /// This is used to implement assembler directives such as .word, .quad,
00534   /// etc.
00535   ///
00536   /// @param Value - The value to emit.
00537   /// @param Size - The size of the integer (in bytes) to emit. This must
00538   /// match a native machine width.
00539   /// @param Loc - The location of the expression for error reporting.
00540   virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
00541                              const SMLoc &Loc = SMLoc());
00542 
00543   void EmitValue(const MCExpr *Value, unsigned Size,
00544                  const SMLoc &Loc = SMLoc());
00545 
00546   /// EmitIntValue - Special case of EmitValue that avoids the client having
00547   /// to pass in a MCExpr for constant integers.
00548   virtual void EmitIntValue(uint64_t Value, unsigned Size);
00549 
00550   virtual void EmitULEB128Value(const MCExpr *Value);
00551 
00552   virtual void EmitSLEB128Value(const MCExpr *Value);
00553 
00554   /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
00555   /// client having to pass in a MCExpr for constant integers.
00556   void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
00557 
00558   /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
00559   /// client having to pass in a MCExpr for constant integers.
00560   void EmitSLEB128IntValue(int64_t Value);
00561 
00562   /// EmitSymbolValue - Special case of EmitValue that avoids the client
00563   /// having to pass in a MCExpr for MCSymbols.
00564   void EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
00565                        bool IsSectionRelative = false);
00566 
00567   /// EmitGPRel64Value - Emit the expression @p Value into the output as a
00568   /// gprel64 (64-bit GP relative) value.
00569   ///
00570   /// This is used to implement assembler directives such as .gpdword on
00571   /// targets that support them.
00572   virtual void EmitGPRel64Value(const MCExpr *Value);
00573 
00574   /// EmitGPRel32Value - Emit the expression @p Value into the output as a
00575   /// gprel32 (32-bit GP relative) value.
00576   ///
00577   /// This is used to implement assembler directives such as .gprel32 on
00578   /// targets that support them.
00579   virtual void EmitGPRel32Value(const MCExpr *Value);
00580 
00581   /// EmitFill - Emit NumBytes bytes worth of the value specified by
00582   /// FillValue.  This implements directives such as '.space'.
00583   virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
00584 
00585   /// \brief Emit NumBytes worth of zeros.
00586   /// This function properly handles data in virtual sections.
00587   virtual void EmitZeros(uint64_t NumBytes);
00588 
00589   /// EmitValueToAlignment - Emit some number of copies of @p Value until
00590   /// the byte alignment @p ByteAlignment is reached.
00591   ///
00592   /// If the number of bytes need to emit for the alignment is not a multiple
00593   /// of @p ValueSize, then the contents of the emitted fill bytes is
00594   /// undefined.
00595   ///
00596   /// This used to implement the .align assembler directive.
00597   ///
00598   /// @param ByteAlignment - The alignment to reach. This must be a power of
00599   /// two on some targets.
00600   /// @param Value - The value to use when filling bytes.
00601   /// @param ValueSize - The size of the integer (in bytes) to emit for
00602   /// @p Value. This must match a native machine width.
00603   /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
00604   /// the alignment cannot be reached in this many bytes, no bytes are
00605   /// emitted.
00606   virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
00607                                     unsigned ValueSize = 1,
00608                                     unsigned MaxBytesToEmit = 0);
00609 
00610   /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
00611   /// is reached.
00612   ///
00613   /// This used to align code where the alignment bytes may be executed.  This
00614   /// can emit different bytes for different sizes to optimize execution.
00615   ///
00616   /// @param ByteAlignment - The alignment to reach. This must be a power of
00617   /// two on some targets.
00618   /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
00619   /// the alignment cannot be reached in this many bytes, no bytes are
00620   /// emitted.
00621   virtual void EmitCodeAlignment(unsigned ByteAlignment,
00622                                  unsigned MaxBytesToEmit = 0);
00623 
00624   /// EmitValueToOffset - Emit some number of copies of @p Value until the
00625   /// byte offset @p Offset is reached.
00626   ///
00627   /// This is used to implement assembler directives such as .org.
00628   ///
00629   /// @param Offset - The offset to reach. This may be an expression, but the
00630   /// expression must be associated with the current section.
00631   /// @param Value - The value to use when filling bytes.
00632   /// @return false on success, true if the offset was invalid.
00633   virtual bool EmitValueToOffset(const MCExpr *Offset,
00634                                  unsigned char Value = 0);
00635 
00636   /// @}
00637 
00638   /// EmitFileDirective - Switch to a new logical file.  This is used to
00639   /// implement the '.file "foo.c"' assembler directive.
00640   virtual void EmitFileDirective(StringRef Filename);
00641 
00642   /// Emit the "identifiers" directive.  This implements the
00643   /// '.ident "version foo"' assembler directive.
00644   virtual void EmitIdent(StringRef IdentString) {}
00645 
00646   /// EmitDwarfFileDirective - Associate a filename with a specified logical
00647   /// file number.  This implements the DWARF2 '.file 4 "foo.c"' assembler
00648   /// directive.
00649   virtual unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
00650                                           StringRef Filename,
00651                                           unsigned CUID = 0);
00652 
00653   /// EmitDwarfLocDirective - This implements the DWARF2
00654   // '.loc fileno lineno ...' assembler directive.
00655   virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
00656                                      unsigned Column, unsigned Flags,
00657                                      unsigned Isa, unsigned Discriminator,
00658                                      StringRef FileName);
00659 
00660   virtual MCSymbol *getDwarfLineTableSymbol(unsigned CUID);
00661   virtual void EmitCFISections(bool EH, bool Debug);
00662   void EmitCFIStartProc(bool IsSimple);
00663   void EmitCFIEndProc();
00664   virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
00665   virtual void EmitCFIDefCfaOffset(int64_t Offset);
00666   virtual void EmitCFIDefCfaRegister(int64_t Register);
00667   virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
00668   virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
00669   virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
00670   virtual void EmitCFIRememberState();
00671   virtual void EmitCFIRestoreState();
00672   virtual void EmitCFISameValue(int64_t Register);
00673   virtual void EmitCFIRestore(int64_t Register);
00674   virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
00675   virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
00676   virtual void EmitCFIEscape(StringRef Values);
00677   virtual void EmitCFISignalFrame();
00678   virtual void EmitCFIUndefined(int64_t Register);
00679   virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
00680   virtual void EmitCFIWindowSave();
00681 
00682   virtual void EmitWinCFIStartProc(const MCSymbol *Symbol);
00683   virtual void EmitWinCFIEndProc();
00684   virtual void EmitWinCFIStartChained();
00685   virtual void EmitWinCFIEndChained();
00686   virtual void EmitWinCFIPushReg(unsigned Register);
00687   virtual void EmitWinCFISetFrame(unsigned Register, unsigned Offset);
00688   virtual void EmitWinCFIAllocStack(unsigned Size);
00689   virtual void EmitWinCFISaveReg(unsigned Register, unsigned Offset);
00690   virtual void EmitWinCFISaveXMM(unsigned Register, unsigned Offset);
00691   virtual void EmitWinCFIPushFrame(bool Code);
00692   virtual void EmitWinCFIEndProlog();
00693 
00694   virtual void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except);
00695   virtual void EmitWinEHHandlerData();
00696 
00697   /// EmitInstruction - Emit the given @p Instruction into the current
00698   /// section.
00699   virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI);
00700 
00701   /// \brief Set the bundle alignment mode from now on in the section.
00702   /// The argument is the power of 2 to which the alignment is set. The
00703   /// value 0 means turn the bundle alignment off.
00704   virtual void EmitBundleAlignMode(unsigned AlignPow2);
00705 
00706   /// \brief The following instructions are a bundle-locked group.
00707   ///
00708   /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
00709   ///                     the end of a bundle.
00710   virtual void EmitBundleLock(bool AlignToEnd);
00711 
00712   /// \brief Ends a bundle-locked group.
00713   virtual void EmitBundleUnlock();
00714 
00715   /// EmitRawText - If this file is backed by a assembly streamer, this dumps
00716   /// the specified string in the output .s file.  This capability is
00717   /// indicated by the hasRawTextSupport() predicate.  By default this aborts.
00718   void EmitRawText(const Twine &String);
00719 
00720   /// Flush - Causes any cached state to be written out.
00721   virtual void Flush() {}
00722 
00723   /// FinishImpl - Streamer specific finalization.
00724   virtual void FinishImpl();
00725   /// Finish - Finish emission of machine code.
00726   void Finish();
00727 
00728   virtual bool mayHaveInstructions() const { return true; }
00729 };
00730 
00731 /// createNullStreamer - Create a dummy machine code streamer, which does
00732 /// nothing. This is useful for timing the assembler front end.
00733 MCStreamer *createNullStreamer(MCContext &Ctx);
00734 
00735 /// createAsmStreamer - Create a machine code streamer which will print out
00736 /// assembly for the native target, suitable for compiling with a native
00737 /// assembler.
00738 ///
00739 /// \param InstPrint - If given, the instruction printer to use. If not given
00740 /// the MCInst representation will be printed.  This method takes ownership of
00741 /// InstPrint.
00742 ///
00743 /// \param CE - If given, a code emitter to use to show the instruction
00744 /// encoding inline with the assembly. This method takes ownership of \p CE.
00745 ///
00746 /// \param TAB - If given, a target asm backend to use to show the fixup
00747 /// information in conjunction with encoding information. This method takes
00748 /// ownership of \p TAB.
00749 ///
00750 /// \param ShowInst - Whether to show the MCInst representation inline with
00751 /// the assembly.
00752 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
00753                               bool isVerboseAsm, bool useDwarfDirectory,
00754                               MCInstPrinter *InstPrint, MCCodeEmitter *CE,
00755                               MCAsmBackend *TAB, bool ShowInst);
00756 
00757 /// createMachOStreamer - Create a machine code streamer which will generate
00758 /// Mach-O format object files.
00759 ///
00760 /// Takes ownership of \p TAB and \p CE.
00761 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
00762                                 raw_ostream &OS, MCCodeEmitter *CE,
00763                                 bool RelaxAll = false,
00764                                 bool LabelSections = false);
00765 
00766 /// createELFStreamer - Create a machine code streamer which will generate
00767 /// ELF format object files.
00768 MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
00769                               raw_ostream &OS, MCCodeEmitter *CE, bool RelaxAll,
00770                               bool NoExecStack);
00771 
00772 } // end namespace llvm
00773 
00774 #endif