OLD | NEW |
---|---|
(Empty) | |
1 //===-- pnacl-freeze.cpp - The low-level PNaCl bitcode freezer --------===// | |
2 // | |
3 //===----------------------------------------------------------------------===// | |
4 // | |
5 // This utility may be invoked in the following manner: | |
6 // llvm-compress [Options] x.bc - read x.bc and generate compressed y.bcc | |
7 // | |
8 // Options: | |
9 // --help - Output information about command line switches | |
10 // | |
Karl
2013/04/24 18:25:59
Cleaned up comments describing command.
| |
11 //===----------------------------------------------------------------------===// | |
12 | |
13 #include "llvm/IR/LLVMContext.h" | |
14 #include "llvm/Assembly/AssemblyAnnotationWriter.h" | |
15 #include "llvm/Bitcode/PNaCl/PNaClReaderWriter.h" | |
16 #include "llvm/Bitcode/ReaderWriter.h" | |
17 #include "llvm/DebugInfo.h" | |
18 #include "llvm/IR/IntrinsicInst.h" | |
19 #include "llvm/IR/Module.h" | |
20 #include "llvm/IR/Type.h" | |
21 #include "llvm/Support/CommandLine.h" | |
22 #include "llvm/Support/DataStream.h" | |
23 #include "llvm/Support/FormattedStream.h" | |
24 #include "llvm/Support/ManagedStatic.h" | |
25 #include "llvm/Support/MemoryBuffer.h" | |
26 #include "llvm/Support/PrettyStackTrace.h" | |
27 #include "llvm/Support/Signals.h" | |
28 #include "llvm/Support/ToolOutputFile.h" | |
29 #include "llvm/Support/system_error.h" | |
30 | |
31 // llvm/Bitcode/BitstreamWriter.h | |
32 | |
33 using namespace llvm; | |
34 | |
35 | |
36 static cl::opt<std::string> | |
37 OutputFilename("o", cl::desc("Specify output filename"), cl::value_desc("filenam e")); | |
38 | |
39 static cl::opt<std::string> | |
40 InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::Required); | |
41 | |
42 static void WriteOutputFile(const Module *M) { | |
43 | |
44 std::string FrozenFilename = | |
45 (OutputFilename.size() == 0 ? (InputFilename + ".frozen") : OutputFilename); | |
46 | |
47 std::string ErrorInfo; | |
48 OwningPtr<tool_output_file> Out | |
49 (new tool_output_file(FrozenFilename.c_str(), ErrorInfo, | |
50 raw_fd_ostream::F_Binary)); | |
51 if (!ErrorInfo.empty()) { | |
52 errs() << ErrorInfo << '\n'; | |
53 exit(1); | |
54 } | |
55 | |
56 PNaClWriteBitcodeToFile(M, Out->os()); | |
57 | |
58 // Declare success. | |
59 Out->keep(); | |
60 } | |
61 | |
62 int main(int argc, char **argv) { | |
63 // Print a stack trace if we signal out. | |
64 sys::PrintStackTraceOnErrorSignal(); | |
65 PrettyStackTraceProgram X(argc, argv); | |
66 | |
67 LLVMContext &Context = getGlobalContext(); | |
68 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. | |
69 | |
70 cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .bc compressor\n"); | |
71 | |
72 std::string ErrorMessage; | |
73 std::auto_ptr<Module> M; | |
74 | |
75 // Use the bitcode streaming interface | |
76 DataStreamer *streamer = getDataFileStreamer(InputFilename, &ErrorMessage); | |
77 if (streamer) { | |
78 std::string DisplayFilename = InputFilename; | |
79 M.reset(getStreamedBitcodeModule(DisplayFilename, streamer, Context, | |
80 &ErrorMessage)); | |
81 if(M.get() != 0 && M->MaterializeAllPermanently(&ErrorMessage)) { | |
82 M.reset(); | |
83 } | |
84 } | |
85 | |
86 if (M.get() == 0) { | |
87 errs() << argv[0] << ": "; | |
88 if (ErrorMessage.size()) | |
89 errs() << ErrorMessage << "\n"; | |
90 else | |
91 errs() << "bitcode didn't read correctly.\n"; | |
92 return 1; | |
93 } | |
94 | |
95 WriteOutputFile(M.get()); | |
96 return 0; | |
97 } | |
OLD | NEW |