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-thaw.cpp - The low-level NaCl bitcode thawer ----------------===// | 6 //===-- pnacl-thaw.cpp - The low-level NaCl bitcode thawer ----------------===// |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // Converts NaCl wire format back to LLVM bitcode. | 10 // Converts NaCl wire format back to LLVM bitcode. |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "llvm/Support/Signals.h" | 26 #include "llvm/Support/Signals.h" |
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 static cl::opt<std::string> | 31 static cl::opt<std::string> |
32 OutputFilename("o", cl::desc("Specify thawed pexe filename"), | 32 OutputFilename("o", cl::desc("Specify thawed pexe filename"), |
33 cl::value_desc("filename")); | 33 cl::value_desc("filename")); |
34 | 34 |
35 static cl::opt<std::string> | 35 static cl::opt<std::string> |
36 InputFilename(cl::Positional, cl::desc("<frozen file>"), cl::Required); | 36 InputFilename(cl::Positional, cl::desc("<frozen file>"), cl::init("-")); |
37 | 37 |
38 static void WriteOutputFile(const Module *M) { | 38 static void WriteOutputFile(const Module *M) { |
39 | 39 |
40 std::string ThawedFilename = | 40 std::string ThawedFilename(OutputFilename); |
41 (OutputFilename.size() == 0 ? (InputFilename + ".thawed") : OutputFilename); | 41 if (OutputFilename.size() == 0) { |
| 42 std::string input_filename; |
| 43 if (InputFilename == "-") |
| 44 input_filename = "<stdin>"; |
| 45 else |
| 46 input_filename = InputFilename; |
| 47 ThawedFilename = input_filename + ".thawed"; |
| 48 } |
42 | 49 |
43 std::string ErrorInfo; | 50 std::string ErrorInfo; |
44 OwningPtr<tool_output_file> Out | 51 OwningPtr<tool_output_file> Out |
45 (new tool_output_file(ThawedFilename.c_str(), ErrorInfo, | 52 (new tool_output_file(ThawedFilename.c_str(), ErrorInfo, |
46 raw_fd_ostream::F_Binary)); | 53 raw_fd_ostream::F_Binary)); |
47 if (!ErrorInfo.empty()) { | 54 if (!ErrorInfo.empty()) { |
48 errs() << ErrorInfo << '\n'; | 55 errs() << ErrorInfo << '\n'; |
49 exit(1); | 56 exit(1); |
50 } | 57 } |
51 | 58 |
(...skipping 13 matching lines...) Expand all Loading... |
65 | 72 |
66 cl::ParseCommandLineOptions( | 73 cl::ParseCommandLineOptions( |
67 argc, argv, "Converts NaCl pexe wire format into LLVM bitcode format\n"); | 74 argc, argv, "Converts NaCl pexe wire format into LLVM bitcode 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(getNaClStreamedBitcodeModule(DisplayFilename, streamer, Context, | 87 M.reset(getNaClStreamedBitcodeModule(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 |