summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-dis/llvm-dis.cpp
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2016-11-02 00:08:19 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2016-11-02 00:08:19 +0000
commit028eb5a3f823c25e6c3040d300910e23ed69e788 (patch)
tree9d3065523337ebcf7489b238e95435c17c14a273 /llvm/tools/llvm-dis/llvm-dis.cpp
parentce898dbb8135f1bd6b9b94c851bc0f8e99b72330 (diff)
downloadbcm5719-llvm-028eb5a3f823c25e6c3040d300910e23ed69e788.tar.gz
bcm5719-llvm-028eb5a3f823c25e6c3040d300910e23ed69e788.zip
Bitcode: Change reader interface to take memory buffers.
As proposed on llvm-dev: http://lists.llvm.org/pipermail/llvm-dev/2016-October/106595.html This change also fixes an API oddity where BitstreamCursor::Read() would return zero for the first read past the end of the bitstream, but would report_fatal_error for subsequent reads. Now we always report_fatal_error for all reads past the end. Updated clients to check for the end of the bitstream before reading from it. I also needed to add padding to the invalid bitcode tests in test/Bitcode/. This is because the streaming interface was not checking that the file size is a multiple of 4. Differential Revision: https://reviews.llvm.org/D26219 llvm-svn: 285773
Diffstat (limited to 'llvm/tools/llvm-dis/llvm-dis.cpp')
-rw-r--r--llvm/tools/llvm-dis/llvm-dis.cpp39
1 files changed, 12 insertions, 27 deletions
diff --git a/llvm/tools/llvm-dis/llvm-dis.cpp b/llvm/tools/llvm-dis/llvm-dis.cpp
index 88333aeb688..69533ccac52 100644
--- a/llvm/tools/llvm-dis/llvm-dis.cpp
+++ b/llvm/tools/llvm-dis/llvm-dis.cpp
@@ -26,7 +26,6 @@
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/DataStream.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FormattedStream.h"
@@ -139,34 +138,20 @@ static void diagnosticHandler(const DiagnosticInfo &DI, void *Context) {
}
static Expected<std::unique_ptr<Module>> openInputFile(LLVMContext &Context) {
- if (MaterializeMetadata) {
- ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr =
- MemoryBuffer::getFileOrSTDIN(InputFilename);
- if (!MBOrErr)
- return errorCodeToError(MBOrErr.getError());
- ErrorOr<std::unique_ptr<Module>> MOrErr =
- getLazyBitcodeModule(std::move(*MBOrErr), Context,
- /*ShouldLazyLoadMetadata=*/true);
- if (!MOrErr)
- return errorCodeToError(MOrErr.getError());
+ ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr =
+ MemoryBuffer::getFileOrSTDIN(InputFilename);
+ if (!MBOrErr)
+ return errorCodeToError(MBOrErr.getError());
+ ErrorOr<std::unique_ptr<Module>> MOrErr =
+ getLazyBitcodeModule(std::move(*MBOrErr), Context,
+ /*ShouldLazyLoadMetadata=*/true);
+ if (!MOrErr)
+ return errorCodeToError(MOrErr.getError());
+ if (MaterializeMetadata)
(*MOrErr)->materializeMetadata();
- return std::move(*MOrErr);
- } else {
- std::string ErrorMessage;
- std::unique_ptr<DataStreamer> Streamer =
- getDataFileStreamer(InputFilename, &ErrorMessage);
- if (!Streamer)
- return make_error<StringError>(ErrorMessage, inconvertibleErrorCode());
- std::string DisplayFilename;
- if (InputFilename == "-")
- DisplayFilename = "<stdin>";
- else
- DisplayFilename = InputFilename;
- ErrorOr<std::unique_ptr<Module>> MOrErr =
- getStreamedBitcodeModule(DisplayFilename, std::move(Streamer), Context);
+ else
(*MOrErr)->materializeAll();
- return std::move(*MOrErr);
- }
+ return std::move(*MOrErr);
}
int main(int argc, char **argv) {
OpenPOWER on IntegriCloud