Make 64bit args and float args work correct with calls. Thanks to Chris
[oota-llvm.git] / lib / Target / SparcV8 / SparcV8AsmPrinter.cpp
index 6c3bd7645dbf40b37296a9f129fc09c855a9ead8..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);
@@ -261,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();
@@ -274,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");
@@ -305,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!"
@@ -561,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";
   }
 }
 
@@ -570,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);
@@ -597,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:
@@ -613,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";