Make sure that bool,byte and short arguments are the right type when loaded
[oota-llvm.git] / lib / Target / SparcV8 / SparcV8AsmPrinter.cpp
index 1d0cbac38411dca161a4821b05ceb2eec9c06f46..e8048482784c0726b8414219a1636da084abb361 100644 (file)
@@ -38,8 +38,10 @@ namespace {
     SparcV8AsmPrinter(std::ostream &O, TargetMachine &TM) : AsmPrinter(O, TM) {
       Data16bitsDirective = "\t.half\t";
       Data32bitsDirective = "\t.word\t";
-      Data64bitsDirective = "\t.xword\t";
+      Data64bitsDirective = 0;  // .xword is only supported by V9.
       ZeroDirective = 0;  // no .zero or .space!
+      CommentString = "!";
+      ConstantPoolSection = "\t.section \".rodata\",#alloc\n";
     }
 
     /// We name each basic block in a Function with a unique number, so
@@ -54,6 +56,7 @@ namespace {
     }
 
     void printOperand(const MachineInstr *MI, int opNum);
+    void printMemOperand(const MachineInstr *MI, int opNum);
     bool printInstruction(const MachineInstr *MI);  // autogenerated.
     bool runOnMachineFunction(MachineFunction &F);
     bool doInitialization(Module &M);
@@ -109,9 +112,10 @@ bool SparcV8AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
   for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
        I != E; ++I) {
     // Print a label for the basic block.
-    O << ".LBB" << Mang->getValueName(MF.getFunction ())
-      << "_" << I->getNumber () << ":\t! "
-      << I->getBasicBlock ()->getName () << "\n";
+    if (I != MF.begin())
+      O << ".LBB" << Mang->getValueName(MF.getFunction ())
+        << "_" << I->getNumber () << ":\t! "
+        << I->getBasicBlock ()->getName () << "\n";
     for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
          II != E; ++II) {
       // Print the assembly for the instruction.
@@ -132,8 +136,8 @@ void SparcV8AsmPrinter::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 || MI->getOpcode() == V8::ADDri)
+             && !MO.isRegister() && !MO.isImmediate()) {
     O << "%lo(";
     CloseParen = true;
   }
@@ -182,6 +186,31 @@ void SparcV8AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
   if (CloseParen) O << ")";
 }
 
+void SparcV8AsmPrinter::printMemOperand(const MachineInstr *MI, int opNum) {
+  printOperand(MI, opNum);
+  MachineOperand::MachineOperandType OpTy = MI->getOperand(opNum+1).getType();
+  
+  if ((OpTy == MachineOperand::MO_VirtualRegister ||
+       OpTy == MachineOperand::MO_MachineRegister) &&
+      MI->getOperand(opNum+1).getReg() == V8::G0)
+    return;   // don't print "+%g0"
+  if ((OpTy == MachineOperand::MO_SignExtendedImmed ||
+       OpTy == MachineOperand::MO_UnextendedImmed) &&
+      MI->getOperand(opNum+1).getImmedValue() == 0)
+    return;   // don't print "+0"
+  
+  O << "+";
+  if (OpTy == MachineOperand::MO_GlobalAddress ||
+      OpTy == MachineOperand::MO_ConstantPoolIndex) {
+    O << "%lo(";
+    printOperand(MI, opNum+1);
+    O << ")";
+  } else {
+    printOperand(MI, opNum+1);
+  }
+}
+
+
 bool SparcV8AsmPrinter::doInitialization(Module &M) {
   Mang = new Mangler(M);
   return false; // success