Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* Copyright 2013 The Native Client Authors. All rights reserved. | 1 /* Copyright 2013 The Native Client Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can | 2 * Use of this source code is governed by a BSD-style license that can |
| 3 * be found in the LICENSE file. | 3 * be found in the LICENSE file. |
| 4 */ | 4 */ |
| 5 | 5 |
| 6 //===-- pnacl-freeze.cpp - The low-level NaCl bitcode freezer --------===// | 6 //===-- pnacl-freeze.cpp - The low-level NaCl bitcode freezer --------===// |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // Generates NaCl pexe wire format. | 10 // Generates NaCl pexe wire format. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "llvm/Support/ToolOutputFile.h" | 27 #include "llvm/Support/ToolOutputFile.h" |
| 28 | 28 |
| 29 using namespace llvm; | 29 using namespace llvm; |
| 30 | 30 |
| 31 | 31 |
| 32 static cl::opt<std::string> | 32 static cl::opt<std::string> |
| 33 OutputFilename("o", cl::desc("Specify output filename"), | 33 OutputFilename("o", cl::desc("Specify output filename"), |
| 34 cl::value_desc("filename")); | 34 cl::value_desc("filename")); |
| 35 | 35 |
| 36 static cl::opt<std::string> | 36 static cl::opt<std::string> |
| 37 InputFilename(cl::Positional, cl::desc("<pexe file>"), cl::Required); | 37 InputFilename(cl::Positional, cl::desc("<pexe file>"), cl::init("-")); |
| 38 | 38 |
| 39 static void WriteOutputFile(const Module *M) { | 39 static void WriteOutputFile(const Module *M) { |
| 40 | 40 |
| 41 std::string FrozenFilename = | 41 std::string FrozenFilename(OutputFilename); |
| 42 (OutputFilename.size() == 0 ? (InputFilename + ".frozen") : OutputFilename); | 42 if (OutputFilename.size() == 0) { |
| 43 std::string input_filename; | |
| 44 if (InputFilename == "-") | |
| 45 input_filename = "<stdin>"; | |
|
jvoung (off chromium)
2013/05/02 22:12:50
What some of the other tools do is set OutputFilen
Karl
2013/05/06 16:21:51
I guess this is ok. I just have to redirect my min
| |
| 46 else | |
| 47 input_filename = InputFilename; | |
| 48 FrozenFilename = input_filename + ".frozen"; | |
| 49 } | |
| 43 | 50 |
| 44 std::string ErrorInfo; | 51 std::string ErrorInfo; |
| 45 OwningPtr<tool_output_file> Out | 52 OwningPtr<tool_output_file> Out |
| 46 (new tool_output_file(FrozenFilename.c_str(), ErrorInfo, | 53 (new tool_output_file(FrozenFilename.c_str(), ErrorInfo, |
| 47 raw_fd_ostream::F_Binary)); | 54 raw_fd_ostream::F_Binary)); |
| 48 if (!ErrorInfo.empty()) { | 55 if (!ErrorInfo.empty()) { |
| 49 errs() << ErrorInfo << '\n'; | 56 errs() << ErrorInfo << '\n'; |
| 50 exit(1); | 57 exit(1); |
| 51 } | 58 } |
| 52 | 59 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 65 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. | 72 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. |
| 66 | 73 |
| 67 cl::ParseCommandLineOptions(argc, argv, "Generates NaCl pexe wire format\n"); | 74 cl::ParseCommandLineOptions(argc, argv, "Generates NaCl pexe wire format\n"); |
| 68 | 75 |
| 69 std::string ErrorMessage; | 76 std::string ErrorMessage; |
| 70 std::auto_ptr<Module> M; | 77 std::auto_ptr<Module> M; |
| 71 | 78 |
| 72 // Use the bitcode streaming interface | 79 // Use the bitcode streaming interface |
| 73 DataStreamer *streamer = getDataFileStreamer(InputFilename, &ErrorMessage); | 80 DataStreamer *streamer = getDataFileStreamer(InputFilename, &ErrorMessage); |
| 74 if (streamer) { | 81 if (streamer) { |
| 75 std::string DisplayFilename = InputFilename; | 82 std::string DisplayFilename; |
| 83 if (InputFilename == "-") | |
| 84 DisplayFilename = "<stdin>"; | |
| 85 else | |
| 86 DisplayFilename = InputFilename; | |
| 76 M.reset(getStreamedBitcodeModule(DisplayFilename, streamer, Context, | 87 M.reset(getStreamedBitcodeModule(DisplayFilename, streamer, Context, |
| 77 &ErrorMessage)); | 88 &ErrorMessage)); |
| 78 if(M.get() != 0 && M->MaterializeAllPermanently(&ErrorMessage)) { | 89 if(M.get() != 0 && M->MaterializeAllPermanently(&ErrorMessage)) { |
| 79 M.reset(); | 90 M.reset(); |
| 80 } | 91 } |
| 81 } | 92 } |
| 82 | 93 |
| 83 if (M.get() == 0) { | 94 if (M.get() == 0) { |
| 84 errs() << argv[0] << ": "; | 95 errs() << argv[0] << ": "; |
| 85 if (ErrorMessage.size()) | 96 if (ErrorMessage.size()) |
| 86 errs() << ErrorMessage << "\n"; | 97 errs() << ErrorMessage << "\n"; |
| 87 else | 98 else |
| 88 errs() << "bitcode didn't read correctly.\n"; | 99 errs() << "bitcode didn't read correctly.\n"; |
| 89 return 1; | 100 return 1; |
| 90 } | 101 } |
| 91 | 102 |
| 92 WriteOutputFile(M.get()); | 103 WriteOutputFile(M.get()); |
| 93 return 0; | 104 return 0; |
| 94 } | 105 } |
| OLD | NEW |