Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: tools/pnacl-thaw/pnacl-thaw.cpp

Issue 14642019: Allow pnacl-freeze/thaw to redirect to stdin/stdout. (Closed) Base URL: http://git.chromium.org/native_client/pnacl-llvm.git@master
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 12 matching lines...) Expand all
23 #include "llvm/Support/DataStream.h" 23 #include "llvm/Support/DataStream.h"
24 #include "llvm/Support/ManagedStatic.h" 24 #include "llvm/Support/ManagedStatic.h"
25 #include "llvm/Support/PrettyStackTrace.h" 25 #include "llvm/Support/PrettyStackTrace.h"
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"), cl::init("-"));
jvoung (off chromium) 2013/05/06 18:48:54 tab?
Karl 2013/05/06 20:13:06 Done.
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 =
41 (OutputFilename.size() == 0 ? (InputFilename + ".thawed") : OutputFilename);
42
43 std::string ErrorInfo; 40 std::string ErrorInfo;
44 OwningPtr<tool_output_file> Out 41 OwningPtr<tool_output_file> Out
45 (new tool_output_file(ThawedFilename.c_str(), ErrorInfo, 42 (new tool_output_file(OutputFilename.c_str(), ErrorInfo,
46 raw_fd_ostream::F_Binary)); 43 raw_fd_ostream::F_Binary));
47 if (!ErrorInfo.empty()) { 44 if (!ErrorInfo.empty()) {
48 errs() << ErrorInfo << '\n'; 45 errs() << ErrorInfo << '\n';
49 exit(1); 46 exit(1);
50 } 47 }
51 48
52 WriteBitcodeToFile(M, Out->os()); 49 WriteBitcodeToFile(M, Out->os());
53 50
54 // Declare success. 51 // Declare success.
55 Out->keep(); 52 Out->keep();
56 } 53 }
57 54
58 int main(int argc, char **argv) { 55 int main(int argc, char **argv) {
59 // Print a stack trace if we signal out. 56 // Print a stack trace if we signal out.
60 sys::PrintStackTraceOnErrorSignal(); 57 sys::PrintStackTraceOnErrorSignal();
61 PrettyStackTraceProgram X(argc, argv); 58 PrettyStackTraceProgram X(argc, argv);
62 59
63 LLVMContext &Context = getGlobalContext(); 60 LLVMContext &Context = getGlobalContext();
64 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. 61 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
65 62
66 cl::ParseCommandLineOptions( 63 cl::ParseCommandLineOptions(
67 argc, argv, "Converts NaCl pexe wire format into LLVM bitcode format\n"); 64 argc, argv, "Converts NaCl pexe wire format into LLVM bitcode format\n");
68 65
69 std::string ErrorMessage; 66 std::string ErrorMessage;
70 std::auto_ptr<Module> M; 67 std::auto_ptr<Module> M;
71 68
72 // Use the bitcode streaming interface 69 // Use the bitcode streaming interface
73 DataStreamer *streamer = getDataFileStreamer(InputFilename, &ErrorMessage); 70 DataStreamer *streamer = getDataFileStreamer(InputFilename, &ErrorMessage);
74 if (streamer) { 71 if (streamer) {
75 std::string DisplayFilename = InputFilename; 72 std::string DisplayFilename;
73 if (InputFilename == "-")
74 DisplayFilename = "<stdin>";
75 else
76 DisplayFilename = InputFilename;
76 M.reset(getNaClStreamedBitcodeModule(DisplayFilename, streamer, Context, 77 M.reset(getNaClStreamedBitcodeModule(DisplayFilename, streamer, Context,
77 &ErrorMessage)); 78 &ErrorMessage));
78 if(M.get() != 0 && M->MaterializeAllPermanently(&ErrorMessage)) { 79 if(M.get() != 0 && M->MaterializeAllPermanently(&ErrorMessage)) {
79 M.reset(); 80 M.reset();
80 } 81 }
81 } 82 }
82 83
83 if (M.get() == 0) { 84 if (M.get() == 0) {
84 errs() << argv[0] << ": "; 85 errs() << argv[0] << ": ";
85 if (ErrorMessage.size()) 86 if (ErrorMessage.size())
86 errs() << ErrorMessage << "\n"; 87 errs() << ErrorMessage << "\n";
87 else 88 else
88 errs() << "bitcode didn't read correctly.\n"; 89 errs() << "bitcode didn't read correctly.\n";
89 return 1; 90 return 1;
90 } 91 }
91 92
92 WriteOutputFile(M.get()); 93 WriteOutputFile(M.get());
93 return 0; 94 return 0;
94 } 95 }
OLDNEW
« tools/pnacl-freeze/pnacl-freeze.cpp ('K') | « tools/pnacl-freeze/pnacl-freeze.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698