What should be the last unnecessary <iostream>s in the library.
[oota-llvm.git] / lib / Target / ARM / ARMAsmPrinter.cpp
index 51a0f883d2ddb10874df8a4b7fca49c9056c93f2..e57a7685077820bfd3a32e421843bb4c9f75e1ff 100644 (file)
@@ -18,7 +18,6 @@
 #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("asm-printer", "Number of machine instrs printed");
 
   static const char *ARMCondCodeToString(ARMCC::CondCodes CC) {
     switch (CC) {
@@ -64,6 +62,8 @@ namespace {
       : AsmPrinter(O, TM, T) {
     }
 
+    std::set<std::string> ExtWeakSymbols;
+
     /// We name each basic block in a Function with a unique number, so
     /// that we can consistently refer to them later. This is cleared
     /// at the beginning of each call to runOnMachineFunction().
@@ -128,7 +128,7 @@ bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
     break;
   case Function::WeakLinkage:
   case Function::LinkOnceLinkage:
-    assert(0 && "Not implemented");
+    O << TAI->getWeakRefDirective() << CurrentFnName << "\n";
     break;
   }
   EmitAlignment(2, F);
@@ -245,6 +245,9 @@ void ARMAsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
     GlobalValue *GV = MO.getGlobal();
     std::string Name = Mang->getValueName(GV);
     O << Name;
+    if (GV->hasExternalWeakLinkage()) {
+      ExtWeakSymbols.insert(Name);
+    }
   }
     break;
   case MachineOperand::MO_ExternalSymbol:
@@ -292,6 +295,7 @@ bool ARMAsmPrinter::doFinalization(Module &M) {
     unsigned Align = TD->getTypeAlignment(C->getType());
 
     if (C->isNullValue() &&
+        !I->hasSection() &&
         (I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
          I->hasWeakLinkage())) {
       SwitchToDataSection(".data", I);
@@ -300,9 +304,6 @@ bool ARMAsmPrinter::doFinalization(Module &M) {
 
       O << "\t.comm " << name << "," << TD->getTypeSize(C->getType())
         << "," << (unsigned)TD->getTypeAlignment(C->getType());
-      O << "\t\t";
-      O << TAI->getCommentString() << " ";
-      WriteAsOperand(O, I, true, true, &M);
       O << "\n";
     } else {
       switch (I->getLinkage()) {
@@ -329,6 +330,13 @@ bool ARMAsmPrinter::doFinalization(Module &M) {
     }
   }
 
+  if (ExtWeakSymbols.begin() != ExtWeakSymbols.end())
+    SwitchToDataSection("");
+  for (std::set<std::string>::iterator i = ExtWeakSymbols.begin(),
+         e = ExtWeakSymbols.end(); i != e; ++i) {
+    O << TAI->getWeakRefDirective() << *i << "\n";
+  }
+
   AsmPrinter::doFinalization(M);
   return false; // success
 }