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

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

Issue 939073008: Rebased PNaCl localmods in LLVM to 223109 (Closed)
Patch Set: undo localmod Created 5 years, 10 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-freeze/Makefile ('k') | tools/pnacl-llc/CMakeLists.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 NaCl bitcode freezer --------===//
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Generates NaCl pexe wire format.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h"
15 #include "llvm/Bitcode/ReaderWriter.h"
16 #include "llvm/IR/LLVMContext.h"
17 #include "llvm/IR/Module.h"
18 #include "llvm/Support/CommandLine.h"
19 #include "llvm/Support/DataStream.h"
20 #include "llvm/Support/FileSystem.h"
21 #include "llvm/Support/ManagedStatic.h"
22 #include "llvm/Support/PrettyStackTrace.h"
23 #include "llvm/Support/Signals.h"
24 #include "llvm/Support/StreamingMemoryObject.h"
25 #include "llvm/Support/ToolOutputFile.h"
26
27 using namespace llvm;
28
29
30 static cl::opt<std::string>
31 OutputFilename("o", cl::desc("Specify output filename"),
32 cl::value_desc("filename"), cl::init("-"));
33
34 static cl::opt<std::string>
35 InputFilename(cl::Positional, cl::desc("<pexe file>"), cl::init("-"));
36
37 static void WriteOutputFile(const Module *M) {
38
39 std::error_code EC;
40 std::unique_ptr<tool_output_file> Out(
41 new tool_output_file(OutputFilename, EC, sys::fs::F_None));
42 if (EC) {
43 errs() << EC.message() << '\n';
44 exit(1);
45 }
46
47 NaClWriteBitcodeToFile(M, Out->os(), /* AcceptSupportedOnly = */ false);
48
49 // Declare success.
50 Out->keep();
51 }
52
53 int main(int argc, char **argv) {
54 // Print a stack trace if we signal out.
55 sys::PrintStackTraceOnErrorSignal();
56 PrettyStackTraceProgram X(argc, argv);
57
58 LLVMContext &Context = getGlobalContext();
59 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
60
61 cl::ParseCommandLineOptions(argc, argv, "Generates NaCl pexe wire format\n");
62
63 std::string ErrorMessage;
64 std::auto_ptr<Module> M;
65
66 // Use the bitcode streaming interface
67 DataStreamer *streamer = getDataFileStreamer(InputFilename, &ErrorMessage);
68 std::unique_ptr<StreamingMemoryObject> Buffer(
69 new StreamingMemoryObjectImpl(streamer));
70 if (streamer) {
71 std::string DisplayFilename;
72 if (InputFilename == "-")
73 DisplayFilename = "<stdin>";
74 else
75 DisplayFilename = InputFilename;
76 M.reset(getStreamedBitcodeModule(DisplayFilename, Buffer.release(), Context,
77 &ErrorMessage));
78 if (M.get())
79 if (std::error_code EC = M->materializeAllPermanently()) {
80 ErrorMessage = EC.message();
81 M.reset();
82 }
83 }
84
85 if (!M.get()) {
86 errs() << argv[0] << ": ";
87 if (ErrorMessage.size())
88 errs() << ErrorMessage << "\n";
89 else
90 errs() << "bitcode didn't read correctly.\n";
91 return 1;
92 }
93
94 WriteOutputFile(M.get());
95 return 0;
96 }
OLDNEW
« no previous file with comments | « tools/pnacl-freeze/Makefile ('k') | tools/pnacl-llc/CMakeLists.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698