diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2006-11-30 16:50:26 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2006-11-30 16:50:26 +0000 |
commit | 96839be87f630c4cc14e0fa1778db1bd0cca82bf (patch) | |
tree | 8419b9bd068e37891df44fe7a372f65934219b7b /tools/llvm-upgrade/llvm-upgrade.cpp | |
parent | 56918c82dea63c801667efeba5cb8ffd24f07387 (diff) |
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
Diffstat (limited to 'tools/llvm-upgrade/llvm-upgrade.cpp')
-rw-r--r-- | tools/llvm-upgrade/llvm-upgrade.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/tools/llvm-upgrade/llvm-upgrade.cpp b/tools/llvm-upgrade/llvm-upgrade.cpp index 9db8ee5f46..60c36eb87f 100644 --- a/tools/llvm-upgrade/llvm-upgrade.cpp +++ b/tools/llvm-upgrade/llvm-upgrade.cpp @@ -34,7 +34,7 @@ InputFilename(cl::Positional, cl::desc("<input .llvm file>"), cl::init("-")); 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 main(int argc, char **argv) { 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 @@ int main(int argc, char **argv) { } 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; |