llvm-mc/Mach-O: Move symbol indices into the MCSymbolData structure.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80088 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp
index 26f6d5c..a9bbfa1 100644
--- a/lib/MC/MCAssembler.cpp
+++ b/lib/MC/MCAssembler.cpp
@@ -333,7 +333,7 @@
   }
 
   void BindIndirectSymbols(MCAssembler &Asm,
-                           DenseMap<MCSymbol*, MCSymbolData*> &SymbolMap) {
+                           DenseMap<const MCSymbol*,MCSymbolData*> &SymbolMap) {
     // This is the point where 'as' creates actual symbols for indirect symbols
     // (in the following two passes). It would be easier for us to do this
     // sooner when we see the attribute, but that makes getting the order in the
@@ -475,6 +475,15 @@
     std::sort(ExternalSymbolData.begin(), ExternalSymbolData.end());
     std::sort(UndefinedSymbolData.begin(), UndefinedSymbolData.end());
 
+    // Set the symbol indices.
+    Index = 0;
+    for (unsigned i = 0, e = LocalSymbolData.size(); i != e; ++i)
+      LocalSymbolData[i].SymbolData->setIndex(Index++);
+    for (unsigned i = 0, e = ExternalSymbolData.size(); i != e; ++i)
+      ExternalSymbolData[i].SymbolData->setIndex(Index++);
+    for (unsigned i = 0, e = UndefinedSymbolData.size(); i != e; ++i)
+      UndefinedSymbolData[i].SymbolData->setIndex(Index++);
+
     // The string table is padded to a multiple of 4.
     //
     // FIXME: Check to see if this varies per arch.
@@ -488,7 +497,7 @@
     // Compute the symbol -> symbol data map.
     //
     // FIXME: This should not be here.
-    DenseMap<MCSymbol*, MCSymbolData *> SymbolMap;
+    DenseMap<const MCSymbol*, MCSymbolData *> SymbolMap;
     for (MCAssembler::symbol_iterator it = Asm.symbol_begin(),
            ie = Asm.symbol_end(); it != ie; ++it)
       SymbolMap[&it->getSymbol()] = it;
@@ -576,24 +585,7 @@
 
     // Write the symbol table data, if used.
     if (NumSymbols) {
-      // FIXME: We shouldn't need this index table.
-      DenseMap<MCSymbol*, unsigned> SymbolIndexMap;
-      for (unsigned i = 0, e = LocalSymbolData.size(); i != e; ++i) {
-        MCSymbol &Symbol = LocalSymbolData[i].SymbolData->getSymbol();
-        SymbolIndexMap.insert(std::make_pair(&Symbol, SymbolIndexMap.size()));
-      }
-      for (unsigned i = 0, e = ExternalSymbolData.size(); i != e; ++i) {
-        MCSymbol &Symbol = ExternalSymbolData[i].SymbolData->getSymbol();
-        SymbolIndexMap.insert(std::make_pair(&Symbol, SymbolIndexMap.size()));
-      }
-      for (unsigned i = 0, e = UndefinedSymbolData.size(); i != e; ++i) {
-        MCSymbol &Symbol = UndefinedSymbolData[i].SymbolData->getSymbol();
-        SymbolIndexMap.insert(std::make_pair(&Symbol, SymbolIndexMap.size()));
-      }
-
       // Write the indirect symbol entries.
-      //
-      // FIXME: We need the symbol index map for this.
       for (MCAssembler::indirect_symbol_iterator
              it = Asm.indirect_symbol_begin(),
              ie = Asm.indirect_symbol_end(); it != ie; ++it) {
@@ -615,7 +607,7 @@
           }
         }
 
-        Write32(SymbolIndexMap[it->Symbol]);
+        Write32(SymbolMap[it->Symbol]->getIndex());
       }
 
       // FIXME: Check that offsets match computed ones.
@@ -678,7 +670,7 @@
 MCSymbolData::MCSymbolData(MCSymbol &_Symbol, MCFragment *_Fragment,
                            uint64_t _Offset, MCAssembler *A)
   : Symbol(_Symbol), Fragment(_Fragment), Offset(_Offset),
-    IsExternal(false), IsPrivateExtern(false), Flags(0)
+    IsExternal(false), IsPrivateExtern(false), Flags(0), Index(0)
 {
   if (A)
     A->getSymbolList().push_back(this);