blob: 1e76f28f659787f3c6f7ebbddfaf4c4739ebc52f [file] [log] [blame]
Nick Lewyckyf7a3c502010-09-07 18:14:24 +00001//===-- 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 Christopher50880d02010-09-18 18:52:28 +000017#include "llvm/Support/raw_ostream.h"
18#include "llvm/ADT/SmallString.h"
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000019#include "llvm/CodeGen/AsmPrinter.h"
Eric Christopher50880d02010-09-18 18:52:28 +000020#include "llvm/CodeGen/MachineInstr.h"
21#include "llvm/MC/MCStreamer.h"
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000022#include "llvm/Target/TargetRegistry.h"
23
24using namespace llvm;
25
26namespace {
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 Christopher50880d02010-09-18 18:52:28 +000032
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 Lewyckyf7a3c502010-09-07 18:14:24 +000038 };
39} // namespace
40
Eric Christopher50880d02010-09-18 18:52:28 +000041void 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 Lewyckyf7a3c502010-09-07 18:14:24 +000051// Force static initialization.
Eric Christopher50880d02010-09-18 18:52:28 +000052extern "C" void LLVMInitializePTXAsmPrinter() {
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000053 RegisterAsmPrinter<PTXAsmPrinter> X(ThePTXTarget);
54}