Allow llvm-upgrade to read from stdin. Configure the lexer for reading
from C++ std::istream.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32041 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/llvm-upgrade/llvm-upgrade.cpp b/tools/llvm-upgrade/llvm-upgrade.cpp
index 9db8ee5..60c36eb 100644
--- a/tools/llvm-upgrade/llvm-upgrade.cpp
+++ b/tools/llvm-upgrade/llvm-upgrade.cpp
@@ -34,7 +34,7 @@
 
 static cl::opt<std::string>
 OutputFilename("o", cl::desc("Override output filename"),
-               cl::value_desc("filename"));
+               cl::value_desc("filename"), cl::init("-"));
 
 static cl::opt<bool>
 Force("f", cl::desc("Overwrite output files"));
@@ -45,6 +45,7 @@
 
   int exitCode = 0;
   std::ostream *Out = 0;
+  std::istream *In = 0;
   try {
     if (OutputFilename != "") {   // Specified an output filename?
       if (OutputFilename != "-") {  // Not stdout?
@@ -84,25 +85,35 @@
         }
 
         Out = new std::ofstream(OutputFilename.c_str(), std::ios::out |
-                                std::ios::trunc | std::ios::binary);
+                                std::ios::trunc);
         // Make sure that the Out file gets unlinked from the disk if we get a
         // SIGINT
         sys::RemoveFileOnSignal(sys::Path(OutputFilename));
       }
     }
 
+    if (InputFilename == "-") {
+      In = &std::cin;
+      InputFilename = "<stdin>";
+    } else {
+      In = new std::ifstream(InputFilename.c_str());
+    }
+
     if (!Out->good()) {
       llvm_cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
       return 1;
     }
 
-    UpgradeAssembly(InputFilename, *Out);
+    if (!In->good()) {
+      llvm_cerr << argv[0] << ": error opening " << InputFilename << "!\n";
+      return 1;
+    }
 
-    /*
+    UpgradeAssembly(InputFilename, *In, *Out);
+
   } catch (const std::string& caught_message) {
     llvm_cerr << argv[0] << ": " << caught_message << "\n";
     exitCode = 1;
-    */
   } catch (...) {
     llvm_cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
     exitCode = 1;