[cfe-commits] r64248 - /cfe/trunk/Driver/PrintPreprocessedOutput.cpp

Chris Lattner sabre at nondot.org
Tue Feb 10 14:28:19 PST 2009


Author: lattner
Date: Tue Feb 10 16:28:19 2009
New Revision: 64248

URL: http://llvm.org/viewvc/llvm-project?rev=64248&view=rev
Log:
make -dM emit macros in a deterministic (sorted) order instead of 
random hash table order, I don't like non-determinstic output.

Modified:
    cfe/trunk/Driver/PrintPreprocessedOutput.cpp

Modified: cfe/trunk/Driver/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/PrintPreprocessedOutput.cpp?rev=64248&r1=64247&r2=64248&view=diff

==============================================================================
--- cfe/trunk/Driver/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/Driver/PrintPreprocessedOutput.cpp Tue Feb 10 16:28:19 2009
@@ -583,7 +583,6 @@
     OS << ' ';
   
   llvm::SmallVector<char, 128> SpellingBuffer;
-  
   for (MacroInfo::tokens_iterator I = MI.tokens_begin(), E = MI.tokens_end();
        I != E; ++I) {
     if (I->hasLeadingSpace())
@@ -599,6 +598,14 @@
   OS << "\n";
 }
 
+namespace {
+  struct SortMacrosByID {
+    typedef std::pair<IdentifierInfo*, MacroInfo*> id_macro_pair;
+    bool operator()(const id_macro_pair &LHS, const id_macro_pair &RHS) const {
+      return strcmp(LHS.first->getName(), RHS.first->getName()) < 0;
+    }
+  };
+}
 
 /// DoPrintPreprocessedInput - This implements -E mode.
 ///
@@ -629,9 +636,14 @@
     do PP.Lex(Tok);
     while (Tok.isNot(tok::eof));
     
+    std::vector<std::pair<IdentifierInfo*, MacroInfo*> > MacrosByID;
     for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end();
          I != E; ++I)
-      PrintMacroDefinition(*I->first, *I->second, PP, OS);
+      MacrosByID.push_back(*I);
+    std::sort(MacrosByID.begin(), MacrosByID.end(), SortMacrosByID());
+    
+    for (unsigned i = 0, e = MacrosByID.size(); i != e; ++i)
+      PrintMacroDefinition(*MacrosByID[i].first, *MacrosByID[i].second, PP, OS);
     
   } else {
     PrintPPOutputPPCallbacks *Callbacks;





More information about the cfe-commits mailing list