1 //===-- MSP430AsmPrinter.cpp - MSP430 LLVM assembly writer ------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains a printer that converts from our internal representation
11 // of machine-dependent LLVM code to the MSP430 assembly language.
13 //===----------------------------------------------------------------------===//
15 #define DEBUG_TYPE "asm-printer"
17 #include "MSP430InstrInfo.h"
18 #include "MSP430TargetMachine.h"
19 #include "llvm/Constants.h"
20 #include "llvm/DerivedTypes.h"
21 #include "llvm/Module.h"
22 #include "llvm/CodeGen/AsmPrinter.h"
23 #include "llvm/CodeGen/DwarfWriter.h"
24 #include "llvm/CodeGen/MachineModuleInfo.h"
25 #include "llvm/CodeGen/MachineFunctionPass.h"
26 #include "llvm/CodeGen/MachineConstantPool.h"
27 #include "llvm/CodeGen/MachineInstr.h"
28 #include "llvm/Target/TargetAsmInfo.h"
29 #include "llvm/Target/TargetData.h"
30 #include "llvm/ADT/Statistic.h"
31 #include "llvm/Support/Compiler.h"
32 #include "llvm/Support/Mangler.h"
33 #include "llvm/Support/raw_ostream.h"
37 STATISTIC(EmittedInsts, "Number of machine instrs printed");
40 class VISIBILITY_HIDDEN MSP430AsmPrinter : public AsmPrinter {
42 MSP430AsmPrinter(raw_ostream &O, MSP430TargetMachine &TM,
43 const TargetAsmInfo *TAI, bool Fast, bool Verbose)
44 : AsmPrinter(O, TM, TAI, Fast, Verbose) {}
46 virtual const char *getPassName() const {
47 return "MSP430 Assembly Printer";
50 bool printInstruction(const MachineInstr *MI); // autogenerated.
51 void printMachineInstruction(const MachineInstr * MI);
52 bool runOnMachineFunction(MachineFunction &F);
53 bool doInitialization(Module &M);
54 bool doFinalization(Module &M);
56 void getAnalysisUsage(AnalysisUsage &AU) const {
57 AsmPrinter::getAnalysisUsage(AU);
61 } // end of anonymous namespace
63 #include "MSP430GenAsmWriter.inc"
65 /// createMSP430CodePrinterPass - Returns a pass that prints the MSP430
66 /// assembly code for a MachineFunction to the given output stream,
67 /// using the given target machine description. This should work
68 /// regardless of whether the function is in SSA form.
70 FunctionPass *llvm::createMSP430CodePrinterPass(raw_ostream &o,
71 MSP430TargetMachine &tm,
72 bool fast, bool verbose) {
73 return new MSP430AsmPrinter(o, tm, tm.getTargetAsmInfo(), fast, verbose);
76 bool MSP430AsmPrinter::doInitialization(Module &M) {
77 Mang = new Mangler(M, "", TAI->getPrivateGlobalPrefix());
78 return false; // success
82 bool MSP430AsmPrinter::doFinalization(Module &M) {
83 return AsmPrinter::doFinalization(M);
86 bool MSP430AsmPrinter::runOnMachineFunction(MachineFunction &F) {
87 // We didn't modify anything
91 void MSP430AsmPrinter::printMachineInstruction(const MachineInstr * MI) {
94 // Call the autogenerated instruction printer routines.
95 if (printInstruction(MI))
98 assert(0 && "Should not happen");