Extend SerializedModuleLoader to load modules from a bitstream.

Add tools/lldb-moduleimport-test, which simulates LLDB importing modules
from the __apple_ast section in Mach-O files and use it to regression-test
the new API.

Swift SVN r7709
This commit is contained in:
Adrian Prantl
2013-08-29 00:57:05 +00:00
parent 6d34a127ee
commit 31c926660f
8 changed files with 255 additions and 20 deletions

View File

@@ -15,6 +15,8 @@
#include "swift/AST/ModuleLoader.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/Support/MemoryBuffer.h"
#include <map>
namespace swift {
class ASTContext;
@@ -25,6 +27,7 @@ class ModuleFile;
class SerializedModuleLoader : public ModuleLoader {
private:
ASTContext &Ctx;
std::map<std::string, llvm::OwningPtr<llvm::MemoryBuffer> > Bitstreams;
/// A { module, generation # } pair.
using LoadedModulePair = std::pair<std::unique_ptr<ModuleFile>, unsigned>;
@@ -58,6 +61,15 @@ public:
virtual Module *
loadModule(SourceLoc importLoc, Module::AccessPathTy path) override;
/// \brief Register a bitstream that contains the serialized module
/// for the given module path. This API is intended to be used by
/// LLDB to add swiftmodules discovered in the __apple_ast section
/// of a Mach-O file to the search path.
void registerBitstream(std::string path,
llvm::OwningPtr<llvm::MemoryBuffer> &&input) {
Bitstreams[path].reset(input.take());
}
/// \brief Look for declarations associated with the given name.
///
/// \param module The module to search.