Printing support for more stuff
[oota-llvm.git] / lib / Target / SparcV9 / SparcV9AsmPrinter.cpp
index 58a60b0977517b3b755cf9ece2adf4874e8ef77a..38518eef41c2c9ebd23df1ffa645047112387351 100644 (file)
@@ -13,8 +13,7 @@
 
 #include "SparcInternals.h"
 #include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/CodeGen/MachineCodeForBasicBlock.h"
-#include "llvm/CodeGen/MachineCodeForMethod.h"
+#include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
@@ -140,9 +139,9 @@ public:
   //
   string getID(const Value *V, const char *Prefix, const char *FPrefix = 0) {
     string Result = FPrefix ? FPrefix : "";  // "Forced prefix"
-    
+
     Result +=  V->hasName() ? V->getName() : string(Prefix);
-    
+
     // Qualify all internal names with a unique id.
     if (!isExternal(V)) {
       int valId = idTable->Table.getValSlot(V);
@@ -154,9 +153,12 @@ public:
           valId = I->second;
       }
       Result = Result + "_" + itostr(valId);
+
+      // Replace or prefix problem characters in the name
+      Result = getValidSymbolName(Result);
     }
-    
-    return getValidSymbolName(Result);
+
+    return Result;
   }
   
   // getID Wrappers - Ensure consistent usage...
@@ -295,7 +297,7 @@ struct SparcFunctionAsmPrinter : public FunctionPass, public AsmPrinter {
 
   void emitFunction(const Function &F);
 private :
-  void emitBasicBlock(const BasicBlock *BB);
+  void emitBasicBlock(const MachineBasicBlock &MBB);
   void emitMachineInst(const MachineInstr *MI);
   
   unsigned int printOperands(const MachineInstr *MI, unsigned int opNum);
@@ -383,7 +385,7 @@ SparcFunctionAsmPrinter::printOneOperand(const MachineOperand &mop)
   else
     needBitsFlag = false;
   
-  switch (mop.getOperandType())
+  switch (mop.getType())
     {
     case MachineOperand::MO_VirtualRegister:
     case MachineOperand::MO_CCRegister:
@@ -441,10 +443,10 @@ SparcFunctionAsmPrinter::emitMachineInst(const MachineInstr *MI)
 {
   unsigned Opcode = MI->getOpCode();
 
-  if (TargetInstrDescriptors[Opcode].iclass & M_DUMMY_PHI_FLAG)
+  if (Target.getInstrInfo().isDummyPhiInstr(Opcode))
     return;  // IGNORE PHI NODES
 
-  toAsm << "\t" << TargetInstrDescriptors[Opcode].opCodeString << "\t";
+  toAsm << "\t" << Target.getInstrInfo().getName(Opcode) << "\t";
 
   unsigned Mask = getOperandMask(Opcode);
   
@@ -455,25 +457,21 @@ SparcFunctionAsmPrinter::emitMachineInst(const MachineInstr *MI)
       if (NeedComma) toAsm << ", ";         // Handle comma outputing
       NeedComma = true;
       N = printOperands(MI, OpNum);
-    }
-  else
-    N = 1;
+    } else
+      N = 1;
   
   toAsm << "\n";
 }
 
 void
-SparcFunctionAsmPrinter::emitBasicBlock(const BasicBlock *BB)
+SparcFunctionAsmPrinter::emitBasicBlock(const MachineBasicBlock &MBB)
 {
   // Emit a label for the basic block
-  toAsm << getID(BB) << ":\n";
-
-  // Get the vector of machine instructions corresponding to this bb.
-  const MachineCodeForBasicBlock &MIs = MachineCodeForBasicBlock::get(BB);
-  MachineCodeForBasicBlock::const_iterator MII = MIs.begin(), MIE = MIs.end();
+  toAsm << getID(MBB.getBasicBlock()) << ":\n";
 
   // Loop over all of the instructions in the basic block...
-  for (; MII != MIE; ++MII)
+  for (MachineBasicBlock::const_iterator MII = MBB.begin(), MIE = MBB.end();
+       MII != MIE; ++MII)
     emitMachineInst(*MII);
   toAsm << "\n";  // Seperate BB's with newlines
 }
@@ -490,8 +488,9 @@ SparcFunctionAsmPrinter::emitFunction(const Function &F)
   toAsm << methName << ":\n";
 
   // Output code for all of the basic blocks in the function...
-  for (Function::const_iterator I = F.begin(), E = F.end(); I != E; ++I)
-    emitBasicBlock(I);
+  MachineFunction &MF = MachineFunction::get(&F);
+  for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); I != E; ++I)
+    emitBasicBlock(*I);
 
   // Output a .size directive so the debugger knows the extents of the function
   toAsm << ".EndOf_" << methName << ":\n\t.size "
@@ -586,6 +585,8 @@ static string getAsCString(const ConstantArray *CVA) {
 
     if (C == '"') {
       Result += "\\\"";
+    } else if (C == '\\') {
+      Result += "\\\\";
     } else if (isprint(C)) {
       Result += C;
     } else {
@@ -863,7 +864,7 @@ void SparcModuleAsmPrinter::FoldConstants(const Module &M,
   for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I)
     if (!I->isExternal()) {
       const hash_set<const Constant*> &pool =
-        MachineCodeForMethod::get(I).getConstantPoolValues();
+        MachineFunction::get(I).getConstantPoolValues();
       MC.insert(pool.begin(), pool.end());
     }
 }