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 13 matching lines...) Expand all Loading... | |
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 | 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"), cl::init("-")); |
jvoung (off chromium)
2013/05/06 18:48:54
tab?
Karl
2013/05/06 20:13:06
Done.
| |
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 = | |
42 (OutputFilename.size() == 0 ? (InputFilename + ".frozen") : OutputFilename); | |
43 | |
44 std::string ErrorInfo; | 41 std::string ErrorInfo; |
45 OwningPtr<tool_output_file> Out | 42 OwningPtr<tool_output_file> Out |
46 (new tool_output_file(FrozenFilename.c_str(), ErrorInfo, | 43 (new tool_output_file(OutputFilename.c_str(), ErrorInfo, |
47 raw_fd_ostream::F_Binary)); | 44 raw_fd_ostream::F_Binary)); |
48 if (!ErrorInfo.empty()) { | 45 if (!ErrorInfo.empty()) { |
49 errs() << ErrorInfo << '\n'; | 46 errs() << ErrorInfo << '\n'; |
50 exit(1); | 47 exit(1); |
51 } | 48 } |
52 | 49 |
53 NaClWriteBitcodeToFile(M, Out->os()); | 50 NaClWriteBitcodeToFile(M, Out->os()); |
54 | 51 |
55 // Declare success. | 52 // Declare success. |
56 Out->keep(); | 53 Out->keep(); |
57 } | 54 } |
58 | 55 |
59 int main(int argc, char **argv) { | 56 int main(int argc, char **argv) { |
60 // Print a stack trace if we signal out. | 57 // Print a stack trace if we signal out. |
61 sys::PrintStackTraceOnErrorSignal(); | 58 sys::PrintStackTraceOnErrorSignal(); |
62 PrettyStackTraceProgram X(argc, argv); | 59 PrettyStackTraceProgram X(argc, argv); |
63 | 60 |
64 LLVMContext &Context = getGlobalContext(); | 61 LLVMContext &Context = getGlobalContext(); |
65 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. | 62 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. |
66 | 63 |
67 cl::ParseCommandLineOptions(argc, argv, "Generates NaCl pexe wire format\n"); | 64 cl::ParseCommandLineOptions(argc, argv, "Generates NaCl pexe wire 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(getStreamedBitcodeModule(DisplayFilename, streamer, Context, | 77 M.reset(getStreamedBitcodeModule(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 } |
OLD | NEW |