OLD | NEW |
---|---|
(Empty) | |
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 | |
3 * be found in the LICENSE file. | |
4 */ | |
5 | |
6 //===-- pnacl-freeze.cpp - The low-level PNaCl bitcode freezer --------===// | |
7 // | |
8 //===----------------------------------------------------------------------===// | |
9 // | |
10 // Generates PNaCl pexe wire format. | |
11 // | |
12 // This utility may be invoked in the following manner: | |
13 // pnacl-freeze [options] <pexe file> | |
14 | |
15 // Options: | |
16 // -help - Output information about command line switches | |
jvoung (off chromium)
2013/04/25 17:42:45
Probably don't need to put the commandline usage h
Karl
2013/04/25 20:48:17
Done.
Karl
2013/04/25 20:48:17
Done.
| |
17 // -o=<filename> - Specify output filename | |
18 // | |
19 //===----------------------------------------------------------------------===// | |
20 | |
21 #include "llvm/IR/LLVMContext.h" | |
22 #include "llvm/Assembly/AssemblyAnnotationWriter.h" | |
23 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" | |
24 #include "llvm/Bitcode/ReaderWriter.h" | |
jvoung (off chromium)
2013/04/25 17:42:45
Perhaps add a TODO that it should only use one of
Karl
2013/04/25 20:48:17
This can't be done. We need stuff in ReaderWriter
| |
25 #include "llvm/DebugInfo.h" | |
26 #include "llvm/IR/IntrinsicInst.h" | |
27 #include "llvm/IR/Module.h" | |
28 #include "llvm/IR/Type.h" | |
29 #include "llvm/Support/CommandLine.h" | |
30 #include "llvm/Support/DataStream.h" | |
31 #include "llvm/Support/FormattedStream.h" | |
32 #include "llvm/Support/ManagedStatic.h" | |
33 #include "llvm/Support/MemoryBuffer.h" | |
34 #include "llvm/Support/PrettyStackTrace.h" | |
35 #include "llvm/Support/Signals.h" | |
36 #include "llvm/Support/ToolOutputFile.h" | |
37 #include "llvm/Support/system_error.h" | |
38 | |
39 // llvm/Bitcode/BitstreamWriter.h | |
40 | |
41 using namespace llvm; | |
42 | |
43 | |
44 static cl::opt<std::string> | |
45 OutputFilename("o", cl::desc("Specify output filename"), cl::value_desc("filenam e")); | |
jvoung (off chromium)
2013/04/25 17:42:45
80 col
Karl
2013/04/25 20:48:17
Done.
| |
46 | |
47 static cl::opt<std::string> | |
48 InputFilename(cl::Positional, cl::desc("<pexe file>"), cl::Required); | |
49 | |
50 static void WriteOutputFile(const Module *M) { | |
51 | |
52 std::string FrozenFilename = | |
53 (OutputFilename.size() == 0 ? (InputFilename + ".frozen") : OutputFilename); | |
jvoung (off chromium)
2013/04/25 17:42:45
Does this mean we can't do "pnacl-freeze input.pex
Karl
2013/04/25 20:48:17
Note that pnacl-thaw is only for command line usag
jvoung (off chromium)
2013/04/25 22:25:36
Ok, just wondering if handling that like the other
| |
54 | |
55 std::string ErrorInfo; | |
56 OwningPtr<tool_output_file> Out | |
57 (new tool_output_file(FrozenFilename.c_str(), ErrorInfo, | |
jvoung (off chromium)
2013/04/25 17:42:45
is the style supposed to indent the (new...)?
Karl
2013/04/25 20:48:17
I followed the style from llvm-as (i.e. I copied l
| |
58 raw_fd_ostream::F_Binary)); | |
59 if (!ErrorInfo.empty()) { | |
60 errs() << ErrorInfo << '\n'; | |
61 exit(1); | |
62 } | |
63 | |
64 PNaClWriteBitcodeToFile(M, Out->os()); | |
65 | |
66 // Declare success. | |
67 Out->keep(); | |
68 } | |
69 | |
70 int main(int argc, char **argv) { | |
71 // Print a stack trace if we signal out. | |
72 sys::PrintStackTraceOnErrorSignal(); | |
73 PrettyStackTraceProgram X(argc, argv); | |
74 | |
75 LLVMContext &Context = getGlobalContext(); | |
76 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. | |
77 | |
78 cl::ParseCommandLineOptions(argc, argv, "Generates PNaCl pexe wire format\n"); | |
79 | |
80 std::string ErrorMessage; | |
81 std::auto_ptr<Module> M; | |
82 | |
83 // Use the bitcode streaming interface | |
84 DataStreamer *streamer = getDataFileStreamer(InputFilename, &ErrorMessage); | |
85 if (streamer) { | |
86 std::string DisplayFilename = InputFilename; | |
87 M.reset(getStreamedBitcodeModule(DisplayFilename, streamer, Context, | |
88 &ErrorMessage)); | |
89 if(M.get() != 0 && M->MaterializeAllPermanently(&ErrorMessage)) { | |
90 M.reset(); | |
91 } | |
92 } | |
93 | |
94 if (M.get() == 0) { | |
95 errs() << argv[0] << ": "; | |
96 if (ErrorMessage.size()) | |
97 errs() << ErrorMessage << "\n"; | |
98 else | |
99 errs() << "bitcode didn't read correctly.\n"; | |
100 return 1; | |
101 } | |
102 | |
103 WriteOutputFile(M.get()); | |
104 return 0; | |
105 } | |
OLD | NEW |