Add special handling for pseudo-instructions (print them as comments).
[oota-llvm.git] / lib / Target / SparcV8 / SparcV8AsmPrinter.cpp
index 09d61b7b2d9951b5c6b2a86fa4fe5b38c2049c03..34cdade711b48752227bf9bda092202fcd7136b1 100644 (file)
@@ -206,10 +206,7 @@ void V8Printer::emitConstantValueOnly(const Constant *CV) {
 void V8Printer::emitGlobalConstant(const Constant *CV) {  
   const TargetData &TD = TM.getTargetData();
 
-  if (CV->isNullValue()) {
-    O << "\t.zero\t " << TD.getTypeSize(CV->getType()) << "\n";      
-    return;
-  } else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
+  if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
     if (CVA->isString()) {
       O << "\t.ascii\t";
       printAsCString(O, CVA);
@@ -240,7 +237,7 @@ void V8Printer::emitGlobalConstant(const Constant *CV) {
 
       // Insert the field padding unless it's zero bytes...
       if (padSize)
-        O << "\t.zero\t " << padSize << "\n";      
+        O << "\t.skip\t " << padSize << "\n";      
     }
     assert(sizeSoFar == cvsLayout->StructSize &&
            "Layout of constant struct may be incorrect!");
@@ -368,15 +365,6 @@ bool V8Printer::runOnMachineFunction(MachineFunction &MF) {
   return false;
 }
 
-
-std::string LowercaseString (const std::string &S) {
-  std::string result (S);
-  for (unsigned i = 0; i < S.length(); ++i) 
-    if (isupper (result[i]))
-      result[i] = tolower(result[i]);
-  return result;
-}
-
 void V8Printer::printOperand(const MachineInstr *MI, int opNum) {
   const MachineOperand &MO = MI->getOperand (opNum);
   const MRegisterInfo &RI = *TM.getRegisterInfo();
@@ -384,7 +372,8 @@ void V8Printer::printOperand(const MachineInstr *MI, int opNum) {
   if (MI->getOpcode() == V8::SETHIi && !MO.isRegister() && !MO.isImmediate()) {
     O << "%hi(";
     CloseParen = true;
-  } else if (MI->getOpcode() ==V8::ORri &&!MO.isRegister() &&!MO.isImmediate()) {
+  } else if (MI->getOpcode() ==V8::ORri &&!MO.isRegister() &&!MO.isImmediate())
+  {
     O << "%lo(";
     CloseParen = true;
   }
@@ -423,20 +412,27 @@ void V8Printer::printOperand(const MachineInstr *MI, int opNum) {
   case MachineOperand::MO_ExternalSymbol:
     O << MO.getSymbolName();
     break;
+  case MachineOperand::MO_ConstantPoolIndex:
+    O << ".CPI" << CurrentFnName << "_" << MO.getConstantPoolIndex();
+    break;
   default:
-    O << "<unknown operand type>"; break;    
+    O << "<unknown operand type>"; abort (); break;    
   }
   if (CloseParen) O << ")";
 }
 
 static bool isLoadInstruction (const MachineInstr *MI) {
   switch (MI->getOpcode ()) {
-  case V8::LDSBmr:
-  case V8::LDSHmr:
-  case V8::LDUBmr:
-  case V8::LDUHmr:
-  case V8::LDmr:
-  case V8::LDDmr:
+  case V8::LDSB:
+  case V8::LDSH:
+  case V8::LDUB:
+  case V8::LDUH:
+  case V8::LD:
+  case V8::LDD:
+  case V8::LDFrr:
+  case V8::LDFri:
+  case V8::LDDFrr:
+  case V8::LDDFri:
     return true;
   default:
     return false;
@@ -445,10 +441,27 @@ static bool isLoadInstruction (const MachineInstr *MI) {
 
 static bool isStoreInstruction (const MachineInstr *MI) {
   switch (MI->getOpcode ()) {
-  case V8::STBrm:
-  case V8::STHrm:
-  case V8::STrm:
-  case V8::STDrm:
+  case V8::STB:
+  case V8::STH:
+  case V8::ST:
+  case V8::STD:
+  case V8::STFrr:
+  case V8::STFri:
+  case V8::STDFrr:
+  case V8::STDFri:
+    return true;
+  default:
+    return false;
+  }
+}
+
+static bool isPseudoInstruction (const MachineInstr *MI) {
+  switch (MI->getOpcode ()) {
+  case V8::PHI:
+  case V8::ADJCALLSTACKUP:
+  case V8::ADJCALLSTACKDOWN:
+  case V8::IMPLICIT_USE:
+  case V8::IMPLICIT_DEF:
     return true;
   default:
     return false;
@@ -484,6 +497,11 @@ void V8Printer::printMachineInstruction(const MachineInstr *MI) {
   unsigned Opcode = MI->getOpcode();
   const TargetInstrInfo &TII = *TM.getInstrInfo();
   const TargetInstrDescriptor &Desc = TII.get(Opcode);
+
+  // If it's a pseudo-instruction, comment it out.
+  if (isPseudoInstruction (MI))
+    O << "! ";
+
   O << Desc.Name << " ";
   
   // Printing memory instructions is a special case.
@@ -545,7 +563,7 @@ static void SwitchSection(std::ostream &OS, std::string &CurSection,
   if (CurSection != NewSection) {
     CurSection = NewSection;
     if (!CurSection.empty())
-      OS << "\t" << NewSection << "\n";
+      OS << "\t.section " << NewSection << "\n";
   }
 }