Revert 42908 for now.
[oota-llvm.git] / lib / Target / Sparc / SparcAsmPrinter.cpp
index 1e6efcbeaf288de5cfd46417ea7c42a340fe212f..98d59ee8cb9352e8f6d9e5aebbfe7657f68f7827 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
+#define DEBUG_TYPE "asm-printer"
 #include "Sparc.h"
 #include "SparcInstrInfo.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
-#include "llvm/Assembly/Writer.h"
 #include "llvm/CodeGen/AsmPrinter.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/CodeGen/MachineConstantPool.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/MathExtras.h"
 #include <cctype>
-#include <iostream>
 using namespace llvm;
 
-namespace {
-  Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed");
+STATISTIC(EmittedInsts, "Number of machine instrs printed");
 
+namespace {
   struct VISIBILITY_HIDDEN SparcAsmPrinter : public AsmPrinter {
     SparcAsmPrinter(std::ostream &O, TargetMachine &TM, const TargetAsmInfo *T)
       : AsmPrinter(O, TM, T) {
@@ -94,15 +93,17 @@ bool SparcAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
   // What's my mangled name?
   CurrentFnName = Mang->getValueName(MF.getFunction());
 
-  // Print out labels for the function.
-  SwitchToTextSection(".text", MF.getFunction());
-  EmitAlignment(4, MF.getFunction());
+  // Print out the label for the function.
+  const Function *F = MF.getFunction();
+  SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
+  EmitAlignment(4, F);
   O << "\t.globl\t" << CurrentFnName << "\n";
   O << "\t.type\t" << CurrentFnName << ", #function\n";
   O << CurrentFnName << ":\n";
 
   // Number each basic block so that we can consistently refer to them
   // in PC-relative references.
+  // FIXME: Why not use the MBB numbers?
   NumberForBB.clear();
   for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
        I != E; ++I) {
@@ -183,8 +184,6 @@ void SparcAsmPrinter::printMemOperand(const MachineInstr *MI, int opNum,
     return;
   }
   
-  MachineOperand::MachineOperandType OpTy = MI->getOperand(opNum+1).getType();
-  
   if (MI->getOperand(opNum+1).isRegister() &&
       MI->getOperand(opNum+1).getReg() == SP::G0)
     return;   // don't print "+%g0"
@@ -230,7 +229,7 @@ bool SparcAsmPrinter::doFinalization(Module &M) {
       std::string name = Mang->getValueName(I);
       Constant *C = I->getInitializer();
       unsigned Size = TD->getTypeSize(C->getType());
-      unsigned Align = TD->getTypeAlignment(C->getType());
+      unsigned Align = TD->getPrefTypeAlignment(C->getType());
 
       if (C->isNullValue() &&
           (I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
@@ -240,9 +239,7 @@ bool SparcAsmPrinter::doFinalization(Module &M) {
           O << "\t.local " << name << "\n";
 
         O << "\t.comm " << name << "," << TD->getTypeSize(C->getType())
-          << "," << (unsigned)TD->getTypeAlignment(C->getType());
-        O << "\t\t! ";
-        WriteAsOperand(O, I, true, true, &M);
+          << "," << Align;
         O << "\n";
       } else {
         switch (I->getLinkage()) {
@@ -269,20 +266,25 @@ bool SparcAsmPrinter::doFinalization(Module &M) {
             SwitchToDataSection(".data", I);
           break;
         case GlobalValue::GhostLinkage:
-          std::cerr << "Should not have any unmaterialized functions!\n";
+          cerr << "Should not have any unmaterialized functions!\n";
+          abort();
+        case GlobalValue::DLLImportLinkage:
+          cerr << "DLLImport linkage is not supported by this target!\n";
           abort();
+        case GlobalValue::DLLExportLinkage:
+          cerr << "DLLExport linkage is not supported by this target!\n";
+          abort();
+        default:
+          assert(0 && "Unknown linkage type!");          
         }
 
         O << "\t.align " << Align << "\n";
         O << "\t.type " << name << ",#object\n";
         O << "\t.size " << name << "," << Size << "\n";
-        O << name << ":\t\t\t\t! ";
-        WriteAsOperand(O, I, true, true, &M);
-        O << "\n";
+        O << name << ":\n";
         EmitGlobalConstant(C);
       }
     }
 
-  AsmPrinter::doFinalization(M);
-  return false; // success
+  return AsmPrinter::doFinalization(M);
 }