[llvm-commits] [llvm] r80088 - in /llvm/trunk: include/llvm/MC/MCAssembler.h lib/MC/MCAssembler.cpp

Daniel Dunbar daniel at zuster.org
Wed Aug 26 06:57:54 PDT 2009


Author: ddunbar
Date: Wed Aug 26 08:57:54 2009
New Revision: 80088

URL: http://llvm.org/viewvc/llvm-project?rev=80088&view=rev
Log:
llvm-mc/Mach-O: Move symbol indices into the MCSymbolData structure.

Modified:
    llvm/trunk/include/llvm/MC/MCAssembler.h
    llvm/trunk/lib/MC/MCAssembler.cpp

Modified: llvm/trunk/include/llvm/MC/MCAssembler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAssembler.h?rev=80088&r1=80087&r2=80088&view=diff

==============================================================================
--- llvm/trunk/include/llvm/MC/MCAssembler.h (original)
+++ llvm/trunk/include/llvm/MC/MCAssembler.h Wed Aug 26 08:57:54 2009
@@ -286,7 +286,7 @@
   unsigned getAlignment() const { return Alignment; }
   void setAlignment(unsigned Value) { Alignment = Value; }
 
-  /// @name Section List Access
+  /// @name Fragment Access
   /// @{
 
   const FragmentListType &getFragmentList() const { return Fragments; }
@@ -324,7 +324,7 @@
     assert(FileSize != ~UINT64_C(0) && "File size not set!");
     return FileSize;
   }
-  void setFileSize(uint64_t Value) { FileSize = Value; }
+  void setFileSize(uint64_t Value) { FileSize = Value; }  
 
   /// @}
 };
@@ -352,6 +352,9 @@
   /// additional per symbol information which is not easily classified.
   uint32_t Flags;
 
+  /// Index - Index field, for use by the object file implementation.
+  uint64_t Index;
+
 public:
   // Only for use as sentinel.
   MCSymbolData();
@@ -385,6 +388,12 @@
   /// setFlags - Set the (implementation defined) symbol flags.
   void setFlags(uint32_t Value) { Flags = Value; }
   
+  /// getIndex - Get the (implementation defined) index.
+  uint64_t getIndex() const { return Index; }
+
+  /// setIndex - Set the (implementation defined) index.
+  void setIndex(uint64_t Value) { Index = Value; }
+  
   /// @}  
 };
 

Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=80088&r1=80087&r2=80088&view=diff

==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Wed Aug 26 08:57:54 2009
@@ -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);





More information about the llvm-commits mailing list