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

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, 8 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-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 pexe wire format back to LLVM pexe.
jvoung (off chromium) 2013/04/29 18:02:08 nit: "pexe" seems like a NaCl thing, so perhaps ju
Karl 2013/04/29 20:44:37 Done.
11 // 11 //
12 //===----------------------------------------------------------------------===// 12 //===----------------------------------------------------------------------===//
13 13
14 #include "llvm/IR/LLVMContext.h" 14 #include "llvm/IR/LLVMContext.h"
15 #include "llvm/Assembly/AssemblyAnnotationWriter.h" 15 #include "llvm/IR/LLVMContext.h"
jvoung (off chromium) 2013/04/29 18:02:08 include the context header only once?
Karl 2013/04/29 20:44:37 Done.
16 // Note: We need the following to provide the API for calling the NaCl 16 // Note: We need the following to provide the API for calling the NaCl
17 // Bitcode Writer to generate the frozen file. 17 // Bitcode Reader to read the frozen file.
18 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" 18 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h"
19 // Note: We need the following to provide the API for calling the (LLVM) 19 // Note: We need the following to provide the API for calling the (LLVM)
20 // Bitcode Reader to read in the corresonding pexe file to freeze. 20 // Bitcode Writer to generate the corresponding LLVM bitcode file.
21 #include "llvm/Bitcode/ReaderWriter.h" 21 #include "llvm/Bitcode/ReaderWriter.h"
22 #include "llvm/DebugInfo.h"
jvoung (off chromium) 2013/04/29 18:02:08 can you apply similar cleanup to pnacl-freeze?
Karl 2013/04/29 20:44:37 Done.
23 #include "llvm/IR/IntrinsicInst.h"
24 #include "llvm/IR/Module.h" 22 #include "llvm/IR/Module.h"
25 #include "llvm/IR/Type.h"
26 #include "llvm/Support/CommandLine.h" 23 #include "llvm/Support/CommandLine.h"
27 #include "llvm/Support/DataStream.h" 24 #include "llvm/Support/DataStream.h"
28 #include "llvm/Support/FormattedStream.h"
29 #include "llvm/Support/ManagedStatic.h" 25 #include "llvm/Support/ManagedStatic.h"
30 #include "llvm/Support/MemoryBuffer.h"
31 #include "llvm/Support/PrettyStackTrace.h" 26 #include "llvm/Support/PrettyStackTrace.h"
32 #include "llvm/Support/Signals.h" 27 #include "llvm/Support/Signals.h"
33 #include "llvm/Support/ToolOutputFile.h" 28 #include "llvm/Support/ToolOutputFile.h"
34 #include "llvm/Support/system_error.h"
35
36 // llvm/Bitcode/BitstreamWriter.h
37 29
38 using namespace llvm; 30 using namespace llvm;
39 31
40
41 static cl::opt<std::string> 32 static cl::opt<std::string>
42 OutputFilename("o", cl::desc("Specify output filename"), 33 OutputFilename("o", cl::desc("Specify thawed pexe filename"),
43 cl::value_desc("filename")); 34 cl::value_desc("filename"));
44 35
45 static cl::opt<std::string> 36 static cl::opt<std::string>
46 InputFilename(cl::Positional, cl::desc("<pexe file>"), cl::Required); 37 InputFilename(cl::Positional, cl::desc("<frozen file>"), cl::Required);
47 38
48 static void WriteOutputFile(const Module *M) { 39 static void WriteOutputFile(const Module *M) {
49 40
50 std::string FrozenFilename = 41 std::string ThawedFilename =
51 (OutputFilename.size() == 0 ? (InputFilename + ".frozen") : OutputFilename); 42 (OutputFilename.size() == 0 ? (InputFilename + ".thawed") : OutputFilename);
52 43
53 std::string ErrorInfo; 44 std::string ErrorInfo;
54 OwningPtr<tool_output_file> Out 45 OwningPtr<tool_output_file> Out
55 (new tool_output_file(FrozenFilename.c_str(), ErrorInfo, 46 (new tool_output_file(ThawedFilename.c_str(), ErrorInfo,
56 raw_fd_ostream::F_Binary)); 47 raw_fd_ostream::F_Binary));
57 if (!ErrorInfo.empty()) { 48 if (!ErrorInfo.empty()) {
58 errs() << ErrorInfo << '\n'; 49 errs() << ErrorInfo << '\n';
59 exit(1); 50 exit(1);
60 } 51 }
61 52
62 NaClWriteBitcodeToFile(M, Out->os()); 53 WriteBitcodeToFile(M, Out->os());
63 54
64 // Declare success. 55 // Declare success.
65 Out->keep(); 56 Out->keep();
66 } 57 }
67 58
68 int main(int argc, char **argv) { 59 int main(int argc, char **argv) {
69 // Print a stack trace if we signal out. 60 // Print a stack trace if we signal out.
70 sys::PrintStackTraceOnErrorSignal(); 61 sys::PrintStackTraceOnErrorSignal();
71 PrettyStackTraceProgram X(argc, argv); 62 PrettyStackTraceProgram X(argc, argv);
72 63
73 LLVMContext &Context = getGlobalContext(); 64 LLVMContext &Context = getGlobalContext();
74 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. 65 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
75 66
76 cl::ParseCommandLineOptions(argc, argv, "Generates NaCl pexe wire format\n"); 67 cl::ParseCommandLineOptions(
68 argc, argv, "Converts NaCl pexe wire format into LLVM bitcode format\n");
77 69
78 std::string ErrorMessage; 70 std::string ErrorMessage;
79 std::auto_ptr<Module> M; 71 std::auto_ptr<Module> M;
80 72
81 // Use the bitcode streaming interface 73 // Use the bitcode streaming interface
82 DataStreamer *streamer = getDataFileStreamer(InputFilename, &ErrorMessage); 74 DataStreamer *streamer = getDataFileStreamer(InputFilename, &ErrorMessage);
83 if (streamer) { 75 if (streamer) {
84 std::string DisplayFilename = InputFilename; 76 std::string DisplayFilename = InputFilename;
85 M.reset(getStreamedBitcodeModule(DisplayFilename, streamer, Context, 77 M.reset(getNaClStreamedBitcodeModule(DisplayFilename, streamer, Context,
86 &ErrorMessage)); 78 &ErrorMessage));
87 if(M.get() != 0 && M->MaterializeAllPermanently(&ErrorMessage)) { 79 if(M.get() != 0 && M->MaterializeAllPermanently(&ErrorMessage)) {
88 M.reset(); 80 M.reset();
89 } 81 }
90 } 82 }
91 83
92 if (M.get() == 0) { 84 if (M.get() == 0) {
93 errs() << argv[0] << ": "; 85 errs() << argv[0] << ": ";
94 if (ErrorMessage.size()) 86 if (ErrorMessage.size())
95 errs() << ErrorMessage << "\n"; 87 errs() << ErrorMessage << "\n";
96 else 88 else
97 errs() << "bitcode didn't read correctly.\n"; 89 errs() << "bitcode didn't read correctly.\n";
98 return 1; 90 return 1;
99 } 91 }
100 92
101 WriteOutputFile(M.get()); 93 WriteOutputFile(M.get());
102 return 0; 94 return 0;
103 } 95 }
OLDNEW
« lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp ('K') | « tools/pnacl-thaw/Makefile ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698