1 //===-- X86/Printer.cpp - Convert X86 code to human readable rep. ---------===//
3 // This file contains a printer that converts from our internal representation
4 // of LLVM code to a nice human readable form that is suitable for debuggging.
6 //===----------------------------------------------------------------------===//
9 #include "X86InstrInfo.h"
10 #include "llvm/Pass.h"
11 #include "llvm/Function.h"
12 #include "llvm/Target/TargetMachine.h"
13 #include "llvm/CodeGen/MachineFunction.h"
14 #include "llvm/CodeGen/MachineInstr.h"
17 struct Printer : public FunctionPass {
21 Printer(TargetMachine &tm, std::ostream &o) : TM(tm), O(o) {}
23 bool runOnFunction(Function &F);
27 /// createX86CodePrinterPass - Print out the specified machine code function to
28 /// the specified stream. This function should work regardless of whether or
29 /// not the function is in SSA form or not.
31 Pass *createX86CodePrinterPass(TargetMachine &TM, std::ostream &O) {
32 return new Printer(TM, O);
36 /// runOnFunction - This uses the X86InstructionInfo::print method
37 /// to print assembly for each instruction.
38 bool Printer::runOnFunction (Function & F)
40 static unsigned bbnumber = 0;
41 MachineFunction & MF = MachineFunction::get (&F);
42 const MachineInstrInfo & MII = TM.getInstrInfo ();
44 O << "# x86 printing only sorta implemented so far!\n";
46 // Print out labels for the function.
47 O << "\t.globl\t" << F.getName () << "\n";
48 O << "\t.type\t" << F.getName () << ", @function\n";
49 O << F.getName () << ":\n";
51 // Print out code for the function.
52 for (MachineFunction::const_iterator bb_i = MF.begin (), bb_e = MF.end ();
55 // Print a label for the basic block.
56 O << ".BB" << bbnumber++ << ":\n";
57 for (MachineBasicBlock::const_iterator i_i = bb_i->begin (), i_e =
58 bb_i->end (); i_i != i_e; ++i_i)
60 // Print the assembly for the instruction.
66 // We didn't modify anything.
71 // print - Print out an x86 instruction in intel syntax
72 void X86InstrInfo::print(const MachineInstr *MI, std::ostream &O) const {
74 O << getName(MI->getOpCode()) << "\n";