1 //===-- MFunction.cpp - Implementation code for the MFunction class -------===//
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 //===----------------------------------------------------------------------===//
8 #include "llvm/CodeGen/MFunction.h"
9 #include "llvm/Target/MInstructionInfo.h"
10 #include "llvm/Target/MRegisterInfo.h"
13 static void printMRegister(unsigned RegNo, const MRegisterInfo &MRI,
15 if (RegNo < MRegisterInfo::FirstVirtualRegister) {
16 OS << "%" << MRI[RegNo].Name; // Hard registers are prefixed with %
18 OS << "reg" << RegNo; // SSA registers are printed with 'reg' prefix
22 static void printMInstruction(const MInstruction &MI, std::ostream &OS,
23 const MInstructionInfo &MII) {
24 const MRegisterInfo &MRI = MII.getRegisterInfo();
26 if (MI.getDestinationReg() != MRegisterInfo::NoRegister) {// Produces a value?
27 printMRegister(MI.getDestinationReg(), MRI, OS);
31 OS << MII[MI.getOpcode()].Name << " ";
33 for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
34 if (i != 0) OS << ", ";
35 switch (MI.getOperandInterpretation(i)) {
36 case MOperand::Register:
37 printMRegister(MI.getRegisterOperand(i), MRI, OS);
39 case MOperand::SignExtImmediate:
40 OS << MI.getSignExtOperand(i) << "s";
42 case MOperand::ZeroExtImmediate:
43 OS << MI.getZeroExtOperand(i) << "z";
45 case MOperand::PCRelativeDisp:
46 if (MI.getPCRelativeOperand(i) >= 0)
47 OS << "pc+" << MI.getPCRelativeOperand(i);
49 OS << "pc" << MI.getPCRelativeOperand(i);
52 OS << "*UNKNOWN OPERAND INTERPRETATION*";
59 /// print - Provide a way to get a simple debugging dump. This dumps the
60 /// machine code in a simple "assembly" language that is not really suitable
61 /// for an assembler, but is useful for debugging. This is completely target
64 void MFunction::print(std::ostream &OS, const MInstructionInfo &MII) const {
65 for (const_iterator I = begin(), E = end(); I != E; ++I) {
66 for (MBasicBlock::const_iterator II = I->begin(), IE = I->end();
68 printMInstruction(*II, OS, MII);
69 OS << "\n"; // blank line between basic blocks...
73 void MFunction::dump(const MInstructionInfo &MII) const {
74 print(std::cerr, MII);