summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/Reader.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2014-12-12 07:31:09 +0000
committerRui Ueyama <ruiu@google.com>2014-12-12 07:31:09 +0000
commit1d510428e8d110e9f1f4dcf3f2f0ea189948f330 (patch)
tree018a03c36d7c5fac2e806fdd884e376259377a5d /lld/lib/ReaderWriter/Reader.cpp
parentadb3864744c20a7d4046718d2e0486cab2a02b06 (diff)
downloadbcm5719-llvm-1d510428e8d110e9f1f4dcf3f2f0ea189948f330.tar.gz
bcm5719-llvm-1d510428e8d110e9f1f4dcf3f2f0ea189948f330.zip
Separate file parsing from File's constructors.
This is a second patch for InputGraph cleanup. Sorry about the size of the patch, but what I did in this patch is basically moving code from constructor to a new method, parse(), so the amount of new code is small. This has no change in functionality. We've discussed the issue that we have too many classes to represent a concept of "file". We have File subclasses that represent files read from disk. In addition to that, we have bunch of InputElement subclasses (that are part of InputGraph) that represent command line arguments for input file names. InputElement is a wrapper for File. InputElement has parseFile method. The method instantiates a File. The File's constructor reads a file from disk and parses that. Because parseFile method is called from multiple worker threads, file parsing is processed in parallel. In other words, one reason why we needed the wrapper classes is because a File would start reading a file as soon as it is instantiated. So, the reason why we have too many classes here is at least partly because of the design flaw of File class. Just like threads in a good threading library, we need to separate instantiation from "start" method, so that we can instantiate File objects when we need them (which should be very fast because it involves only one mmap() and no real file IO) and use them directly instead of the wrapper classes. Later, we call parse() on each file in parallel to let them do actual file IO. In this design, we can eliminate a reason to have the wrapper classes. In order to minimize the size of the patch, I didn't go so far as to replace the wrapper classes with File classes. The wrapper classes are still there. In this patch, we call parse() immediately after instantiating a File, so this really has no change in functionality. Eventually the call of parse() should be moved to Driver::link(). That'll be done in another patch. llvm-svn: 224102
Diffstat (limited to 'lld/lib/ReaderWriter/Reader.cpp')
-rw-r--r--lld/lib/ReaderWriter/Reader.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/lld/lib/ReaderWriter/Reader.cpp b/lld/lib/ReaderWriter/Reader.cpp
index f7077199c0b..a730d0d216f 100644
--- a/lld/lib/ReaderWriter/Reader.cpp
+++ b/lld/lib/ReaderWriter/Reader.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+#include "lld/Core/File.h"
#include "lld/ReaderWriter/Reader.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Errc.h"
@@ -38,9 +39,16 @@ Registry::parseFile(std::unique_ptr<MemoryBuffer> &mb,
StringRef extension = llvm::sys::path::extension(mb->getBufferIdentifier());
// Ask each registered reader if it can handle this file type or extension.
- for (const std::unique_ptr<Reader> &reader : _readers)
- if (reader->canParse(fileType, extension, *mb))
- return reader->parseFile(mb, *this, result);
+ for (const std::unique_ptr<Reader> &reader : _readers) {
+ if (!reader->canParse(fileType, extension, *mb))
+ continue;
+ if (std::error_code ec = reader->parseFile(mb, *this, result))
+ return ec;
+ for (std::unique_ptr<File> &file : result)
+ if (std::error_code ec = file->parse())
+ return ec;
+ return std::error_code();
+ }
// No Reader could parse this file.
return make_error_code(llvm::errc::executable_format_error);
OpenPOWER on IntegriCloud