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

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

Issue 14314016: Copy LLVM bitcode reader to generate a PNaCl wire format reader. (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
« no previous file with comments | « tools/pnacl-thaw/Makefile ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-freeze.cpp - The low-level NaCl bitcode freezer --------===// 6 //===-- pnacl-thaw.cpp - The low-level NaCl bitcode thawer ----------------===//
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // Generates NaCl pexe wire format. 10 // Converts NaCl wire format back to LLVM bitcode.
11 // 11 //
12 //===----------------------------------------------------------------------===// 12 //===----------------------------------------------------------------------===//
13 13
14 #include "llvm/IR/LLVMContext.h" 14 #include "llvm/IR/LLVMContext.h"
15 // Note: We need the following to provide the API for calling the NaCl 15 // Note: We need the following to provide the API for calling the NaCl
16 // Bitcode Writer to generate the frozen file. 16 // Bitcode Reader to read the frozen file.
17 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" 17 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h"
18 // Note: We need the following to provide the API for calling the (LLVM) 18 // Note: We need the following to provide the API for calling the (LLVM)
19 // Bitcode Reader to read in the corresonding pexe file to freeze. 19 // Bitcode Writer to generate the corresponding LLVM bitcode file.
20 #include "llvm/Bitcode/ReaderWriter.h" 20 #include "llvm/Bitcode/ReaderWriter.h"
21 #include "llvm/IR/Module.h" 21 #include "llvm/IR/Module.h"
22 #include "llvm/Support/CommandLine.h" 22 #include "llvm/Support/CommandLine.h"
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
32 static cl::opt<std::string> 31 static cl::opt<std::string>
33 OutputFilename("o", cl::desc("Specify output filename"), 32 OutputFilename("o", cl::desc("Specify thawed pexe filename"),
34 cl::value_desc("filename")); 33 cl::value_desc("filename"));
35 34
36 static cl::opt<std::string> 35 static cl::opt<std::string>
37 InputFilename(cl::Positional, cl::desc("<pexe file>"), cl::Required); 36 InputFilename(cl::Positional, cl::desc("<frozen file>"), cl::Required);
38 37
39 static void WriteOutputFile(const Module *M) { 38 static void WriteOutputFile(const Module *M) {
40 39
41 std::string FrozenFilename = 40 std::string ThawedFilename =
42 (OutputFilename.size() == 0 ? (InputFilename + ".frozen") : OutputFilename); 41 (OutputFilename.size() == 0 ? (InputFilename + ".thawed") : OutputFilename);
43 42
44 std::string ErrorInfo; 43 std::string ErrorInfo;
45 OwningPtr<tool_output_file> Out 44 OwningPtr<tool_output_file> Out
46 (new tool_output_file(FrozenFilename.c_str(), ErrorInfo, 45 (new tool_output_file(ThawedFilename.c_str(), ErrorInfo,
47 raw_fd_ostream::F_Binary)); 46 raw_fd_ostream::F_Binary));
48 if (!ErrorInfo.empty()) { 47 if (!ErrorInfo.empty()) {
49 errs() << ErrorInfo << '\n'; 48 errs() << ErrorInfo << '\n';
50 exit(1); 49 exit(1);
51 } 50 }
52 51
53 NaClWriteBitcodeToFile(M, Out->os()); 52 WriteBitcodeToFile(M, Out->os());
54 53
55 // Declare success. 54 // Declare success.
56 Out->keep(); 55 Out->keep();
57 } 56 }
58 57
59 int main(int argc, char **argv) { 58 int main(int argc, char **argv) {
60 // Print a stack trace if we signal out. 59 // Print a stack trace if we signal out.
61 sys::PrintStackTraceOnErrorSignal(); 60 sys::PrintStackTraceOnErrorSignal();
62 PrettyStackTraceProgram X(argc, argv); 61 PrettyStackTraceProgram X(argc, argv);
63 62
64 LLVMContext &Context = getGlobalContext(); 63 LLVMContext &Context = getGlobalContext();
65 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. 64 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
66 65
67 cl::ParseCommandLineOptions(argc, argv, "Generates NaCl pexe wire format\n"); 66 cl::ParseCommandLineOptions(
67 argc, argv, "Converts NaCl pexe wire format into LLVM bitcode format\n");
68 68
69 std::string ErrorMessage; 69 std::string ErrorMessage;
70 std::auto_ptr<Module> M; 70 std::auto_ptr<Module> M;
71 71
72 // Use the bitcode streaming interface 72 // Use the bitcode streaming interface
73 DataStreamer *streamer = getDataFileStreamer(InputFilename, &ErrorMessage); 73 DataStreamer *streamer = getDataFileStreamer(InputFilename, &ErrorMessage);
74 if (streamer) { 74 if (streamer) {
75 std::string DisplayFilename = InputFilename; 75 std::string DisplayFilename = InputFilename;
76 M.reset(getStreamedBitcodeModule(DisplayFilename, streamer, Context, 76 M.reset(getNaClStreamedBitcodeModule(DisplayFilename, streamer, Context,
77 &ErrorMessage)); 77 &ErrorMessage));
78 if(M.get() != 0 && M->MaterializeAllPermanently(&ErrorMessage)) { 78 if(M.get() != 0 && M->MaterializeAllPermanently(&ErrorMessage)) {
79 M.reset(); 79 M.reset();
80 } 80 }
81 } 81 }
82 82
83 if (M.get() == 0) { 83 if (M.get() == 0) {
84 errs() << argv[0] << ": "; 84 errs() << argv[0] << ": ";
85 if (ErrorMessage.size()) 85 if (ErrorMessage.size())
86 errs() << ErrorMessage << "\n"; 86 errs() << ErrorMessage << "\n";
87 else 87 else
88 errs() << "bitcode didn't read correctly.\n"; 88 errs() << "bitcode didn't read correctly.\n";
89 return 1; 89 return 1;
90 } 90 }
91 91
92 WriteOutputFile(M.get()); 92 WriteOutputFile(M.get());
93 return 0; 93 return 0;
94 } 94 }
OLDNEW
« no previous file with comments | « tools/pnacl-thaw/Makefile ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698