Made a fix so that you can print out MachineInstrs that belong to a MachineBasicBlock that is not yet attached to a MachineFunction. This change includes changing the third operand (TargetMachine) to a pointer for the MachineInstr::print function.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14389 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp
index f1a5c3e..3f7e713 100644
--- a/lib/CodeGen/MachineInstr.cpp
+++ b/lib/CodeGen/MachineInstr.cpp
@@ -235,8 +235,14 @@
 }
 
 static void print(const MachineOperand &MO, std::ostream &OS,
-                  const TargetMachine &TM) {
-  const MRegisterInfo *MRI = TM.getRegisterInfo();
+                  const TargetMachine *TM) {
+ 
+ const MRegisterInfo *MRI = 0;
+  
+ if(TM)
+   MRI = TM->getRegisterInfo();
+  
+
   bool CloseParen = true;
   if (MO.isHiBits32())
     OS << "%lm(";
@@ -313,7 +319,7 @@
     OS << ")";
 }
 
-void MachineInstr::print(std::ostream &OS, const TargetMachine &TM) const {
+void MachineInstr::print(std::ostream &OS, const TargetMachine *TM) const {
   unsigned StartOp = 0;
 
    // Specialize printing if op#0 is definition
@@ -322,7 +328,11 @@
     OS << " = ";
     ++StartOp;   // Don't print this operand again!
   }
-  OS << TM.getInstrInfo()->getName(getOpcode());
+
+  //Must check if Target machine is not null because machine BB could not
+  //be attached to a Machine function yet
+  if(TM)
+    OS << TM->getInstrInfo()->getName(getOpcode());
   
   for (unsigned i = StartOp, e = getNumOperands(); i != e; ++i) {
     const MachineOperand& mop = getOperand(i);
@@ -361,7 +371,10 @@
   // info for the instruction.
   if (const MachineBasicBlock *MBB = MI.getParent()) {
     const MachineFunction *MF = MBB->getParent();
-    MI.print(os, MF->getTarget());
+    if(MF)
+      MI.print(os, &MF->getTarget());
+    else
+      MI.print(os, 0);
     return os;
   }