Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 1 | //===-- PTXAsmPrinter.cpp - PTX LLVM assembly writer ----------------------===// |
| 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 contains a printer that converts from our internal representation |
| 11 | // of machine-dependent LLVM code to PTX assembly language. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "PTX.h" |
| 16 | #include "PTXTargetMachine.h" |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 17 | #include "llvm/Support/raw_ostream.h" |
| 18 | #include "llvm/ADT/SmallString.h" |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/AsmPrinter.h" |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineInstr.h" |
| 21 | #include "llvm/MC/MCStreamer.h" |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 22 | #include "llvm/Target/TargetRegistry.h" |
| 23 | |
| 24 | using namespace llvm; |
| 25 | |
| 26 | namespace { |
| 27 | class PTXAsmPrinter : public AsmPrinter { |
| 28 | public: |
| 29 | explicit PTXAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) : |
| 30 | AsmPrinter(TM, Streamer) {} |
| 31 | const char *getPassName() const { return "PTX Assembly Printer"; } |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 32 | |
| 33 | virtual void EmitInstruction(const MachineInstr *MI); |
| 34 | |
| 35 | // autogen'd. |
| 36 | void printInstruction(const MachineInstr *MI, raw_ostream &OS); |
| 37 | static const char *getRegisterName(unsigned RegNo); |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 38 | }; |
| 39 | } // namespace |
| 40 | |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 41 | void PTXAsmPrinter::EmitInstruction(const MachineInstr *MI) { |
| 42 | SmallString<128> str; |
| 43 | raw_svector_ostream os(str); |
| 44 | printInstruction(MI, os); |
| 45 | os << ';'; |
| 46 | OutStreamer.EmitRawText(os.str()); |
| 47 | } |
| 48 | |
| 49 | #include "PTXGenAsmWriter.inc" |
| 50 | |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 51 | // Force static initialization. |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 52 | extern "C" void LLVMInitializePTXAsmPrinter() { |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 53 | RegisterAsmPrinter<PTXAsmPrinter> X(ThePTXTarget); |
| 54 | } |