For PR786:
[oota-llvm.git] / lib / Target / Sparc / SparcAsmPrinter.cpp
index 0de7fb032bb28ff27aad7ebc3a336b1d24728aae..2e6a470af8e93922e1ce827ec825a548f2a6b9c4 100644 (file)
@@ -22,6 +22,7 @@
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/CodeGen/MachineConstantPool.h"
 #include "llvm/CodeGen/MachineInstr.h"
+#include "llvm/Target/TargetAsmInfo.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Support/Mangler.h"
@@ -36,14 +37,9 @@ using namespace llvm;
 namespace {
   Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed");
 
-  struct SparcAsmPrinter : public AsmPrinter {
-    SparcAsmPrinter(std::ostream &O, TargetMachine &TM) : AsmPrinter(O, TM) {
-      Data16bitsDirective = "\t.half\t";
-      Data32bitsDirective = "\t.word\t";
-      Data64bitsDirective = 0;  // .xword is only supported by V9.
-      ZeroDirective = "\t.skip\t";
-      CommentString = "!";
-      ConstantPoolSection = "\t.section \".rodata\",#alloc\n";
+  struct VISIBILITY_HIDDEN SparcAsmPrinter : public AsmPrinter {
+    SparcAsmPrinter(std::ostream &O, TargetMachine &TM, const TargetAsmInfo *T)
+      : AsmPrinter(O, TM, T) {
     }
 
     /// We name each basic block in a Function with a unique number, so
@@ -78,7 +74,7 @@ namespace {
 ///
 FunctionPass *llvm::createSparcCodePrinterPass(std::ostream &o,
                                                TargetMachine &tm) {
-  return new SparcAsmPrinter(o, tm);
+  return new SparcAsmPrinter(o, tm, tm.getTargetAsmInfo());
 }
 
 /// runOnMachineFunction - This uses the printMachineInstruction()
@@ -98,15 +94,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) {
@@ -167,7 +165,7 @@ void SparcAsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
     O << MO.getSymbolName();
     break;
   case MachineOperand::MO_ConstantPoolIndex:
-    O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << "_"
+    O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_"
       << MO.getConstantPoolIndex();
     break;
   default:
@@ -187,8 +185,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"
@@ -275,6 +271,14 @@ bool SparcAsmPrinter::doFinalization(Module &M) {
         case GlobalValue::GhostLinkage:
           std::cerr << "Should not have any unmaterialized functions!\n";
           abort();
+        case GlobalValue::DLLImportLinkage:
+          std::cerr << "DLLImport linkage is not supported by this target!\n";
+          abort();
+        case GlobalValue::DLLExportLinkage:
+          std::cerr << "DLLExport linkage is not supported by this target!\n";
+          abort();
+        default:
+          assert(0 && "Unknown linkage type!");          
         }
 
         O << "\t.align " << Align << "\n";