blob: 6b0f5100c30d2a088bc1173837e2caf238e88c36 [file] [log] [blame]
Anton Korobeynikovf2c3e172009-05-03 12:57:15 +00001//===-- MSP430AsmPrinter.cpp - MSP430 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 the MSP430 assembly language.
12//
13//===----------------------------------------------------------------------===//
14
15#define DEBUG_TYPE "asm-printer"
16#include "MSP430.h"
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"
34
35using namespace llvm;
36
37STATISTIC(EmittedInsts, "Number of machine instrs printed");
38
39namespace {
40 class VISIBILITY_HIDDEN MSP430AsmPrinter : public AsmPrinter {
41 public:
42 MSP430AsmPrinter(raw_ostream &O, MSP430TargetMachine &TM,
43 const TargetAsmInfo *TAI, bool Fast, bool Verbose)
44 : AsmPrinter(O, TM, TAI, Fast, Verbose) {}
45
46 virtual const char *getPassName() const {
47 return "MSP430 Assembly Printer";
48 }
49
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);
55
56 void getAnalysisUsage(AnalysisUsage &AU) const {
57 AsmPrinter::getAnalysisUsage(AU);
58 AU.setPreservesAll();
59 }
60 };
61} // end of anonymous namespace
62
63#include "MSP430GenAsmWriter.inc"
64
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.
69///
70FunctionPass *llvm::createMSP430CodePrinterPass(raw_ostream &o,
71 MSP430TargetMachine &tm,
72 bool fast, bool verbose) {
73 return new MSP430AsmPrinter(o, tm, tm.getTargetAsmInfo(), fast, verbose);
74}
75
76bool MSP430AsmPrinter::doInitialization(Module &M) {
77 Mang = new Mangler(M, "", TAI->getPrivateGlobalPrefix());
78 return false; // success
79}
80
81
82bool MSP430AsmPrinter::doFinalization(Module &M) {
83 return AsmPrinter::doFinalization(M);
84}
85
Anton Korobeynikov09c42f52009-05-03 13:01:41 +000086bool MSP430AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
87 // Print out code for the function.
88 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
89 I != E; ++I) {
90 // Print a label for the basic block.
91 if (I != MF.begin()) {
92 printBasicBlockLabel(I, true , true);
93 O << '\n';
94 }
95
96 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
97 II != E; ++II) {
98 // Print the assembly for the instruction.
99 O << "\t";
100 printMachineInstruction(II);
101 }
102
103 // Each Basic Block is separated by a newline
104 O << '\n';
105 }
106
Anton Korobeynikovf2c3e172009-05-03 12:57:15 +0000107 // We didn't modify anything
108 return false;
109}
110
111void MSP430AsmPrinter::printMachineInstruction(const MachineInstr * MI) {
112 ++EmittedInsts;
113
114 // Call the autogenerated instruction printer routines.
115 if (printInstruction(MI))
116 return;
117
118 assert(0 && "Should not happen");
119}