OLD | NEW |
---|---|
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-freeze.cpp - The low-level NaCl bitcode freezer --------===// |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // Generates NaCl pexe wire format. | 10 // Generates NaCl pexe wire format. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 // Print a stack trace if we signal out. | 54 // Print a stack trace if we signal out. |
55 sys::PrintStackTraceOnErrorSignal(); | 55 sys::PrintStackTraceOnErrorSignal(); |
56 PrettyStackTraceProgram X(argc, argv); | 56 PrettyStackTraceProgram X(argc, argv); |
57 | 57 |
58 LLVMContext &Context = getGlobalContext(); | 58 LLVMContext &Context = getGlobalContext(); |
59 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. | 59 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. |
60 | 60 |
61 cl::ParseCommandLineOptions(argc, argv, "Generates NaCl pexe wire format\n"); | 61 cl::ParseCommandLineOptions(argc, argv, "Generates NaCl pexe wire format\n"); |
62 | 62 |
63 std::string ErrorMessage; | 63 std::string ErrorMessage; |
64 std::auto_ptr<Module> M; | 64 std::unique_ptr<Module> M; |
65 | 65 |
66 // Use the bitcode streaming interface | 66 // Use the bitcode streaming interface |
67 DataStreamer *streamer = getDataFileStreamer(InputFilename, &ErrorMessage); | 67 DataStreamer *streamer = getDataFileStreamer(InputFilename, &ErrorMessage); |
68 std::unique_ptr<StreamingMemoryObject> Buffer( | 68 std::unique_ptr<StreamingMemoryObject> Buffer( |
69 new StreamingMemoryObjectImpl(streamer)); | 69 new StreamingMemoryObjectImpl(streamer)); |
70 if (streamer) { | 70 if (streamer) { |
71 std::string DisplayFilename; | 71 std::string DisplayFilename; |
72 if (InputFilename == "-") | 72 if (InputFilename == "-") |
73 DisplayFilename = "<stdin>"; | 73 DisplayFilename = "<stdin>"; |
74 else | 74 else |
75 DisplayFilename = InputFilename; | 75 DisplayFilename = InputFilename; |
76 M.reset(getStreamedBitcodeModule(DisplayFilename, Buffer.release(), Context, | 76 ErrorOr<std::unique_ptr<Module>> MOrErr = |
77 &ErrorMessage)); | 77 getStreamedBitcodeModule(DisplayFilename, Buffer.release(), Context); |
78 if (M.get()) | 78 M = std::move(*MOrErr); |
79 if (std::error_code EC = M->materializeAllPermanently()) { | 79 M->materializeAllPermanently(); |
80 ErrorMessage = EC.message(); | |
81 M.reset(); | |
82 } | |
83 } | 80 } |
84 | 81 |
85 if (!M.get()) { | 82 if (!M.get()) { |
jvoung (off chromium)
2015/05/26 20:39:45
could be the else { } from if (streamer), since it
Derek Schuff
2015/05/26 22:01:33
Done.
| |
86 errs() << argv[0] << ": "; | 83 errs() << argv[0] << ": "; |
87 if (ErrorMessage.size()) | 84 if (ErrorMessage.size()) |
88 errs() << ErrorMessage << "\n"; | 85 errs() << ErrorMessage << "\n"; |
89 else | 86 else |
90 errs() << "bitcode didn't read correctly.\n"; | 87 errs() << "bitcode didn't read correctly.\n"; |
91 return 1; | 88 return 1; |
92 } | 89 } |
93 | 90 |
94 WriteOutputFile(M.get()); | 91 WriteOutputFile(M.get()); |
95 return 0; | 92 return 0; |
96 } | 93 } |
OLD | NEW |