diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2010-11-28 14:48:34 +0000 | 
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2010-11-28 14:48:34 +0000 | 
| commit | 164c797676319f76b952b98073c5c3fcd5727d6c (patch) | |
| tree | 6852822256e9e8d3f8f3fd6403dc77b4c1efefce /llvm/lib | |
| parent | 8a3a7923eb0746a1b972606a19fb2ada9856140a (diff) | |
| download | bcm5719-llvm-164c797676319f76b952b98073c5c3fcd5727d6c.tar.gz bcm5719-llvm-164c797676319f76b952b98073c5c3fcd5727d6c.zip | |
Move the PTXMCAsmStreamer class to the .cpp file.
llvm-svn: 120241
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Target/PTX/PTXMCAsmStreamer.cpp | 182 | ||||
| -rw-r--r-- | llvm/lib/Target/PTX/PTXMCAsmStreamer.h | 196 | ||||
| -rw-r--r-- | llvm/lib/Target/PTX/PTXTargetMachine.cpp | 9 | 
3 files changed, 181 insertions, 206 deletions
| diff --git a/llvm/lib/Target/PTX/PTXMCAsmStreamer.cpp b/llvm/lib/Target/PTX/PTXMCAsmStreamer.cpp index 6b6c0e10883..3f9e8b4f329 100644 --- a/llvm/lib/Target/PTX/PTXMCAsmStreamer.cpp +++ b/llvm/lib/Target/PTX/PTXMCAsmStreamer.cpp @@ -7,18 +7,180 @@  //  //===----------------------------------------------------------------------===// -#include "PTXMCAsmStreamer.h" +#include "llvm/ADT/OwningPtr.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/Twine.h"  #include "llvm/MC/MCAsmInfo.h" +#include "llvm/MC/MCContext.h" +#include "llvm/MC/MCCodeEmitter.h"  #include "llvm/MC/MCExpr.h"  #include "llvm/MC/MCInst.h" +#include "llvm/MC/MCInstPrinter.h" +#include "llvm/MC/MCStreamer.h"  #include "llvm/MC/MCSymbol.h" -#include "llvm/ADT/Twine.h"  #include "llvm/Support/ErrorHandling.h"  #include "llvm/Support/MathExtras.h"  #include "llvm/Support/Format.h" +#include "llvm/Support/FormattedStream.h" +#include "llvm/Support/raw_ostream.h"  using namespace llvm; +namespace { +class PTXMCAsmStreamer : public MCStreamer { +  formatted_raw_ostream &OS; +  const MCAsmInfo &MAI; +  OwningPtr<MCInstPrinter> InstPrinter; +  OwningPtr<MCCodeEmitter> Emitter; + +  SmallString<128> CommentToEmit; +  raw_svector_ostream CommentStream; + +  unsigned IsLittleEndian : 1; +  unsigned IsVerboseAsm : 1; +  unsigned ShowInst : 1; + +public: +  PTXMCAsmStreamer(MCContext &Context, +                   formatted_raw_ostream &os, +                   bool isLittleEndian, +                   bool isVerboseAsm, +                   MCInstPrinter *printer, +                   MCCodeEmitter *emitter, +                   bool showInst) +    : MCStreamer(Context), OS(os), MAI(Context.getAsmInfo()), +      InstPrinter(printer), Emitter(emitter), CommentStream(CommentToEmit), +      IsLittleEndian(isLittleEndian), IsVerboseAsm(isVerboseAsm), +      ShowInst(showInst) { +    if (InstPrinter && IsVerboseAsm) +      InstPrinter->setCommentStream(CommentStream); +  } + +  ~PTXMCAsmStreamer() {} + +  bool isLittleEndian() const { return IsLittleEndian; } + +  inline void EmitEOL() { +    // If we don't have any comments, just emit a \n. +    if (!IsVerboseAsm) { +      OS << '\n'; +      return; +    } +    EmitCommentsAndEOL(); +  } +  void EmitCommentsAndEOL(); + +  /// isVerboseAsm - Return true if this streamer supports verbose assembly at +  /// all. +  virtual bool isVerboseAsm() const { return IsVerboseAsm; } + +  /// hasRawTextSupport - We support EmitRawText. +  virtual bool hasRawTextSupport() const { return true; } + +  /// AddComment - Add a comment that can be emitted to the generated .s +  /// file if applicable as a QoI issue to make the output of the compiler +  /// more readable.  This only affects the MCAsmStreamer, and only when +  /// verbose assembly output is enabled. +  virtual void AddComment(const Twine &T); + +  /// AddEncodingComment - Add a comment showing the encoding of an instruction. +  virtual void AddEncodingComment(const MCInst &Inst); + +  /// GetCommentOS - Return a raw_ostream that comments can be written to. +  /// Unlike AddComment, you are required to terminate comments with \n if you +  /// use this method. +  virtual raw_ostream &GetCommentOS() { +    if (!IsVerboseAsm) +      return nulls();  // Discard comments unless in verbose asm mode. +    return CommentStream; +  } + +  /// AddBlankLine - Emit a blank line to a .s file to pretty it up. +  virtual void AddBlankLine() { +    EmitEOL(); +  } + +  /// @name MCStreamer Interface +  /// @{ + +  virtual void SwitchSection(const MCSection *Section); + +  virtual void InitSections() { +  } + +  virtual void EmitLabel(MCSymbol *Symbol); + +  virtual void EmitAssemblerFlag(MCAssemblerFlag Flag); + +  virtual void EmitThumbFunc(MCSymbol *Func); + +  virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value); + +  virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol); + +  virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute); + +  virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue); +  virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol); +  virtual void EmitCOFFSymbolStorageClass(int StorageClass); +  virtual void EmitCOFFSymbolType(int Type); +  virtual void EndCOFFSymbolDef(); +  virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value); +  virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, +                                unsigned ByteAlignment); + +  /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol. +  /// +  /// @param Symbol - The common symbol to emit. +  /// @param Size - The size of the common symbol. +  virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size); + +  virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0, +                            unsigned Size = 0, unsigned ByteAlignment = 0); + +  virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol, +                              uint64_t Size, unsigned ByteAlignment = 0); + +  virtual void EmitBytes(StringRef Data, unsigned AddrSpace); + +  virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace); +  virtual void EmitIntValue(uint64_t Value, unsigned Size, unsigned AddrSpace); +  virtual void EmitULEB128Value(const MCExpr *Value, unsigned AddrSpace = 0); +  virtual void EmitSLEB128Value(const MCExpr *Value, unsigned AddrSpace = 0); +  virtual void EmitGPRel32Value(const MCExpr *Value); + + +  virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue, +                        unsigned AddrSpace); + +  virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0, +                                    unsigned ValueSize = 1, +                                    unsigned MaxBytesToEmit = 0); + +  virtual void EmitCodeAlignment(unsigned ByteAlignment, +                                 unsigned MaxBytesToEmit = 0); + +  virtual void EmitValueToOffset(const MCExpr *Offset, +                                 unsigned char Value = 0); + +  virtual void EmitFileDirective(StringRef Filename); +  virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Filename); + +  virtual void EmitInstruction(const MCInst &Inst); + +  /// EmitRawText - If this file is backed by an assembly streamer, this dumps +  /// the specified string in the output .s file.  This capability is +  /// indicated by the hasRawTextSupport() predicate. +  virtual void EmitRawText(StringRef String); + +  virtual void Finish(); + +  /// @} + +}; // class PTXMCAsmStreamer + +} +  /// TODO: Add appropriate implementation of Emit*() methods when needed  void PTXMCAsmStreamer::AddComment(const Twine &T) { @@ -381,11 +543,13 @@ void PTXMCAsmStreamer::EmitRawText(StringRef String) {  void PTXMCAsmStreamer::Finish() {} -MCStreamer *llvm::createPTXAsmStreamer(MCContext &Context, -                                       formatted_raw_ostream &OS, -                                       bool isLittleEndian, -                                       bool isVerboseAsm, MCInstPrinter *IP, -                                       MCCodeEmitter *CE, bool ShowInst) { -  return new PTXMCAsmStreamer(Context, OS, isLittleEndian, isVerboseAsm, -                              IP, CE, ShowInst); +namespace llvm { +  MCStreamer *createPTXAsmStreamer(MCContext &Context, +                                   formatted_raw_ostream &OS, +                                   bool isLittleEndian, +                                   bool isVerboseAsm, MCInstPrinter *IP, +                                   MCCodeEmitter *CE, bool ShowInst) { +    return new PTXMCAsmStreamer(Context, OS, isLittleEndian, isVerboseAsm, +                                IP, CE, ShowInst); +  }  } diff --git a/llvm/lib/Target/PTX/PTXMCAsmStreamer.h b/llvm/lib/Target/PTX/PTXMCAsmStreamer.h deleted file mode 100644 index bd596549c38..00000000000 --- a/llvm/lib/Target/PTX/PTXMCAsmStreamer.h +++ /dev/null @@ -1,196 +0,0 @@ -//===- PTXMCAsmStreamer.h - PTX Text Assembly Output ------------*- C++ -*-===// -// -//                     The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file declares the PTXMCAsmStreamer class. -// -//===----------------------------------------------------------------------===// - -#ifndef PTX_MCASMSTREAMER_H -#define PTX_MCASMSTREAMER_H - -#include "llvm/MC/MCStreamer.h" -#include "llvm/MC/MCCodeEmitter.h" -#include "llvm/MC/MCContext.h" -#include "llvm/MC/MCInstPrinter.h" -#include "llvm/MC/MCSectionMachO.h" -#include "llvm/ADT/OwningPtr.h" -#include "llvm/ADT/SmallString.h" -#include "llvm/Support/FormattedStream.h" - -namespace llvm { -class MCContext; -class MCInstPrinter; -class Twine; - -class PTXMCAsmStreamer : public MCStreamer { -  formatted_raw_ostream &OS; -  const MCAsmInfo &MAI; -  OwningPtr<MCInstPrinter> InstPrinter; -  OwningPtr<MCCodeEmitter> Emitter; - -  SmallString<128> CommentToEmit; -  raw_svector_ostream CommentStream; - -  unsigned IsLittleEndian : 1; -  unsigned IsVerboseAsm : 1; -  unsigned ShowInst : 1; - -public: -  PTXMCAsmStreamer(MCContext &Context, -                   formatted_raw_ostream &os, -                   bool isLittleEndian, -                   bool isVerboseAsm, -                   MCInstPrinter *printer, -                   MCCodeEmitter *emitter, -                   bool showInst) -    : MCStreamer(Context), OS(os), MAI(Context.getAsmInfo()), -      InstPrinter(printer), Emitter(emitter), CommentStream(CommentToEmit), -      IsLittleEndian(isLittleEndian), IsVerboseAsm(isVerboseAsm), -      ShowInst(showInst) { -    if (InstPrinter && IsVerboseAsm) -      InstPrinter->setCommentStream(CommentStream); -  } - -  ~PTXMCAsmStreamer() {} - -  bool isLittleEndian() const { return IsLittleEndian; } - -  inline void EmitEOL() { -    // If we don't have any comments, just emit a \n. -    if (!IsVerboseAsm) { -      OS << '\n'; -      return; -    } -    EmitCommentsAndEOL(); -  } -  void EmitCommentsAndEOL(); - -  /// isVerboseAsm - Return true if this streamer supports verbose assembly at -  /// all. -  virtual bool isVerboseAsm() const { return IsVerboseAsm; } - -  /// hasRawTextSupport - We support EmitRawText. -  virtual bool hasRawTextSupport() const { return true; } - -  /// AddComment - Add a comment that can be emitted to the generated .s -  /// file if applicable as a QoI issue to make the output of the compiler -  /// more readable.  This only affects the MCAsmStreamer, and only when -  /// verbose assembly output is enabled. -  virtual void AddComment(const Twine &T); - -  /// AddEncodingComment - Add a comment showing the encoding of an instruction. -  virtual void AddEncodingComment(const MCInst &Inst); - -  /// GetCommentOS - Return a raw_ostream that comments can be written to. -  /// Unlike AddComment, you are required to terminate comments with \n if you -  /// use this method. -  virtual raw_ostream &GetCommentOS() { -    if (!IsVerboseAsm) -      return nulls();  // Discard comments unless in verbose asm mode. -    return CommentStream; -  } - -  /// AddBlankLine - Emit a blank line to a .s file to pretty it up. -  virtual void AddBlankLine() { -    EmitEOL(); -  } - -  /// @name MCStreamer Interface -  /// @{ - -  virtual void SwitchSection(const MCSection *Section); - -  virtual void InitSections() { -    // FIXME, this is MachO specific, but the testsuite -    // expects this. -    SwitchSection(getContext(). -                  getMachOSection("__TEXT", "__text", -                                  MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, -                                  0, SectionKind::getText())); -  } - -  virtual void EmitLabel(MCSymbol *Symbol); - -  virtual void EmitAssemblerFlag(MCAssemblerFlag Flag); - -  virtual void EmitThumbFunc(MCSymbol *Func); - -  virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value); - -  virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol); - -  virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute); - -  virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue); -  virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol); -  virtual void EmitCOFFSymbolStorageClass(int StorageClass); -  virtual void EmitCOFFSymbolType(int Type); -  virtual void EndCOFFSymbolDef(); -  virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value); -  virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, -                                unsigned ByteAlignment); - -  /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol. -  /// -  /// @param Symbol - The common symbol to emit. -  /// @param Size - The size of the common symbol. -  virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size); - -  virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0, -                            unsigned Size = 0, unsigned ByteAlignment = 0); - -  virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol, -                              uint64_t Size, unsigned ByteAlignment = 0); - -  virtual void EmitBytes(StringRef Data, unsigned AddrSpace); - -  virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace); -  virtual void EmitIntValue(uint64_t Value, unsigned Size, unsigned AddrSpace); -  virtual void EmitULEB128Value(const MCExpr *Value, unsigned AddrSpace = 0); -  virtual void EmitSLEB128Value(const MCExpr *Value, unsigned AddrSpace = 0); -  virtual void EmitGPRel32Value(const MCExpr *Value); - - -  virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue, -                        unsigned AddrSpace); - -  virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0, -                                    unsigned ValueSize = 1, -                                    unsigned MaxBytesToEmit = 0); - -  virtual void EmitCodeAlignment(unsigned ByteAlignment, -                                 unsigned MaxBytesToEmit = 0); - -  virtual void EmitValueToOffset(const MCExpr *Offset, -                                 unsigned char Value = 0); - -  virtual void EmitFileDirective(StringRef Filename); -  virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Filename); - -  virtual void EmitInstruction(const MCInst &Inst); - -  /// EmitRawText - If this file is backed by an assembly streamer, this dumps -  /// the specified string in the output .s file.  This capability is -  /// indicated by the hasRawTextSupport() predicate. -  virtual void EmitRawText(StringRef String); - -  virtual void Finish(); - -  /// @} - -}; // class PTXMCAsmStreamer - -MCStreamer *createPTXAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS, -                                 bool isLittleEndian, bool isVerboseAsm, -                                 MCInstPrinter *InstPrint, -                                 MCCodeEmitter *CE, -                                 bool ShowInst); -} // namespace llvm - -#endif // PTX_MCASMSTREAMER_H diff --git a/llvm/lib/Target/PTX/PTXTargetMachine.cpp b/llvm/lib/Target/PTX/PTXTargetMachine.cpp index b60e531708d..f62a5299a11 100644 --- a/llvm/lib/Target/PTX/PTXTargetMachine.cpp +++ b/llvm/lib/Target/PTX/PTXTargetMachine.cpp @@ -13,13 +13,20 @@  #include "PTX.h"  #include "PTXMCAsmInfo.h" -#include "PTXMCAsmStreamer.h"  #include "PTXTargetMachine.h"  #include "llvm/PassManager.h"  #include "llvm/Target/TargetRegistry.h"  using namespace llvm; +namespace llvm { +  MCStreamer *createPTXAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS, +                                   bool isLittleEndian, bool isVerboseAsm, +                                   MCInstPrinter *InstPrint, +                                   MCCodeEmitter *CE, +                                   bool ShowInst); +} +  extern "C" void LLVMInitializePTXTarget() {    RegisterTargetMachine<PTXTargetMachine> X(ThePTXTarget);    RegisterAsmInfo<PTXMCAsmInfo> Y(ThePTXTarget); | 

