Make 64bit args and float args work correct with calls. Thanks to Chris
[oota-llvm.git] / lib / Target / SparcV8 / SparcV8AsmPrinter.cpp
index 973d7e4f87baac916a70a9531cb186290803c6f9..71210536e79a0c5c57eaca4706dd53eccf477639 100644 (file)
@@ -23,9 +23,9 @@
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Support/Mangler.h"
-#include "Support/Statistic.h"
-#include "Support/StringExtras.h"
-#include "Support/CommandLine.h"
+#include "llvm/ADT/Statistic.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/CommandLine.h"
 #include <cctype>
 using namespace llvm;
 
@@ -131,7 +131,7 @@ static void printAsCString(std::ostream &O, const ConstantArray *CVA) {
 // Print out the specified constant, without a storage class.  Only the
 // constants valid in constant expressions can occur here.
 void V8Printer::emitConstantValueOnly(const Constant *CV) {
-  if (CV->isNullValue())
+  if (CV->isNullValue() || isa<UndefValue> (CV))
     O << "0";
   else if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) {
     assert(CB == ConstantBool::True);
@@ -212,22 +212,20 @@ void V8Printer::emitGlobalConstant(const Constant *CV) {
       printAsCString(O, CVA);
       O << "\n";
     } else { // Not a string.  Print the values in successive locations
-      const std::vector<Use> &constValues = CVA->getValues();
-      for (unsigned i=0; i < constValues.size(); i++)
-        emitGlobalConstant(cast<Constant>(constValues[i].get()));
+      for (unsigned i = 0, e = CVA->getNumOperands(); i != e; i++)
+        emitGlobalConstant(CVA->getOperand(i));
     }
     return;
   } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
     // Print the fields in successive locations. Pad to align if needed!
     const StructLayout *cvsLayout = TD.getStructLayout(CVS->getType());
-    const std::vector<Use>& constValues = CVS->getValues();
     unsigned sizeSoFar = 0;
-    for (unsigned i=0, N = constValues.size(); i < N; i++) {
-      const Constant* field = cast<Constant>(constValues[i].get());
+    for (unsigned i = 0, e = CVS->getNumOperands(); i != e; i++) {
+      const Constant* field = CVS->getOperand(i);
 
       // Check if padding is needed and insert one or more 0s.
       unsigned fieldSize = TD.getTypeSize(field->getType());
-      unsigned padSize = ((i == N-1? cvsLayout->StructSize
+      unsigned padSize = ((i == e-1? cvsLayout->StructSize
                            : cvsLayout->MemberOffsets[i+1])
                           - cvsLayout->MemberOffsets[i]) - fieldSize;
       sizeSoFar += fieldSize + padSize;
@@ -263,10 +261,20 @@ void V8Printer::emitGlobalConstant(const Constant *CV) {
         uint64_t UVal;
       } U;
       U.FVal = Val;
-      O << ".quad\t" << U.UVal << "\t! double " << Val << "\n";
+      O << ".word\t0x" << std::hex << (U.UVal >> 32) << std::dec << "\t! double " << Val << "\n";
+      O << ".word\t0x" << std::hex << (U.UVal & 0xffffffffUL) << std::dec << "\t! double " << Val << "\n";
       return;
     }
     }
+  } else if (isa<UndefValue> (CV)) {
+    unsigned size = TD.getTypeSize (CV->getType ());
+    O << "\t.skip\t " << size << "\n";      
+    return;
+  } else if (isa<ConstantAggregateZero> (CV)) {
+    unsigned size = TD.getTypeSize (CV->getType ());
+    for (unsigned i = 0; i < size; ++i)
+         O << "\t.byte 0\n";
+    return;
   }
 
   const Type *type = CV->getType();
@@ -276,15 +284,15 @@ void V8Printer::emitGlobalConstant(const Constant *CV) {
     O << ".byte";
     break;
   case Type::UShortTyID: case Type::ShortTyID:
-    O << ".word";
+    O << ".half";
     break;
   case Type::FloatTyID: case Type::PointerTyID:
   case Type::UIntTyID: case Type::IntTyID:
-    O << ".long";
+    O << ".word";
     break;
   case Type::DoubleTyID:
   case Type::ULongTyID: case Type::LongTyID:
-    O << ".quad";
+    O << ".xword";
     break;
   default:
     assert (0 && "Can't handle printing this type of thing");
@@ -307,7 +315,7 @@ void V8Printer::printConstantPool(MachineConstantPool *MCP) {
   if (CP.empty()) return;
 
   for (unsigned i = 0, e = CP.size(); i != e; ++i) {
-    O << "\t.section .rodata\n";
+    O << "\t.section \".rodata\"\n";
     O << "\t.align " << (unsigned)TD.getTypeAlignment(CP[i]->getType())
       << "\n";
     O << ".CPI" << CurrentFnName << "_" << i << ":\t\t\t\t\t!"
@@ -563,7 +571,7 @@ static void SwitchSection(std::ostream &OS, std::string &CurSection,
   if (CurSection != NewSection) {
     CurSection = NewSection;
     if (!CurSection.empty())
-      OS << "\t.section " << NewSection << "\n";
+      OS << "\t.section \"" << NewSection << "\"\n";
   }
 }
 
@@ -572,7 +580,7 @@ bool V8Printer::doFinalization(Module &M) {
   std::string CurSection;
 
   // Print out module-level global variables here.
-  for (Module::const_giterator I = M.gbegin(), E = M.gend(); I != E; ++I)
+  for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
     if (I->hasInitializer()) {   // External global require no code
       O << "\n\n";
       std::string name = Mang->getValueName(I);
@@ -599,7 +607,7 @@ bool V8Printer::doFinalization(Module &M) {
           // Nonnull linkonce -> weak
           O << "\t.weak " << name << "\n";
           SwitchSection(O, CurSection, "");
-          O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n";
+          O << "\t.section\t\".llvm.linkonce.d." << name << "\",\"aw\",@progbits\n";
           break;
         
         case GlobalValue::AppendingLinkage:
@@ -615,6 +623,9 @@ bool V8Printer::doFinalization(Module &M) {
           else
             SwitchSection(O, CurSection, ".data");
           break;
+        case GlobalValue::GhostLinkage:
+          std::cerr << "Should not have any unmaterialized functions!\n";
+          abort();
         }
 
         O << "\t.align " << Align << "\n";